Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: some minor changes

File size: 5.6 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/**
29   useable FunctionParameters are:
30   l_INT:    int
31   l_LONG:   long
32   l_SHORT:  short
33   l_FLOAT:  float
34   l_STRING: const char*
35*/
36
37#define l_INT_TYPE int
38#define l_INT_FUNC atoi
39
40#define l_LONG_TYPE long
41#define l_LONG_FUNC atol
42
43#define l_SHORT_TYPE short
44#define l_SHORT_FUNC atoi
45
46#define l_FLOAT_TYPE float
47#define l_FLOAT_FUNC atof
48
49#define l_STRING_TYPE const char*
50#define l_STRING_FUNC
51
52
53/**
54   \brief a Macro to easily implement many different Constructors for the LoadParam-Class
55   \param type1 The type of the first functionParameter
56*/
57#define LoadParam1(type1) \
58 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE)) \
59    { \
60      const char* loadString = grabParameter(root, paramName); \
61      if (loadString != NULL) \
62        (*pt2Object.*function)(type1##_FUNC(loadString)); \
63      else \
64        PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
65    }
66
67
68// 2. TYPES
69#define LoadParam2(type1, type2) \
70 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE)) \
71    { \
72      const char* loadString = grabParameter(root, paramName); \
73      if (loadString != NULL) \
74        { \
75          SubString subLoads(loadString); \
76          if (subLoads.getCount() == 2) \
77            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1))); \
78          else \
79            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
80                      paramName, pt2Object->getClassName(), 2, subLoads.getCount()); \
81        } \
82      else \
83        PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
84    };
85
86
87// 3. TYPES
88#define LoadParam3(type1, type2, type3) \
89 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE)) \
90    { \
91      const char* loadString = grabParameter(root, paramName); \
92      if (loadString != NULL) \
93        { \
94          SubString subLoads(loadString); \
95          if (subLoads.getCount() == 3) \
96            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2))); \
97          else \
98            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
99                      paramName, pt2Object->getClassName(), 3, subLoads.getCount()); \
100        } \
101      else \
102        PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
103    };
104
105
106// 4. TYPES
107#define LoadParam4(type1, type2, type3, type4) \
108 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE)) \
109    { \
110      const char* loadString = grabParameter(root, paramName); \
111      if (loadString != NULL) \
112        { \
113          SubString subLoads(loadString); \
114          if (subLoads.getCount() == 4) \
115            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3))); \
116          else \
117            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
118                      paramName, pt2Object->getClassName(), 4, subLoads.getCount()); \
119        } \
120      else \
121        PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
122    };
123
124
125// 5. TYPES
126#define LoadParam5(type1, type2, type3, type4, type5) \
127 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE)) \
128    { \
129      const char* loadString = grabParameter(root, paramName); \
130      if (loadString != NULL) \
131        { \
132          SubString subLoads(loadString); \
133          if (subLoads.getCount() == 5) \
134            (*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))); \
135          else \
136            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
137                      paramName, pt2Object->getClassName(), 5, subLoads.getCount()); \
138        } \
139      else \
140        PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
141    };
142
143
144class LoadParamDescription
145{
146 private:
147  int paramCount;
148  char** types;
149};
150
151// abstract Base class
152class BaseLoadParam
153{
154 public:
155};
156
157
158// derived template class
159template<class T> class LoadParam : public BaseLoadParam
160{
161 public:
162  LoadParam1(l_STRING);
163  LoadParam2(l_STRING, l_STRING);
164  LoadParam3(l_STRING, l_STRING, l_STRING);
165  LoadParam4(l_STRING, l_STRING, l_STRING, l_STRING);
166
167  LoadParam1(l_INT);
168  LoadParam2(l_INT, l_INT);
169  LoadParam3(l_INT, l_INT, l_INT);
170  LoadParam4(l_INT, l_INT, l_INT, l_INT);
171
172  LoadParam1(l_FLOAT);
173  LoadParam2(l_FLOAT, l_FLOAT);
174  LoadParam3(l_FLOAT, l_FLOAT, l_FLOAT);
175  LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
176};
177
178
179#endif /* _LOAD_PARAM_H */
Note: See TracBrowser for help on using the repository browser.