YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
ObjectFactory.hxx
Go to the documentation of this file.
1
#ifndef YAPOG_OBJECTFACTORY_HXX
2
# define YAPOG_OBJECTFACTORY_HXX
3
4
# include "
YAPOG/Game/Factory/ILoadable.hpp
"
5
# include "
YAPOG/Game/Factory/IIDLoadable.hpp
"
6
# include "
YAPOG/Game/Factory/IObjectIDLoader.hpp
"
7
# include "
YAPOG/Game/Factory/IObjectLoader.hpp
"
8
# include "
YAPOG/System/Error/Exception.hpp
"
9
# include "
YAPOG/System/StringHelper.hpp
"
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>
43
inline
T*
ObjectFactory::Create
(
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
YAPOG
include
YAPOG
Game
Factory
ObjectFactory.hxx
Generated on Mon Sep 17 2012 22:24:23 for YAPOG by
1.8.1.1