20 #include <unordered_map> 
   22 #include <torquescript/storedvalue.hpp> 
   29     class ConsoleObjectDescriptor;
 
   30     struct ObjectInstantiationDescriptor;
 
   32     typedef ConsoleObject* (*InitializeConsoleObjectFromDescriptorPointer)(Interpreter* interpreter, 
struct ObjectInstantiationDescriptor& descriptor);
 
   34     extern std::unordered_map<std::string, ConsoleObjectDescriptor*>* sConsoleObjectDescriptors;
 
   35     static std::unordered_map<std::string, ConsoleObjectDescriptor*>* getConsoleObjectDescriptors()
 
   37         if (sConsoleObjectDescriptors)
 
   39             return sConsoleObjectDescriptors;
 
   41         return sConsoleObjectDescriptors = 
new std::unordered_map<std::string, ConsoleObjectDescriptor*>();
 
   47             ConsoleObjectDescriptor(
const std::string& name, 
const std::string& parentName, InitializeConsoleObjectFromDescriptorPointer initializePointer) : mName(name), mParentName(parentName), mInitializePointer(initializePointer)
 
   49                 std::unordered_map<std::string, ConsoleObjectDescriptor*>* descriptors = getConsoleObjectDescriptors();
 
   51                 assert(descriptors->find(name) == descriptors->end());
 
   52                 descriptors->insert(std::make_pair(name, 
this));
 
   56             std::string mParentName;
 
   57             std::vector<std::string> mHierarchy;
 
   58             InitializeConsoleObjectFromDescriptorPointer mInitializePointer;
 
   61     static std::vector<std::string> relinkNamespace(
const std::string& space)
 
   63         std::unordered_map<std::string, ConsoleObjectDescriptor*>* descriptors = getConsoleObjectDescriptors();
 
   65         auto search = descriptors->find(space);
 
   66         if (search == descriptors->end())
 
   68             throw std::runtime_error(
"Fatal error in relink namespaces!");
 
   71         ConsoleObjectDescriptor* currentDescriptor = search->second;
 
   73         std::vector<std::string> result;
 
   74         result.push_back(currentDescriptor->mParentName);
 
   77         if (currentDescriptor->mParentName == 
"ConsoleObject")
 
   82         std::vector<std::string> children = relinkNamespace(currentDescriptor->mParentName);
 
   83         result.insert(result.end(), children.begin(), children.end());
 
   87     static void relinkNamespaces()
 
   89         std::unordered_map<std::string, ConsoleObjectDescriptor*>* descriptors = getConsoleObjectDescriptors();
 
   91         for (
auto&& entry : *descriptors)
 
   94             entry.second->mHierarchy = relinkNamespace(entry.second->mName);
 
   95             entry.second->mHierarchy.insert(entry.second->mHierarchy.begin(), entry.second->mName);
 
   99     template <
typename classType>
 
  105     #define DECLARE_CONSOLE_OBJECT(type, super)                                         \ 
  107         struct TypeInformation<type>                                                    \ 
  109             typedef TypeInformation<super> ParentInfo;                                  \ 
  110             static std::string getName()                                                \ 
  114             static std::vector<std::string> getHierarchy()                              \ 
  116                 const std::string current = #type;                                      \ 
  117                 std::vector<std::string> result;                                        \ 
  118                 result.push_back(current);                                              \ 
  119                 const std::vector<std::string> upper = ParentInfo::getHierarchy();      \ 
  120                 result.insert(result.end(), upper.begin(), upper.end());                \ 
  123             static ConsoleObjectDescriptor* Descriptor;                                 \ 
  126     #define DECLARE_CONSOLE_OBJECT_BODY()                                               \ 
  128             virtual std::string getClassName() override;                                \ 
  130     #define IMPLEMENT_CONSOLE_OBJECT(type, super)                                                                   \ 
  131         ConsoleObjectDescriptor* TypeInformation<type>::Descriptor = new ConsoleObjectDescriptor(#type, #super, type::instantiateFromDescriptor);    \ 
  132         std::string type::getClassName()                                                                            \ 
  169             virtual bool addChild(std::shared_ptr<ConsoleObject> child);
 
  181         static std::string getName()
 
  183             return "ConsoleObject";
 
  186         static std::vector<std::string> getHierarchy()
 
  188             std::vector<std::string> result;
 
  189             result.push_back(
"ConsoleObject");
 
Definition: consoleobject.hpp:45
 
Base class for object instances recognized by the interpreter. These object instances may contain mem...
Definition: consoleobject.hpp:143
 
virtual std::string getClassName()=0
Retrieves the class name of this ConsoleObject instance.
 
void setTaggedField(const std::string &name, StoredValue value)
Sets a tagged field by name on the object.
 
std::unordered_map< std::string, StoredValue > mTaggedFields
A mapping of tagged field names to their stored values.
Definition: consoleobject.hpp:175
 
StoredValue * getTaggedField(const std::string &name)
Retrieves a tagged field by name from the object.
 
The interpreter class represents a high level instance of the TorqueScript interpreter....
Definition: interpreter.hpp:46
 
Storage class used to keep variable values in-memory of arbitrary data types. The data types supporte...
Definition: storedvalue.hpp:80