16 ifstream ifs(filename);
23 cout <<
"Error loading " << filename <<
" message: " 27 cout <<
"read " << size() <<
" entries from " << filename << endl;
32 cout <<
"Error loading " << filename << endl;
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();
50 m_CSel = m_Selection.begin();
51 return m_Selection.size();
56 if(m_Selection.empty())
return 0;
59 if(m_CSel==m_Selection.end()) {
60 m_CSel = m_Selection.begin();
64 m_CSel = m_Selection.end();
67 if(m_CSel==m_Selection.begin()) {
68 m_CSel = m_Selection.end();
73 m_CSel = m_Selection.begin();
79 std::list<dword>& sel)
81 ifstream is(fname.c_str());
88 if(selid) sel.push_back(selid);
95 const std::list<dword>& sel)
97 ofstream os(fname.c_str());
99 for(list<dword>::const_iterator csel = sel.begin();
100 csel != sel.end(); csel++)
113 if(s.id) sp[s.id] = s;
120 for(map<dword,Species>::const_iterator s=sp.begin(); s!=sp.end(); s++)
121 os << s->second << endl;
134 const string& token = is.
getKey();
135 const string& value = is.
getValue();
137 if(token ==
"species_id") {
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")
154 map<string,string>::const_iterator s=sp.find(fields);
155 if(sp.
m_Flags && fields ==
"flags")
157 else if(s != sp.end()) os << s->first <<
" " << s->second << endl;
170 return m_Flags & flag;
174 return m_Flags |= flag;
178 return m_Flags &= ~flag;
184 for(
int b=0; b<32 && s_SPFLAGS[b]; b++,bv=bv<<1)
185 if(m_Flags&bv) fs += s_SPFLAGS[b];
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;
199 for(map<string,string>::const_iterator rs=sp.begin();
200 rs != sp.end(); rs++)
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;
212 if(lv != rv)
return false;
215 if(lv.find(rv) == lv.npos)
return false;
218 if(lv > rv)
return false;
221 if(lv < rv)
return false;
232 const_iterator s=find(
"scale");
234 istringstream(s->second)>>scale;
247 sp.erase(
"species_id");
248 m_Selectors.push_back(sp);
250 cout << m_Selectors.size() <<
" records read from " << filename << endl;
257 m_CSel = m_Selectors.begin();
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()) {
269 if(n == m_DB.end()) {
271 if(!wrap)
return false;
274 if(n == m_DB.begin()) {
277 if(!wrap)
return false;
280 m_CSpecies = n->second;
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;
293 list<Species>::iterator osel = m_Selectors.end();
294 while(m_CSel != osel)
296 if(osel == m_Selectors.end()) osel = m_CSel;
298 if(m_CSel == m_Selectors.begin()) {
299 m_CSel = m_Selectors.end();
303 }
else if(walkdir>0) {
305 if(m_CSel == m_Selectors.end()) {
306 m_CSel = m_Selectors.begin();
310 dword nsel = m_DB.select(*m_CSel);
311 if(nsel >= mincount) {
312 cout << nsel <<
" records found using selector:" << endl
317 cout <<
" no records found using selector:" <<endl<<*m_CSel;
320 if(m_CSel == m_Selectors.end()) {
321 m_CSel = m_Selectors.begin();
ostream & operator<<(ostream &os, const SpeciesDB &sp)
dword readFlagString(const std::string &flags)
const std::string & getFilename() const
bool nextSelector(int walkdir=1, bool wrap=true, dword mincount=1)
ParseFile & operator>>(ParseFile &is, SpeciesDB &sp)
bool hasFlag(dword flag) const
dword writeSelection(const std::string &fname) const
dword getSelectionID(int dir=0, bool wrap=true)
const std::string & getValue() const
static const char * SFIELDS[]
bool load(const char *filename)
dword setFlag(dword flag)
bool load(const char *filename)
const std::string & getPath() const
const std::string & getKey() const
const char * getMessage() const
dword loadSelection(const std::string &fname)
bool select(const Species &sp, enum SpCompare how=Species::CMP_CONTAINS) const
dword select(const Species &rhs, enum Species::SpCompare how=Species::CMP_CONTAINS)
std::string getFlagString() const
dword unsetFlag(dword flag)
bool nextSelection(int dir=1, bool wrap=true)
void pushLine(const std::string &line)
void update()
should be called when data base has changed