Structural deformable models
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
Species Class Reference

#include <SpeciesDB.h>

Inheritance diagram for Species:
Inheritance graph
[legend]
Collaboration diagram for Species:
Collaboration graph
[legend]

Public Types

enum  SpFlags {
  FLIPPED =0x01, QUALITY =0x02, SCALE =0x04, SEL1 =0x08,
  DEL =0x10, SEL2 =0x20, SEL3 =0x04, SEL4 =0x80,
  SEL5 =0x100
}
 
enum  SpCompare { CMP_EQUALS, CMP_CONTAINS, CMP_LESSER, CMP_GREATER }
 

Public Member Functions

 Species (dword _id=0, dword _flags=0)
 
Speciesoperator= (const Species &rhs)
 
void reset ()
 
bool hasFlag (dword flag) const
 
dword setFlag (dword flag)
 
dword unsetFlag (dword flag)
 
dword readFlagString (const std::string &flags)
 
std::string getFlagString () const
 
bool select (const Species &sp, enum SpCompare how=Species::CMP_CONTAINS) const
 
dword getScale () const
 

Public Attributes

dword id
 
dword m_Flags
 

Static Public Attributes

static const char * SFIELDS []
 
static const char s_SPFLAGS []
 

Friends

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

Detailed Description

Definition at line 12 of file SpeciesDB.h.

Member Enumeration Documentation

Enumerator
CMP_EQUALS 
CMP_CONTAINS 
CMP_LESSER 
CMP_GREATER 

Definition at line 20 of file SpeciesDB.h.

Enumerator
FLIPPED 
QUALITY 
SCALE 
SEL1 
DEL 
SEL2 
SEL3 
SEL4 
SEL5 

Definition at line 16 of file SpeciesDB.h.

16  {
17  FLIPPED=0x01, QUALITY=0x02, SCALE=0x04, SEL1=0x08, DEL=0x10,
18  SEL2=0x20, SEL3=0x04, SEL4=0x80, SEL5=0x100
19  };

Constructor & Destructor Documentation

Species::Species ( dword  _id = 0,
dword  _flags = 0 
)
inline

Definition at line 21 of file SpeciesDB.h.

21 : id(_id), m_Flags(_flags) {}
dword id
Definition: SpeciesDB.h:41
dword m_Flags
Definition: SpeciesDB.h:42

Member Function Documentation

string Species::getFlagString ( ) const

Definition at line 181 of file SpeciesDB.cpp.

Referenced by ImageWindow::changeSpecies(), Brain::doCommand(), Brain::loadSpecies(), operator<<(), operator=(), and Brain::triggerTest().

181  {
182  dword bv=1;
183  string fs;
184  for(int b=0; b<32 && s_SPFLAGS[b]; b++,bv=bv<<1)
185  if(m_Flags&bv) fs += s_SPFLAGS[b];
186  return fs;
187 }
dword m_Flags
Definition: SpeciesDB.h:42
unsigned long dword
Definition: simpletypes.h:6
static const char s_SPFLAGS[]
Definition: SpeciesDB.h:15
dword Species::getScale ( ) const

Definition at line 229 of file SpeciesDB.cpp.

Referenced by ImageWindow::changeSpecies(), Brain::doCommand(), Brain::loadData(), Brain::loadSpecies(), and operator=().

230 {
231  dword scale=0;
232  const_iterator s=find("scale");
233  if(s!=end()) {
234  istringstream(s->second)>>scale;
235  }
236  return scale;
237 }
unsigned long dword
Definition: simpletypes.h:6
bool Species::hasFlag ( dword  flag) const

Definition at line 169 of file SpeciesDB.cpp.

Referenced by operator=(), and Brain::run().

169  {
170  return m_Flags & flag;
171 }
dword m_Flags
Definition: SpeciesDB.h:42
Species& Species::operator= ( const Species rhs)
inline

Definition at line 22 of file SpeciesDB.h.

References CMP_CONTAINS, getFlagString(), getScale(), hasFlag(), id, m_Flags, operator<<, operator>>, readFlagString(), reset(), select(), setFlag(), and unsetFlag().

22  {
23  if(&rhs == this) return *this;
24  std::map<std::string, std::string>::operator=(rhs);
25  id = rhs.id;
26  m_Flags = rhs.m_Flags;
27  return *this;
28  }
dword id
Definition: SpeciesDB.h:41
dword m_Flags
Definition: SpeciesDB.h:42
dword Species::readFlagString ( const std::string &  flags)

Definition at line 189 of file SpeciesDB.cpp.

Referenced by Brain::doCommand(), operator=(), and operator>>().

189  {
190  m_Flags = 0;
191  dword bv=1;
192  for(int b=0; b<32 && s_SPFLAGS[b]; b++,bv=(bv<<1))
193  if(flags.find(s_SPFLAGS[b]) != flags.npos) m_Flags |= bv;
194  return m_Flags;
195 }
dword m_Flags
Definition: SpeciesDB.h:42
unsigned long dword
Definition: simpletypes.h:6
static const char s_SPFLAGS[]
Definition: SpeciesDB.h:15
void Species::reset ( )

Definition at line 163 of file SpeciesDB.cpp.

Referenced by Brain::load(), and operator=().

163  {
164  clear();
165  m_Flags = 0;
166  id = 0;
167 }
dword m_Flags
Definition: SpeciesDB.h:42
bool Species::select ( const Species sp,
enum SpCompare  how = Species::CMP_CONTAINS 
) const

Definition at line 197 of file SpeciesDB.cpp.

Referenced by SpeciesDB::getFilename(), and operator=().

198 {
199  for(map<string,string>::const_iterator rs=sp.begin();
200  rs != sp.end(); rs++)
201  {
202  map<string,string>::const_iterator s=find(rs->first);
203  if(s == end()) return false;
204  const string &lv = s->second;
205  const string &rv = rs->second;
206  if(s->first == "flags") {
207  for(string::const_iterator f=rv.begin(); f!=rv.end(); f++)
208  if(lv.find(*f)==lv.npos) return false;
209  } else {
210  switch(how) {
211  case CMP_EQUALS:
212  if(lv != rv) return false;
213  break;
214  case CMP_CONTAINS:
215  if(lv.find(rv) == lv.npos) return false;
216  break;
217  case CMP_LESSER:
218  if(lv > rv) return false;
219  break;
220  case CMP_GREATER:
221  if(lv < rv) return false;
222  break;
223  }
224  }
225  }
226  return true;
227 }
dword Species::setFlag ( dword  flag)

Definition at line 173 of file SpeciesDB.cpp.

Referenced by operator=(), and Brain::triggerTest().

173  {
174  return m_Flags |= flag;
175 }
dword m_Flags
Definition: SpeciesDB.h:42
dword Species::unsetFlag ( dword  flag)

Definition at line 177 of file SpeciesDB.cpp.

Referenced by operator=(), and Brain::triggerTest().

177  {
178  return m_Flags &= ~flag;
179 }
dword m_Flags
Definition: SpeciesDB.h:42

Friends And Related Function Documentation

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

Definition at line 149 of file SpeciesDB.cpp.

Referenced by operator=(), and SpeciesDB::SpeciesDB().

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,
Species sp 
)
friend

Definition at line 128 of file SpeciesDB.cpp.

Referenced by operator=(), and SpeciesDB::SpeciesDB().

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

Member Data Documentation

dword Species::id
dword Species::m_Flags

Definition at line 42 of file SpeciesDB.h.

Referenced by operator<<(), operator=(), and operator>>().

const char Species::s_SPFLAGS[]
static

Definition at line 15 of file SpeciesDB.h.

const char* Species::SFIELDS[]
static

Definition at line 14 of file SpeciesDB.h.

Referenced by operator<<().


The documentation for this class was generated from the following files: