sqrat  0.9
sqrat
 All Classes Functions Variables Enumerations Enumerator Pages
sqratConst.h
1 //
2 // SqratConst: Constant and Enumeration Binding
3 //
4 
5 //
6 // Copyright (c) 2009 Brandon Jones
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
26 //
27 
28 #if !defined(_SCRAT_CONST_H_)
29 #define _SCRAT_CONST_H_
30 
31 #include <squirrel.h>
32 #include <string.h>
33 
34 #include "sqratObject.h"
35 
36 namespace Sqrat {
37 
47 class Enumeration : public Object {
48 public:
62  Enumeration(HSQUIRRELVM v = DefaultVM::Get(), bool createTable = true) : Object(v, false) {
63  if(createTable) {
64  sq_newtable(vm);
65  sq_getstackobj(vm,-1,&obj);
66  sq_addref(vm, &obj);
67  sq_pop(vm,1);
68  }
69  }
70 
80  virtual Enumeration& Const(const SQChar* name, const int val) {
81  BindValue<int>(name, val, false);
82  return *this;
83  }
84 
94  virtual Enumeration& Const(const SQChar* name, const float val) {
95  BindValue<float>(name, val, false);
96  return *this;
97  }
98 
108  virtual Enumeration& Const(const SQChar* name, const SQChar* val) {
109  BindValue<const SQChar*>(name, val, false);
110  return *this;
111  }
112 };
113 
123 class ConstTable : public Enumeration {
124 public:
131  ConstTable(HSQUIRRELVM v = DefaultVM::Get()) : Enumeration(v, false) {
132  sq_pushconsttable(vm);
133  sq_getstackobj(vm,-1, &obj);
134  sq_pop(v,1); // No addref needed, since the consttable is always around
135  }
136 
146  virtual ConstTable& Const(const SQChar* name, const int val) {
147  Enumeration::Const(name, val);
148  return *this;
149  }
150 
160  virtual ConstTable& Const(const SQChar* name, const float val) {
161  Enumeration::Const(name, val);
162  return *this;
163  }
164 
174  virtual ConstTable& Const(const SQChar* name, const SQChar* val) {
175  Enumeration::Const(name, val);
176  return *this;
177  }
178 
188  ConstTable& Enum(const SQChar* name, Enumeration& en) {
189  sq_pushobject(vm, GetObject());
190  sq_pushstring(vm, name, -1);
191  sq_pushobject(vm, en.GetObject());
192  sq_newslot(vm, -3, false);
193  sq_pop(vm,1); // pop table
194  return *this;
195  }
196 };
197 
198 }
199 
200 #endif
ConstTable & Enum(const SQChar *name, Enumeration &en)
Definition: sqratConst.h:188
static HSQUIRRELVM Get()
Definition: sqratUtil.h:92
virtual ConstTable & Const(const SQChar *name, const SQChar *val)
Definition: sqratConst.h:174
ConstTable(HSQUIRRELVM v=DefaultVM::Get())
Definition: sqratConst.h:131
virtual Enumeration & Const(const SQChar *name, const int val)
Definition: sqratConst.h:80
Definition: sqratConst.h:123
virtual ConstTable & Const(const SQChar *name, const int val)
Definition: sqratConst.h:146
virtual HSQOBJECT GetObject() const
Definition: sqratObject.h:182
virtual Enumeration & Const(const SQChar *name, const float val)
Definition: sqratConst.h:94
Definition: sqratObject.h:48
virtual Enumeration & Const(const SQChar *name, const SQChar *val)
Definition: sqratConst.h:108
Enumeration(HSQUIRRELVM v=DefaultVM::Get(), bool createTable=true)
Definition: sqratConst.h:62
Definition: sqratConst.h:47
virtual ConstTable & Const(const SQChar *name, const float val)
Definition: sqratConst.h:160