YAPOG  0.0.1
Yet Another Pokemon Online Game
ObjectFactory.hxx
Go to the documentation of this file.
1 #ifndef YAPOG_OBJECTFACTORY_HXX
2 # define YAPOG_OBJECTFACTORY_HXX
3 
10 
11 namespace yap
12 {
13  template <typename T>
14  T* ObjectFactory::Get (const String& typeName, const ID& id)
15  {
16  if (!objectIDLoaders_.Contains (typeName))
17  YAPOG_THROW("Loader `" + typeName + "' does not exist.");
18 
19  return static_cast<T*> (objectIDLoaders_[typeName]->Load (id));
20  }
21 
22  template <typename T>
23  inline T* ObjectFactory::Create (const String& typeName, const ID& id)
24  {
25  if (!objectIDLoaders_.Contains (typeName))
26  YAPOG_THROW("Loader `" + typeName + "' does not exist.");
27 
28  IObjectIDLoader* loader = objectIDLoaders_[typeName];
29 
30  IIDLoadable* object = loader->Load (id);
31  ICloneable* newObject = object->Clone ();
32 
33  return static_cast<T*> (newObject);
34  }
35 
36  template <typename T>
37  inline T* ObjectFactory::Create (const ID& typeID, const ID& id)
38  {
39  return Create<T> (GetType (typeID), id);
40  }
41 
42  template <typename T>
44  const String& typeName,
45  IReader& reader,
46  const String& rootNodeName)
47  {
48  if (!objectLoaders_.Contains (typeName))
49  YAPOG_THROW("Loader `" + typeName + "' does not exist.");
50 
51  IObjectLoader* loader = objectLoaders_[typeName];
52 
53  ILoadable* object = loader->Load (reader, rootNodeName);
54 
55  return static_cast<T*> (object);
56  }
57 } // namespace yap
58 
59 #endif // YAPOG_OBJECTFACTORY_HXX