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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#ifndef _SIMFIELDDICTIONARY_H_
 30#define _SIMFIELDDICTIONARY_H_
 31
 32// Forward Refs
 33class ConsoleBaseType;
 34class SimObject;
 35
 36#include "core/stringTable.h"
 37#include "core/stream/stream.h"
 38
 39#ifndef _TORQUE_STRING_H_
 40#include "core/util/str.h"
 41#endif
 42
 43/// Dictionary to keep track of dynamic fields on SimObject.
 44class SimFieldDictionary
 45{
 46   friend class SimFieldDictionaryIterator;
 47
 48public:
 49   struct Entry
 50   {
 51      Entry() : slotName(StringTable->EmptyString()), value(NULL), next(NULL), type(NULL) {};
 52
 53      StringTableEntry slotName;
 54      char *value;
 55      Entry *next;
 56      ConsoleBaseType *type;
 57   };
 58   enum
 59   {
 60      HashTableSize = 19
 61   };
 62   Entry *mHashTable[HashTableSize];
 63
 64private:
 65   static Entry   *smFreeList;
 66
 67   void           freeEntry(Entry *entry);
 68   Entry*         addEntry(U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value = 0);
 69
 70   static U32     getHashValue(StringTableEntry slotName);
 71   static U32     getHashValue(const String& fieldName);
 72
 73   U32   mNumFields;
 74
 75   /// In order to efficiently detect when a dynamic field has been
 76   /// added or deleted, we increment this every time we add or
 77   /// remove a field.
 78   U32 mVersion;
 79
 80public:
 81   const U32 getVersion() const { return mVersion; }
 82
 83   SimFieldDictionary();
 84   ~SimFieldDictionary();
 85   void setFieldType(StringTableEntry slotName, const char *typeString);
 86   void setFieldType(StringTableEntry slotName, const U32 typeId);
 87   void setFieldType(StringTableEntry slotName, ConsoleBaseType *type);
 88   void setFieldValue(StringTableEntry slotName, const char *value);
 89   const char *getFieldValue(StringTableEntry slotName);
 90   U32 getFieldType(StringTableEntry slotName) const;
 91   Entry  *findDynamicField(const String &fieldName) const;
 92   Entry  *findDynamicField(StringTableEntry fieldName) const;
 93   void writeFields(SimObject *obj, Stream &strem, U32 tabStop);
 94   void printFields(SimObject *obj);
 95   void assignFrom(SimFieldDictionary *dict);
 96   U32   getNumFields() const { return mNumFields; }
 97
 98   Entry  *operator[](U32 index);
 99   void setFieldValue(StringTableEntry slotName, const char *value, ConsoleBaseType *type, bool no_replace);
100   void assignFrom(SimFieldDictionary *dict, const char* filter, bool no_replace);
101};
102
103class SimFieldDictionaryIterator
104{
105   SimFieldDictionary *          mDictionary;
106   S32                           mHashIndex;
107   SimFieldDictionary::Entry *   mEntry;
108
109public:
110   SimFieldDictionaryIterator(SimFieldDictionary*);
111   SimFieldDictionary::Entry* operator++();
112   SimFieldDictionary::Entry* operator*();
113};
114
115
116#endif // _SIMFIELDDICTIONARY_H_
117