Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader/src/util/loading/load_param.h @ 4253

Last change on this file since 4253 was 4253, checked in by bensch, 19 years ago

orxonox/branches/levelLoader: constifization

File size: 6.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16/*!
17    \file load_param.h
18    \brief A Class and macro-functions, that makes our lives easy to load-in parameters
19*/
20
21#ifndef _LOAD_PARAM_H
22#define _LOAD_PARAM_H
23
24#include "factory.h"
25#include "debug.h"
26#include "substring.h"
27
28// Forward Declaration //
29template<class T> class tList;
30
31/**
32   useable FunctionParameters are:
33   l_INT:    int
34   l_LONG:   long
35   l_SHORT:  short
36   l_FLOAT:  float
37   l_STRING: const char*
38*/
39
40#define l_INT_TYPE int
41#define l_INT_FUNC atoi
42#define l_INT_NAME "int"
43
44#define l_LONG_TYPE long
45#define l_LONG_FUNC atol
46#define l_LONG_NAME "long"
47
48#define l_SHORT_TYPE short
49#define l_SHORT_FUNC atoi
50#define l_SHORT_NAME "short"
51
52#define l_FLOAT_TYPE float
53#define l_FLOAT_FUNC atof
54#define l_FLOAT_NAME "float"
55
56#define l_STRING_TYPE const char*
57#define l_STRING_FUNC
58#define l_STRING_NAME "string"
59
60
61/**
62   \brief a Macro to easily implement many different Constructors for the LoadParam-Class
63   \param type1 The type of the first functionParameter
64*/
65#define LoadParam1(type1) \
66 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE)) \
67  : BaseLoadParam(pt2Object, type1##_NAME) \
68    { \
69      const char* loadString = grabParameter(root, paramName); \
70      if (loadString != NULL && root != NULL) \
71        (*pt2Object.*function)(type1##_FUNC(loadString)); \
72      else \
73        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
74    }
75
76
77// 2. TYPES
78#define LoadParam2(type1, type2) \
79 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE)) \
80  : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME) \
81    { \
82      const char* loadString = grabParameter(root, paramName); \
83      if (loadString != NULL && root != NULL) \
84        { \
85          SubString subLoads(loadString); \
86          if (subLoads.getCount() == 2) \
87            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1))); \
88          else \
89            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
90                      paramName, pt2Object->getClassName(), 2, subLoads.getCount()); \
91        } \
92      else \
93        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
94    }
95
96
97// 3. TYPES
98#define LoadParam3(type1, type2, type3) \
99 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE))\
100  : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME, type3##_NAME) \
101    { \
102      const char* loadString = grabParameter(root, paramName); \
103      if (loadString != NULL && root != NULL) \
104        { \
105          SubString subLoads(loadString); \
106          if (subLoads.getCount() == 3) \
107            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2))); \
108          else \
109            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
110                      paramName, pt2Object->getClassName(), 3, subLoads.getCount()); \
111        } \
112      else \
113        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
114    }
115
116
117// 4. TYPES
118#define LoadParam4(type1, type2, type3, type4) \
119 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE)) \
120  : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \
121    { \
122      const char* loadString = grabParameter(root, paramName); \
123      if (loadString != NULL && root != NULL) \
124        { \
125          SubString subLoads(loadString); \
126          if (subLoads.getCount() == 4) \
127            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3))); \
128          else \
129            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
130                      paramName, pt2Object->getClassName(), 4, subLoads.getCount()); \
131        } \
132      else \
133        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
134    }
135
136
137// 5. TYPES
138#define LoadParam5(type1, type2, type3, type4, type5) \
139 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE)) \
140  : BaseLoadParam(pt2Object, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \
141    { \
142      const char* loadString = grabParameter(root, paramName); \
143      if (loadString != NULL && root != NULL) \
144        { \
145          SubString subLoads(loadString); \
146          if (subLoads.getCount() == 5) \
147            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3)), type5##_FUNC(subLoads.getString(4))); \
148          else \
149            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
150                      paramName, pt2Object->getClassName(), 5, subLoads.getCount()); \
151        } \
152      else \
153        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
154    }
155
156
157
158#define CREATE_LOAD_DOC(CLASS_NAME) \
159  void documentLoadClass##CLASS_NAME(void) \
160    { \
161      if(LoadClassDescription::parametersDescription) \
162        { \
163          CLASS_NAME docuClass; \
164          docuClass.loadParams(NULL); \
165        } \
166    }
167//  documentLoadClass();
168
169
170class LoadParamDescription
171{
172 private:
173  int paramCount;
174  char** types;
175  const char* className;
176
177};
178
179class LoadClassDescription
180{
181 public:
182
183
184  static bool parametersDescription;
185 
186 private:
187  tList<LoadParamDescription>* paramList;
188};
189
190// abstract Base class
191class BaseLoadParam
192{
193 protected:
194  BaseLoadParam(BaseObject* object, const char* type1 = NULL, const char* type2 = NULL,
195                const char* type3 = NULL, const char* type4 = NULL, const char* type5 = NULL);
196
197 protected:
198  LoadParamDescription* description;
199};
200
201
202// derived template class
203template<class T> class LoadParam : public BaseLoadParam
204{
205 public:
206  LoadParam1(l_STRING);
207  LoadParam2(l_STRING, l_STRING);
208  LoadParam3(l_STRING, l_STRING, l_STRING);
209  LoadParam4(l_STRING, l_STRING, l_STRING, l_STRING);
210
211  LoadParam1(l_INT);
212  LoadParam2(l_INT, l_INT);
213  LoadParam3(l_INT, l_INT, l_INT);
214  LoadParam4(l_INT, l_INT, l_INT, l_INT);
215
216  LoadParam1(l_FLOAT);
217  LoadParam2(l_FLOAT, l_FLOAT);
218  LoadParam3(l_FLOAT, l_FLOAT, l_FLOAT);
219  LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
220};
221
222
223#endif /* _LOAD_PARAM_H */
Note: See TracBrowser for help on using the repository browser.