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

#include <SpeciesDB.h>

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

Public Member Functions

 SpeciesDB ()
 
 SpeciesDB (const char *filename)
 
bool load (const char *filename)
 
const std::string & getDirectory () const
 
const std::string & getFilename () const
 
dword select (const Species &rhs, enum Species::SpCompare how=Species::CMP_CONTAINS)
 
dword select (const std::list< dword > &idlist)
 
dword getSelectionID (int dir=0, bool wrap=true)
 
dword loadSelection (const std::string &fname)
 
dword writeSelection (const std::string &fname) const
 

Static Public Member Functions

static dword loadSelection (const std::string &fname, std::list< dword > &sel)
 
static dword writeSelection (const std::string &fname, const std::list< dword > &sel)
 

Protected Attributes

std::string m_Directory
 
std::string m_Filename
 
std::list< dwordm_Selection
 
std::list< dword >::iterator m_CSel
 

Friends

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

Detailed Description

Definition at line 45 of file SpeciesDB.h.

Constructor & Destructor Documentation

SpeciesDB::SpeciesDB ( )
inline

Definition at line 47 of file SpeciesDB.h.

47 {}
SpeciesDB::SpeciesDB ( const char *  filename)
inline

Definition at line 48 of file SpeciesDB.h.

References Species::operator<<, and Species::operator>>.

48  {
49  load(filename);
50  }
bool load(const char *filename)
Definition: SpeciesDB.cpp:13

Member Function Documentation

const std::string& SpeciesDB::getDirectory ( ) const
inline

Definition at line 55 of file SpeciesDB.h.

Referenced by ImageWindow::changeSpecies(), Brain::loadSpecies(), and ImageWindow::onKeyPress().

55 { return m_Directory; }
std::string m_Directory
Definition: SpeciesDB.h:69
const std::string& SpeciesDB::getFilename ( ) const
inline

Definition at line 56 of file SpeciesDB.h.

References Species::CMP_CONTAINS, and Species::select().

Referenced by Brain::doCommand().

56 { return m_Filename; }
std::string m_Filename
Definition: SpeciesDB.h:70
dword SpeciesDB::getSelectionID ( int  dir = 0,
bool  wrap = true 
)

Definition at line 54 of file SpeciesDB.cpp.

55 {
56  if(m_Selection.empty()) return 0;
57  if(dir==1) { // dir>0
58  m_CSel++;
59  if(m_CSel==m_Selection.end()) {
60  m_CSel = m_Selection.begin();
61  if(!wrap) return 0;
62  }
63  } else if(dir>1) {
64  m_CSel = m_Selection.end();
65  m_CSel--;
66  } else if(dir==-1) { // dir<0
67  if(m_CSel==m_Selection.begin()) {
68  m_CSel = m_Selection.end();
69  m_CSel--;
70  if(!wrap) return 0;
71  } else m_CSel--;
72  } else if(dir < -1) {
73  m_CSel = m_Selection.begin();
74  }
75  return *m_CSel;
76 }
std::list< dword > m_Selection
Definition: SpeciesDB.h:71
std::list< dword >::iterator m_CSel
Definition: SpeciesDB.h:72
bool SpeciesDB::load ( const char *  filename)

Definition at line 13 of file SpeciesDB.cpp.

References ParseFile::getFilename(), IOException::getMessage(), ParseFile::getPath(), and operator>>().

Referenced by ImageWindow::create(), Brain::loadDB(), and ImageWindow::onLoadImage().

14 {
15  clear();
16  ifstream ifs(filename);
17  ifs.close();
18  ParseFile pf(filename);
19  if(pf) {
20  try {
21  operator>>(pf, *this);
22  } catch (const IOException *e) {
23  cout << "Error loading " << filename << " message: "
24  << e->getMessage() << endl;
25  return false;
26  }
27  cout << "read " << size() << " entries from " << filename << endl;
28  m_Directory = pf.getPath();
29  m_Filename = pf.getFilename();
30  return true;
31  } else {
32  cout << "Error loading " << filename << endl;
33  return false;
34  }
35 }
friend ParseFile & operator>>(ParseFile &is, SpeciesDB &sp)
Definition: SpeciesDB.cpp:108
const char * getMessage() const
Definition: Errors.h:41
std::string m_Directory
Definition: SpeciesDB.h:69
std::string m_Filename
Definition: SpeciesDB.h:70
dword SpeciesDB::loadSelection ( const std::string &  fname)
inline

Definition at line 61 of file SpeciesDB.h.

62  { return loadSelection(fname, m_Selection); }
dword loadSelection(const std::string &fname)
Definition: SpeciesDB.h:61
std::list< dword > m_Selection
Definition: SpeciesDB.h:71
dword SpeciesDB::loadSelection ( const std::string &  fname,
std::list< dword > &  sel 
)
static

Definition at line 78 of file SpeciesDB.cpp.

80 {
81  ifstream is(fname.c_str());
82  if(is) {
83  sel.clear();
84  is >> ws;
85  while(is) {
86  dword selid=0;
87  is >> selid;
88  if(selid) sel.push_back(selid);
89  }
90  } else return 0;
91  return sel.size();
92 }
unsigned long dword
Definition: simpletypes.h:6
dword SpeciesDB::select ( const Species rhs,
enum Species::SpCompare  how = Species::CMP_CONTAINS 
)

Definition at line 37 of file SpeciesDB.cpp.

Referenced by Brain::doCommand().

38 {
39  m_Selection.clear();
40  for(map<dword,Species>::const_iterator s=begin(); s!=end(); s++)
41  if(s->second.select(sp, how))
42  m_Selection.push_back(s->second.id);
43  m_CSel = m_Selection.begin();
44  return m_Selection.size();
45 }
std::list< dword > m_Selection
Definition: SpeciesDB.h:71
std::list< dword >::iterator m_CSel
Definition: SpeciesDB.h:72
dword SpeciesDB::select ( const std::list< dword > &  idlist)

Definition at line 47 of file SpeciesDB.cpp.

48 {
49  m_Selection = idlist;
50  m_CSel = m_Selection.begin();
51  return m_Selection.size();
52 }
std::list< dword > m_Selection
Definition: SpeciesDB.h:71
std::list< dword >::iterator m_CSel
Definition: SpeciesDB.h:72
dword SpeciesDB::writeSelection ( const std::string &  fname) const
inline

Definition at line 63 of file SpeciesDB.h.

64  { return writeSelection(fname, m_Selection); }
dword writeSelection(const std::string &fname) const
Definition: SpeciesDB.h:63
std::list< dword > m_Selection
Definition: SpeciesDB.h:71
dword SpeciesDB::writeSelection ( const std::string &  fname,
const std::list< dword > &  sel 
)
static

Definition at line 94 of file SpeciesDB.cpp.

96 {
97  ofstream os(fname.c_str());
98  if(os) {
99  for(list<dword>::const_iterator csel = sel.begin();
100  csel != sel.end(); csel++)
101  {
102  os << *csel << endl;
103  }
104  } else return 0;
105  return sel.size();
106 }

Friends And Related Function Documentation

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

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 }
ParseFile& operator>> ( ParseFile is,
SpeciesDB sp 
)
friend

Definition at line 108 of file SpeciesDB.cpp.

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

Member Data Documentation

std::list<dword>::iterator SpeciesDB::m_CSel
protected

Definition at line 72 of file SpeciesDB.h.

std::string SpeciesDB::m_Directory
protected

Definition at line 69 of file SpeciesDB.h.

std::string SpeciesDB::m_Filename
protected

Definition at line 70 of file SpeciesDB.h.

std::list<dword> SpeciesDB::m_Selection
protected

Definition at line 71 of file SpeciesDB.h.


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