6 void PS_Database::reinit(
const char *_name,
bool _readonly) {
8 db_file->reinit(_name, _readonly);
13 db_name2id_map.clear();
14 db_id2name_map.clear();
15 if (!db_rootnode.isNull()) db_rootnode.setNull();
22 unsigned long int number_of_species = 0;
25 for (
unsigned long int i = 0; i < number_of_species; ++i) {
30 unsigned int length_of_name;
32 _file->
get(buffer, length_of_name);
34 string name(buffer, length_of_name);
35 _id2name_map[
id] = name;
36 _name2id_map[name] =
id;
45 for (
ID2NameMapCIter i = _id2name_map.begin(); i != _id2name_map.end(); ++i) {
49 unsigned int length_of_name = i->second.size();
51 _file->
put(i->second.c_str(), length_of_name);
56 if (!db_rootnode.isNull()) db_rootnode.setNull();
58 db_rootnode->load(_file);
62 if (db_rootnode.isNull())
return;
63 db_rootnode->save(_file);
67 char *buffer = (
char *) malloc(FILE_ID.size());
68 _file->
get(buffer, FILE_ID.size());
69 bool file_ok = (FILE_ID.compare(buffer) == 0);
70 if (buffer) free(buffer);
75 _file->
put(FILE_ID.c_str(), FILE_ID.size());
78 void PS_Database::callback(
void *_caller) {
82 if (!((
PS_Node *)_caller)->hasProbes())
return;
91 pair<bool, PS_NodePtr> child = current_node->
getChild(0);
93 current_node = child.second;
98 path.insert((db_id == db_file2db_id_map.end()) ?
id : db_id->second);
104 current_node = db_rootnode;
105 for (
IDSetCIter id=path.begin();
id != path.end(); ++
id) {
115 bool PS_Database::merge(
const char *_other_db_name) {
123 if (!readHeader(other_db_file))
return false;
124 readMappings(other_db_file, other_id2name_map, other_name2id_map);
129 SpeciesID next_usable_ID = (db_id2name_map.rbegin()->first > other_id2name_map.rbegin()->first) ? db_id2name_map.rbegin()->first + 1 : other_id2name_map.rbegin()->first + 1;
134 db_file2db_id_map.clear();
135 for (
Name2IDMapCIter i=db_name2id_map.begin(); i != db_name2id_map.end(); ++i) {
140 if (other_i == other_name2id_map.end()) {
145 if (other_i2 != other_id2name_map.end()) {
150 if (i2 == db_name2id_map.end()) {
152 db_file2db_id_map[other_i2->first] = next_usable_ID;
155 other_name2id_map.erase(other_i2->second);
160 else if (other_i->second != i->second) {
162 db_file2db_id_map[other_i->second] = i->second;
164 other_name2id_map.erase(other_i);
169 other_name2id_map.erase(other_i);
176 for (
Name2IDMapCIter other_i=other_name2id_map.begin(); other_i != other_name2id_map.end(); ++other_i) {
177 db_file2db_id_map[other_i->second] = next_usable_ID;
180 db_MAX_ID = next_usable_ID-1;
183 if (db_file2db_id_map.empty()) {
184 return db_rootnode->append(other_db_file);
188 if (db_path.isNull()) db_path =
new PS_Node(-1);
189 return db_path->
read(other_db_file,
this);
void put_ulong(unsigned long int _ul)
void get(void *_data, int _length)
static const bool READONLY
Name2IDMap::const_iterator Name2IDMapCIter
std::set< SpeciesID > IDSet
PS_NodePtr assertChild(SpeciesID _id)
void addProbes(PS_ProbeSetCIter _begin, PS_ProbeSetCIter _end)
ID2IDMap::const_iterator ID2IDMapCIter
ID2NameMap::iterator ID2NameMapIter
char buffer[MESSAGE_BUFFERSIZE]
void put_uint(unsigned int _ui)
void get_uint(unsigned int &_ui)
void put(const void *_data, int _length)
bool read(PS_FileBuffer *_fb, PS_Callback *_call_destination)
static const int BUFFER_SIZE
std::map< std::string, SpeciesID > Name2IDMap
Name2IDMap::iterator Name2IDMapIter
void get_ulong(unsigned long int &_ul)
ID2NameMap::const_iterator ID2NameMapCIter
pair< bool, PS_NodePtr > getChild(SpeciesID id)
std::map< SpeciesID, std::string > ID2NameMap
IDSet::const_iterator IDSetCIter