Skip to content

Commit 270ea8c

Browse files
author
Dilawar Singh
committed
empty element()
1 parent a1eed3a commit 270ea8c

File tree

4 files changed

+100
-119
lines changed

4 files changed

+100
-119
lines changed

basecode/Eref.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,60 @@
1010
#include "header.h"
1111
#include "../shell/Shell.h"
1212

13-
Eref::Eref()
14-
: e_( 0 ), i_( 0 ), f_( 0 )
13+
Eref::Eref() : e_(0), i_(0), f_(0)
1514
{
16-
;
15+
;
1716
}
1817

19-
Eref::Eref( Element* e, unsigned int index, unsigned int field )
20-
: e_( e ), i_( index ), f_( field )
18+
Eref::Eref(Element* e, unsigned int index, unsigned int field)
19+
: e_(e), i_(index), f_(field)
2120
{
22-
;
21+
;
2322
}
2423

25-
ostream& operator <<( ostream& s, const Eref& e )
24+
ostream& operator<<(ostream& s, const Eref& e)
2625
{
27-
if ( e.i_ == 0 ) {
28-
if ( e.f_ == 0 )
29-
s << e.e_->getName();
30-
else
31-
s << e.e_->getName() << "[0][" << e.f_ << "]";
32-
} else {
33-
if ( e.f_ == 0 )
34-
s << e.e_->getName() << "[" << e.i_ << "]";
35-
else
36-
s << e.e_->getName() << "[" << e.i_ << "][" << e.f_ << "]";
37-
}
38-
return s;
26+
if (e.i_ == 0) {
27+
if (e.f_ == 0)
28+
s << e.e_->getName();
29+
else
30+
s << e.e_->getName() << "[0][" << e.f_ << "]";
31+
} else {
32+
if (e.f_ == 0)
33+
s << e.e_->getName() << "[" << e.i_ << "]";
34+
else
35+
s << e.e_->getName() << "[" << e.i_ << "][" << e.f_ << "]";
36+
}
37+
return s;
3938
}
4039

4140
char* Eref::data() const
4241
{
43-
assert( isDataHere() );
44-
return e_->data( e_->rawIndex( i_ ), f_ );
42+
assert(isDataHere());
43+
return e_->data(e_->rawIndex(i_), f_);
4544
}
4645

4746
bool Eref::isDataHere() const
4847
{
49-
return ( e_->getNode( i_ ) == Shell::myNode() );
48+
return (e_->getNode(i_) == Shell::myNode());
5049
}
5150

5251
unsigned int Eref::getNode() const
5352
{
54-
return e_->getNode( i_ );
53+
return e_->getNode(i_);
5554
}
5655

5756
ObjId Eref::objId() const
5857
{
59-
return ObjId( e_->id(), i_, f_ );
58+
return ObjId(e_->id(), i_, f_);
6059
}
6160

6261
Id Eref::id() const
6362
{
64-
return e_->id();
63+
return e_->id();
6564
}
6665

67-
const vector< MsgDigest >& Eref::msgDigest( unsigned int bindIndex ) const
66+
const vector<MsgDigest>& Eref::msgDigest(unsigned int bindIndex) const
6867
{
69-
return e_->msgDigest( i_ * e_->cinfo()->numBindIndex() + bindIndex );
68+
return e_->msgDigest(i_ * e_->cinfo()->numBindIndex() + bindIndex);
7069
}

basecode/Id.cpp

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,24 @@
1515
// Id creation
1616
//////////////////////////////////////////////////////////////
1717

18-
Id::Id()
19-
// : id_( 0 ), index_( 0 )
20-
: id_( 0 )
18+
Id::Id() : id_(0)
2119
{
2220
;
2321
}
2422

25-
Id::Id( unsigned int id )
26-
: id_( id )
23+
Id::Id(unsigned int id) : id_(id)
2724
{
2825
;
2926
}
3027

31-
Id::Id( const string& path, const string& separator )
28+
Id::Id(const string& path, const string& separator)
3229
{
33-
Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
34-
assert( shell );
35-
id_ = shell->doFind( path ).id.id_;
30+
Shell* shell = reinterpret_cast<Shell*>(Id().eref().data());
31+
assert(shell);
32+
id_ = shell->doFind(path).id.id_;
3633
}
3734

38-
Id::Id( const ObjId& oi )
39-
: id_( oi.id.id_ )
35+
Id::Id(const ObjId& oi) : id_(oi.id.id_)
4036
{
4137
;
4238
}
@@ -46,19 +42,19 @@ Id::Id( const ObjId& oi )
4642
* out of the existing range, but it would be nice to have a heuristic
4743
* on how outrageous the incoming value is.
4844
*/
49-
Id Id::str2Id( const std::string& s )
45+
Id Id::str2Id(const std::string& s)
5046
{
5147
// unsigned int val = atoi( s.c_str() );
52-
return Id( s );
48+
return Id(s);
5349
}
5450

5551
//////////////////////////////////////////////////////////////
5652
// Element array static access function. Private.
5753
//////////////////////////////////////////////////////////////
5854

59-
vector< Element* >& Id::elements()
55+
vector<Element*>& Id::elements()
6056
{
61-
static vector< Element* > e;
57+
static vector<Element*> e;
6258
return e;
6359
}
6460

@@ -67,31 +63,29 @@ vector< Element* >& Id::elements()
6763
//////////////////////////////////////////////////////////////
6864

6965
// static func to convert id into a string.
70-
string Id::id2str( Id id )
66+
string Id::id2str(Id id)
7167
{
7268
return id.path();
7369
}
7470

7571
// Function to convert it into its fully separated path.
76-
string Id::path( const string& separator) const
72+
string Id::path(const string& separator) const
7773
{
78-
string ret = Neutral::path( eref() );
74+
string ret = Neutral::path(eref());
7975

8076
// FIXME: Monday 09 March 2020 12:30:27 PM IST, Dilawar Singh
81-
// This beaks the path comparison. Getting x.path from x returned in a
77+
// This beaks the path comparison. Getting x.path from x returned in a
8278
// list by moose.wildcardFind() and getting path from here doesn't math
8379
// when this is enabled.
8480
// If we want to remove [0] then it should be done globally and not just
8581
// here.
8682

87-
// Trim off trailing []
88-
assert( ret.length() > 0 );
89-
while ( ret.back() == ']' )
90-
{
91-
size_t pos = ret.find_last_of( '[' );
92-
if ( pos != string::npos && pos > 0 )
93-
{
94-
ret = ret.substr( 0, pos );
83+
// Trim off trailing []
84+
assert(ret.length() > 0);
85+
while (ret.back() == ']') {
86+
size_t pos = ret.find_last_of('[');
87+
if (pos != string::npos && pos > 0) {
88+
ret = ret.substr(0, pos);
9589
}
9690
}
9791

@@ -111,26 +105,26 @@ string Id::path( const string& separator) const
111105
* deprecated
112106
Element* Id::operator()() const
113107
{
114-
return elements()[ id_ ];
108+
return elements()[ id_ ];
115109
}
116110
*/
117111

118112
/// Synonym for Id::operator()()
119113
Element* Id::element() const
120114
{
121-
return elements()[ id_ ];
115+
return elements()[id_];
122116
}
123117

124118
/*
125119
unsigned int Id::index() const
126120
{
127-
return index_;
121+
return index_;
128122
}
129123
*/
130124

131125
Eref Id::eref() const
132126
{
133-
return Eref( elements()[ id_ ], 0 );
127+
return Eref(elements()[id_], 0);
134128
// return Eref( elements()[ id_ ], index_ );
135129
}
136130

@@ -140,8 +134,8 @@ Id Id::nextId()
140134
// Should really look up 'available' list.
141135
// Should really put the returned value onto the 'reserved' list
142136
// so they don't go dangling.
143-
Id ret( elements().size() );
144-
elements().push_back( 0 );
137+
Id ret(elements().size());
138+
elements().push_back(0);
145139
return ret;
146140
}
147141

@@ -151,53 +145,49 @@ unsigned int Id::numIds()
151145
return elements().size();
152146
}
153147

154-
void Id::bindIdToElement( Element* e )
148+
void Id::bindIdToElement(Element* e)
155149
{
156-
if ( elements().size() <= id_ )
157-
{
158-
if ( elements().size() % 1000 == 0 )
159-
{
160-
elements().reserve( elements().size() + 1000 );
150+
if (elements().size() <= id_) {
151+
if (elements().size() % 1000 == 0) {
152+
elements().reserve(elements().size() + 1000);
161153
}
162-
elements().resize( id_ + 1, 0 );
154+
elements().resize(id_ + 1, 0);
163155
}
164-
assert( elements()[ id_ ] == 0 );
156+
assert(elements()[id_] == 0);
165157
/*
166158
if ( elements()[ id_ ] != 0 )
167-
cout << "Warning: assigning Element to existing id " << id_ << "\n";
168-
*/
169-
elements()[ id_ ] = e;
159+
cout << "Warning: assigning Element to existing id " << id_ << "\n";
160+
*/
161+
elements()[id_] = e;
170162
// cout << "Id::bindIdToElement '" << e->getName() << "' = " << id_ << endl;
171163
}
172164

173165
/*
174166
Id Id::create( Element* e )
175167
{
176-
Id ret( elements().size() );
177-
elements().push_back( e );
178-
return ret;
168+
Id ret( elements().size() );
169+
elements().push_back( e );
170+
return ret;
179171
}
180172
*/
181173

182174
void Id::destroy() const
183175
{
184-
if ( elements()[ id_ ] )
185-
{
186-
// cout << "Id::destroy '" << elements()[ id_ ]->getName() << "' = " << id_ << endl;
187-
delete elements()[ id_ ];
188-
elements()[ id_ ] = 0;
176+
if (elements()[id_]) {
177+
// cout << "Id::destroy '" << elements()[ id_ ]->getName() << "' = " <<
178+
// id_ << endl;
179+
delete elements()[id_];
180+
elements()[id_] = 0;
189181
// Put id_ on 'available' list
190-
}
191-
else
192-
{
182+
} else {
193183
cout << "Warning: Id::destroy: " << id_ << " already zeroed\n";
194184
}
195185
}
196186

197187
void Id::zeroOut() const
198188
{
199-
assert ( id_ < elements().size() );
200-
elements()[ id_ ] = 0;
189+
assert(id_ < elements().size());
190+
elements()[id_] = 0;
201191
}
202192

203193
unsigned int Id::value() const
@@ -207,11 +197,9 @@ unsigned int Id::value() const
207197

208198
void Id::clearAllElements()
209199
{
210-
for ( vector< Element* >::iterator
211-
i = elements().begin(); i != elements().end(); ++i )
212-
{
213-
if ( *i )
214-
{
200+
for (vector<Element*>::iterator i = elements().begin();
201+
i != elements().end(); ++i) {
202+
if (*i) {
215203
(*i)->clearAllMsgs();
216204
delete *i;
217205
}
@@ -222,28 +210,28 @@ void Id::clearAllElements()
222210
// Id utility
223211
//////////////////////////////////////////////////////////////
224212

225-
ostream& operator <<( ostream& s, const Id& i )
213+
ostream& operator<<(ostream& s, const Id& i)
226214
{
227215
s << i.id_;
228216
/*
229217
if ( i.index_ == 0 )
230-
s << i.id_;
218+
s << i.id_;
231219
else
232-
s << i.id_ << "[" << i.index_ << "]";
220+
s << i.id_ << "[" << i.index_ << "]";
233221
*/
234222
return s;
235223
}
236224

237-
istream& operator >>( istream& s, Id& i )
225+
istream& operator>>(istream& s, Id& i)
238226
{
239227
s >> i.id_;
240228
return s;
241229
}
242230

243231
/*
244232
Id::Id( unsigned int id, unsigned int index )
245-
: id_( id ), index_( index )
233+
: id_( id ), index_( index )
246234
{
247-
;
235+
;
248236
}
249237
*/

0 commit comments

Comments
 (0)