Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/util/parameter.h b/util/parameter.h
new file mode 100644
index 00000000..bc04ba4b
--- /dev/null
+++ b/util/parameter.h
@@ -0,0 +1,63 @@
+#ifndef _paintown_parameter_h
+#define _paintown_parameter_h
+
+/* parameters are to be used to control the dynamic extent of values. values
+ * can be pushed onto the current extent and are automatically popped off
+ * upon function return.
+ * this is similar to 'parameters' in Racket.
+ *
+ * This class is not thread safe.
+ */
+
+#include <vector>
+
+namespace Util{
+
+/* the static variable `stack' has to be defined somewhere. use this syntax to define it
+ * template <> vector<int> Parameter<int>::stack;
+ */
+template <class Value>
+class Parameter{
+public:
+ /* push a new value on the stack */
+ Parameter(const Value & what):
+ items(0){
+ push(what);
+ }
+
+ Parameter():
+ items(0){
+ }
+
+ /* pop last value */
+ ~Parameter(){
+ for (int i = 0; i < items; i++){
+ if (stack.size() > 0){
+ stack.pop_back();
+ }
+ }
+ }
+
+ void push(const Value & what){
+ items += 1;
+ stack.push_back(what);
+ }
+
+ /* get the current value */
+ static Value current(){
+ if (stack.size() > 0){
+ return stack.back();
+ }
+ return Value();
+ }
+
+ static std::vector<Value> stack;
+
+protected:
+ /* number of things pushed onto the stack by this object */
+ int items;
+};
+
+}
+
+#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:21 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68717
Default Alt Text
(1 KB)

Event Timeline