1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * |
---|
4 | * |
---|
5 | * License notice: |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (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, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | * |
---|
21 | * Author: |
---|
22 | * Fabian 'x3n' Landau |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #ifndef _XMLPort_H__ |
---|
29 | #define _XMLPort_H__ |
---|
30 | |
---|
31 | #include "util/XMLIncludes.h" |
---|
32 | #include "util/MultiTypeMath.h" |
---|
33 | #include "Functor.h" |
---|
34 | |
---|
35 | #include "CorePrereqs.h" |
---|
36 | |
---|
37 | |
---|
38 | #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, loading) \ |
---|
39 | orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ |
---|
40 | if (!xmlcontainer##loadfunction##savefunction) \ |
---|
41 | { \ |
---|
42 | xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction)); \ |
---|
43 | this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \ |
---|
44 | } \ |
---|
45 | xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) |
---|
46 | |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | class _CoreExport XMLPortParamContainer |
---|
51 | { |
---|
52 | public: |
---|
53 | XMLPortParamContainer(); |
---|
54 | |
---|
55 | inline const std::string& getName() const |
---|
56 | { return this->paramname_; } |
---|
57 | |
---|
58 | XMLPortParamContainer& description(const std::string description); |
---|
59 | const std::string& getDescription(); |
---|
60 | |
---|
61 | XMLPortParamContainer& defaultValues(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) |
---|
62 | { |
---|
63 | this->defaultValues_[0] = param1; |
---|
64 | this->defaultValues_[1] = param2; |
---|
65 | this->defaultValues_[2] = param3; |
---|
66 | this->defaultValues_[3] = param4; |
---|
67 | this->defaultValues_[4] = param5; |
---|
68 | |
---|
69 | return (*this); |
---|
70 | } |
---|
71 | |
---|
72 | protected: |
---|
73 | std::string classname_; |
---|
74 | std::string paramname_; |
---|
75 | MultiTypeMath defaultValues_[5]; |
---|
76 | |
---|
77 | private: |
---|
78 | LanguageEntryLabel description_; |
---|
79 | bool bAddedDescription_; |
---|
80 | bool bAddedDefaultValues_; |
---|
81 | }; |
---|
82 | |
---|
83 | template <class T> |
---|
84 | class XMLPortClassParamContainer : public XMLPortParamContainer |
---|
85 | { |
---|
86 | public: |
---|
87 | XMLPortClassParamContainer(const std::string classname, const std::string paramname, FunctorMember<T>* loadfunction, FunctorMember<T>* savefunction) |
---|
88 | { |
---|
89 | this->classname_ = classname; |
---|
90 | this->paramname_ = paramname; |
---|
91 | this->loadfunction_ = loadfunction; |
---|
92 | this->savefunction_ = savefunction; |
---|
93 | } |
---|
94 | |
---|
95 | XMLPortParamContainer& port(T* object, Element& xmlelement, bool loading) |
---|
96 | { |
---|
97 | if (loading) |
---|
98 | { |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | } |
---|
103 | |
---|
104 | return (*this); |
---|
105 | } |
---|
106 | |
---|
107 | private: |
---|
108 | FunctorMember<T>* loadfunction_; |
---|
109 | FunctorMember<T>* savefunction_; |
---|
110 | }; |
---|
111 | } |
---|
112 | |
---|
113 | #endif /* _XMLPort_H__ */ |
---|