MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
LoadModels.cpp File Reference
#include <fstream>
#include "header.h"
#include "Shell.h"
#include "../utility/strutil.h"
#include "../utility/Vec.h"
#include "LoadModels.h"
#include "../biophysics/ReadCell.h"
#include "../biophysics/SwcSegment.h"
#include "../biophysics/ReadSwc.h"
#include "../kinetics/ReadKkit.h"
#include "../kinetics/ReadCspace.h"
#include "../utility/print_function.hpp"
+ Include dependency graph for LoadModels.cpp:

Go to the source code of this file.

Functions

bool findModelParent (Id cwe, const string &path, Id &parentId, string &modelName)
 
ModelType findModelType (string filename, ifstream &fin, string &line)
 

Function Documentation

bool findModelParent ( Id  cwe,
const string &  path,
Id parentId,
string &  modelName 
)

Identify parent Id from path that can optionally have the model name as the last part. Pass back the parent Id, and the model name. Returns true on success. Cases: First set: we want to fill in "model" as modelName "" where we want <cwe>/model "/" where we want /model. "/foo" where foo exists, so we want /foo/model "foo" where <cwe>/foo exists, and we want <cwe>/foo/model Second set: the last part of the path has the model name. "bar" where we want <cwe>/bar "/bar" where we want /bar "/foo/bar" where we want /foo/bar "foo/bar" where we want <cwe>/foo/bar

Definition at line 81 of file LoadModels.cpp.

References Id::element(), Element::getName(), ObjId::id, Neutral::parent(), Id::path(), and path.

Referenced by Shell::doLoadModel(), and testFindModelParent().

83 {
84  modelName = "model";
85  string fullPath = path;
86 
87  if ( path.length() == 0 )
88  {
89  parentId = cwe;
90  return 1;
91  }
92 
93  if ( path == "/" )
94  {
95  parentId = Id();
96  return 1;
97  }
98 
99  if ( path[0] != '/' )
100  {
101  string temp = cwe.path();
102  if ( temp[temp.length() - 1] == '/' )
103  fullPath = temp + path;
104  else
105  fullPath = temp + "/" + path;
106  }
107 
108  Id paId( fullPath );
109  if ( paId == Id() ) // Path includes new model name
110  {
111  string::size_type pos = fullPath.find_last_of( "/" );
112  assert( pos != string::npos );
113  string head = fullPath.substr( 0, pos );
114  Id ret( head );
115  // When head = "" it means paId should be root.
116  if ( ret == Id() && head != "" && head != "/root" )
117  return 0;
118  parentId = ret;
119  modelName = fullPath.substr( pos + 1 );
120  return 1;
121  }
122  else // Path is an existing element.
123  {
124  parentId = Neutral::parent( paId ).id;
125  modelName = paId.element()->getName();
126  return 1;
127  }
128  return 0;
129 }
static ObjId parent(const Eref &e)
Definition: Neutral.cpp:701
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
Id id
Definition: ObjId.h:98
Definition: Id.h:17
const string & getName() const
Definition: Element.cpp:56
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ModelType findModelType ( string  filename,
ifstream &  fin,
string &  line 
)

Definition at line 24 of file LoadModels.cpp.

References CSPACE, DOTP, KKIT, SWC, moose::trim(), and UNKNOWN.

Referenced by Shell::doLoadModel().

25 {
26  if ( filename.substr( filename.length() - 2 ) == ".p" )
27  return DOTP;
28 
29  if ( filename.substr( filename.length() - 4 ) == ".swc" )
30  return SWC;
31 
32  getline( fin, line );
33  line = moose::trim(line);
34  if ( line == "//genesis" )
35  {
36  getline( fin, line );
37  line = moose::trim(line);
38  if ( line.substr( 0, 7 ) == "// kkit" )
39  return KKIT;
40  }
41  if ( line.substr( 0, 9 ) == "// DOQCS" )
42  {
43  while ( getline( fin, line ) )
44  {
45  line = moose::trim(line);
46  if ( line.substr( 0, 7 ) == "// kkit" )
47  return KKIT;
48  }
49  }
50 
51  unsigned long pos = line.find_first_of( ":" );
52  string copyLine= line;
53  if (pos != string::npos )
54  {
55  copyLine = line.substr(pos+2);
56  }
57 
58  if ( copyLine.length() >= 6 && copyLine[0] == '|' && copyLine[5] == '|' )
59  return CSPACE;
60 
61  return UNKNOWN;
62 }
Definition: LoadModels.h:18
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function: