00001
00011 #ifndef ENTITYTEMPLATETABLE_H
00012 #define ENTITYTEMPLATETABLE_H
00013
00014 #include <boost/shared_ptr.hpp>
00015 #include "EntityInstance.h"
00016 #include "TemplateTable.h"
00017 #include "EntityTemplate.h"
00018 #include "BehaviorTemplateTable.h"
00019 #include "LibraryEntities.h"
00020 #include "util/Error.h"
00021
00022 namespace green
00023 {
00024 class EntityTemplateTable : public TemplateTable
00025 {
00026 protected:
00027 BehaviorTemplateTablePtr mBehaviorTemplates;
00028
00029 public:
00030
00031 Key AddEntry(const Name& name, EntityTemplatePtr entry)
00032 {
00033 CHECK_SHARED(entry);
00034 return TemplateTable::AddEntry(name, entry);
00035 }
00036
00037 void SetBehaviorTemplateTable(BehaviorTemplateTablePtr behaviors) {
00038 CHECK_SHARED(behaviors);
00039 mBehaviorTemplates = behaviors;
00040 }
00041
00050 EntityInstancePtr
00051 Instantiate(Key key, ArgListPtr initArgs) const
00052 {
00053 CHECK_SHARED(initArgs);
00054 EntityTemplatePtr entry = ENTITY_TEMPLATE_CAST(
00055 this->_checkInstArgs(key, initArgs));
00056
00057 CHECK_SHARED(entry);
00058
00059
00060 EntityInstancePtr instance(new EntityInstance(key, entry, mBehaviorTemplates));
00061 instance->SetTemplate(key);
00062
00063
00064 this->_doInstantiate(instance, entry, initArgs);
00065
00066
00067 return instance;
00068
00069 }
00070
00071 };
00072 typedef boost::shared_ptr<EntityTemplateTable> EntityTemplateTablePtr;
00073 #define ENTITY_TEMPLATE_TABLE_CAST(x) boost::dynamic_pointer_cast<EntityTemplateTable>(x)
00074 }
00075
00076 #endif