X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/blobdiff_plain/c7f552fd8888da2f0d8cfb228fe0f28d3df3a12c..b4b6f2ea75b9f0f3ca918f5b84016610bf7a4d4f:/interpretor/preprocessor/faust-0.9.47mr3/compiler/tlib/property.hh diff --git a/interpretor/preprocessor/faust-0.9.47mr3/compiler/tlib/property.hh b/interpretor/preprocessor/faust-0.9.47mr3/compiler/tlib/property.hh new file mode 100644 index 0000000..eef723c --- /dev/null +++ b/interpretor/preprocessor/faust-0.9.47mr3/compiler/tlib/property.hh @@ -0,0 +1,152 @@ +#ifndef __PROPERTY__ +#define __PROPERTY__ + +#include "tree.hh" + +template class property +{ + Tree fKey; + + P* access(Tree t) + { + Tree d = t->getProperty(fKey); + return d ? (P*)(d->node().getPointer()) : 0; + } + +public: + + property () : fKey(tree(Node(unique("property_")))) {} + + property (const char* keyname) : fKey(tree(Node(keyname))) {} + + void set(Tree t, const P& data) + { + P* p = access(t); + if (p) { + *p = data; + } else { + t->setProperty(fKey, tree(Node(new P(data)))); + } + } + + bool get(Tree t, P& data) + { + P* p = access(t); + if (p) { + data = *p; + return true; + } else { + return false; + } + } + + void clear(Tree t) + { + P* p = access(t); + if (p) { delete p; } + t->clearProperty(fKey); + } +}; + + +template<> class property +{ + Tree fKey; + +public: + + property () : fKey(tree(Node(unique("property_")))) {} + + property (const char* keyname) : fKey(tree(Node(keyname))) {} + + void set(Tree t, Tree data) + { + t->setProperty(fKey, data); + } + + bool get(Tree t, Tree& data) + { + Tree d = t->getProperty(fKey); + if (d) { + data = d; + return true; + } else { + return false; + } + } + + void clear(Tree t) + { + t->clearProperty(fKey); + } +}; + + +template<> class property +{ + Tree fKey; + +public: + + property () : fKey(tree(Node(unique("property_")))) {} + + property (const char* keyname) : fKey(tree(Node(keyname))) {} + + void set(Tree t, int i) + { + t->setProperty(fKey, tree(Node(i))); + } + + bool get(Tree t, int& i) + { + Tree d = t->getProperty(fKey); + if (d) { + i = d->node().getInt(); + return true; + } else { + return false; + } + } + + void clear(Tree t) + { + t->clearProperty(fKey); + } +}; + + +template<> class property +{ + Tree fKey; + +public: + + property () : fKey(tree(Node(unique("property_")))) {} + + property (const char* keyname) : fKey(tree(Node(keyname))) {} + + void set(Tree t, double x) + { + t->setProperty(fKey, tree(Node(x))); + } + + bool get(Tree t, double& x) + { + Tree d = t->getProperty(fKey); + if (d) { + x = d->node().getDouble(); + return true; + } else { + return false; + } + } + + void clear(Tree t) + { + t->clearProperty(fKey); + } +}; + + + +#endif