Structural deformable models
Macros | Functions
SpeciesDB.cpp File Reference
#include <sstream>
#include "SpeciesDB.h"
#include "Errors.h"
Include dependency graph for SpeciesDB.cpp:

Go to the source code of this file.

Macros

#define _SP_DEFINE_
 

Functions

ParseFileoperator>> (ParseFile &is, SpeciesDB &sp)
 
ostream & operator<< (ostream &os, const SpeciesDB &sp)
 
ParseFileoperator>> (ParseFile &is, Species &sp)
 
ostream & operator<< (ostream &os, const Species &sp)
 

Macro Definition Documentation

#define _SP_DEFINE_

Definition at line 5 of file SpeciesDB.cpp.

Function Documentation

ostream& operator<< ( std::ostream &  os,
const SpeciesDB sp 
)

Definition at line 118 of file SpeciesDB.cpp.

119 {
120  for(map<dword,Species>::const_iterator s=sp.begin(); s!=sp.end(); s++)
121  os << s->second << endl;
122  return os;
123 }
ostream& operator<< ( std::ostream &  os,
const Species sp 
)

Definition at line 149 of file SpeciesDB.cpp.

References Species::getFlagString(), Species::m_Flags, NULL, and Species::SFIELDS.

150 {
151  int entry=0;
152  while(Species::SFIELDS[entry] != NULL) {
153  const string fields(Species::SFIELDS[entry]);
154  map<string,string>::const_iterator s=sp.find(fields);
155  if(sp.m_Flags && fields == "flags")
156  os << fields << " " << sp.getFlagString() << endl;
157  else if(s != sp.end()) os << s->first << " " << s->second << endl;
158  entry++;
159  }
160  return os;
161 }
#define NULL
Definition: simpletypes.h:9
static const char * SFIELDS[]
Definition: SpeciesDB.h:14
dword m_Flags
Definition: SpeciesDB.h:42
std::string getFlagString() const
Definition: SpeciesDB.cpp:181
ParseFile& operator>> ( ParseFile is,
SpeciesDB sp 
)

Definition at line 108 of file SpeciesDB.cpp.

Referenced by SpeciesDB::load().

109 {
110  Species s;
111  while(is) {
112  is >> s;
113  if(s.id) sp[s.id] = s;
114  }
115  return is;
116 }
ParseFile& operator>> ( ParseFile is,
Species sp 
)

Definition at line 128 of file SpeciesDB.cpp.

References ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getValue(), Species::id, Species::m_Flags, ParseFile::pushLine(), and Species::readFlagString().

129 {
130  sp.clear();
131  sp.id = 0;
132  sp.m_Flags = 0;
133  while(is.getNextLine()) {
134  const string& token = is.getKey();
135  const string& value = is.getValue();
136  //cout << "token: " << token << " value: " << value << endl;
137  if(token == "species_id") {
138  if(sp.id != 0) { is.pushLine(); return is; }
139  istringstream(value) >> sp.id;
140  } else if(sp.id == 0) {
141  throw new IOException("record didn't start with 'species_id'");
142  } else if(token == "flags")
143  sp.readFlagString(value);
144  sp[token] = value;
145  }
146  return is;
147 }
dword readFlagString(const std::string &flags)
Definition: SpeciesDB.cpp:189
dword id
Definition: SpeciesDB.h:41
const std::string & getValue() const
Definition: ParseFile.h:57
dword m_Flags
Definition: SpeciesDB.h:42
const std::string & getKey() const
Definition: ParseFile.h:56
void pushLine(const std::string &line)
Definition: ParseFile.h:74
const bool getNextLine()
Definition: ParseFile.h:59