Structural deformable models
Public Member Functions | Public Attributes | List of all members
DBSelector Class Reference

#include <SpeciesDB.h>

Collaboration diagram for DBSelector:
Collaboration graph
[legend]

Public Member Functions

 DBSelector (SpeciesDB &db)
 
 DBSelector (SpeciesDB &db, const char *filename)
 
bool load (const char *filename)
 
void update ()
 should be called when data base has changed More...
 
SpeciesgetCurSpecies ()
 Returns a handle to the currently selected species in the data base. More...
 
bool nextSelection (int dir=1, bool wrap=true)
 
bool nextSelector (int walkdir=1, bool wrap=true, dword mincount=1)
 

Public Attributes

SpeciesDBm_DB
 
std::list< Speciesm_Selectors
 
std::list< Species >::iterator m_CSel
 
Species m_CSpecies
 

Detailed Description

This class helps to select subsets of a data base. As well it assists in navigation through the selectors and the resulting selections.

Definition at line 78 of file SpeciesDB.h.

Constructor & Destructor Documentation

DBSelector::DBSelector ( SpeciesDB db)
inline

Definition at line 80 of file SpeciesDB.h.

80 : m_DB(db), m_CSel(m_Selectors.begin()) {};
SpeciesDB & m_DB
Definition: SpeciesDB.h:109
std::list< Species > m_Selectors
Definition: SpeciesDB.h:110
std::list< Species >::iterator m_CSel
Definition: SpeciesDB.h:111
DBSelector::DBSelector ( SpeciesDB db,
const char *  filename 
)
inline

Definition at line 81 of file SpeciesDB.h.

82  : m_DB(db), m_CSel(m_Selectors.begin())
83  { load(filename); }
SpeciesDB & m_DB
Definition: SpeciesDB.h:109
std::list< Species > m_Selectors
Definition: SpeciesDB.h:110
bool load(const char *filename)
Definition: SpeciesDB.cpp:241
std::list< Species >::iterator m_CSel
Definition: SpeciesDB.h:111

Member Function Documentation

Species& DBSelector::getCurSpecies ( )
inline

Returns a handle to the currently selected species in the data base.

Definition at line 90 of file SpeciesDB.h.

Referenced by Brain::doCommand(), Brain::loadDB(), Brain::loadDBSelector(), ImageWindow::onKeyPress(), Brain::run(), and Brain::triggerTest().

91  {
92  std::map<dword,Species>::iterator n = m_DB.find(
94  if(n != m_DB.end()) return n->second;
95  else return m_CSpecies;
96  }
SpeciesDB & m_DB
Definition: SpeciesDB.h:109
dword getSelectionID(int dir=0, bool wrap=true)
Definition: SpeciesDB.cpp:54
Species m_CSpecies
Definition: SpeciesDB.h:112
bool DBSelector::load ( const char *  filename)

Load a set of species used as selectors for filtering the data base. Calls update() afterwards.

Definition at line 241 of file SpeciesDB.cpp.

Referenced by ImageWindow::create(), and Brain::loadDBSelector().

242 {
243  ParseFile rf(filename);
244  while(rf) {
245  Species sp;
246  rf >> sp;
247  sp.erase("species_id");
248  m_Selectors.push_back(sp);
249  }
250  cout << m_Selectors.size() << " records read from " << filename << endl;
251  update();
252  return true;
253 }
std::list< Species > m_Selectors
Definition: SpeciesDB.h:110
void update()
should be called when data base has changed
Definition: SpeciesDB.cpp:255
bool DBSelector::nextSelection ( int  dir = 1,
bool  wrap = true 
)

Move on to next selection.

Parameters
dir-1 move backwards, 1 move forwards, 0 just refresh
wrapif false then return false if end of selection list has been reached. Otherwise just wrap around.

Definition at line 261 of file SpeciesDB.cpp.

Referenced by Brain::doCommand(), ImageWindow::onKeyPress(), Brain::run(), and Brain::triggerTest().

262 {
263  if(m_DB.empty()) return false;
264  if(!m_DB.getSelectionID()) {
265  map<dword,Species>::iterator n = m_DB.find(m_CSpecies.id);
266  if(n != m_DB.end()) {
267  if(dir>0) {
268  n++;
269  if(n == m_DB.end()) {
270  n = m_DB.begin();
271  if(!wrap) return false;
272  }
273  } else if(dir<0) {
274  if(n == m_DB.begin()) {
275  n = m_DB.end();
276  n--;
277  if(!wrap) return false;
278  } else n--;
279  }
280  m_CSpecies = n->second;
281  } else return false;
282  } else {
283  map<dword,Species>::iterator n = m_DB.find(
284  m_DB.getSelectionID(dir,wrap));
285  if(n != m_DB.end()) m_CSpecies = n->second;
286  else return false;
287  }
288  return true;
289 }
SpeciesDB & m_DB
Definition: SpeciesDB.h:109
dword id
Definition: SpeciesDB.h:41
dword getSelectionID(int dir=0, bool wrap=true)
Definition: SpeciesDB.cpp:54
Species m_CSpecies
Definition: SpeciesDB.h:112
bool DBSelector::nextSelector ( int  walkdir = 1,
bool  wrap = true,
dword  mincount = 1 
)

Move on to next selector.

Parameters
walkdir-1=move backwards, 1=move forwards (default), 0=just refresh
wrapif false then return false if end of selector list has been reached. Otherwise just wrap around.

Definition at line 291 of file SpeciesDB.cpp.

Referenced by ImageWindow::onKeyPress(), and Brain::triggerTest().

291  {
292  bool ret = true;
293  list<Species>::iterator osel = m_Selectors.end();
294  while(m_CSel != osel)
295  {
296  if(osel == m_Selectors.end()) osel = m_CSel;
297  if(walkdir<0) {
298  if(m_CSel == m_Selectors.begin()) {
299  m_CSel = m_Selectors.end();
300  ret = wrap;
301  }
302  m_CSel--;
303  } else if(walkdir>0) {
304  m_CSel++;
305  if(m_CSel == m_Selectors.end()) {
306  m_CSel = m_Selectors.begin();
307  ret = wrap;
308  }
309  }
310  dword nsel = m_DB.select(*m_CSel);
311  if(nsel >= mincount) {
312  cout << nsel << " records found using selector:" << endl
313  << *m_CSel;
314  nextSelection(0);
315  osel = m_CSel;
316  } else {
317  cout << " no records found using selector:" <<endl<<*m_CSel;
318  }
319  }
320  if(m_CSel == m_Selectors.end()) {
321  m_CSel = m_Selectors.begin();
322  return false;
323  }
324  return ret;
325 }
SpeciesDB & m_DB
Definition: SpeciesDB.h:109
std::list< Species > m_Selectors
Definition: SpeciesDB.h:110
unsigned long dword
Definition: simpletypes.h:6
std::list< Species >::iterator m_CSel
Definition: SpeciesDB.h:111
dword select(const Species &rhs, enum Species::SpCompare how=Species::CMP_CONTAINS)
Definition: SpeciesDB.cpp:37
bool nextSelection(int dir=1, bool wrap=true)
Definition: SpeciesDB.cpp:261
void DBSelector::update ( )

should be called when data base has changed

Definition at line 255 of file SpeciesDB.cpp.

Referenced by Brain::loadDB().

256 {
257  m_CSel = m_Selectors.begin();
258  nextSelector(0);
259 }
bool nextSelector(int walkdir=1, bool wrap=true, dword mincount=1)
Definition: SpeciesDB.cpp:291
std::list< Species > m_Selectors
Definition: SpeciesDB.h:110
std::list< Species >::iterator m_CSel
Definition: SpeciesDB.h:111

Member Data Documentation

std::list<Species>::iterator DBSelector::m_CSel

Definition at line 111 of file SpeciesDB.h.

Species DBSelector::m_CSpecies

Definition at line 112 of file SpeciesDB.h.

SpeciesDB& DBSelector::m_DB

Definition at line 109 of file SpeciesDB.h.

std::list<Species> DBSelector::m_Selectors

Definition at line 110 of file SpeciesDB.h.


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