Console hides immediately / Cleaned up controller hook
[supertux.git] / src / squirrel / squirrel / sqtable.h
index 820639c..8d90f7b 100644 (file)
@@ -1,88 +1,86 @@
-/*     see copyright notice in squirrel.h */
-#ifndef _SQTABLE_H_
-#define _SQTABLE_H_
-/*
-* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
-* http://www.lua.org/copyright.html#4
-* http://www.lua.org/source/4.0.1/src_ltable.c.html
-*/
-
-#include "sqstring.h"
-
-#define hashptr(p)  (((unsigned long)(p)) >> 3)
-
-struct SQTable : public SQDelegable 
-{
-private:
-       struct _HashNode
-       {
-               SQObjectPtr val;
-               SQObjectPtr key;
-               _HashNode *next;
-       };
-       _HashNode *_firstfree;
-       _HashNode *_nodes;
-       int _numofnodes;
-       int _usednodes;
-       
-///////////////////////////
-       void AllocNodes(int nSize);
-       void Rehash(bool force);
-       SQTable(SQSharedState *ss, int nInitialSize);
-public:
-       static SQTable* Create(SQSharedState *ss,int nInitialSize)
-       {
-               SQTable *newtable = (SQTable*)SQ_MALLOC(sizeof(SQTable));
-               new (newtable) SQTable(ss, nInitialSize);
-               newtable->_delegate = NULL;
-               return newtable;
-       }
-       void Finalize();
-       SQTable *Clone();
-       ~SQTable()
-       {
-               SetDelegate(NULL);
-               REMOVE_FROM_CHAIN(&_sharedstate->_gc_chain, this);
-               for (int i = 0; i < _numofnodes; i++) _nodes[i].~_HashNode();
-               SQ_FREE(_nodes, _numofnodes * sizeof(_HashNode));
-       }
-#ifndef NO_GARBAGE_COLLECTOR 
-       void Mark(SQCollectable **chain);
-#endif
-       inline unsigned long HashKey(const SQObjectPtr &key)
-       {
-               switch(type(key)){
-                       case OT_STRING:         return _string(key)->_hash;
-                       case OT_FLOAT:          return (unsigned long)((long)_float(key));
-                       case OT_INTEGER:        return (unsigned long)((long)_integer(key));
-                       default:                        return hashptr(key._unVal.pRefCounted);
-               }
-       }
-       inline _HashNode *_Get(const SQObjectPtr &key,unsigned long hash)
-       {
-               _HashNode *n = &_nodes[hash];
-               do{
-                       if(_rawval(n->key) == _rawval(key) && type(n->key) == type(key)){
-                               return n;
-                       }
-               }while(n = n->next);
-               return NULL;
-       }
-       bool Get(const SQObjectPtr &key,SQObjectPtr &val);
-       void Remove(const SQObjectPtr &key);
-       bool Set(const SQObjectPtr &key, const SQObjectPtr &val);
-       //returns true if a new slot has been created false if it was already present
-       bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);
-       int Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
-       
-       int CountUsed();
-       void Release()
-       {
-               sq_delete(this, SQTable);
-       }
-       bool SetDelegate(SQTable *mt);
-       
-
-};
-
-#endif //_SQTABLE_H_
+/*     see copyright notice in squirrel.h */\r
+#ifndef _SQTABLE_H_\r
+#define _SQTABLE_H_\r
+/*\r
+* The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)\r
+* http://www.lua.org/copyright.html#4\r
+* http://www.lua.org/source/4.0.1/src_ltable.c.html\r
+*/\r
+\r
+#include "sqstring.h"\r
+\r
+#define hashptr(p)  (((SQHash)(reinterpret_cast<long>(p))) >> 3)\r
+\r
+struct SQTable : public SQDelegable \r
+{\r
+private:\r
+       struct _HashNode\r
+       {\r
+               SQObjectPtr val;\r
+               SQObjectPtr key;\r
+               _HashNode *next;\r
+       };\r
+       _HashNode *_firstfree;\r
+       _HashNode *_nodes;\r
+       SQInteger _numofnodes;\r
+       SQInteger _usednodes;\r
+       \r
+///////////////////////////\r
+       void AllocNodes(SQInteger nSize);\r
+       void Rehash(bool force);\r
+       SQTable(SQSharedState *ss, SQInteger nInitialSize);\r
+public:\r
+       static SQTable* Create(SQSharedState *ss,SQInteger nInitialSize)\r
+       {\r
+               SQTable *newtable = (SQTable*)SQ_MALLOC(sizeof(SQTable));\r
+               new (newtable) SQTable(ss, nInitialSize);\r
+               newtable->_delegate = NULL;\r
+               return newtable;\r
+       }\r
+       void Finalize();\r
+       SQTable *Clone();\r
+       ~SQTable()\r
+       {\r
+               SetDelegate(NULL);\r
+               REMOVE_FROM_CHAIN(&_sharedstate->_gc_chain, this);\r
+               for (SQInteger i = 0; i < _numofnodes; i++) _nodes[i].~_HashNode();\r
+               SQ_FREE(_nodes, _numofnodes * sizeof(_HashNode));\r
+       }\r
+#ifndef NO_GARBAGE_COLLECTOR \r
+       void Mark(SQCollectable **chain);\r
+#endif\r
+       inline SQHash HashKey(const SQObjectPtr &key)\r
+       {\r
+               switch(type(key)){\r
+                       case OT_STRING:         return _string(key)->_hash;\r
+                       case OT_FLOAT:          return (SQHash)((SQInteger)_float(key));\r
+                       case OT_INTEGER:        return (SQHash)((SQInteger)_integer(key));\r
+                       default:                        return hashptr(key._unVal.pRefCounted);\r
+               }\r
+       }\r
+       inline _HashNode *_Get(const SQObjectPtr &key,SQHash hash)\r
+       {\r
+               _HashNode *n = &_nodes[hash];\r
+               do{\r
+                       if(_rawval(n->key) == _rawval(key) && type(n->key) == type(key)){\r
+                               return n;\r
+                       }\r
+               }while(n = n->next);\r
+               return NULL;\r
+       }\r
+       bool Get(const SQObjectPtr &key,SQObjectPtr &val);\r
+       void Remove(const SQObjectPtr &key);\r
+       bool Set(const SQObjectPtr &key, const SQObjectPtr &val);\r
+       //returns true if a new slot has been created false if it was already present\r
+       bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);\r
+       SQInteger Next(bool getweakrefs,const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);\r
+       \r
+       SQInteger CountUsed(){ return _usednodes;}\r
+       void Release()\r
+       {\r
+               sq_delete(this, SQTable);\r
+       }\r
+       \r
+};\r
+\r
+#endif //_SQTABLE_H_\r