MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Wildcard.h File Reference
#include <string>
#include <vector>
+ Include dependency graph for Wildcard.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int allChildren (ObjId start, unsigned int index, const string &insideBrace, vector< ObjId > &ret)
 
bool matchBeforeBrace (ObjId id, const string &wild)
 
int simpleWildcardFind (const string &path, vector< ObjId > &ret)
 
int wildcardFind (const string &n, vector< ObjId > &ret)
 

Function Documentation

int allChildren ( ObjId  start,
unsigned int  index,
const string &  insideBrace,
vector< ObjId > &  ret 
)

Recursive function to compare all descendants and cram matches into ret. Returns number of matches. Index is either ALLDATA == ~0U, or a specified number. insideBrace is a string that can be empty, or specify one of the expressions: [TYPE==<string>] [TYPE=<string>] [CLASS=<string>] [ISA=<string>] [ISA==<string>] [TYPE!=<string>] [CLASS!=<string>] [ISA!=<string>] [FIELD(<fieldName)=<string>]

Recursive function to compare all descendants and cram matches into ret. Returns number of matches.

Definition at line 495 of file Wildcard.cpp.

References allChildren(), ALLDATA, Neutral::children(), ObjId::dataIndex, ObjId::eref(), and matchInsideBrace().

Referenced by allChildren(), moose::CompartmentBase::setGeomAndElec(), and singleLevelWildcard().

497 {
498  unsigned int nret = ret.size();
499  vector< Id > kids;
500  Neutral::children( start.eref(), kids );
501  vector< Id >::iterator i;
502  for ( i = kids.begin(); i != kids.end(); i++ )
503  {
504  if ( i->element()->hasFields() )
505  {
506  if ( matchInsideBrace( *i, insideBrace ) )
507  {
508  if ( index == ALLDATA )
509  {
510  ObjId oid( *i, start.dataIndex );
511  ret.push_back( oid );
512  }
513  else if (index < i->element()->numField( start.dataIndex ) )
514  {
515  ObjId oid( *i, start.dataIndex, index );
516  ret.push_back( oid );
517  }
518  }
519  }
520  else
521  {
522  for ( unsigned int j = 0; j < i->element()->numData(); ++j )
523  {
524  ObjId oid( *i, j );
525  allChildren( oid, index, insideBrace, ret );
526  if ( (index == ALLDATA || index == j) && matchInsideBrace( oid, insideBrace ) )
527  ret.push_back( oid );
528  }
529  }
530  }
531  return ret.size() - nret;
532 }
Definition: ObjId.h:20
static void children(const Eref &e, vector< Id > &ret)
Definition: Neutral.cpp:342
const unsigned int ALLDATA
Used by ObjId and Eref.
Definition: consts.cpp:22
int allChildren(ObjId start, unsigned int index, const string &insideBrace, vector< ObjId > &ret)
Definition: Wildcard.cpp:495
static bool matchInsideBrace(ObjId id, const string &inside)
Definition: Wildcard.cpp:322
Eref eref() const
Definition: ObjId.cpp:66
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool matchBeforeBrace ( ObjId  id,
const string &  wild 
)

matchBeforeBrace checks to see if the wildcard string 'name' matches up with the name of the id. Rules:

may be used at multiple places in the wildcard.

It substitutes for any number of characters.

? may be used any number of times in the wildcard, and must substitute exactly for characters.

If bracesInName, then the Id name itself includes braces.

Definition at line 432 of file Wildcard.cpp.

References Shell::chopString(), and findWithSingleCharWildcard().

Referenced by Neuron::getSpinesFromExpression(), matchName(), and testWildcard().

433 {
434  if ( wild == "#" || wild == "##" )
435  return true;
436 
437  string ename = id.element()->getName();
438  if ( wild == ename )
439  return true;
440 
441  // Check if the wildcard string has any # or ? symbols.
442  if ( wild.find_first_of( "#?" ) == string::npos )
443  return false;
444 
445  // Break the 'wild' into the sections that must match, at the #s.
446  // Then go through each of these sections doing a match to ename.
447  // If not found, then return false.
448  vector< string > chops;
449  Shell::chopString( wild, chops, '#' );
450  unsigned int prev = 0;
451  unsigned int start = 0;
452 
453  for ( vector< string >::iterator
454  i = chops.begin(); i != chops.end(); ++i )
455  {
456  start = findWithSingleCharWildcard( ename, prev, *i );
457  if ( start == ~0U )
458  return false;
459  if ( prev == 0 && start > 0 && wild[0] != '#' )
460  return false;
461  prev = start + i->length();
462  }
463  return true;
464 
465  /*
466 
467  string::size_type pre = name.find( "#" );
468  string::size_type post = name.rfind( "#" );
469 
470  // # may only be used once in the wildcard, but substitutes for any
471  // number of characters.
472  if ( pre != string::npos && post == pre ) {
473  if ( ename.length() < ( name.length() - post - 1 ) )
474  return false;
475  unsigned int epos = ename.length() - ( name.length() - post - 1 );
476  return ( name.substr( 0, pre ) == ename.substr( 0, pre ) &&
477  name.substr( post + 1 ) == ename.substr( epos ) );
478  }
479 
480  // ? may be used any number of times in the wildcard, and
481  // must substitute exactly for characters.
482  if ( name.length() != ename.length() )
483  return 0;
484  for ( unsigned int i = 0; i < name.length(); i++ )
485  if ( name[i] != '?' && name[i] != ename[i] )
486  return false;
487  return true;
488  */
489 }
static bool chopString(const string &path, vector< string > &ret, char separator= '/')
Definition: Shell.cpp:459
unsigned int findWithSingleCharWildcard(const string &name, unsigned int start, const string &wild)
Definition: Wildcard.cpp:405

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int simpleWildcardFind ( const string &  path,
vector< ObjId > &  ret 
)

simpleWildcardFind returns the number of Ids found. This is the basic wildcardFind function, working on a single tree. It adds entries into the vector 'ret' with Ids found according to the path string. It preserves the order of the returned Ids as the order of elements traversed in the search. It does NOT eliminate duplicates. This is a depth-first search. Note that it does NOT list every entry in arrays, only the base Element.

Wildcard search rules are like this:

  • Multiple wildcard paths can be specified, separated by commas
  • Each wildcard path looks like a file path, separated by '/'
  • At each level of the wildcard path, we have element specifiers.
  • Each specifier can be a single fully specified element, or a wildcard.
  • Substrings of the specifier can be wildcarded with '#'
    • The entire specifier can also be a '#'
  • Characters of the specifier can be wildcarded with '?'
  • An entire recursive tree can be specified using '##'
  • As a qualifier to any of the wildcard specifiers we can use expressions enclosed in square brackets. These expressions are of the form: [TYPE==<string>] [TYPE=<string>] [CLASS=<string>] [ISA=<string>] [ISA==<string>] [TYPE!=<string>] [CLASS!=<string>] [ISA!=<string>] [FIELD(<fieldName)=<string>]

This is the basic wildcardFind function, working on a single tree. It adds entries into the vector 'ret' with Ids found according to the path string. It preserves the order of the returned Ids as the order of elements traversed in the search. It does NOT eliminate duplicates. This is a depth-first search. Note that it does the dumb but backward compatible thing with Ids of arrays: it lists every entry.

It returns the number of Ids found here.

Definition at line 137 of file Wildcard.cpp.

References Shell::chopString(), and innerFind().

Referenced by setMethod(), Dsolve::setPath(), testWildcard(), wildcardFind(), and wildcardTestFunc().

138 {
139  if ( path.length() == 0 )
140  return 0;
141  unsigned int n = ret.size();
142  vector< string > wildcards;
143  Shell::chopString( path, wildcards, ',' );
144  // separateString( path, wildcards, "," );
145  vector< string >::iterator i;
146  for ( i = wildcards.begin(); i != wildcards.end(); ++i )
147  innerFind( *i, ret );
148 
149  return ret.size() - n;
150 }
static int innerFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:89
static bool chopString(const string &path, vector< string > &ret, char separator= '/')
Definition: Shell.cpp:459
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int wildcardFind ( const string &  n,
vector< ObjId > &  ret 
)

wildcardFind returns the number of Ids found. This behaves the same as simpleWildcardFind, except that it eliminates non-unique entries, and in the process will scramble the ordering.

Definition at line 169 of file Wildcard.cpp.

References myUnique(), and simpleWildcardFind().

Referenced by Neuron::buildElist(), doClassSpecificMessaging(), Shell::doStart(), ReadKkit::dumpPlots(), Neuron::getExprElist(), Neuron::getExprVal(), Shell::innerUseClock(), moose_wildcardFind(), Stoich::setPath(), Dsolve::setStoich(), NeuroMesh::setSubTreePath(), writeGroup(), and writeKkit().

170 {
171  ret.resize( 0 );
172  simpleWildcardFind( path, ret );
173  myUnique( ret );
174  return ret.size();
175 }
int simpleWildcardFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:137
static void myUnique(vector< ObjId > &ret)
Definition: Wildcard.cpp:152
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function: