diff options
author | Georg Holzmann <grholzi@users.sourceforge.net> | 2005-10-21 11:56:32 +0000 |
---|---|---|
committer | Georg Holzmann <grholzi@users.sourceforge.net> | 2005-10-21 11:56:32 +0000 |
commit | 1d6d1e8c73193f57a9c98387ea42eb91eb4d21d1 (patch) | |
tree | 8d0853fe30b12c73774c786f02f3d3011b147d4c /PDContainer/src | |
parent | df8ac7c52ff0dfc8e2ba828c4226ed34b0e9ebfc (diff) |
only moving to a new directory
svn path=/trunk/externals/grh/; revision=3740
Diffstat (limited to 'PDContainer/src')
-rwxr-xr-x | PDContainer/src/HDeque.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HList.cpp | 111 | ||||
-rwxr-xr-x | PDContainer/src/HMap.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HMultiMap.cpp | 38 | ||||
-rwxr-xr-x | PDContainer/src/HMultiSet.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HPrioQueue.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HQueue.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HSet.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HStack.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/HVector.cpp | 15 | ||||
-rwxr-xr-x | PDContainer/src/PDContainer.cpp | 78 | ||||
-rwxr-xr-x | PDContainer/src/h_deque.cpp | 578 | ||||
-rwxr-xr-x | PDContainer/src/h_list.cpp | 442 | ||||
-rwxr-xr-x | PDContainer/src/h_map.cpp | 334 | ||||
-rwxr-xr-x | PDContainer/src/h_multimap.cpp | 331 | ||||
-rwxr-xr-x | PDContainer/src/h_multiset.cpp | 220 | ||||
-rwxr-xr-x | PDContainer/src/h_prioqueue.cpp | 250 | ||||
-rwxr-xr-x | PDContainer/src/h_queue.cpp | 165 | ||||
-rwxr-xr-x | PDContainer/src/h_set.cpp | 220 | ||||
-rwxr-xr-x | PDContainer/src/h_stack.cpp | 165 | ||||
-rwxr-xr-x | PDContainer/src/h_vector.cpp | 488 |
21 files changed, 3540 insertions, 0 deletions
diff --git a/PDContainer/src/HDeque.cpp b/PDContainer/src/HDeque.cpp new file mode 100755 index 0000000..3a1c317 --- /dev/null +++ b/PDContainer/src/HDeque.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HDeque.cpp + + +#include "include/HDeque.h" + diff --git a/PDContainer/src/HList.cpp b/PDContainer/src/HList.cpp new file mode 100755 index 0000000..9a5935f --- /dev/null +++ b/PDContainer/src/HList.cpp @@ -0,0 +1,111 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HList.cpp + + +#include "include/HList.h" + + +//---------------------------------------------------- +/* reads from an input file and adds the data to + * the current namespace + * Fileformat: see saveToFile + * returns true on success + */ +bool HList::readFromFile(string filename) +{ + makeIterator(); + + ifstream infile; + infile.open(filename.c_str()); + + if(!infile) + return false; + + Element key; + + string line; + bool go_on = false; + char type; + string symbol; + t_float number; + int key_count; + + while (getline(infile, line)) + { + // first parse the instream, to get the number of atoms + // (= size of the list) + + istringstream instream(line); + ostringstream key_str(""); + + go_on = false; key_count = 0; + while(!go_on) + { + instream >> type; + if (instream.eof()) + { + go_on = true; + break; + } + if (type == 's') + { + key_count++; + instream >> symbol; + key_str << "s " << symbol; + } + if (type == 'f') + { + key_count++; + instream >> number; + key_str << "f " << number; + } + if (instream.eof()) + go_on = true; + key_str << " "; + } + + // now objects, parse again the data + // 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)",dataname_.c_str()); + + istringstream key_istr(key_str.str()); + + for(int i = 0; i < key_count; i++) + { + key_istr >> type; + if (type == 's') + { + key_istr >> symbol; + SETSYMBOL(&key_atom[i],gensym(const_cast<char*>(symbol.c_str()))); + } + if (type == 'f') + { + key_istr >> number; + SETFLOAT(&key_atom[i],number); + } + } + + key.setAtoms(key_count,key_atom); + + // insert the data + data_[h_namespace_].insert(iter_,key); + + freebytes(key_atom, key_count*sizeof(t_atom)); + } + + infile.close(); + + return true; +} diff --git a/PDContainer/src/HMap.cpp b/PDContainer/src/HMap.cpp new file mode 100755 index 0000000..c7e8534 --- /dev/null +++ b/PDContainer/src/HMap.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HMap.cpp + + +#include "include/HMap.h" + diff --git a/PDContainer/src/HMultiMap.cpp b/PDContainer/src/HMultiMap.cpp new file mode 100755 index 0000000..ecc482e --- /dev/null +++ b/PDContainer/src/HMultiMap.cpp @@ -0,0 +1,38 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HMultiMap.cpp + + +#include "include/HMultiMap.h" + + +//--------------------------------------------------- +/* Get a value from the specific Key with the index number + * index starts with 0 + * returns an element wich points to 0 if nothing was found !!! + */ +Element &HMultiMap::get(Element &key, int index) const +{ + int count = 0; + + for (multimap<Element,Element>::iterator it = data_[h_namespace_].begin(); + it != data_[h_namespace_].end(); ++it) + { + if ((*it).first == key) + { + if(index == count++) + return ((*it).second); + } + } + + // throw an exception if nothing was found + throw "h_multimap, get: Element not found !"; +} diff --git a/PDContainer/src/HMultiSet.cpp b/PDContainer/src/HMultiSet.cpp new file mode 100755 index 0000000..07dd564 --- /dev/null +++ b/PDContainer/src/HMultiSet.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HMultiSet.cpp + + +#include "include/HMultiSet.h" + diff --git a/PDContainer/src/HPrioQueue.cpp b/PDContainer/src/HPrioQueue.cpp new file mode 100755 index 0000000..f998530 --- /dev/null +++ b/PDContainer/src/HPrioQueue.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HPrioQueue.cpp + + +#include "include/HPrioQueue.h" + diff --git a/PDContainer/src/HQueue.cpp b/PDContainer/src/HQueue.cpp new file mode 100755 index 0000000..0fa012b --- /dev/null +++ b/PDContainer/src/HQueue.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HQueue.cpp + + +#include "include/HQueue.h" + diff --git a/PDContainer/src/HSet.cpp b/PDContainer/src/HSet.cpp new file mode 100755 index 0000000..f6caf2b --- /dev/null +++ b/PDContainer/src/HSet.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HSet.cpp + + +#include "include/HSet.h" + diff --git a/PDContainer/src/HStack.cpp b/PDContainer/src/HStack.cpp new file mode 100755 index 0000000..ea9fc35 --- /dev/null +++ b/PDContainer/src/HStack.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HStack.cpp + + +#include "include/HStack.h" + diff --git a/PDContainer/src/HVector.cpp b/PDContainer/src/HVector.cpp new file mode 100755 index 0000000..94616c4 --- /dev/null +++ b/PDContainer/src/HVector.cpp @@ -0,0 +1,15 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// HVector.cpp + + +#include "include/HVector.h" + diff --git a/PDContainer/src/PDContainer.cpp b/PDContainer/src/PDContainer.cpp new file mode 100755 index 0000000..fc27477 --- /dev/null +++ b/PDContainer/src/PDContainer.cpp @@ -0,0 +1,78 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// PDContainer.cpp + + +#include "include/GlobalStuff.h" + + +typedef struct PDContainer +{ + t_object x_obj; +} t_PDContainer; + +t_class *PDContainer_class; + +static void PDContainer_help(void) +{ + post("\nPD-Container, Version: "PDC_VERSION""); + post("------------------------------------------"); + post("this is an implementation of the container"); + post("objects from the Standard Template"); + post("Library (STL) of C++"); + post("for documentation see the help patches"); + post("(by Georg Holzmann <grh@mur.at>, 2004)"); + post("------------------------------------------\n"); +} + +static void *PDContainer_new(void) +{ + t_PDContainer *x = (t_PDContainer *)pd_new(PDContainer_class); + return (void *)x; +} + +//----------------------------------------------------- +// declaration of the setup functions: +void h_map_setup(); +void h_multimap_setup(); +void h_set_setup(); +void h_multiset_setup(); +void h_vector_setup(); +void h_deque_setup(); +void h_queue_setup(); +void h_priority_queue_setup(); +void h_stack_setup(); +void h_list_setup(); +//-end-of-declaration---------------------------------- + +extern "C" void PDContainer_setup(void) +{ + //--------------------------------------------------- + // call all the setup functions: + h_map_setup(); + h_multimap_setup(); + h_set_setup(); + h_multiset_setup(); + h_vector_setup(); + h_deque_setup(); + h_queue_setup(); + h_priority_queue_setup(); + h_stack_setup(); + h_list_setup(); + //-end----------------------------------------------- + + post("\nPD-Container, Version: "PDC_VERSION", by Georg Holzmann <grh@mur.at>, 2004-2005"); + + // without an argument the following two methods wont work ??? why?? because of c++? + PDContainer_class = class_new(gensym("PDContainer"), (t_newmethod)PDContainer_new, + 0, sizeof(t_PDContainer), CLASS_DEFAULT, A_DEFFLOAT, 0); + class_addmethod(PDContainer_class, (t_method)PDContainer_help, gensym("help"), A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_deque.cpp b/PDContainer/src/h_deque.cpp new file mode 100755 index 0000000..6246a51 --- /dev/null +++ b/PDContainer/src/h_deque.cpp @@ -0,0 +1,578 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_deque.cpp + + +#include "include/HDeque.h" + + +static t_class *h_deque_class; +static t_class *proxy_class; + +typedef struct _h_deque +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HDeque *hdeque; + Element value; + bool event_set; +} t_h_deque; + +typedef struct proxy +{ + t_object obj; + t_int index; // number of proxy inlet(s) + t_h_deque *x; // we'll put the other struct in here +} t_proxy; + +static void h_deque_set(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_deque, set: invalid index!"); + return; + } + + if ( index >= x->hdeque->getSize() || index < 0 ) + { + post("h_deque, set: invalid index!"); + return; + } + + if(!x->event_set) + { + post("h_deque, set: you must first set a value at right inlet!"); + return; + } + + x->hdeque->set( index , x->value); + x->event_set = false; +} + +static void h_deque_insert(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_deque, insert: invalid index!"); + return; + } + + if ( index >= x->hdeque->getSize() || index < 0 ) + { + post("h_deque, insert: invalid index!"); + return; + } + + if(!x->event_set) + { + post("h_deque, insert: you must first set a value at right inlet!"); + return; + } + + x->hdeque->insert( index , x->value); + x->event_set = false; +} + +static void h_deque_value(t_proxy *p, t_symbol *s, int argc, t_atom *argv) +{ + t_h_deque *x = (t_h_deque *)(p->x); + + // symbol without selector "symbol": + if(argc == 0) + { + t_atom tmp; + SETSYMBOL(&tmp, s); + x->value.setAtoms(1, &tmp); + x->event_set = true; + return; + } + + // input is a list without selector "list": + if ( argc && (strcmp(s->s_name,"list")!=0) + && (strcmp(s->s_name,"float")!=0) + && (strcmp(s->s_name,"symbol")!=0) + && (strcmp(s->s_name,"pointer")!=0) ) + { + t_atom *atoms = (t_atom*)getbytes( (argc+1)*sizeof(t_atom) ); + + // add the selector symbol to the list: + SETSYMBOL(atoms, s); + + for(int i=0; i<argc; i++) + { + if(argv[i].a_type == A_FLOAT) + SETFLOAT(&atoms[i+1],argv[i].a_w.w_float); + if(argv[i].a_type == A_SYMBOL) + SETSYMBOL(&atoms[i+1],argv[i].a_w.w_symbol); + if(argv[i].a_type == A_POINTER) + SETPOINTER(&atoms[i+1],argv[i].a_w.w_gpointer); + } + + x->value.setAtoms(argc+1, atoms); + + x->event_set = true; + freebytes(atoms, (argc+1)*sizeof(t_atom)); + return; + } + + // "normal" input (list, float or symbol): + if (argc) + { + x->value.setAtoms(argc, argv); + x->event_set = true; + return; + } +} + +static void h_deque_get(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_deque, get: invalid index!"); + return; + } + + if ( index >= x->hdeque->getSize() || index < 0 ) + { + post("h_deque, get: invalid index!"); + return; + } + + Element output = x->hdeque->get( index ); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); +} + +static void h_deque_push_back(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hdeque->pushBack(key); + } + else + post("h_deque, pushback: no arguments"); +} + +static void h_deque_pop_back(t_h_deque *x) +{ + if(x->hdeque->getSize()<=0) + { + post("h_deque, popback: size is already 0 !"); + return; + } + + x->hdeque->popBack(); +} + +static void h_deque_back(t_h_deque *x) +{ + if(x->hdeque->getSize() == 0) + { + post("h_deque, back: size is 0 !"); + return; + } + + Element output = x->hdeque->back(); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); +} + +static void h_deque_push_front(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hdeque->pushFront(key); + } + else + post("h_deque, pushfront: no arguments"); +} + +static void h_deque_pop_front(t_h_deque *x) +{ + if(x->hdeque->getSize()<=0) + { + post("h_deque, popfront: size is already 0 !"); + return; + } + + x->hdeque->popFront(); +} + +static void h_deque_front(t_h_deque *x) +{ + if(x->hdeque->getSize() == 0) + { + post("h_deque, front: size is 0 !"); + return; + } + + Element output = x->hdeque->front(); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); +} + +static void h_deque_remove(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_deque, remove: invalid index!"); + return; + } + + if ( index >= x->hdeque->getSize() || index < 0 ) + { + post("h_deque, remove: invalid index!"); + return; + } + + x->hdeque->remove(index); + x->event_set = false; +} + +static void h_deque_resize(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + int size; + if(argc && (argv[0].a_type == A_FLOAT)) + size = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_deque, resize: invalid index!"); + return; + } + + if ( size < 0 ) + { + post("h_deque, size: invalid size!"); + return; + } + + x->hdeque->resize( size ); +} + +static void h_deque_getsize(t_h_deque *x) +{ + outlet_float(x->out1,x->hdeque->getSize()); +} + +static void h_deque_help(t_h_deque *x) +{ + x->hdeque->help(); +} + +static void h_deque_set_namespace(t_h_deque *x, t_symbol *s) +{ + x->hdeque->setNamespace(s->s_name); +} + +static void h_deque_get_namespace(t_h_deque *x) +{ + post("h_deque current namespace: %s",x->hdeque->getNamespace().c_str()); +} + +static void h_deque_print(t_h_deque *x) +{ + x->hdeque->printAllIndex(); +} + +static void h_deque_clear(t_h_deque *x) +{ + x->hdeque->clearNamespace(); +} + +static void h_deque_clear_all(t_h_deque *x) +{ + x->hdeque->clearAll(); +} + +static void h_deque_save(t_h_deque *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hdeque->saveToFile(filename)) + post("h_deque: data of namespace %s written to file %s", + x->hdeque->getNamespace().c_str(),s->s_name); + else + post("h_deque: couldn't write to file %s",s->s_name); +} + +static void h_deque_read(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hdeque->readFromFile(filename)) + post("h_deque: couldn't read from file %s",s->s_name); +} + +static void h_deque_read_at(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + string symbol; + int index=0; + + switch(argc) + { + default: + post("h_deque read: only two argument are possible!"); + break; + case 2: + symbol = argv[0].a_w.w_symbol->s_name; + index = (int)argv[1].a_w.w_float; + break; + case 1: + symbol = argv[0].a_w.w_symbol->s_name; + index = 0; + break; + case 0: + post("h_deque read: no filename!"); + } + + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, (char*)symbol.c_str(), filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hdeque->readFromFile2(filename,index)) + post("h_deque: couldn't read from file %s",s->s_name); +} + +static void h_deque_save_xml(t_h_deque *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hdeque->saveToFileXML(filename)) + post("h_deque: data of namespace %s written to file %s", + x->hdeque->getNamespace().c_str(),s->s_name); + else + post("h_deque: couldn't write to file %s",s->s_name); +} + +static void h_deque_read_xml(t_h_deque *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hdeque->readFromFileXML(filename)) + post("h_deque: couldn't read from file %s",s->s_name); +} + +static void h_deque_read_at_xml(t_h_deque *x, t_symbol *s, int argc, t_atom *argv) +{ + string symbol; + int index=0; + + switch(argc) + { + default: + post("h_deque read: only two argument are possible!"); + break; + case 2: + symbol = argv[0].a_w.w_symbol->s_name; + index = (int)argv[1].a_w.w_float; + break; + case 1: + symbol = argv[0].a_w.w_symbol->s_name; + index = 0; + break; + case 0: + post("h_deque read: no filename!"); + } + + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, (char*)symbol.c_str(), filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hdeque->readFromFile2XML(filename,index)) + post("h_deque: couldn't read from file %s",s->s_name); +} + +static void *h_deque_new(t_symbol *s, int argc, t_atom *argv) +{ + t_h_deque *x = (t_h_deque *)pd_new(h_deque_class); + t_proxy *inlet = (t_proxy *)pd_new(proxy_class); // for the proxy inlet + + inlet->x = x; // make x visible to the proxy inlets + + switch(argc) + { + default: + post("h_deque warning: only one argument for namespace is possible!"); + case 1: + x->hdeque = new HDeque(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hdeque = new HDeque(); + break; + } + + // we are going to create a proxy inlet no. 0 + // it belongs to the object x but the destination is t_proxy + inlet->index = 0; + inlet_new(&x->x_obj, &inlet->obj.ob_pd, 0,0); + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_deque_free(t_h_deque *x) +{ + delete x->hdeque; + return (void *)x; +} + +void h_deque_setup(void) +{ + // the object class + h_deque_class = class_new(gensym("h_deque"), (t_newmethod)h_deque_new, + (t_method)h_deque_free, sizeof(t_h_deque), + CLASS_DEFAULT, A_GIMME, 0); + + // a class for the proxy-inlet + proxy_class = class_new(gensym("h_deque_proxy"), NULL, NULL, sizeof(t_proxy), + CLASS_PD|CLASS_NOINLET, A_NULL); + + class_addmethod(h_deque_class, (t_method)h_deque_set, + gensym("set"), A_GIMME, 0); + class_addmethod(h_deque_class, (t_method)h_deque_insert, + gensym("insert"), A_GIMME, 0); + class_addanything(proxy_class, (t_method)h_deque_value); // the right inlet + class_addmethod(h_deque_class, (t_method)h_deque_get, + gensym("get"), A_GIMME, 0); + class_addmethod(h_deque_class, (t_method)h_deque_push_back, + gensym("pushback"), A_GIMME, 0); + class_addmethod(h_deque_class, (t_method)h_deque_pop_back, + gensym("popback"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_back, + gensym("back"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_push_front, + gensym("pushfront"), A_GIMME, 0); + class_addmethod(h_deque_class, (t_method)h_deque_pop_front, + gensym("popfront"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_front, + gensym("front"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_remove, + gensym("remove"), A_GIMME, 0); + class_addmethod(h_deque_class, (t_method)h_deque_resize, + gensym("resize"), A_GIMME , 0); + class_addmethod(h_deque_class, (t_method)h_deque_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_deque_class, (t_method)h_deque_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_deque_class, (t_method)h_deque_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_deque_class, (t_method)h_deque_save, + gensym("save"), A_DEFSYMBOL, 0); + class_addmethod(h_deque_class, (t_method)h_deque_read, + gensym("read"), A_DEFSYMBOL, 0); + class_addmethod(h_deque_class, (t_method)h_deque_read_at, + gensym("readat"), A_GIMME, 0); + class_addmethod(h_deque_class, (t_method)h_deque_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_deque_class, (t_method)h_deque_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + class_addmethod(h_deque_class, (t_method)h_deque_read_at_xml, + gensym("readatXML"), A_GIMME, 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_deque_class, (t_method)h_deque_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_list.cpp b/PDContainer/src/h_list.cpp new file mode 100755 index 0000000..bbe9b68 --- /dev/null +++ b/PDContainer/src/h_list.cpp @@ -0,0 +1,442 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_list.cpp + + +#include "include/HList.h" + + +static t_class *h_list_class; + +typedef struct _h_list +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2, *out3; + HList *hlist; +} t_h_list; + +static void h_list_push_back(t_h_list *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hlist->pushBack(key); + } + else + post("h_list, pushback: no arguments"); +} + +static void h_list_pop_back(t_h_list *x) +{ + if(x->hlist->getSize()<=0) + { + post("h_list, popback: size is 0 !"); + return; + } + + x->hlist->popBack(); +} + +static void h_list_push_front(t_h_list *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hlist->pushFront(key); + } + else + post("h_list, pushfront: no arguments"); +} + +static void h_list_pop_front(t_h_list *x) +{ + if(x->hlist->getSize()<=0) + { + post("h_list, popfront: size is 0 !"); + return; + } + + x->hlist->popFront(); +} + +static void h_list_back(t_h_list *x) +{ + if(x->hlist->getSize() == 0) + { + outlet_bang(x->out3); + return; + } + + Element output = x->hlist->back(); + + if(output.getLength() == 1) // symbol, float or pointer + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + outlet_bang(x->out3); +} + +static void h_list_front(t_h_list *x) +{ + if(x->hlist->getSize() == 0) + { + outlet_bang(x->out3); + return; + } + + Element output = x->hlist->front(); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + outlet_bang(x->out3); +} + +static void h_list_get(t_h_list *x) +{ + if(x->hlist->getSize() == 0) + { + outlet_bang(x->out3); + return; + } + + Element output; + + try + { output = x->hlist->get(); } + + catch(const char* s) + { + // if there was no Element found, put out a bang at the right outlet + post("%s", s); + outlet_bang(x->out3); + return; + } + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + outlet_bang(x->out3); +} + +static void h_list_insert(t_h_list *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hlist->insert(key); + } + else + post("h_list, insert: no arguments"); +} + +static void h_list_modify(t_h_list *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hlist->modify(key); + } + else + post("h_list, modify: no arguments"); +} + +static void h_list_remove(t_h_list *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hlist->remove(key); + } + else + post("h_list, remove: no arguments"); +} + +static void h_list_delete(t_h_list *x) +{ + x->hlist->del(); +} + +static void h_list_begin(t_h_list *x) +{ + x->hlist->begin(); +} + +static void h_list_end(t_h_list *x) +{ + x->hlist->end(); +} + +static void h_list_next(t_h_list *x) +{ + x->hlist->next(); +} + +static void h_list_last(t_h_list *x) +{ + x->hlist->last(); +} + +static void h_list_unique(t_h_list *x) +{ + x->hlist->unique(); +} + +static void h_list_reverse(t_h_list *x) +{ + x->hlist->reverse(); +} + +static void h_list_sort(t_h_list *x) +{ + x->hlist->sort(); +} + +static void h_list_getsize(t_h_list *x) +{ + outlet_float(x->out2,x->hlist->getSize()); +} + +static void h_list_get_iter_pos(t_h_list *x) +{ + outlet_float(x->out1,x->hlist->getIterPos()); +} + +static void h_list_set_iter_pos(t_h_list *x, t_floatarg f) +{ + x->hlist->setIterPos(static_cast<int>(f)); +} + +static void h_list_help(t_h_list *x) +{ + x->hlist->help(); +} + +static void h_list_set_namespace(t_h_list *x, t_symbol *s) +{ + x->hlist->setNamespace(s->s_name); +} + +static void h_list_get_namespace(t_h_list *x) +{ + post("h_list current namespace: %s",x->hlist->getNamespace().c_str()); +} + +static void h_list_clear(t_h_list *x) +{ + x->hlist->clearNamespace(); +} + +static void h_list_clear_all(t_h_list *x) +{ + x->hlist->clearAll(); +} + +static void h_list_print(t_h_list *x) +{ + x->hlist->printAllIndex(); +} + +static void h_list_save(t_h_list *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hlist->saveToFile(filename)) + post("h_list: data of namespace %s written to file %s", + x->hlist->getNamespace().c_str(),s->s_name); + else + post("h_list: couldn't write to file %s",s->s_name); +} + +static void h_list_read(t_h_list *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hlist->readFromFile(filename)) + post("h_list: couldn't read from file %s",s->s_name); +} + +static void h_list_save_xml(t_h_list *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hlist->saveToFileXML(filename)) + post("h_list: data of namespace %s written to file %s", + x->hlist->getNamespace().c_str(),s->s_name); + else + post("h_list: couldn't write to file %s",s->s_name); +} + +static void h_list_read_xml(t_h_list *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hlist->readFromFileXML(filename)) + post("h_list: couldn't read from file %s",s->s_name); +} + +static void *h_list_new(t_symbol *s, int argc, t_atom *argv) +{ + t_h_list *x = (t_h_list *)pd_new(h_list_class); + + switch(argc) + { + default: + post("h_list warning: only one argument for namespace is possible!"); + case 1: + x->hlist = new HList(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hlist = new HList(); + break; + } + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_float); + x->out3 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_list_free(t_h_list *x) +{ + delete x->hlist; + return (void *)x; +} + +void h_list_setup(void) +{ + // the object class + h_list_class = class_new(gensym("h_list"), (t_newmethod)h_list_new, + (t_method)h_list_free, sizeof(t_h_list), + CLASS_DEFAULT, A_GIMME, 0); + + class_addmethod(h_list_class, (t_method)h_list_push_back, + gensym("pushback"), A_GIMME, 0); + class_addmethod(h_list_class, (t_method)h_list_pop_back, + gensym("popback"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_push_front, + gensym("pushfront"), A_GIMME, 0); + class_addmethod(h_list_class, (t_method)h_list_pop_front, + gensym("popfront"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_back, + gensym("back"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_front, + gensym("front"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_get, + gensym("get"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_insert, + gensym("insert"), A_GIMME, 0); + class_addmethod(h_list_class, (t_method)h_list_modify, + gensym("modify"), A_GIMME, 0); + class_addmethod(h_list_class, (t_method)h_list_remove, + gensym("remove"), A_GIMME, 0); + class_addmethod(h_list_class, (t_method)h_list_delete, + gensym("delete"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_list_class, (t_method)h_list_get_iter_pos, + gensym("getiter"), A_DEFFLOAT , 0); + class_addmethod(h_list_class, (t_method)h_list_set_iter_pos, + gensym("setiter"), A_DEFFLOAT , 0); + class_addmethod(h_list_class, (t_method)h_list_begin, + gensym("begin"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_end, + gensym("end"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_next, + gensym("next"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_last, + gensym("last"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_unique, + gensym("unique"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_reverse, + gensym("reverse"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_sort, + gensym("sort"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_list_class, (t_method)h_list_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_list_class, (t_method)h_list_save, + gensym("save"), A_DEFSYMBOL , 0); + class_addmethod(h_list_class, (t_method)h_list_read, + gensym("read"), A_DEFSYMBOL , 0); + class_addmethod(h_list_class, (t_method)h_list_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_list_class, (t_method)h_list_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_list_class, (t_method)h_list_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_map.cpp b/PDContainer/src/h_map.cpp new file mode 100755 index 0000000..11ce59e --- /dev/null +++ b/PDContainer/src/h_map.cpp @@ -0,0 +1,334 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_map.cpp + + +#include "include/HMap.h" + + +static t_class *h_map_class; +static t_class *proxy_class; + +typedef struct _h_map +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HMap *hmap; + Element value; + bool event_set; +} t_h_map; + +typedef struct proxy +{ + t_object obj; + t_int index; // number of proxy inlet(s) + t_h_map *x; // we'll put the other struct in here +} t_proxy; + +static void h_map_add(t_h_map *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!x->event_set) + { + post("h_map, add: you must first set a value at right inlet!"); + return; + } + + if(argc) + { + Element key(argc,argv); + x->hmap->add(key, x->value); + x->event_set = false; + } + else + post("h_map, add: no arguments"); +} + +static void h_map_value(t_proxy *p, t_symbol *s, int argc, t_atom *argv) +{ + t_h_map *x = (t_h_map *)(p->x); + + // symbol without selector "symbol": + if(argc == 0) + { + t_atom tmp; + SETSYMBOL(&tmp, s); + x->value.setAtoms(1, &tmp); + x->event_set = true; + return; + } + + // input is a list without selector "list": + if ( argc && (strcmp(s->s_name,"list")!=0) + && (strcmp(s->s_name,"float")!=0) + && (strcmp(s->s_name,"symbol")!=0) + && (strcmp(s->s_name,"pointer")!=0) ) + { + t_atom *atoms = (t_atom*)getbytes( (argc+1)*sizeof(t_atom) ); + + // add the selector symbol to the list: + SETSYMBOL(atoms, s); + + for(int i=0; i<argc; i++) + { + if(argv[i].a_type == A_FLOAT) + SETFLOAT(&atoms[i+1],argv[i].a_w.w_float); + if(argv[i].a_type == A_SYMBOL) + SETSYMBOL(&atoms[i+1],argv[i].a_w.w_symbol); + if(argv[i].a_type == A_POINTER) + SETPOINTER(&atoms[i+1],argv[i].a_w.w_gpointer); + } + + x->value.setAtoms(argc+1, atoms); + + x->event_set = true; + freebytes(atoms, (argc+1)*sizeof(t_atom)); + return; + } + + // "normal" input (list, float, symbol or pointer): + if (argc) + { + x->value.setAtoms(argc, argv); + x->event_set = true; + return; + } +} + +static void h_map_get(t_h_map *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_map, get: no arguments"); + return; + } + + Element key(argc,argv); + Element output; + + try + { output = x->hmap->get( key ); } + + catch(const char* s) + { + // if there was no Element found, put out a bang at the right outlet + post("%s", s); + outlet_bang(x->out2); + return; + } + + if(output.getLength() == 1) // symbol, float or pointer + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); +} + +static void h_map_remove(t_h_map *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_map, remove: no arguments"); + return; + } + + Element key(argc,argv); + + try + { x->hmap->remove( key ); } + + catch(const char* s) + { post("%s", s); } +} + +static void h_map_getsize(t_h_map *x) +{ + outlet_float(x->out1,x->hmap->getSize()); +} + +static void h_map_help(t_h_map *x) +{ + x->hmap->help(); +} + +static void h_map_set_namespace(t_h_map *x, t_symbol *s) +{ + x->hmap->setNamespace(s->s_name); +} + +static void h_map_get_namespace(t_h_map *x) +{ + post("h_map current namespace: %s",x->hmap->getNamespace().c_str()); +} + +static void h_map_print(t_h_map *x) +{ + x->hmap->printAll(); +} + +static void h_map_clear(t_h_map *x) +{ + x->hmap->clearNamespace(); +} + +static void h_map_clear_all(t_h_map *x) +{ + x->hmap->clearAll(); +} + +static void h_map_save(t_h_map *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hmap->saveToFile(filename)) + post("h_map: data of namespace %s written to file %s", + x->hmap->getNamespace().c_str(),s->s_name); + else + post("h_map: couldn't write to file %s",s->s_name); +} + +static void h_map_save_xml(t_h_map *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hmap->saveToFileXML(filename)) + post("h_map: data of namespace %s written to file %s", + x->hmap->getNamespace().c_str(),s->s_name); + else + post("h_map: couldn't write to file %s",s->s_name); +} + +static void h_map_read(t_h_map *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hmap->readFromFile(filename)) + post("h_map: couldn't read from file %s",s->s_name); +} + +static void h_map_read_xml(t_h_map *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hmap->readFromFileXML(filename)) + post("h_map: couldn't read from file %s",s->s_name); +} + +static void *h_map_new(t_symbol *s, int argc, t_atom *argv) +{ + + t_h_map *x = (t_h_map *)pd_new(h_map_class); + t_proxy *inlet = (t_proxy *)pd_new(proxy_class); // for the proxy inlet + + inlet->x = x; // make x visible to the proxy inlets + + switch(argc) + { + default: + post("h_map warning: only one argument for namespace is possible!"); + case 1: + x->hmap = new HMap(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hmap = new HMap(); + break; + } + + // we are going to create a proxy inlet no. 0 + // it belongs to the object x but the destination is t_proxy + inlet->index = 0; + inlet_new(&x->x_obj, &inlet->obj.ob_pd, 0,0); + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_map_free(t_h_map *x) +{ + delete x->hmap; + return (void *)x; +} + +void h_map_setup(void) +{ + // the object class + h_map_class = class_new(gensym("h_map"), (t_newmethod)h_map_new, + (t_method)h_map_free, sizeof(t_h_map), + CLASS_DEFAULT, A_GIMME, 0); + + // a class for the proxy-inlet + proxy_class = class_new(gensym("h_map_proxy"), NULL, NULL, sizeof(t_proxy), + CLASS_PD|CLASS_NOINLET, A_NULL); + + class_addmethod(h_map_class, (t_method)h_map_add, + gensym("add"), A_GIMME , 0); + class_addanything(proxy_class, (t_method)h_map_value); // the right inlet + class_addmethod(h_map_class, (t_method)h_map_get, + gensym("get"), A_GIMME , 0); + class_addmethod(h_map_class, (t_method)h_map_remove, + gensym("remove"), A_GIMME , 0); + class_addmethod(h_map_class, (t_method)h_map_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_map_class, (t_method)h_map_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_map_class, (t_method)h_map_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_map_class, (t_method)h_map_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_map_class, (t_method)h_map_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_map_class, (t_method)h_map_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_map_class, (t_method)h_map_save, + gensym("save"), A_DEFSYMBOL , 0); + class_addmethod(h_map_class, (t_method)h_map_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_map_class, (t_method)h_map_read, + gensym("read"), A_DEFSYMBOL , 0); + class_addmethod(h_map_class, (t_method)h_map_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_map_class, (t_method)h_map_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_multimap.cpp b/PDContainer/src/h_multimap.cpp new file mode 100755 index 0000000..8449fd9 --- /dev/null +++ b/PDContainer/src/h_multimap.cpp @@ -0,0 +1,331 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_multimap.cpp + + +#include "include/HMultiMap.h" + + +static t_class *h_multimap_class; +static t_class *proxy_class; + +typedef struct _h_multimap +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HMultiMap *hmultimap; + Element value; + bool event_set; +} t_h_multimap; + +typedef struct proxy +{ + t_object obj; + t_int index; // number of proxy inlet(s) + t_h_multimap *x; // we'll put the other struct in here +} t_proxy; + +static void h_multimap_add(t_h_multimap *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!x->event_set) + { + post("h_multimap, add: you must first set a value at right inlet!"); + return; + } + + if(argc) + { + Element key(argc,argv); + x->hmultimap->add(key, x->value); + x->event_set = false; + } + else + post("h_multimap, add: no arguments"); +} + +static void h_multimap_value(t_proxy *p, t_symbol *s, int argc, t_atom *argv) +{ + t_h_multimap *x = (t_h_multimap *)(p->x); + + // symbol without selector "symbol": + if(argc == 0) + { + t_atom tmp; + SETSYMBOL(&tmp, s); + x->value.setAtoms(1, &tmp); + x->event_set = true; + return; + } + + // input is a list without selector "list": + // input is a list without selector "list": + if ( argc && (strcmp(s->s_name,"list")!=0) + && (strcmp(s->s_name,"float")!=0) + && (strcmp(s->s_name,"symbol")!=0) + && (strcmp(s->s_name,"pointer")!=0) ) + { + t_atom *atoms = (t_atom*)getbytes( (argc+1)*sizeof(t_atom) ); + + // add the selector symbol to the list: + SETSYMBOL(atoms, s); + + for(int i=0; i<argc; i++) + { + if(argv[i].a_type == A_FLOAT) + SETFLOAT(&atoms[i+1],argv[i].a_w.w_float); + if(argv[i].a_type == A_SYMBOL) + SETSYMBOL(&atoms[i+1],argv[i].a_w.w_symbol); + if(argv[i].a_type == A_POINTER) + SETPOINTER(&atoms[i+1],argv[i].a_w.w_gpointer); + } + + x->value.setAtoms(argc+1, atoms); + + x->event_set = true; + freebytes(atoms, (argc+1)*sizeof(t_atom)); + return; + } + + // "normal" input (list, float, symbol or pointer): + if (argc) + { + x->value.setAtoms(argc, argv); + x->event_set = true; + return; + } +} + +static void h_multimap_get(t_h_multimap *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_multimap, get: no arguments"); + return; + } + + // outputs all the values of one key one after an other + + Element key(argc,argv); + int value_nr = x->hmultimap->getNr( key ); + + outlet_float(x->out1,value_nr); + + for(int i=0; i < value_nr; i++) + { + Element output; + try + { output = x->hmultimap->get(key, i); } + catch(const char* s) + { + post("%s", s); + continue; + } + + if(output.getLength() == 1) // symbol, float or pointer + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + } + if(output.getLength() > 1) // list + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + } +} + +static void h_multimap_remove(t_h_multimap *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_multimap, remove: no arguments"); + return; + } + + Element key(argc,argv); + try + { x->hmultimap->remove( key ); } + catch(const char* s) + { post("%s", s); } +} + +static void h_multimap_getsize(t_h_multimap *x) +{ + outlet_float(x->out2,x->hmultimap->getSize()); +} + +static void h_multimap_help(t_h_multimap *x) +{ + x->hmultimap->help(); +} + +static void h_multimap_set_namespace(t_h_multimap *x, t_symbol *s) +{ + x->hmultimap->setNamespace(s->s_name); +} + +static void h_multimap_get_namespace(t_h_multimap *x) +{ + post("h_multimap current namespace: %s",x->hmultimap->getNamespace().c_str()); +} + +static void h_multimap_print(t_h_multimap *x) +{ + x->hmultimap->printAll(); +} + +static void h_multimap_clear(t_h_multimap *x) +{ + x->hmultimap->clearNamespace(); +} + +static void h_multimap_clear_all(t_h_multimap *x) +{ + x->hmultimap->clearAll(); +} + +static void h_multimap_save(t_h_multimap *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hmultimap->saveToFile(filename)) + post("h_multimap: data of namespace %s written to file %s", + x->hmultimap->getNamespace().c_str(),s->s_name); + else + post("h_multimap: couldn't write to file %s",s->s_name); +} + +static void h_multimap_save_xml(t_h_multimap *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hmultimap->saveToFileXML(filename)) + post("h_multimap: data of namespace %s written to file %s", + x->hmultimap->getNamespace().c_str(),s->s_name); + else + post("h_multimap: couldn't write to file %s",s->s_name); +} + +static void h_multimap_read(t_h_multimap *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hmultimap->readFromFile(filename)) + post("h_multimap: couldn't read from file %s",s->s_name); +} + +static void h_multimap_read_xml(t_h_multimap *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hmultimap->readFromFileXML(filename)) + post("h_multimap: couldn't read from file %s",s->s_name); +} + +static void *h_multimap_new(t_symbol *s, int argc, t_atom *argv) +{ + + t_h_multimap *x = (t_h_multimap *)pd_new(h_multimap_class); + t_proxy *inlet = (t_proxy *)pd_new(proxy_class); // for the proxy inlet + + inlet->x = x; // make x visible to the proxy inlets + + switch(argc) + { + default: + post("h_multimap warning: only one argument for namespace is possible!"); + case 1: + x->hmultimap = new HMultiMap(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hmultimap = new HMultiMap(); + break; + } + + // we are going to create a proxy inlet no. 0 + // it belongs to the object x but the destination is t_proxy + inlet->index = 0; + inlet_new(&x->x_obj, &inlet->obj.ob_pd, 0,0); + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_float); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_multimap_free(t_h_multimap *x) +{ + delete x->hmultimap; + return (void *)x; +} + +void h_multimap_setup(void) +{ + h_multimap_class = class_new(gensym("h_multimap"), (t_newmethod)h_multimap_new, + (t_method)h_multimap_free, sizeof(t_h_multimap), + CLASS_DEFAULT, A_GIMME, 0); + + // a class for the proxy-inlet + proxy_class = class_new(gensym("h_map_proxy"), NULL, NULL, sizeof(t_proxy), + CLASS_PD|CLASS_NOINLET, A_NULL); + + class_addmethod(h_multimap_class, (t_method)h_multimap_add, + gensym("add"), A_GIMME , 0); + class_addanything(proxy_class, (t_method)h_multimap_value); // the right inlet + class_addmethod(h_multimap_class, (t_method)h_multimap_get, + gensym("get"), A_GIMME , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_remove, + gensym("remove"), A_GIMME , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_save, + gensym("save"), A_DEFSYMBOL , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_read, + gensym("read"), A_DEFSYMBOL , 0); + class_addmethod(h_multimap_class, (t_method)h_multimap_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_multimap_class, (t_method)h_multimap_help, + gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_multiset.cpp b/PDContainer/src/h_multiset.cpp new file mode 100755 index 0000000..0886a8b --- /dev/null +++ b/PDContainer/src/h_multiset.cpp @@ -0,0 +1,220 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_multiset.cpp + + +#include "include/HMultiSet.h" + + +static t_class *h_multiset_class; + +typedef struct _h_multiset +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1; + HMultiSet *hmultiset; +} t_h_multiset; + +static void h_multiset_add(t_h_multiset *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_multiset, add: no arguments"); + return; + } + + Element key(argc,argv); + x->hmultiset->add( key ); +} + +static void h_multiset_get(t_h_multiset *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_multiset, get: no arguments"); + return; + } + + Element key(argc,argv); + int output = x->hmultiset->get( key ); + + outlet_float(x->out0, output); +} + +static void h_multiset_remove(t_h_multiset *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_multiset, remove: no arguments"); + return; + } + + Element key(argc,argv); + x->hmultiset->remove( key ); +} + +static void h_multiset_getsize(t_h_multiset *x) +{ + outlet_float(x->out1,x->hmultiset->getSize()); +} + +static void h_multiset_help(t_h_multiset *x) +{ + x->hmultiset->help(); +} + +static void h_multiset_set_namespace(t_h_multiset *x, t_symbol *s) +{ + x->hmultiset->setNamespace(s->s_name); +} + +static void h_multiset_get_namespace(t_h_multiset *x) +{ + post("h_multiset current namespace: %s",x->hmultiset->getNamespace().c_str()); +} + +static void h_multiset_print(t_h_multiset *x) +{ + x->hmultiset->printAll(); +} + +static void h_multiset_clear(t_h_multiset *x) +{ + x->hmultiset->clearNamespace(); +} + +static void h_multiset_clear_all(t_h_multiset *x) +{ + x->hmultiset->clearAll(); +} + +static void h_multiset_save(t_h_multiset *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hmultiset->saveToFile(filename)) + post("h_multiset: data of namespace %s written to file %s", + x->hmultiset->getNamespace().c_str(),s->s_name); + else + post("h_multiset: couldn't write to file %s",s->s_name); +} + +static void h_multiset_read(t_h_multiset *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hmultiset->readFromFile(filename)) + post("h_multiset: couldn't read from file %s",s->s_name); +} + +static void h_multiset_save_xml(t_h_multiset *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hmultiset->saveToFileXML(filename)) + post("h_multiset: data of namespace %s written to file %s", + x->hmultiset->getNamespace().c_str(),s->s_name); + else + post("h_multiset: couldn't write to file %s",s->s_name); +} + +static void h_multiset_read_xml(t_h_multiset *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hmultiset->readFromFileXML(filename)) + post("h_multiset: couldn't read from file %s",s->s_name); +} + +static void *h_multiset_new(t_symbol *s, int argc, t_atom *argv) +{ + + t_h_multiset *x = (t_h_multiset *)pd_new(h_multiset_class); + + switch(argc) + { + default: + post("h_multiset warning: only one argument for namespace is possible!"); + case 1: + x->hmultiset = new HMultiSet(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hmultiset = new HMultiSet(); + break; + } + + x->out0 = outlet_new(&x->x_obj, &s_float); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_multiset_free(t_h_multiset *x) +{ + delete x->hmultiset; + return (void *)x; +} + +void h_multiset_setup(void) +{ + // the object class + h_multiset_class = class_new(gensym("h_multiset"), (t_newmethod)h_multiset_new, + (t_method)h_multiset_free, sizeof(t_h_multiset), + CLASS_DEFAULT, A_GIMME, 0); + + class_addmethod(h_multiset_class, (t_method)h_multiset_add, + gensym("add"), A_GIMME , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_get, + gensym("get"), A_GIMME , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_remove, + gensym("remove"), A_GIMME , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_save, + gensym("save"), A_DEFSYMBOL , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_read, + gensym("read"), A_DEFSYMBOL , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_multiset_class, (t_method)h_multiset_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_multiset_class, (t_method)h_multiset_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_prioqueue.cpp b/PDContainer/src/h_prioqueue.cpp new file mode 100755 index 0000000..9f770ed --- /dev/null +++ b/PDContainer/src/h_prioqueue.cpp @@ -0,0 +1,250 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_prioqueue.cpp + + +#include "include/HPrioQueue.h" + + +static t_class *h_priority_queue_class; +static t_class *proxy_class; + +typedef struct _h_priority_queue +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HPrioQueue *hpriority_queue; + Element value; + bool event_set; +} t_h_priority_queue; + +typedef struct proxy +{ + t_object obj; + t_int index; // number of proxy inlet(s) + t_h_priority_queue *x; // we'll put the other struct in here +} t_proxy; + +static void h_priority_queue_push(t_h_priority_queue *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!x->event_set) + { + post("h_priority_queue, insert: you must first set a value at right inlet!"); + return; + } + + float prio; + if(argc && (argv[0].a_type == A_FLOAT)) + prio = static_cast<float>(argv[0].a_w.w_float); + else + { + post("h_priority_queue, push: invalid priority!"); + return; + } + + x->hpriority_queue->push(prio,x->value); + x->event_set = false; +} + +static void h_priority_queue_value(t_proxy *p, t_symbol *s, int argc, t_atom *argv) +{ + t_h_priority_queue *x = (t_h_priority_queue *)(p->x); + + // symbol without selector "symbol": + if(argc == 0) + { + t_atom tmp; + SETSYMBOL(&tmp, s); + x->value.setAtoms(1, &tmp); + x->event_set = true; + return; + } + + // input is a list without selector "list": + if ( argc && (strcmp(s->s_name,"list")!=0) + && (strcmp(s->s_name,"float")!=0) + && (strcmp(s->s_name,"symbol")!=0) + && (strcmp(s->s_name,"pointer")!=0) ) + { + t_atom *atoms = (t_atom*)getbytes( (argc+1)*sizeof(t_atom) ); + + // add the selector symbol to the list: + SETSYMBOL(atoms, s); + + for(int i=0; i<argc; i++) + { + if(argv[i].a_type == A_FLOAT) + SETFLOAT(&atoms[i+1],argv[i].a_w.w_float); + if(argv[i].a_type == A_SYMBOL) + SETSYMBOL(&atoms[i+1],argv[i].a_w.w_symbol); + if(argv[i].a_type == A_POINTER) + SETPOINTER(&atoms[i+1],argv[i].a_w.w_gpointer); + } + + x->value.setAtoms(argc+1, atoms); + + x->event_set = true; + freebytes(atoms, (argc+1)*sizeof(t_atom)); + return; + } + + // "normal" input (list, float, pointer or symbol): + if (argc) + { + x->value.setAtoms(argc, argv); + x->event_set = true; + return; + } +} + +static void h_priority_queue_top(t_h_priority_queue *x) +{ + if(x->hpriority_queue->getSize()==0) + { + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); + return; + } + + Element output = x->hpriority_queue->top(); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); +} + +static void h_priority_queue_pop(t_h_priority_queue *x) +{ + if(x->hpriority_queue->getSize()<=0) + { + post("h_priority_queue, pop: size is already 0 !"); + return; + } + + x->hpriority_queue->pop(); +} + +static void h_priority_queue_getsize(t_h_priority_queue *x) +{ + outlet_float(x->out1,x->hpriority_queue->getSize()); +} + +static void h_priority_queue_help(t_h_priority_queue *x) +{ + x->hpriority_queue->help(); +} + +static void h_priority_queue_set_namespace(t_h_priority_queue *x, t_symbol *s) +{ + x->hpriority_queue->setNamespace(s->s_name); +} + +static void h_priority_queue_get_namespace(t_h_priority_queue *x) +{ + post("h_priority_queue current namespace: %s",x->hpriority_queue->getNamespace().c_str()); +} + +static void h_priority_queue_clear(t_h_priority_queue *x) +{ + x->hpriority_queue->clearNamespace(); +} + +static void h_priority_queue_clear_all(t_h_priority_queue *x) +{ + x->hpriority_queue->clearAll(); +} + +static void *h_priority_queue_new(t_symbol *s, int argc, t_atom *argv) +{ + t_h_priority_queue *x = (t_h_priority_queue *)pd_new(h_priority_queue_class); + t_proxy *inlet = (t_proxy *)pd_new(proxy_class); // for the proxy inlet + + inlet->x = x; // make x visible to the proxy inlets + + switch(argc) + { + default: + post("h_priority_queue warning: only one argument for namespace is possible!"); + case 1: + x->hpriority_queue = new HPrioQueue(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hpriority_queue = new HPrioQueue(); + break; + } + + // we are going to create a proxy inlet no. 0 + // it belongs to the object x but the destination is t_proxy + inlet->index = 0; + inlet_new(&x->x_obj, &inlet->obj.ob_pd, 0,0); + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_priority_queue_free(t_h_priority_queue *x) +{ + delete x->hpriority_queue; + return (void *)x; +} + +void h_priority_queue_setup(void) +{ + // the object class + h_priority_queue_class = class_new(gensym("h_priority_queue"), (t_newmethod)h_priority_queue_new, + (t_method)h_priority_queue_free, sizeof(t_h_priority_queue), + CLASS_DEFAULT, A_GIMME, 0); + + // a class for the proxy-inlet + proxy_class = class_new(gensym("h_priority_queue_proxy"), NULL, NULL, sizeof(t_proxy), + CLASS_PD|CLASS_NOINLET, A_NULL); + + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_push, + gensym("push"), A_GIMME, 0); + class_addanything(proxy_class, (t_method)h_priority_queue_value); // the right inlet + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_pop, + gensym("pop"), A_DEFFLOAT, 0); + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_top, + gensym("top"), A_DEFFLOAT, 0); + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_priority_queue_class, (t_method)h_priority_queue_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_queue.cpp b/PDContainer/src/h_queue.cpp new file mode 100755 index 0000000..77d5ef7 --- /dev/null +++ b/PDContainer/src/h_queue.cpp @@ -0,0 +1,165 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_queue.cpp + + +#include "include/HQueue.h" + + +static t_class *h_queue_class; + +typedef struct _h_queue +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HQueue *hqueue; +} t_h_queue; + +static void h_queue_push(t_h_queue *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hqueue->push(key); + } + else + post("h_queue, push: no arguments"); +} + +static void h_queue_pop(t_h_queue *x) +{ + if(x->hqueue->getSize()<=0) + { + post("h_queue, pop: size is 0 !"); + return; + } + + x->hqueue->pop(); +} + +static void h_queue_front(t_h_queue *x) +{ + if(x->hqueue->getSize() == 0) + { + outlet_bang(x->out2); + return; + } + + Element output = x->hqueue->front(); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // outlet bang if no data here + outlet_bang(x->out2); +} + +static void h_queue_getsize(t_h_queue *x) +{ + outlet_float(x->out1,x->hqueue->getSize()); +} + +static void h_queue_help(t_h_queue *x) +{ + x->hqueue->help(); +} + +static void h_queue_set_namespace(t_h_queue *x, t_symbol *s) +{ + x->hqueue->setNamespace(s->s_name); +} + +static void h_queue_get_namespace(t_h_queue *x) +{ + post("h_queue current namespace: %s",x->hqueue->getNamespace().c_str()); +} + +static void h_queue_clear(t_h_queue *x) +{ + x->hqueue->clearNamespace(); +} + +static void h_queue_clear_all(t_h_queue *x) +{ + x->hqueue->clearAll(); +} + +static void *h_queue_new(t_symbol *s, int argc, t_atom *argv) +{ + t_h_queue *x = (t_h_queue *)pd_new(h_queue_class); + + switch(argc) + { + default: + post("h_queue warning: only one argument for namespace is possible!"); + case 1: + x->hqueue = new HQueue(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hqueue = new HQueue(); + break; + } + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_queue_free(t_h_queue *x) +{ + delete x->hqueue; + return (void *)x; +} + +void h_queue_setup(void) +{ + // the object class + h_queue_class = class_new(gensym("h_queue"), (t_newmethod)h_queue_new, + (t_method)h_queue_free, sizeof(t_h_queue), + CLASS_DEFAULT, A_GIMME, 0); + + class_addmethod(h_queue_class, (t_method)h_queue_push, + gensym("push"), A_GIMME, 0); + class_addmethod(h_queue_class, (t_method)h_queue_pop, + gensym("pop"), A_DEFFLOAT, 0); + class_addmethod(h_queue_class, (t_method)h_queue_front, + gensym("front"), A_DEFFLOAT, 0); + class_addmethod(h_queue_class, (t_method)h_queue_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_queue_class, (t_method)h_queue_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_queue_class, (t_method)h_queue_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_queue_class, (t_method)h_queue_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_queue_class, (t_method)h_queue_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_queue_class, (t_method)h_queue_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_set.cpp b/PDContainer/src/h_set.cpp new file mode 100755 index 0000000..2e97cef --- /dev/null +++ b/PDContainer/src/h_set.cpp @@ -0,0 +1,220 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_set.cpp + + +#include "include/HSet.h" + + +static t_class *h_set_class; + +typedef struct _h_set +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1; + HSet *hset; +} t_h_set; + +static void h_set_add(t_h_set *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_set, add: no arguments"); + return; + } + + Element key(argc,argv); + x->hset->add( key ); +} + +static void h_set_get(t_h_set *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_set, get: no arguments"); + return; + } + + Element key(argc,argv); + int output = x->hset->get( key ); + + outlet_float(x->out0, output); +} + +static void h_set_remove(t_h_set *x, t_symbol *s, int argc, t_atom *argv) +{ + if(!argc) + { + post("h_set, remove: no arguments"); + return; + } + + Element key(argc,argv); + x->hset->remove( key ); +} + +static void h_set_getsize(t_h_set *x) +{ + outlet_float(x->out1,x->hset->getSize()); +} + +static void h_set_help(t_h_set *x) +{ + x->hset->help(); +} + +static void h_set_set_namespace(t_h_set *x, t_symbol *s) +{ + x->hset->setNamespace(s->s_name); +} + +static void h_set_get_namespace(t_h_set *x) +{ + post("h_set current namespace: %s",x->hset->getNamespace().c_str()); +} + +static void h_set_print(t_h_set *x) +{ + x->hset->printAll(); +} + +static void h_set_clear(t_h_set *x) +{ + x->hset->clearNamespace(); +} + +static void h_set_clear_all(t_h_set *x) +{ + x->hset->clearAll(); +} + +static void h_set_save(t_h_set *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hset->saveToFile(filename)) + post("h_set: data of namespace %s written to file %s", + x->hset->getNamespace().c_str(),s->s_name); + else + post("h_set: couldn't write to file %s",s->s_name); +} + +static void h_set_read(t_h_set *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hset->readFromFile(filename)) + post("h_set: couldn't read from file %s",s->s_name); +} + +static void h_set_save_xml(t_h_set *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hset->saveToFileXML(filename)) + post("h_set: data of namespace %s written to file %s", + x->hset->getNamespace().c_str(),s->s_name); + else + post("h_set: couldn't write to file %s",s->s_name); +} + +static void h_set_read_xml(t_h_set *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hset->readFromFileXML(filename)) + post("h_set: couldn't read from file %s",s->s_name); +} + +static void *h_set_new(t_symbol *s, int argc, t_atom *argv) +{ + + t_h_set *x = (t_h_set *)pd_new(h_set_class); + + switch(argc) + { + default: + post("h_set warning: only one argument for namespace is possible!"); + case 1: + x->hset = new HSet(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hset = new HSet(); + break; + } + + x->out0 = outlet_new(&x->x_obj, &s_float); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_set_free(t_h_set *x) +{ + delete x->hset; + return (void *)x; +} + +void h_set_setup(void) +{ + // the object class + h_set_class = class_new(gensym("h_set"), (t_newmethod)h_set_new, + (t_method)h_set_free, sizeof(t_h_set), + CLASS_DEFAULT, A_GIMME, 0); + + class_addmethod(h_set_class, (t_method)h_set_add, + gensym("add"), A_GIMME , 0); + class_addmethod(h_set_class, (t_method)h_set_get, + gensym("get"), A_GIMME , 0); + class_addmethod(h_set_class, (t_method)h_set_remove, + gensym("remove"), A_GIMME , 0); + class_addmethod(h_set_class, (t_method)h_set_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_set_class, (t_method)h_set_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_set_class, (t_method)h_set_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_set_class, (t_method)h_set_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_set_class, (t_method)h_set_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_set_class, (t_method)h_set_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_set_class, (t_method)h_set_save, + gensym("save"), A_DEFSYMBOL , 0); + class_addmethod(h_set_class, (t_method)h_set_read, + gensym("read"), A_DEFSYMBOL , 0); + class_addmethod(h_set_class, (t_method)h_set_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_set_class, (t_method)h_set_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_set_class, (t_method)h_set_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_stack.cpp b/PDContainer/src/h_stack.cpp new file mode 100755 index 0000000..e82933e --- /dev/null +++ b/PDContainer/src/h_stack.cpp @@ -0,0 +1,165 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_stack.cpp + + +#include "include/HStack.h" + + +static t_class *h_stack_class; + +typedef struct _h_stack +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HStack *hstack; +} t_h_stack; + +static void h_stack_push(t_h_stack *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hstack->push(key); + } + else + post("h_stack, push: no arguments"); +} + +static void h_stack_pop(t_h_stack *x) +{ + if(x->hstack->getSize()<=0) + { + post("h_stack, pop: size is 0 !"); + return; + } + + x->hstack->pop(); +} + +static void h_stack_top(t_h_stack *x) +{ + if(x->hstack->getSize() == 0) + { + outlet_bang(x->out2); + return; + } + + Element output = x->hstack->top(); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // no data + outlet_bang(x->out2); +} + +static void h_stack_getsize(t_h_stack *x) +{ + outlet_float(x->out1,x->hstack->getSize()); +} + +static void h_stack_help(t_h_stack *x) +{ + x->hstack->help(); +} + +static void h_stack_set_namespace(t_h_stack *x, t_symbol *s) +{ + x->hstack->setNamespace(s->s_name); +} + +static void h_stack_get_namespace(t_h_stack *x) +{ + post("h_stack current namespace: %s",x->hstack->getNamespace().c_str()); +} + +static void h_stack_clear(t_h_stack *x) +{ + x->hstack->clearNamespace(); +} + +static void h_stack_clear_all(t_h_stack *x) +{ + x->hstack->clearAll(); +} + +static void *h_stack_new(t_symbol *s, int argc, t_atom *argv) +{ + t_h_stack *x = (t_h_stack *)pd_new(h_stack_class); + + switch(argc) + { + default: + post("h_stack warning: only one argument for namespace is possible!"); + case 1: + x->hstack = new HStack(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hstack = new HStack(); + break; + } + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_stack_free(t_h_stack *x) +{ + delete x->hstack; + return (void *)x; +} + +void h_stack_setup(void) +{ + // the object class + h_stack_class = class_new(gensym("h_stack"), (t_newmethod)h_stack_new, + (t_method)h_stack_free, sizeof(t_h_stack), + CLASS_DEFAULT, A_GIMME, 0); + + class_addmethod(h_stack_class, (t_method)h_stack_push, + gensym("push"), A_GIMME, 0); + class_addmethod(h_stack_class, (t_method)h_stack_pop, + gensym("pop"), A_DEFFLOAT, 0); + class_addmethod(h_stack_class, (t_method)h_stack_top, + gensym("top"), A_DEFFLOAT, 0); + class_addmethod(h_stack_class, (t_method)h_stack_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_stack_class, (t_method)h_stack_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_stack_class, (t_method)h_stack_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_stack_class, (t_method)h_stack_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_stack_class, (t_method)h_stack_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_stack_class, (t_method)h_stack_help, gensym("help"),A_DEFFLOAT, 0); +} diff --git a/PDContainer/src/h_vector.cpp b/PDContainer/src/h_vector.cpp new file mode 100755 index 0000000..d3f76a3 --- /dev/null +++ b/PDContainer/src/h_vector.cpp @@ -0,0 +1,488 @@ +// *********************(c)*2004*********************> +// -holzilib--holzilib--holzilib--holzilib--holzilib-> +// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++> +// +// PDContainer: +// this is a port of the containers from the C++ STL +// (Standard Template Library) +// for usage see the documentation and PD help files +// for license see readme.txt +// +// h_vector.cpp + + +#include "include/HVector.h" + + +static t_class *h_vector_class; +static t_class *proxy_class; + +typedef struct _h_vector +{ + t_object x_obj; + t_canvas *x_canvas; + t_outlet *out0, *out1, *out2; + HVector *hvector; + Element value; + bool event_set; +} t_h_vector; + +typedef struct proxy +{ + t_object obj; + t_int index; // number of proxy inlet(s) + t_h_vector *x; // we'll put the other struct in here +} t_proxy; + +static void h_vector_set(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_vector, set: invalid index!"); + return; + } + + if ( index >= x->hvector->getSize() || index < 0 ) + { + post("h_vector, set: invalid index!"); + return; + } + + if(!x->event_set) + { + post("h_vector, set: you must first set a value at right inlet!"); + return; + } + + x->hvector->set( index , x->value); + x->event_set = false; +} + +static void h_vector_push_back(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + Element key(argc,argv); + x->hvector->pushBack(key); + } + else + post("h_vector, pushback: no arguments"); +} + +static void h_vector_insert(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_vector, insert: invalid index!"); + return; + } + + if ( index >= x->hvector->getSize() || index < 0 ) + { + post("h_vector, insert: invalid index!"); + return; + } + + if(!x->event_set) + { + post("h_vector, insert: you must first set a value at right inlet!"); + return; + } + + x->hvector->insert( index , x->value); + x->event_set = false; +} + +static void h_vector_value(t_proxy *p, t_symbol *s, int argc, t_atom *argv) +{ + t_h_vector *x = (t_h_vector *)(p->x); + + // symbol without selector "symbol": + if(argc == 0) + { + t_atom tmp; + SETSYMBOL(&tmp, s); + x->value.setAtoms(1, &tmp); + x->event_set = true; + return; + } + + // input is a list without selector "list": + if ( argc && (strcmp(s->s_name,"list")!=0) + && (strcmp(s->s_name,"float")!=0) + && (strcmp(s->s_name,"symbol")!=0) + && (strcmp(s->s_name,"pointer")!=0) ) + { + t_atom *atoms = (t_atom*)getbytes( (argc+1)*sizeof(t_atom) ); + + // add the selector symbol to the list: + SETSYMBOL(atoms, s); + + for(int i=0; i<argc; i++) + { + if(argv[i].a_type == A_FLOAT) + SETFLOAT(&atoms[i+1],argv[i].a_w.w_float); + if(argv[i].a_type == A_SYMBOL) + SETSYMBOL(&atoms[i+1],argv[i].a_w.w_symbol); + if(argv[i].a_type == A_POINTER) + SETPOINTER(&atoms[i+1],argv[i].a_w.w_gpointer); + } + + x->value.setAtoms(argc+1, atoms); + + x->event_set = true; + freebytes(atoms, (argc+1)*sizeof(t_atom)); + return; + } + + // "normal" input (list, float or symbol): + if (argc) + { + x->value.setAtoms(argc, argv); + x->event_set = true; + return; + } +} + +static void h_vector_get(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_vector, get: invalid index!"); + return; + } + + if ( index >= x->hvector->getSize() || index < 0 ) + { + post("h_vector, get: invalid index!"); + return; + } + + Element output = x->hvector->get( index ); + + if(output.getLength() == 1) // symbol or float + { + if (output.getAtom()[0].a_type == A_FLOAT) + outlet_float(x->out0, output.getAtom()[0].a_w.w_float); + if (output.getAtom()[0].a_type == A_SYMBOL) + outlet_symbol(x->out0, output.getAtom()[0].a_w.w_symbol); + if (output.getAtom()[0].a_type == A_POINTER) + outlet_pointer(x->out0, output.getAtom()[0].a_w.w_gpointer); + return; + } + if(output.getLength() > 1) // list + { + outlet_list(x->out0,&s_list,output.getLength(),output.getAtom()); + return; + } + + // if there was no Element found, put out a bang at the right outlet + outlet_bang(x->out2); +} + +static void h_vector_pop_back(t_h_vector *x) +{ + if(x->hvector->getSize()<=0) + { + post("h_vector, popback: size is already 0 !"); + return; + } + + x->hvector->popBack(); +} + +static void h_vector_remove(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + int index; + if(argc && (argv[0].a_type == A_FLOAT)) + index = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_vector, remove: invalid index!"); + return; + } + + if ( index >= x->hvector->getSize() || index < 0 ) + { + post("h_vector, remove: invalid index!"); + return; + } + + x->hvector->remove(index); + x->event_set = false; +} + +static void h_vector_resize(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + int size; + if(argc && (argv[0].a_type == A_FLOAT)) + size = static_cast<int>(argv[0].a_w.w_float); + else + { + post("h_vector, resize: invalid index!"); + return; + } + + if ( size < 0 ) + { + post("h_vector, size: invalid size!"); + return; + } + + x->hvector->resize( size ); +} + +static void h_vector_getsize(t_h_vector *x) +{ + outlet_float(x->out1,x->hvector->getSize()); +} + +static void h_vector_help(t_h_vector *x) +{ + x->hvector->help(); +} + +static void h_vector_set_namespace(t_h_vector *x, t_symbol *s) +{ + x->hvector->setNamespace(s->s_name); +} + +static void h_vector_get_namespace(t_h_vector *x) +{ + post("h_vector current namespace: %s",x->hvector->getNamespace().c_str()); +} + +static void h_vector_print(t_h_vector *x) +{ + x->hvector->printAllIndex(); +} + +static void h_vector_clear(t_h_vector *x) +{ + x->hvector->clearNamespace(); +} + +static void h_vector_clear_all(t_h_vector *x) +{ + x->hvector->clearAll(); +} + +static void h_vector_save(t_h_vector *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hvector->saveToFile(filename)) + post("h_vector: data of namespace %s written to file %s", + x->hvector->getNamespace().c_str(),s->s_name); + else + post("h_vector: couldn't write to file %s",s->s_name); +} + +static void h_vector_read(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hvector->readFromFile(filename)) + post("h_vector: couldn't read from file %s",s->s_name); +} + +static void h_vector_read_at(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + string symbol; + int index=0; + + switch(argc) + { + default: + post("h_vector read: only two argument are possible!"); + break; + case 2: + symbol = argv[0].a_w.w_symbol->s_name; + index = (int)argv[1].a_w.w_float; + break; + case 1: + symbol = argv[0].a_w.w_symbol->s_name; + index = 0; + break; + case 0: + post("h_vector read: no filename!"); + } + + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, (char*)symbol.c_str(), filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hvector->readFromFile2(filename,index)) + post("h_vector: couldn't read from file %s",s->s_name); +} + +static void h_vector_save_xml(t_h_vector *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(x->hvector->saveToFileXML(filename)) + post("h_vector: data of namespace %s written to file %s", + x->hvector->getNamespace().c_str(),s->s_name); + else + post("h_vector: couldn't write to file %s",s->s_name); +} + +static void h_vector_read_xml(t_h_vector *x, t_symbol *s) +{ + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hvector->readFromFileXML(filename)) + post("h_vector: couldn't read from file %s",s->s_name); +} + +static void h_vector_read_at_xml(t_h_vector *x, t_symbol *s, int argc, t_atom *argv) +{ + string symbol; + int index=0; + + switch(argc) + { + default: + post("h_vector read: only two argument are possible!"); + break; + case 2: + symbol = argv[0].a_w.w_symbol->s_name; + index = (int)argv[1].a_w.w_float; + break; + case 1: + symbol = argv[0].a_w.w_symbol->s_name; + index = 0; + break; + case 0: + post("h_vector read: no filename!"); + } + + // make correct path + char filnam[MAXPDSTRING]; + char filename[MAXPDSTRING]; + canvas_makefilename(x->x_canvas, (char*)symbol.c_str(), filnam, MAXPDSTRING); + sys_bashfilename(filnam, filename); + + if(!x->hvector->readFromFile2XML(filename,index)) + post("h_vector: couldn't read from file %s",s->s_name); +} + +static void *h_vector_new(t_symbol *s, int argc, t_atom *argv) +{ + t_h_vector *x = (t_h_vector *)pd_new(h_vector_class); + t_proxy *inlet = (t_proxy *)pd_new(proxy_class); // for the proxy inlet + + inlet->x = x; // make x visible to the proxy inlets + + switch(argc) + { + default: + post("h_vector warning: only one argument for namespace is possible!"); + case 1: + x->hvector = new HVector(atom_getsymbol(argv)->s_name); + break; + case 0: + x->hvector = new HVector(); + break; + } + + // we are going to create a proxy inlet no. 0 + // it belongs to the object x but the destination is t_proxy + inlet->index = 0; + inlet_new(&x->x_obj, &inlet->obj.ob_pd, 0,0); + + x->out0 = outlet_new(&x->x_obj, 0); + x->out1 = outlet_new(&x->x_obj, &s_float); + x->out2 = outlet_new(&x->x_obj, &s_bang); + x->x_canvas = canvas_getcurrent(); + + return (void *)x; +} + +static void *h_vector_free(t_h_vector *x) +{ + delete x->hvector; + return (void *)x; +} + +void h_vector_setup(void) +{ + // the object class + h_vector_class = class_new(gensym("h_vector"), (t_newmethod)h_vector_new, + (t_method)h_vector_free, sizeof(t_h_vector), + CLASS_DEFAULT, A_GIMME, 0); + + // a class for the proxy-inlet + proxy_class = class_new(gensym("h_vector_proxy"), NULL, NULL, sizeof(t_proxy), + CLASS_PD|CLASS_NOINLET, A_NULL); + + class_addmethod(h_vector_class, (t_method)h_vector_set, + gensym("set"), A_GIMME, 0); + class_addmethod(h_vector_class, (t_method)h_vector_push_back, + gensym("pushback"), A_GIMME, 0); + class_addmethod(h_vector_class, (t_method)h_vector_insert, + gensym("insert"), A_GIMME, 0); + class_addanything(proxy_class, (t_method)h_vector_value); // the right inlet + class_addmethod(h_vector_class, (t_method)h_vector_get, + gensym("get"), A_GIMME, 0); + class_addmethod(h_vector_class, (t_method)h_vector_pop_back, + gensym("popback"), A_DEFFLOAT, 0); + class_addmethod(h_vector_class, (t_method)h_vector_remove, + gensym("remove"), A_GIMME, 0); + class_addmethod(h_vector_class, (t_method)h_vector_resize, + gensym("resize"), A_GIMME , 0); + class_addmethod(h_vector_class, (t_method)h_vector_getsize, + gensym("getsize"), A_DEFFLOAT , 0); + class_addmethod(h_vector_class, (t_method)h_vector_set_namespace, + gensym("namespace"), A_DEFSYMBOL , 0); + class_addmethod(h_vector_class, (t_method)h_vector_get_namespace, + gensym("getnamespace"), A_DEFFLOAT, 0); + class_addmethod(h_vector_class, (t_method)h_vector_print, + gensym("print"), A_DEFFLOAT, 0); + class_addmethod(h_vector_class, (t_method)h_vector_clear, + gensym("clear"), A_DEFFLOAT, 0); + class_addmethod(h_vector_class, (t_method)h_vector_clear_all, + gensym("clearall"), A_DEFFLOAT, 0); + class_addmethod(h_vector_class, (t_method)h_vector_save, + gensym("save"), A_DEFSYMBOL, 0); + class_addmethod(h_vector_class, (t_method)h_vector_read, + gensym("read"), A_DEFSYMBOL, 0); + class_addmethod(h_vector_class, (t_method)h_vector_read_at, + gensym("readat"), A_GIMME, 0); + class_addmethod(h_vector_class, (t_method)h_vector_save_xml, + gensym("saveXML"), A_DEFSYMBOL , 0); + class_addmethod(h_vector_class, (t_method)h_vector_read_xml, + gensym("readXML"), A_DEFSYMBOL , 0); + class_addmethod(h_vector_class, (t_method)h_vector_read_at_xml, + gensym("readatXML"), A_GIMME, 0); + + // without an argument the following two methods wont work ??? why?? because of c++? + class_addmethod(h_vector_class, (t_method)h_vector_help, gensym("help"),A_DEFFLOAT, 0); +} |