]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programsyntax.h
Refresh lighting and culling uniforms if the camera changes in pop_state
[libs/gl.git] / source / programsyntax.h
index c502ba47a90f32701bc885e44006ff48a8d93c24..14e5d8e786cb679e36c448cf5ca68b1dfe387fd3 100644 (file)
@@ -5,6 +5,7 @@
 #include <map>
 #include <string>
 #include <vector>
+#include <msp/core/refptr.h>
 #include "extension.h"
 
 namespace Msp {
@@ -25,39 +26,43 @@ public:
 };
 
 template<typename T>
-class NodePtr
+class NodePtr: public RefPtr<T>
 {
-private:
-       T *node;
-
 public:
-       NodePtr(T *n = 0): node(n) { }
-       NodePtr(const NodePtr &p): node(clone(p.node)) { }
-       NodePtr &operator=(const NodePtr &p) { delete node; node = clone(p.node); return *this; }
-#if __cplusplus>=201103L
-       NodePtr(NodePtr &&p): node(p.node) { p.node = 0; }
-       NodePtr &operator=(NodePtr &&p) { delete node; node = p.node; p.node = 0; return *this; }
-#endif
-       ~NodePtr() { delete node; }
+       NodePtr() { }
+       NodePtr(T *p): RefPtr<T>(p) { }
+       NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
 
-private:
-       static T *clone(T *n) { return n ? n->clone() : 0; }
+       template<typename U>
+       NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
+
+       template<typename U>
+       NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
+};
 
+template<typename C>
+class NodeContainer: public C
+{
 public:
-       T *operator->() { return node; }
-       const T *operator->() const { return node; }
-       T &operator*() { return *node; }
-       const T &operator*() const { return *node; }
-       operator void *() const { return node; }
+       NodeContainer() { }
+       NodeContainer(const NodeContainer &);
 };
 
+template<typename T>
+class NodeList: public NodeContainer<std::list<RefPtr<T> > >
+{ };
+
+template<typename T>
+class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
+{ };
+
 struct StructDeclaration;
 struct VariableDeclaration;
 struct FunctionDeclaration;
 
 struct Block: Node
 {
-       std::list<NodePtr<Node> > body;
+       NodeList<Node> body;
        bool use_braces;
        std::map<std::string, StructDeclaration *> types;
        std::map<std::string, VariableDeclaration *> variables;
@@ -149,7 +154,7 @@ struct FunctionCall: Expression
        std::string name;
        FunctionDeclaration *declaration;
        bool constructor;
-       std::vector<NodePtr<Expression> > arguments;
+       NodeArray<Expression> arguments;
 
        FunctionCall();
 
@@ -245,7 +250,7 @@ struct FunctionDeclaration: Node
 {
        std::string return_type;
        std::string name;
-       std::vector<NodePtr<VariableDeclaration> > parameters;
+       NodeArray<VariableDeclaration> parameters;
        FunctionDeclaration *definition;
        Block body;