18 unsigned int depth, vector< ObjId >& ret );
21 string& beforeBrace,
string& insideBrace );
24 const string& beforeBrace,
const string& insideBrace );
40 string::size_type pos = mid.find(
')');
41 if ( pos == string::npos )
43 string fieldName = mid.substr( 0, pos );
44 string::size_type pos2 = mid.find_last_of(
"=<>" );
45 if ( pos2 == string::npos )
47 string op = mid.substr( pos + 1, pos2 - pos );
49 string testValue = mid.substr( pos2 + 1 );
51 if ( testValue.length() == 0 )
67 if ( op ==
"==" || op ==
"=" )
68 return ( testValue == actualValue );
70 return ( testValue != actualValue );
72 double v1 = atof( actualValue.c_str() );
73 double v2 = atof( testValue.c_str() );
91 if ( path ==
"/" || path ==
"/root")
93 ret.push_back(
Id() );
97 vector< string > names;
98 vector< vector< unsigned int > > indices;
139 if ( path.length() == 0 )
141 unsigned int n = ret.size();
142 vector< string > wildcards;
145 vector< string >::iterator i;
146 for ( i = wildcards.begin(); i != wildcards.end(); ++i )
149 return ret.size() - n;
154 sort(ret.begin(), ret.end());
157 for (i = 1; i < ret.size(); i++)
159 if (ret[j] != ret[i])
185 if ( path.length() == 0 )
187 unsigned int nret = ret.size();
193 if ( beforeBrace ==
"##" )
195 return allChildren( start, index, insideBrace, ret );
199 vector< Id >::iterator i;
200 for ( i = kids.begin(); i != kids.end(); i++ )
203 index, beforeBrace, insideBrace ) )
207 for (
unsigned int j = 0; j < i->element()->numData(); ++j )
208 ret.push_back(
ObjId( *i, j ) );
210 else if ( i->element()->hasFields() && index < i->element()->numField( start.
dataIndex ) )
214 else if ( !i->element()->hasFields() && index < i->element()->numData() )
216 ret.push_back(
ObjId( *i, index ) );
221 return ret.size() - nret;
244 string& insideBrace )
250 if ( path.length() == 0 )
252 vector< string > names;
254 if ( names.size() == 0 )
256 if ( names.size() >= 1 )
257 beforeBrace = names[0];
258 unsigned int len = beforeBrace.length();
259 if ( len > 0 && beforeBrace[len -1] ==
'#' )
261 if ( names.size() >= 2 )
263 const string& n = names[1];
268 else if ( isdigit( n[0] ) )
270 index = atoi( n.c_str() );
274 insideBrace = n.substr( 0, n.length() - 1 );
277 if ( names.size() == 3 )
279 string n1 = names[2].substr( 0, names[2].length() - 1 );
294 const string& beforeBrace,
const string& insideBrace )
296 string temp =
id.element()->getName();
297 if ( temp.length() <= 0 )
305 if ( insideBrace.length() == 0 )
329 if ( inside.substr(0, 4 ) ==
"TYPE" ||
330 inside.substr(0, 5 ) ==
"CLASS" ||
331 inside.substr(0, 3 ) ==
"ISA" )
333 string::size_type pos = inside.rfind(
"=" );
334 if ( pos == string::npos )
336 bool isEquality = ( inside[ pos - 1 ] !=
'!' );
337 string typeName = inside.substr( pos + 1 );
338 if ( typeName ==
"membrane" )
339 typeName =
"Compartment";
341 if ( inside.substr( 0, 5 ) ==
"CLASS" && typeName ==
"channel" )
342 typeName =
"HHChannel";
345 if ( inside.substr( 0, 3 ) ==
"ISA" )
347 isEqual =
id.element()->cinfo()->isA( typeName );
351 isEqual = ( typeName ==
id.element()->cinfo()->name() );
361 return ( isEqual == isEquality );
363 else if ( inside.substr( 0, 6 ) ==
"FIELD(" )
385 unsigned int len = wild.length();
386 if ( name.length() < len )
388 for (
unsigned int i = 0; i < len; i++ )
390 if ( wild[i] !=
'?' && name[i] != wild[i] )
406 const string&
name,
unsigned int start,
const string& wild )
408 unsigned int len = wild.length();
409 if ( len + start > name.length() )
411 unsigned int end = 1 + name.length() - len;
412 for (
unsigned int i = start; i < end; ++i )
434 if ( wild ==
"#" || wild ==
"##" )
437 string ename =
id.element()->getName();
442 if ( wild.find_first_of(
"#?" ) == string::npos )
448 vector< string > chops;
450 unsigned int prev = 0;
451 unsigned int start = 0;
453 for ( vector< string >::iterator
454 i = chops.begin(); i != chops.end(); ++i )
459 if ( prev == 0 && start > 0 && wild[0] !=
'#' )
461 prev = start + i->length();
496 unsigned int index,
const string& insideBrace, vector< ObjId >& ret )
498 unsigned int nret = ret.size();
501 vector< Id >::iterator i;
502 for ( i = kids.begin(); i != kids.end(); i++ )
504 if ( i->element()->hasFields() )
511 ret.push_back( oid );
513 else if (index < i->element()->numField( start.
dataIndex ) )
516 ret.push_back( oid );
522 for (
unsigned int j = 0; j < i->element()->numData(); ++j )
527 ret.push_back( oid );
531 return ret.size() - nret;
545 unsigned int depth, vector< ObjId >& ret )
548 vector< ObjId > currentLevelIds;
549 if ( depth == path.size() )
551 if ( ret.size() == 0 || ret.back() != start )
553 ret.push_back( start );
560 vector< ObjId >::iterator i;
561 for ( i = currentLevelIds.begin(); i != currentLevelIds.end(); ++i )
571 if ( ne != ret.size() )
573 cout <<
"!\nAssert '" << path <<
"' : expected " <<
574 ne <<
", found " << ret.size() <<
"\n";
577 sort( ret.begin(), ret.end() );
578 for (
unsigned int i = 0; i < ne ; i++ )
580 if ( elist[ i ] != ret[ i ] )
582 cout <<
"!\nAssert " << path <<
": item " << i <<
584 ret[i].element()->getName() <<
"\n";
597 assert( bb ==
"foo" );
599 assert( ib ==
"TYPE=Compartment" );
602 assert( bb ==
"foo" );
603 assert( ib ==
"TYPE=Channel" );
606 assert( bb ==
"foo" );
607 assert( ib ==
"TYPE=membrane" );
610 assert( bb ==
"bar" );
614 assert( bb ==
"zod" );
619 assert( bb ==
"zod#" );
623 assert( bb ==
"zod#" );
627 assert( bb ==
"zod#" );
628 assert( ib ==
"ISA=hippo" );
631 assert( bb ==
"zod#" );
635 assert( bb ==
"zod##" );
639 assert( ret ==
true );
641 assert( ret ==
false );
643 assert( ret ==
true );
645 assert( ret ==
true );
647 assert( ret ==
true );
649 assert( ret ==
false );
651 assert( ret ==
true );
666 Id c1 = shell->
doCreate(
"Arith", a1,
"c1", 1 );
667 Id c2 = shell->
doCreate(
"Arith", a1,
"c2", 1 );
668 Id c3 = shell->
doCreate(
"Arith", a1,
"c3", 1 );
669 Id cIndex = shell->
doCreate(
"Neutral", a1,
"c4", 1 );
670 Id c5 = shell->
doCreate(
"Neutral", a1,
"Seg5_apical_1234_spine_234",1);
707 assert( ret ==
true );
709 assert( ret ==
true );
711 assert( ret ==
true );
713 assert( ret ==
true );
715 assert( ret ==
true );
717 assert( ret ==
false );
719 assert( ret ==
true );
721 assert( ret ==
true );
723 assert( ret ==
true );
725 assert( ret ==
true );
727 assert( ret ==
true );
729 assert( ret ==
false );
731 assert( ret ==
true );
784 ObjId el3[] = { c1, c2, c3, cIndex };
789 for ( i = 0 ; i < 100; i++ )
792 sprintf( name,
"ch%ld", i );
793 el2[i] = shell->
doCreate(
"Annotator", c1, name, 1 );
810 el4[i] = shell->
doCreate(
"IntFire", el2[0],
"g0", 1 );
812 el4[i] = shell->
doCreate(
"IntFire", el2[1],
"g1", 1 );
814 el4[i] = shell->
doCreate(
"IntFire", el2[1],
"g2", 1 );
816 el4[i] = shell->
doCreate(
"IntFire", el2[2],
"g3", 1 );
818 el4[i] = shell->
doCreate(
"IntFire", el2[2],
"g4", 1 );
820 el4[i] = shell->
doCreate(
"IntFire", el2[4],
"g5", 1 );
822 el4[i] = shell->
doCreate(
"IntFire", el2[5],
"g6", 1 );
824 el4[i] = shell->
doCreate(
"IntFire", el2[6],
"g7", 1 );
826 el4[i] = shell->
doCreate(
"IntFire", el2[1],
"g8", 1 );
828 el4[i] = shell->
doCreate(
"IntFire", el2[1],
"g9", 1 );
830 el4[i] = shell->
doCreate(
"IntFire", c2,
"g10", 1 );
832 el4[i] = shell->
doCreate(
"IntFire", c3,
"g11", 1 );
839 Id x = shell->
doCreate(
"Arith", a1,
"x", 5 );
844 assert( vec.size() == 10 );
847 assert( vec.size() == 15 );
850 assert( vec.size() == 5 );
853 Id xyzzy = shell->
doCreate(
"Arith", a1,
"xyzzy", 5 );
854 Id xdotp = shell->
doCreate(
"Arith", a1,
"x.P", 5 );
857 assert( vec.size() == 1 );
860 assert( vec.size() == 1 );
863 assert( vec.size() == 1 );
866 assert( vec.size() == 5 );
870 cout <<
"." << flush;
static int wildcardRelativeFind(ObjId start, const vector< string > &path, unsigned int depth, vector< ObjId > &ret)
int wildcardFind(const string &path, vector< ObjId > &ret)
static int innerFind(const string &path, vector< ObjId > &ret)
static bool chopString(const string &path, vector< string > &ret, char separator= '/')
static double op(double x)
int simpleWildcardFind(const string &path, vector< ObjId > &ret)
int singleLevelWildcard(ObjId start, const string &path, vector< ObjId > &ret)
static void children(const Eref &e, vector< Id > &ret)
static bool set(const ObjId &dest, const string &field, A arg)
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
bool alignedSingleWildcardMatch(const string &name, const string &wild)
const unsigned int ALLDATA
Used by ObjId and Eref.
void wildcardTestFunc(ObjId *elist, unsigned int ne, const string &path)
static bool matchName(ObjId id, unsigned int index, const string &beforeBrace, const string &insideBrace)
static bool strGet(const ObjId &tgt, const string &field, string &ret)
bool matchBeforeBrace(ObjId id, const string &wild)
int allChildren(ObjId start, unsigned int index, const string &insideBrace, vector< ObjId > &ret)
static bool wildcardFieldComparison(ObjId oid, const string &mid)
static void myUnique(vector< ObjId > &ret)
static bool matchInsideBrace(ObjId id, const string &inside)
Element * element() const
unsigned int findWithSingleCharWildcard(const string &name, unsigned int start, const string &wild)
static unsigned int findBraceContent(const string &path, string &beforeBrace, string &insideBrace)
const string & getName() const