]> git.tdb.fi Git - gldbg.git/blobdiff - source/autoconstptr.h
Add classes to track OpenGL state and commands to inspect it
[gldbg.git] / source / autoconstptr.h
diff --git a/source/autoconstptr.h b/source/autoconstptr.h
new file mode 100644 (file)
index 0000000..04e1fba
--- /dev/null
@@ -0,0 +1,30 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#ifndef AUTOCONSTPTR_H_
+#define AUTOCONSTPTR_H_
+
+/**
+A smart pointer that only provides non-const access to the contents if the
+pointer itself is non-const.
+*/
+template<typename T>
+class AutoConstPtr
+{
+private:
+       T *ptr;
+
+public:
+       AutoConstPtr(T *p): ptr(p) { }
+       AutoConstPtr &operator=(T *p) { ptr = p; return *this; }
+       T *operator->() { return ptr; }
+       const T *operator->() const { return ptr; }
+       operator T *() { return ptr; }
+       operator const T *() const { return ptr; }
+};
+
+#endif