ScummVM API documentation
modifier_factory.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MTROPOLIS_MODIFIER_FACTORY_H
23 #define MTROPOLIS_MODIFIER_FACTORY_H
24 
25 #include "mtropolis/data.h"
26 #include "mtropolis/runtime.h"
27 
28 namespace MTropolis {
29 
31  explicit ModifierLoaderContext(ChildLoaderStack *mlc_childLoaderStack);
32 
33  ChildLoaderStack *childLoaderStack;
34 };
35 
37  Common::SharedPtr<Modifier> (*createModifier)(ModifierLoaderContext &context, const Data::DataObject &dataObject);
38 };
39 
41  virtual Common::SharedPtr<Modifier> createModifier(ModifierLoaderContext &context, const Data::PlugInModifier &plugInModifierData) const = 0;
42 };
43 
45 };
46 
47 // Helper classes for plug-in modifier loaders
49  PlugInModifierLoaderContext(ModifierLoaderContext &pmlc_modifierLoaderContext, const Data::PlugInModifier &pmlc_plugInModifierData, PlugIn *pmlc_plugIn);
50 
51  ModifierLoaderContext &modifierLoaderContext;
52  const Data::PlugInModifier &plugInModifierData;
53  PlugIn *plugIn;
54 };
55 
56 template<typename TModifier, typename TModifierData>
58 public:
59  explicit PlugInModifierFactory(PlugIn *plugIn);
60 
61  Common::SharedPtr<Modifier> createModifier(ModifierLoaderContext &context, const Data::PlugInModifier &plugInModifierData) const override;
62  Common::SharedPtr<Data::PlugInModifierData> createModifierData() const override;
63  PlugIn &getPlugIn() const override;
64 
65 private:
66  PlugIn &_plugIn;
67 };
68 
69 template<typename TModifier, typename TModifierData>
71 }
72 
73 template<typename TModifier, typename TModifierData>
75  Common::SharedPtr<TModifier> modifier(new TModifier());
76 
77  PlugInModifierLoaderContext plugInContext(context, plugInModifierData, &_plugIn);
78 
79  Modifier *downcastMod = static_cast<Modifier *>(modifier.get());
80  if (!downcastMod->loadPlugInHeader(plugInContext) || !modifier->load(plugInContext, static_cast<const TModifierData &>(*plugInModifierData.plugInData.get())))
81  modifier.reset();
82  else {
83  if (downcastMod->getName().empty())
84  downcastMod->setName(downcastMod->getDefaultName());
85  downcastMod->setSelfReference(modifier);
86  }
87 
88  return Common::SharedPtr<Modifier>(modifier);
89 }
90 
91 template<typename TModifier, typename TModifierData>
93  return Common::SharedPtr<Data::PlugInModifierData>(new TModifierData());
94 }
95 
96 template<typename TModifier, typename TModifierData>
98  return _plugIn;
99 }
100 
101 SIModifierFactory *getModifierFactoryForDataObjectType(Data::DataObjectTypes::DataObjectType dataObjectType);
102 
103 } // End of namespace MTropolis
104 
105 #endif
Definition: modifier_factory.h:30
Definition: modifier_factory.h:44
void reset()
Definition: ptr.h:278
Definition: runtime.h:1185
Definition: runtime.h:3035
Definition: modifier_factory.h:57
Definition: modifier_factory.h:48
PointerType get() const
Definition: ptr.h:229
Definition: runtime.h:2355
Definition: actions.h:25
Definition: modifier_factory.h:36
Definition: modifier_factory.h:40
Definition: data.h:518
Definition: ptr.h:159
Definition: data.h:1904
Definition: core.h:33