Update of /cvsroot/pure-data/externals/PDContainer/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13094
Modified Files: ContainerBase.h GlobalStuff.h HList.h HMap.h HMultiMap.h HPrioQueue.h MapBase.h QueueStack.h SequBase.h SimpleBase.h Log Message: version 0.2
Index: HPrioQueue.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/HPrioQueue.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HPrioQueue.h 25 Oct 2004 19:02:30 -0000 1.1.1.1 --- HPrioQueue.h 9 Oct 2005 21:52:14 -0000 1.2 *************** *** 71,75 **** { dataname_ = "h_priority_queue"; ! setNamespace(h_namespace); }
--- 71,75 ---- { dataname_ = "h_priority_queue"; ! setNamespace(h_namespace); }
*************** *** 86,90 **** data.element = value;
! data_[h_namespace_].push(data); }
--- 86,90 ---- data.element = value;
! data_[h_namespace_].push(data); }
Index: HList.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/HList.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HList.h 18 Mar 2005 10:14:07 -0000 1.4 --- HList.h 9 Oct 2005 21:52:14 -0000 1.5 *************** *** 15,19 ****
! #include "include/SequBase.h" #include <list>
--- 15,19 ----
! #include "include/SimpleBase.h" #include <list>
*************** *** 138,155 **** makeIterator();
! if(iter_ == data_[h_namespace_].end()) ! { ! post("h_list, get: not possible, go back by 1 (iterator points to the element after the end) !!!"); ! ! // this error handling is not very good, because ! // I can't give back a reference -> I'll change this !!! ! Element nothing; ! return nothing; ! }
! return *iter_; }
! /* removes all element with that value */ virtual void remove(Element value) --- 138,149 ---- makeIterator();
! // key was not found if iterator is pointing to the end ! if(iter_ == data_[h_namespace_].end()) ! throw "h_list, get: Element not found !";
! return *iter_; }
! /* removes all elements with that value */ virtual void remove(Element value) *************** *** 188,192 **** */ virtual int getIterPos() ! { makeIterator(); return i_pos_; --- 182,186 ---- */ virtual int getIterPos() ! { makeIterator(); return i_pos_; *************** *** 246,250 **** i_pos_=data_[h_namespace_].size();
! // this is a hack to make the iterator, i'll change this ! iter_=data_[h_namespace_].begin(); for(int i = 0; i<i_pos_; i++) iter_++; --- 240,244 ---- i_pos_=data_[h_namespace_].size();
! // this is a hack to make the iterator, I'll change this ! iter_=data_[h_namespace_].begin(); for(int i = 0; i<i_pos_; i++) iter_++;
Index: HMultiMap.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/HMultiMap.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HMultiMap.h 25 Oct 2004 19:02:30 -0000 1.1.1.1 --- HMultiMap.h 9 Oct 2005 21:52:14 -0000 1.2 *************** *** 58,61 **** --- 58,68 ---- */ virtual ~HMultiMap() { } + + /* Add a key-value pair + */ + virtual void add(Element key, Element value) + { + this->data_[this->h_namespace_].insert(std::pair<Element,Element>(key,value)); + }
/* Get the Nr. of values from the specific Key
Index: ContainerBase.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/ContainerBase.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ContainerBase.h 29 Oct 2004 11:56:13 -0000 1.2 --- ContainerBase.h 9 Oct 2005 21:52:14 -0000 1.3 *************** *** 128,132 **** post("Library (STL) of C++"); post("for documentation see the help patches"); ! post("(by Georg Holzmann grh@gmx.at, 2004)"); post("------------------------------------------\n"); } --- 128,132 ---- post("Library (STL) of C++"); post("for documentation see the help patches"); ! post("(by Georg Holzmann grh@mur.at, 2004-2005)"); post("------------------------------------------\n"); }
Index: MapBase.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/MapBase.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MapBase.h 5 May 2005 23:00:55 -0000 1.2 --- MapBase.h 9 Oct 2005 21:52:14 -0000 1.3 *************** *** 52,62 **** */ virtual void add(Element key, Element value) ! { data_[h_namespace_].insert(std::pair<Element,Element>(key,value)); }
/* Get a value from the specific Key */ ! virtual Element &get(Element &key) const { ! ContTypeIterator iter = data_[h_namespace_].find(key); return (*iter).second; } --- 52,71 ---- */ virtual void add(Element key, Element value) ! { ! // first remove old entry, then insert ! this->data_[this->h_namespace_].erase(key); ! this->data_[this->h_namespace_].insert(std::pair<Element,Element>(key,value)); ! }
/* Get a value from the specific Key */ ! virtual Element &get(const Element &key) const { ! ContTypeIterator iter = this->data_[this->h_namespace_].find(key); ! ! // key was not found if iterator is pointing to the end ! if(iter == this->data_[this->h_namespace_].end()) ! throw "PDContainer, get: Element not found !"; ! return (*iter).second; } *************** *** 65,69 **** */ virtual void remove(const Element &key) ! { data_[h_namespace_].erase(key); }
/* prints all the data of the current namespace to the console --- 74,81 ---- */ virtual void remove(const Element &key) ! { ! if(!this->data_[this->h_namespace_].erase(key)) ! throw "PDContainer, remove: Element not found !"; ! }
/* prints all the data of the current namespace to the console *************** *** 111,167 **** void MapBase<ContainerType,ContTypeIterator>::printAll() { ! ContTypeIterator iter = data_[h_namespace_].begin();
! post("\n%s: printing namespace %s",dataname_.c_str(),h_namespace_.c_str()); post("--------------------------------------------------");
bool data_here = false; ! while(iter != data_[h_namespace_].end()) { ostringstream output("");
// Key: ! Element key((*iter).first); ! if (key.length > 1) // list { output << "list "; ! for (int i=0; i < key.length; i++) { ! if (key.atom[i].a_type == A_FLOAT) ! output << key.atom[i].a_w.w_float << " "; ! if (key.atom[i].a_type == A_SYMBOL) ! output << key.atom[i].a_w.w_symbol->s_name << " "; } } else // no list { ! if (key.atom[0].a_type == A_FLOAT) ! output << "float " << key.atom[0].a_w.w_float << " "; ! if (key.atom[0].a_type == A_SYMBOL) output << "symbol " ! << key.atom[0].a_w.w_symbol->s_name << " "; }
// Value: output << " -- "; ! Element el((*iter).second); ! if (el.length > 1) // list { output << "list "; ! for (int i=0; i < el.length; i++) { ! if (el.atom[i].a_type == A_FLOAT) ! output << el.atom[i].a_w.w_float << " "; ! if (el.atom[i].a_type == A_SYMBOL) ! output << el.atom[i].a_w.w_symbol->s_name << " "; } } else // no list { ! if (el.atom[0].a_type == A_FLOAT) // hier segfault nach get !!! ! output << "float " << el.atom[0].a_w.w_float << " "; ! if (el.atom[0].a_type == A_SYMBOL) output << "symbol " ! << el.atom[0].a_w.w_symbol->s_name << " "; }
--- 123,187 ---- void MapBase<ContainerType,ContTypeIterator>::printAll() { ! ContTypeIterator iter = this->data_[this->h_namespace_].begin();
! post("\n%s: printing namespace %s",this->dataname_.c_str(),this->h_namespace_.c_str()); post("--------------------------------------------------");
bool data_here = false; ! while(iter != this->data_[this->h_namespace_].end()) { ostringstream output("");
// Key: ! Element key = (*iter).first; ! if (key.getLength() > 1) // list { output << "list "; ! for (int i=0; i < key.getLength(); i++) { ! if (key.getAtom()[i].a_type == A_FLOAT) ! output << key.getAtom()[i].a_w.w_float << " "; ! if (key.getAtom()[i].a_type == A_SYMBOL) ! output << key.getAtom()[i].a_w.w_symbol->s_name << " "; ! if (key.getAtom()[i].a_type == A_POINTER) ! output << "(gpointer)" << key.getAtom()[i].a_w.w_gpointer << " "; } } else // no list { ! if (key.getAtom()[0].a_type == A_FLOAT) ! output << "float " << key.getAtom()[0].a_w.w_float << " "; ! if (key.getAtom()[0].a_type == A_SYMBOL) output << "symbol " ! << key.getAtom()[0].a_w.w_symbol->s_name << " "; ! if (key.getAtom()[0].a_type == A_POINTER) ! output << "pointer " << key.getAtom()[0].a_w.w_gpointer << " "; }
// Value: output << " -- "; ! Element el = (*iter).second; ! if (el.getLength() > 1) // list { output << "list "; ! for (int i=0; i < el.getLength(); i++) { ! if (el.getAtom()[i].a_type == A_FLOAT) ! output << el.getAtom()[i].a_w.w_float << " "; ! if (el.getAtom()[i].a_type == A_SYMBOL) ! output << el.getAtom()[i].a_w.w_symbol->s_name << " "; ! if (el.getAtom()[i].a_type == A_POINTER) ! output << "(gpointer)" << el.getAtom()[i].a_w.w_gpointer << " "; } } else // no list { ! if (el.getAtom()[0].a_type == A_FLOAT) // hier segfault nach get !!! ! output << "float " << el.getAtom()[0].a_w.w_float << " "; ! if (el.getAtom()[0].a_type == A_SYMBOL) output << "symbol " ! << el.getAtom()[0].a_w.w_symbol->s_name << " "; ! if (el.getAtom()[0].a_type == A_POINTER) ! output << "pointer " << el.getAtom()[0].a_w.w_gpointer << " "; }
*************** *** 191,212 **** { ofstream outfile; ! ContTypeIterator iter = data_[h_namespace_].begin(); ! outfile.open(filename.c_str()); ! if(!outfile) return false;
! while(iter != data_[h_namespace_].end()) { ! // add Key: ! Element key((*iter).first); ! ! for (int i=0; i < key.length; i++) { ! if (key.atom[i].a_type == A_FLOAT) ! outfile << "f " << key.atom[i].a_w.w_float << " "; ! if (key.atom[i].a_type == A_SYMBOL) ! outfile << "s " << key.atom[i].a_w.w_symbol->s_name << " "; }
--- 211,249 ---- { ofstream outfile; ! ContTypeIterator iter = this->data_[this->h_namespace_].begin(); ! outfile.open(filename.c_str()); ! if(!outfile) return false;
! while(iter != this->data_[this->h_namespace_].end()) { ! Element key = (*iter).first; ! Element el = (*iter).second; ! bool have_pointer = false; ! ! // check if there is a pointer and then don't store it ! for (int i=0; i < key.getLength(); i++) ! if (key.getAtom()[i].a_type == A_POINTER) ! have_pointer=true; ! for (int i=0; i < el.getLength(); i++) ! if (el.getAtom()[i].a_type == A_POINTER) ! have_pointer=true; ! ! if(have_pointer) ! { ! post("PDContainer: will not store pointers !!!"); ! iter++; ! } ! else ! { ! // add key: ! for (int i=0; i < key.getLength(); i++) { ! if (key.getAtom()[i].a_type == A_FLOAT) ! outfile << "f " << key.getAtom()[i].a_w.w_float << " "; ! if (key.getAtom()[i].a_type == A_SYMBOL) ! outfile << "s " << key.getAtom()[i].a_w.w_symbol->s_name << " "; }
*************** *** 214,229 ****
// add Value: ! Element el((*iter).second); ! ! for (int i=0; i < el.length; i++) { ! if (el.atom[i].a_type == A_FLOAT) ! outfile << "f " << el.atom[i].a_w.w_float << " "; ! if (el.atom[i].a_type == A_SYMBOL) ! outfile << "s " << el.atom[i].a_w.w_symbol->s_name << " "; }
outfile << endl; iter++; }
--- 251,265 ----
// add Value: ! for (int i=0; i < el.getLength(); i++) { ! if (el.getAtom()[i].a_type == A_FLOAT) ! outfile << "f " << el.getAtom()[i].a_w.w_float << " "; ! if (el.getAtom()[i].a_type == A_SYMBOL) ! outfile << "s " << el.getAtom()[i].a_w.w_symbol->s_name << " "; }
outfile << endl; iter++; + } }
*************** *** 243,247 **** { ostringstream output(""); ! ContTypeIterator iter = data_[h_namespace_].begin();
// add XML Header: --- 279,283 ---- { ostringstream output(""); ! ContTypeIterator iter = this->data_[this->h_namespace_].begin();
// add XML Header: *************** *** 249,269 **** << "<!DOCTYPE PDContainer SYSTEM " << "\"http://grh.mur.at/software/pdcontainer_multi.dtd\">\n" ! << "<PDContainer type="" << dataname_ << "">\n";
! while(iter != data_[h_namespace_].end()) { output << "<element>\n";
// add Key: - Element key((*iter).first); - output << "<key>\n";
! for (int i=0; i < key.length; i++) { ! if (key.atom[i].a_type == A_FLOAT) ! output << "<f> " << key.atom[i].a_w.w_float << " </f>\n"; ! if (key.atom[i].a_type == A_SYMBOL) ! output << "<s>" << key.atom[i].a_w.w_symbol->s_name << " </s>\n"; }
--- 285,323 ---- << "<!DOCTYPE PDContainer SYSTEM " << "\"http://grh.mur.at/software/pdcontainer_multi.dtd\">\n" ! << "<PDContainer type="" << this->dataname_ << "">\n";
! while(iter != this->data_[this->h_namespace_].end()) { + Element key((*iter).first); + Element el((*iter).second); + bool have_pointer = false; + + // check if there is a pointer and then don't store it + for (int i=0; i < key.getLength(); i++) + if (key.getAtom()[i].a_type == A_POINTER) + have_pointer=true; + for (int i=0; i < el.getLength(); i++) + if (el.getAtom()[i].a_type == A_POINTER) + have_pointer=true; + + if(have_pointer) + { + post("PDContainer: will not store pointers !!!"); + iter++; + } + else + { + output << "<element>\n";
// add Key: output << "<key>\n";
! for (int i=0; i < key.getLength(); i++) { ! if (key.getAtom()[i].a_type == A_FLOAT) ! output << "<f> " << key.getAtom()[i].a_w.w_float << " </f>\n"; ! if (key.getAtom()[i].a_type == A_SYMBOL) ! output << "<s>" << key.getAtom()[i].a_w.w_symbol->s_name << " </s>\n"; }
*************** *** 272,285 ****
// add Value: - Element el((*iter).second); - output << "<value>\n";
! for (int i=0; i < el.length; i++) { ! if (el.atom[i].a_type == A_FLOAT) ! output << "<f> " << el.atom[i].a_w.w_float << " </f>\n"; ! if (el.atom[i].a_type == A_SYMBOL) ! output << "<s>" << el.atom[i].a_w.w_symbol->s_name << " </s>\n"; }
--- 326,337 ----
// add Value: output << "<value>\n";
! for (int i=0; i < el.getLength(); i++) { ! if (el.getAtom()[i].a_type == A_FLOAT) ! output << "<f> " << el.getAtom()[i].a_w.w_float << " </f>\n"; ! if (el.getAtom()[i].a_type == A_SYMBOL) ! output << "<s>" << el.getAtom()[i].a_w.w_symbol->s_name << " </s>\n"; }
*************** *** 289,292 **** --- 341,346 ----
iter++; + + } }
*************** *** 393,400 **** // Key:
! t_atom *key_atom = new t_atom[key_count]; ! t_atom *val_atom = new t_atom[val_count]; if(key_atom == NULL || val_atom == NULL) ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str());
istringstream key_istr(key_str.str()); --- 447,454 ---- // Key:
! t_atom *key_atom = (t_atom*)getbytes(key_count*sizeof(t_atom)); ! t_atom *val_atom = (t_atom*)getbytes(val_count*sizeof(t_atom)); if(key_atom == NULL || val_atom == NULL) ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str());
istringstream key_istr(key_str.str()); *************** *** 431,445 **** }
! key.length = key_count; ! key.atom = (t_atom*)copybytes(key_atom, key_count * sizeof(t_atom)); ! ! el.length = val_count; ! el.atom = (t_atom*)copybytes(val_atom, val_count * sizeof(t_atom)); ! // insert the data ! data_[h_namespace_].insert(std::pair<Element,Element>(key,el));
! delete[] key_atom; ! delete[] val_atom; }
--- 485,495 ---- }
! key.setAtoms(key_count,key_atom); ! el.setAtoms(val_count, val_atom); // insert the data ! this->data_[this->h_namespace_].insert(std::pair<Element,Element>(key,el));
! freebytes(key_atom, key_count*sizeof(t_atom)); ! freebytes(val_atom, val_count*sizeof(t_atom)); }
*************** *** 492,496 **** }
! if( type != dataname_ ) post("readXML: importing data from %s!", type.c_str() );
--- 542,546 ---- }
! if( type != this->dataname_ ) post("readXML: importing data from %s!", type.c_str() );
*************** *** 510,517 **** key_count++;
! key_atom = new t_atom[key_count]; if(key_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str()); return false; } --- 560,567 ---- key_count++;
! key_atom = (t_atom*)getbytes(key_count*sizeof(t_atom)); if(key_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str()); return false; } *************** *** 556,563 **** val_count++;
! val_atom = new t_atom[val_count]; if(val_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str()); return false; } --- 606,613 ---- val_count++;
! val_atom = (t_atom*)getbytes(val_count*sizeof(t_atom)); if(val_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str()); return false; } *************** *** 590,604 ****
// add the element to the container ! key.length = key_count; ! key.atom = (t_atom*)copybytes(key_atom, key_count * sizeof(t_atom));
! el.length = val_count; ! el.atom = (t_atom*)copybytes(val_atom, val_count * sizeof(t_atom)); ! ! data_[h_namespace_].insert(std::pair<Element,Element>(key,el));
- delete[] key_atom; - delete[] val_atom; - parsed = true; } --- 640,650 ----
// add the element to the container ! key.setAtoms(key_count,key_atom); ! el.setAtoms(val_count,val_atom); ! this->data_[this->h_namespace_].insert(std::pair<Element,Element>(key,el));
! freebytes(key_atom, key_count*sizeof(t_atom)); ! freebytes(val_atom, val_count*sizeof(t_atom));
parsed = true; }
Index: SequBase.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/SequBase.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SequBase.h 5 May 2005 23:00:55 -0000 1.3 --- SequBase.h 9 Oct 2005 21:52:14 -0000 1.4 *************** *** 53,67 **** */ virtual void set(int index, Element value) ! { data_[h_namespace_][index] = value; }
/* get the element from the index */ virtual Element &get(int index) const ! { return data_[h_namespace_][index]; }
/* resize the sequence */ virtual void resize(int size) ! { data_[h_namespace_].resize(size); }
/* inserts an element at the end of --- 53,67 ---- */ virtual void set(int index, Element value) ! { this->data_[this->h_namespace_][index] = value; }
/* get the element from the index */ virtual Element &get(int index) const ! { return this->data_[this->h_namespace_][index]; }
/* resize the sequence */ virtual void resize(int size) ! { this->data_[this->h_namespace_].resize(size); }
/* inserts an element at the end of *************** *** 70,74 **** */ virtual void pushBack(Element value) ! { data_[h_namespace_].push_back(value); }
/* removes the element from the end of --- 70,74 ---- */ virtual void pushBack(Element value) ! { this->data_[this->h_namespace_].push_back(value); }
/* removes the element from the end of *************** *** 77,91 **** */ virtual void popBack() ! { data_[h_namespace_].pop_back(); }
/* returns the last element */ virtual Element &back() const ! { return data_[h_namespace_].back(); }
/* returns the first element */ virtual Element &front() const ! { return data_[h_namespace_].front(); }
/* inserts an element before the element --- 77,91 ---- */ virtual void popBack() ! { this->data_[this->h_namespace_].pop_back(); }
/* returns the last element */ virtual Element &back() const ! { return this->data_[this->h_namespace_].back(); }
/* returns the first element */ virtual Element &front() const ! { return this->data_[this->h_namespace_].front(); }
/* inserts an element before the element *************** *** 93,97 **** */ virtual void insert(int index, Element value) ! { data_[h_namespace_].insert(data_[h_namespace_].begin()+index, value); }
/* removes the element with that index from the --- 93,97 ---- */ virtual void insert(int index, Element value) ! { this->data_[this->h_namespace_].insert(this->data_[this->h_namespace_].begin()+index, value); }
/* removes the element with that index from the *************** *** 99,103 **** */ virtual void remove(int index) ! { data_[h_namespace_].erase(data_[h_namespace_].begin()+index); }
/* reads from an input file and adds the data to --- 99,103 ---- */ virtual void remove(int index) ! { this->data_[this->h_namespace_].erase(this->data_[this->h_namespace_].begin()+index); }
/* reads from an input file and adds the data to *************** *** 142,146 **** t_float number; int key_count; ! int max_index = data_[h_namespace_].size();
while (getline(infile, line)) --- 142,146 ---- t_float number; int key_count; ! int max_index = this->data_[this->h_namespace_].size();
while (getline(infile, line)) *************** *** 151,155 **** if(index < 0 || index >= max_index) { ! post("%s, read: wrong index !!",dataname_.c_str()); return false; } --- 151,155 ---- if(index < 0 || index >= max_index) { ! post("%s, read: wrong index !!",this->dataname_.c_str()); return false; } *************** *** 187,193 **** // into the objects and add them to the container
! t_atom *key_atom = new t_atom[key_count]; if(key_atom == NULL) ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str());
istringstream key_istr(key_str.str()); --- 187,194 ---- // into the objects and add them to the container
! t_atom *key_atom = (t_atom*)getbytes(key_count*sizeof(t_atom)); ! if(key_atom == NULL) ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str());
istringstream key_istr(key_str.str()); *************** *** 208,219 **** }
! key.length = key_count; ! key.atom = (t_atom*)copybytes(key_atom, key_count * sizeof(t_atom)); ! // insert the data ! data_[h_namespace_][index] = key; index++;
! delete[] key_atom; }
--- 209,218 ---- }
! key.setAtoms(key_count,key_atom); // insert the data ! this->data_[this->h_namespace_][index] = key; index++;
! freebytes(key_atom, key_count*sizeof(t_atom)); }
*************** *** 232,239 **** bool SequBase<ContainerType,ContTypeIterator>::readFromFile2XML(string filename, int index) { ! int max_index = data_[h_namespace_].size(); if(index < 0 || index >= max_index) { ! post("%s, read: wrong index !!",dataname_.c_str()); return false; } --- 231,238 ---- bool SequBase<ContainerType,ContTypeIterator>::readFromFile2XML(string filename, int index) { ! int max_index = this->data_[this->h_namespace_].size(); if(index < 0 || index >= max_index) { ! post("%s, read: wrong index !!",this->dataname_.c_str()); return false; } *************** *** 274,278 **** }
! if( type != dataname_ ) post("readXML: importing data from %s!", type.c_str() );
--- 273,277 ---- }
! if( type != this->dataname_ ) post("readXML: importing data from %s!", type.c_str() );
*************** *** 288,295 **** atoms++;
! el_atom = new t_atom[atoms]; if(el_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str()); return false; } --- 287,295 ---- atoms++;
! el_atom = (t_atom*)getbytes(atoms*sizeof(t_atom)); ! if(el_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str()); return false; } *************** *** 323,334 ****
// add the element to the container ! el.length = atoms; ! el.atom = (t_atom*)copybytes(el_atom, atoms * sizeof(t_atom));
// insert the data ! data_[h_namespace_][index] = el; index++;
! delete[] el_atom;
parsed = true; --- 323,333 ----
// add the element to the container ! el.setAtoms(atoms,el_atom);
// insert the data ! this->data_[this->h_namespace_][index] = el; index++;
! freebytes(el_atom, atoms*sizeof(t_atom));
parsed = true;
Index: GlobalStuff.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/GlobalStuff.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GlobalStuff.h 21 Sep 2005 11:52:49 -0000 1.5 --- GlobalStuff.h 9 Oct 2005 21:52:14 -0000 1.6 *************** *** 33,37 ****
// current version ! #define PDC_VERSION "0.1"
--- 33,37 ----
// current version ! #define PDC_VERSION "0.2"
*************** *** 52,55 **** --- 52,58 ---- return (strcmp(atom1.a_w.w_symbol->s_name, atom2.a_w.w_symbol->s_name) == 0); + + if(atom1.a_type == A_POINTER && atom2.a_type == A_POINTER) + return (atom1.a_w.w_gpointer == atom2.a_w.w_gpointer);
return false; *************** *** 63,78 **** class Element { ! public: t_atom *atom; int length;
! Element() : atom(0), length(0) { }
// Copy Constr. ! Element(const Element &src) { ! length = src.length; ! atom = (t_atom*)copybytes(src.atom, length * sizeof(t_atom)); }
--- 66,120 ---- class Element { ! private: t_atom *atom; int length;
! public: ! Element() : atom(NULL), length(0) { }
+ Element(int size_, t_atom *atom_) : atom(NULL), length(0) + { + if(atom_ && size_) + { + length = size_; + + // !!!! FIXME !!!! + // hack to avoid lockating too much memory + // (somewhere I read an uninitialized value ... + // ... but where !?) + if(length>999) + { + post("Element, constr1: invalid construction !!! should be fixed !!!"); + length=0; + atom=NULL; + return; + } + + atom = (t_atom*)copybytes(atom_, length*sizeof(t_atom)); + } + } + // Copy Constr. ! Element(const Element &src) : atom(NULL), length(0) { ! if(src.atom) ! { ! length = src.length; ! ! // !!!! FIXME !!!! ! // hack to avoid lockating too much memory ! // (somewhere I read an uninitialized value ... ! // ... but where !?) ! if(length>999) ! { ! post("Element, constr2: invalid construction !!! should be fixed !!!"); ! length=0; ! atom=NULL; ! return; ! } ! ! atom = (t_atom*)copybytes(src.atom, length*sizeof(t_atom)); ! } }
*************** *** 81,86 **** { if(atom) ! freebytes(atom, length); }
//Assignement Operator --- 123,165 ---- { if(atom) ! freebytes(atom, length*sizeof(t_atom)); ! } ! ! // set atoms and length ! void setAtoms(int size_, t_atom *atom_) ! { ! if(atom) ! { ! freebytes(atom, length*sizeof(t_atom)); ! length=0; ! atom=NULL; ! } ! ! if(atom_) ! { ! length = size_; ! ! // !!!! FIXME !!!! ! // hack to avoid lockating too much memory ! // (somewhere I read an uninitialized value ... ! // ... but where !?) ! if(length>999) ! { ! post("Element, setAtoms: invalid construction !!! should be fixed !!!"); ! length=0; ! atom=NULL; ! return; ! } ! ! atom = (t_atom*)copybytes(atom_, length*sizeof(t_atom)); ! } } + + int getLength() + { return length; } + + // shallow copy !!! + t_atom *getAtom() + { return atom; }
//Assignement Operator *************** *** 88,95 **** { if(atom) ! freebytes(atom, length);
- length = src.length; - atom = (t_atom*)copybytes(src.atom, length * sizeof(t_atom)); return (*this); } --- 167,195 ---- { if(atom) ! { ! freebytes(atom, length*sizeof(t_atom)); ! length=0; ! atom=NULL; ! } ! ! if(src.atom) ! { ! length = src.length; ! ! // !!!! FIXME !!!! ! // hack to avoid lockating too much memory ! // (somewhere I read an uninitialized value ... ! // ... but where !?) ! if(length>999) ! { ! post("Element, assignment: invalid construction !!! should be fixed !!!"); ! length=0; ! atom=NULL; ! return (*this); ! } ! ! atom = (t_atom*)copybytes(src.atom, length*sizeof(t_atom)); ! }
return (*this); } *************** *** 127,137 **** } }
if( atom[index].a_type == A_FLOAT ! && key.atom[index].a_type == A_SYMBOL ) return true;
! if( atom[index].a_type == A_SYMBOL ! && key.atom[index].a_type == A_FLOAT ) return false;
--- 227,251 ---- } } + + // definition: + // A_FLOAT < A_SYMBOL < A_POINTER
if( atom[index].a_type == A_FLOAT ! && key.atom[index].a_type != A_FLOAT ) return true;
! if( atom[index].a_type == A_SYMBOL ) ! { ! if( key.atom[index].a_type == A_FLOAT ) ! return false; ! if( key.atom[index].a_type == A_POINTER ) ! return true; ! } ! ! ! // compare, when they are the same type: ! ! if( atom[index].a_type == A_POINTER ! && key.atom[index].a_type != A_POINTER ) return false;
*************** *** 143,147 **** && key.atom[index].a_type == A_SYMBOL ) return (strcmp(atom[index].a_w.w_symbol->s_name, ! key.atom[index].a_w.w_symbol->s_name) < 0); return false; --- 257,265 ---- && key.atom[index].a_type == A_SYMBOL ) return (strcmp(atom[index].a_w.w_symbol->s_name, ! key.atom[index].a_w.w_symbol->s_name) < 0); ! ! if( atom[index].a_type == A_POINTER ! && key.atom[index].a_type == A_POINTER ) ! return (atom[index].a_w.w_gpointer < key.atom[index].a_w.w_gpointer); return false;
Index: QueueStack.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/QueueStack.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** QueueStack.h 29 Oct 2004 11:56:13 -0000 1.2 --- QueueStack.h 9 Oct 2005 21:52:14 -0000 1.3 *************** *** 54,58 **** */ virtual void pop() ! { data_[h_namespace_].pop(); } };
--- 54,58 ---- */ virtual void pop() ! { this->data_[this->h_namespace_].pop(); } };
Index: HMap.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/HMap.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HMap.h 25 Oct 2004 19:02:30 -0000 1.1.1.1 --- HMap.h 9 Oct 2005 21:52:14 -0000 1.2 *************** *** 25,28 **** --- 25,32 ---- public MapBase< map<Element,Element>, map<Element,Element>::iterator > { + // gcc4.0 food: + //this->data_; + //this->h_namespace_; + //this->dataname_;
private:
Index: SimpleBase.h =================================================================== RCS file: /cvsroot/pure-data/externals/PDContainer/include/SimpleBase.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SimpleBase.h 5 May 2005 23:00:55 -0000 1.2 --- SimpleBase.h 9 Oct 2005 21:52:14 -0000 1.3 *************** *** 77,81 **** * returns true on success */ ! virtual bool saveToFileXML(string filename);
/* reads from an input file and adds the data to --- 77,81 ---- * returns true on success */ ! virtual bool saveToFileXML(string filename);
/* reads from an input file and adds the data to *************** *** 100,115 **** void SimpleBase<ContainerType,ContTypeIterator>::printAll() { ! ContTypeIterator iter = data_[h_namespace_].begin();
! post("\n%s: printing namespace %s",dataname_.c_str(),h_namespace_.c_str()); post("--------------------------------------------------");
bool data_here = false; ! while(iter != data_[h_namespace_].end()) { ostringstream output("");
Element key((*iter)); ! if(key.length == 0) { iter++; --- 100,115 ---- void SimpleBase<ContainerType,ContTypeIterator>::printAll() { ! ContTypeIterator iter = this->data_[this->h_namespace_].begin();
! post("\n%s: printing namespace %s",this->dataname_.c_str(),this->h_namespace_.c_str()); post("--------------------------------------------------");
bool data_here = false; ! while(iter != this->data_[this->h_namespace_].end()) { ostringstream output("");
Element key((*iter)); ! if(key.getLength() == 0) { iter++; *************** *** 117,138 **** }
! if (key.length > 1) // list { output << "list "; ! for (int i=0; i < key.length; i++) { ! if (key.atom[i].a_type == A_FLOAT) ! output << key.atom[i].a_w.w_float << " "; ! if (key.atom[i].a_type == A_SYMBOL) ! output << key.atom[i].a_w.w_symbol->s_name << " "; } } else // no list { ! if (key.atom[0].a_type == A_FLOAT) ! output << "float " << key.atom[0].a_w.w_float << " "; ! if (key.atom[0].a_type == A_SYMBOL) output << "symbol " ! << key.atom[0].a_w.w_symbol->s_name << " "; }
--- 117,142 ---- }
! if (key.getLength() > 1) // list { output << "list "; ! for (int i=0; i < key.getLength(); i++) { ! if (key.getAtom()[i].a_type == A_FLOAT) ! output << key.getAtom()[i].a_w.w_float << " "; ! if (key.getAtom()[i].a_type == A_SYMBOL) ! output << key.getAtom()[i].a_w.w_symbol->s_name << " "; ! if (key.getAtom()[i].a_type == A_POINTER) ! output << "(gpointer)" << key.getAtom()[i].a_w.w_gpointer << " "; } } else // no list { ! if (key.getAtom()[0].a_type == A_FLOAT) ! output << "float " << key.getAtom()[0].a_w.w_float << " "; ! if (key.getAtom()[0].a_type == A_SYMBOL) output << "symbol " ! << key.getAtom()[0].a_w.w_symbol->s_name << " "; ! if (key.getAtom()[0].a_type == A_POINTER) ! output << "pointer " << key.getAtom()[0].a_w.w_gpointer << " "; }
*************** *** 154,169 **** void SimpleBase<ContainerType,ContTypeIterator>::printAllIndex() { ! ContTypeIterator iter = data_[h_namespace_].begin();
! post("\n%s: printing namespace %s",dataname_.c_str(),h_namespace_.c_str()); post("--------------------------------------------------");
bool data_here = false; int i=0; ! while(iter != data_[h_namespace_].end()) { ostringstream output("");
Element key((*iter)); ! if(key.length == 0) { iter++; i++; --- 158,173 ---- void SimpleBase<ContainerType,ContTypeIterator>::printAllIndex() { ! ContTypeIterator iter = this->data_[this->h_namespace_].begin();
! post("\n%s: printing namespace %s",this->dataname_.c_str(),this->h_namespace_.c_str()); post("--------------------------------------------------");
bool data_here = false; int i=0; ! while(iter != this->data_[this->h_namespace_].end()) { ostringstream output("");
Element key((*iter)); ! if(key.getLength() == 0) { iter++; i++; *************** *** 171,192 **** }
! if (key.length > 1) // list { output << "list "; ! for (int i=0; i < key.length; i++) { ! if (key.atom[i].a_type == A_FLOAT) ! output << key.atom[i].a_w.w_float << " "; ! if (key.atom[i].a_type == A_SYMBOL) ! output << key.atom[i].a_w.w_symbol->s_name << " "; } } else // no list { ! if (key.atom[0].a_type == A_FLOAT) ! output << "float " << key.atom[0].a_w.w_float << " "; ! if (key.atom[0].a_type == A_SYMBOL) output << "symbol " ! << key.atom[0].a_w.w_symbol->s_name << " "; }
--- 175,200 ---- }
! if (key.getLength() > 1) // list { output << "list "; ! for (int i=0; i < key.getLength(); i++) { ! if (key.getAtom()[i].a_type == A_FLOAT) ! output << key.getAtom()[i].a_w.w_float << " "; ! if (key.getAtom()[i].a_type == A_SYMBOL) ! output << key.getAtom()[i].a_w.w_symbol->s_name << " "; ! if (key.getAtom()[i].a_type == A_POINTER) ! output << "(gpointer)" << key.getAtom()[i].a_w.w_gpointer << " "; } } else // no list { ! if (key.getAtom()[0].a_type == A_FLOAT) ! output << "float " << key.getAtom()[0].a_w.w_float << " "; ! if (key.getAtom()[0].a_type == A_SYMBOL) output << "symbol " ! << key.getAtom()[0].a_w.w_symbol->s_name << " "; ! if (key.getAtom()[0].a_type == A_POINTER) ! output << "pointer " << key.getAtom()[0].a_w.w_gpointer << " "; }
*************** *** 217,221 **** { ofstream outfile; ! ContTypeIterator iter = data_[h_namespace_].begin();
outfile.open(filename.c_str()); --- 225,229 ---- { ofstream outfile; ! ContTypeIterator iter = this->data_[this->h_namespace_].begin();
outfile.open(filename.c_str()); *************** *** 224,241 **** return false;
! while(iter != data_[h_namespace_].end()) { Element key((*iter));
! for (int i=0; i < key.length; i++) { ! if (key.atom[i].a_type == A_FLOAT) ! outfile << "f " << key.atom[i].a_w.w_float << " "; ! if (key.atom[i].a_type == A_SYMBOL) ! outfile << "s " << key.atom[i].a_w.w_symbol->s_name << " "; }
outfile << endl; iter++; }
--- 232,265 ---- return false;
! while(iter != this->data_[this->h_namespace_].end()) { Element key((*iter)); + bool have_pointer = false;
! // check for pointers first ! for (int i=0; i < key.getLength(); i++) ! if (key.getAtom()[i].a_type == A_POINTER) ! have_pointer = true; ! ! if(have_pointer) ! { ! post("PDContainer warning: pointers can't be saved and are ignored !!!"); ! iter++; ! } ! else ! { ! ! for (int i=0; i < key.getLength(); i++) { ! if (key.getAtom()[i].a_type == A_FLOAT) ! outfile << "f " << key.getAtom()[i].a_w.w_float << " "; ! if (key.getAtom()[i].a_type == A_SYMBOL) ! outfile << "s " << key.getAtom()[i].a_w.w_symbol->s_name << " "; }
outfile << endl; iter++; + + } }
*************** *** 255,259 **** { ostringstream output(""); ! ContTypeIterator iter = data_[h_namespace_].begin();
// add XML Header: --- 279,283 ---- { ostringstream output(""); ! ContTypeIterator iter = this->data_[this->h_namespace_].begin();
// add XML Header: *************** *** 261,280 **** << "<!DOCTYPE PDContainer SYSTEM " << "\"http://grh.mur.at/software/pdcontainer_simple.dtd\">\n" ! << "<PDContainer type="" << dataname_ << "">\n";
! while(iter != data_[h_namespace_].end()) { - output << "<element>\n"; - // add Element: Element el((*iter));
! for (int i=0; i < el.length; i++) { ! if (el.atom[i].a_type == A_FLOAT) ! output << "<f> " << el.atom[i].a_w.w_float << " </f>\n"; ! if (el.atom[i].a_type == A_SYMBOL) ! output << "<s>" << el.atom[i].a_w.w_symbol->s_name << " </s>\n"; }
--- 285,318 ---- << "<!DOCTYPE PDContainer SYSTEM " << "\"http://grh.mur.at/software/pdcontainer_simple.dtd\">\n" ! << "<PDContainer type="" << this->dataname_ << "">\n";
! while(iter != this->data_[this->h_namespace_].end()) { // add Element: Element el((*iter)); + bool have_pointer = false; + + // check for pointers first + for (int i=0; i < el.getLength(); i++) + if (el.getAtom()[i].a_type == A_POINTER) + have_pointer = true;
! if(have_pointer) { ! post("PDContainer warning: pointers can't be saved and are ignored !!!"); ! iter++; ! } ! else ! { ! ! output << "<element>\n"; ! ! for (int i=0; i < el.getLength(); i++) ! { ! if (el.getAtom()[i].a_type == A_FLOAT) ! output << "<f> " << el.getAtom()[i].a_w.w_float << " </f>\n"; ! if (el.getAtom()[i].a_type == A_SYMBOL) ! output << "<s>" << el.getAtom()[i].a_w.w_symbol->s_name << " </s>\n"; }
*************** *** 282,285 **** --- 320,325 ----
iter++; + + } }
*************** *** 358,364 **** // into the objects and add them to the container
! t_atom *key_atom = new t_atom[key_count]; if(key_atom == NULL) ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str());
istringstream key_istr(key_str.str()); --- 398,404 ---- // into the objects and add them to the container
! t_atom *key_atom = (t_atom*)getbytes(key_count*sizeof(t_atom)); if(key_atom == NULL) ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str());
istringstream key_istr(key_str.str()); *************** *** 379,389 **** }
! key.length = key_count; ! key.atom = (t_atom*)copybytes(key_atom, key_count * sizeof(t_atom));
// insert the data ! data_[h_namespace_].insert(data_[h_namespace_].end(),key);
! delete[] key_atom; }
--- 419,428 ---- }
! key.setAtoms(key_count,key_atom);
// insert the data ! this->data_[this->h_namespace_].insert(this->data_[this->h_namespace_].end(),key);
! freebytes(key_atom, key_count*sizeof(t_atom)); }
*************** *** 435,439 **** }
! if( type != dataname_ ) post("readXML: importing data from %s!", type.c_str() );
--- 474,478 ---- }
! if( type != this->dataname_ ) post("readXML: importing data from %s!", type.c_str() );
*************** *** 449,456 **** atoms++;
! el_atom = new t_atom[atoms]; if(el_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",dataname_.c_str()); return false; } --- 488,495 ---- atoms++;
! el_atom = (t_atom*)getbytes(atoms*sizeof(t_atom)); if(el_atom == NULL) { ! post("Fatal Error Out Of Memory (%s-readFromFile)",this->dataname_.c_str()); return false; } *************** *** 484,494 ****
// add the element to the container ! el.length = atoms; ! el.atom = (t_atom*)copybytes(el_atom, atoms * sizeof(t_atom));
// insert it in the container ! data_[h_namespace_].insert(data_[h_namespace_].end(),el);
! delete[] el_atom;
parsed = true; --- 523,532 ----
// add the element to the container ! el.setAtoms(atoms,el_atom);
// insert it in the container ! this->data_[this->h_namespace_].insert(this->data_[this->h_namespace_].end(),el);
! freebytes(el_atom, atoms*sizeof(t_atom));
parsed = true;