Torque3D Documentation / _generateds / simFieldDictionary.h

simFieldDictionary.h

Engine/source/console/simFieldDictionary.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SIMFIELDDICTIONARY_H_
 25#define _SIMFIELDDICTIONARY_H_
 26
 27// Forward Refs
 28class ConsoleBaseType;
 29class SimObject;
 30
 31#include "core/stringTable.h"
 32#include "core/stream/stream.h"
 33
 34#ifndef _TORQUE_STRING_H_
 35#include "core/util/str.h"
 36#endif
 37
 38/// Dictionary to keep track of dynamic fields on SimObject.
 39class SimFieldDictionary
 40{
 41   friend class SimFieldDictionaryIterator;
 42
 43public:
 44   struct Entry
 45   {
 46      Entry() : type( NULL ) {};
 47
 48      StringTableEntry slotName;
 49      char *value;
 50      Entry *next;
 51      ConsoleBaseType *type;
 52   };
 53   enum
 54   {
 55      HashTableSize = 19
 56   };
 57   Entry *mHashTable[HashTableSize];
 58
 59private:
 60   static Entry   *smFreeList;
 61
 62   void           freeEntry(Entry *entry);
 63   Entry*         addEntry( U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value = 0 );
 64
 65   static U32     getHashValue( StringTableEntry slotName );
 66   static U32     getHashValue( const String& fieldName );
 67
 68   U32   mNumFields;
 69
 70   /// In order to efficiently detect when a dynamic field has been
 71   /// added or deleted, we increment this every time we add or
 72   /// remove a field.
 73   U32 mVersion;
 74
 75public:
 76   const U32 getVersion() const { return mVersion; }
 77
 78   SimFieldDictionary();
 79   ~SimFieldDictionary();
 80   void setFieldType(StringTableEntry slotName, const char *typeString);
 81   void setFieldType(StringTableEntry slotName, const U32 typeId);
 82   void setFieldType(StringTableEntry slotName, ConsoleBaseType *type);
 83   void setFieldValue(StringTableEntry slotName, const char *value);
 84   const char *getFieldValue(StringTableEntry slotName);
 85   U32 getFieldType(StringTableEntry slotName) const;
 86   Entry  *findDynamicField(const String &fieldName) const;
 87   Entry  *findDynamicField( StringTableEntry fieldName) const;
 88   void writeFields(SimObject *obj, Stream &strem, U32 tabStop);
 89   void printFields(SimObject *obj);
 90   void assignFrom(SimFieldDictionary *dict);
 91   U32   getNumFields() const { return mNumFields; }
 92
 93   Entry  *operator[](U32 index);
 94};
 95
 96class SimFieldDictionaryIterator
 97{
 98   SimFieldDictionary *          mDictionary;
 99   S32                           mHashIndex;
100   SimFieldDictionary::Entry *   mEntry;
101
102public:
103   SimFieldDictionaryIterator(SimFieldDictionary*);
104   SimFieldDictionary::Entry* operator++();
105   SimFieldDictionary::Entry* operator*();
106};
107
108
109#endif // _SIMFIELDDICTIONARY_H_
110