libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moXmlConfig.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moXmlConfig.cpp
4 
5  ****************************************************************************
6  * *
7  * This source 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 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andr� Colubri
29 
30 *******************************************************************************/
31 
32 #include "moXmlConfig.h"
33 
34 
35 //====================================================================================================================
36 //
37 //
38 // moXmlParam
39 //
40 //
41 //====================================================================================================================
42 
43 /*
44 moXmlParam::moXmlParam()
45 {
46  //subcount = 0;
47 }
48 
49 moXmlParam::moXmlParam( char *nvalue)
50 {
51  moXmlParam::SetValue( nvalue);
52 }
53 
54 moXmlParam::~moXmlParam()
55 {
56 }
57 
58 void moXmlParam::SetValue( char *nvalue)
59 {
60  moText tmp( nvalue);
61 
62  value = nvalue;
63  subcount = 0;
64  tmp.Trim();
65  while( tmp!=moText("") && subcount<MO_MAX_SUBVALOR)
66  {
67  //subvalue[subcount] = tmp.Scan(" \t");
68  subvalue[subcount] = tmp.ScanEx(" \t");
69  subcount++;
70 
71 }
72 
73 moText moXmlParam::GetValue()
74 {
75  return value;
76 }
77 
78 moText moXmlParam::GetValueStr( int i)
79 {
80  if(0<=i && i<subcount)
81  return subvalue[i];
82  else
83  return moText("");
84 }
85 
86 
87 char moXmlParam::GetValueChr( int i)
88 {
89  if(0<=i && i<subcount)
90  return subvalue[i][0];
91  else
92  return '\0';
93 }
94 
95 
96 long moXmlParam::GetValueInt( int i)
97 {
98  long tmp;
99  if(0<=i && i<subcount)
100  {
101  sscanf( subvalue[i], "%d", &tmp);
102  return tmp;
103  }
104  else
105  return 0;
106 }
107 
108 
109 double moXmlParam::GetValueFlt( int i)
110 {
111  //double tmp;
112  float tmp2;
113 
114  if(0<=i && i<subcount)
115  {
116  sscanf( subvalue[i], "%f", &tmp2);
117  //return tmp;
118  return tmp2;
119  }
120  else
121  return 0.0;
122 }
123 
124 //====================================================================================================================
125 //
126 //
127 // moXmlConfig
128 //
129 //
130 //====================================================================================================================
131 
132 
133 moXmlConfig::moXmlConfig()
134 {
135  m_ConfigLoaded = false;
136 
137  param = NULL;
138  paramcount = 0;
139  currentparam = MO_PARAM_NOT_SEL;
140 
141  emptyparam.SetValue("0");
142 }
143 
144 moXmlConfig::~moXmlConfig()
145 {
146  DeleteConfig();
147 
148 }
149 
150 MOboolean
151 moXmlConfig::IsConfigLoaded() {
152 
153  return m_ConfigLoaded;
154 
155 }
156 
157 int moXmlConfig::LoadConfig( char *fname)
158 {
159  m_ConfigLoaded = true;
160 
161  return MO_CONFIG_OK;
162 }
163 
164 int moXmlConfig::SaveConfig( char* fname)
165 {
166 
167  return MO_CONFIG_OK;
168 }
169 
170 void moXmlConfig::DeleteConfig()
171 {
172  paramcount = 0;
173  currentparam = MO_PARAM_NOT_SEL;
174 
175  for( i=0; i<MO_MAX_PARAM; i++)
176  nameparam[i] = "";
177 
178  memset( valuecount, 0, sizeof(valuecount));
179  memset( currentvalue, MO_PARAM_NOT_SEL, sizeof(currentvalue));
180 
181  m_ConfigLoaded = false;
182 }
183 
184 
185 void moXmlConfig::AddParam( char* name)
186 {
187  if(paramcount == 0)
188  {
189  param = new moParam*[MO_MAX_PARAM];
190  if(!param)
191  {
192  printf("Insufficient memory for the configuration.\n");
193  exit(1);
194  }
195  else
196  for( int i=0; i<MO_MAX_PARAM; i++)
197  param[i] = NULL;
198  }
199  currentparam = paramcount;
200  paramcount++;
201  nameparam[currentparam] = name;
202  valuecount[currentparam] = 0;
203 
204 }
205 
206 moParam& moXmlConfig::GetParam( int nroparam, int nroopcion)
207 {
208  if(0<=nroparam && nroparam<paramcount &&
209  0<=nroopcion && nroopcion<valuecount[nroparam])
210  return param[nroparam][nroopcion];
211  else
212  {
213  printf("Parameter out of range.\n");
214  return emptyparam;
215  }
216  return emptyparam;
217 }
218 
219 moParam& moXmlConfig::GetParam( int nroparam)
220 {
221  if(0<=nroparam && nroparam<paramcount &&
222  0<=currentvalue[nroparam] && currentvalue[nroparam]<valuecount[nroparam])
223  return param[nroparam][currentvalue[nroparam]];
224  else
225  {
226  printf("Parameter out of range.\n");
227  return emptyparam;
228  }
229  return emptyparam;
230 }
231 
232 moParam& moXmlConfig::GetParam()
233 {
234  if(0<=currentparam && currentparam<paramcount &&
235  0<=currentvalue[currentparam] && currentvalue[currentparam]<valuecount[currentparam])
236  return param[currentparam][currentvalue[currentparam]];
237  else
238  {
239  printf("Parameter out of range.\n");
240  return emptyparam;
241  }
242  return emptyparam;
243 }
244 
245 void moXmlConfig::SetParam( int nroparam, int nroopcion, moParam& nparam)
246 {
247  if(0<=nroparam && nroparam<paramcount && 0<=nroopcion && nroopcion<valuecount[nroparam])
248  param[nroparam][nroopcion] = nparam;
249 
250 }
251 
252 int moXmlConfig::GetParamCount()
253 {
254  return m_Params.Count();
255 }
256 
257 int moXmlConfig::GetCurrentParam()
258 {
259  return m_ParamIndex;
260 }
261 
262 void moXmlConfig::SetCurrentParam( int nactual)
263 {
264  if(0<=nactual && nactual<m_Params.Count())
265  m_ParamIndex = nactual;
266 }
267 
268 void moXmlConfig::FirstParam()
269 {
270  if(m_ParamIndex!=MO_PARAM_NOT_SEL && m_Params.Count()>0)
271  m_ParamIndex=0;
272 }
273 
274 void moXmlConfig::NextParam()
275 {
276  if(m_ParamIndex!=MO_PARAM_NOT_SEL && m_ParamIndex<m_Params.Count()-1)
277  m_ParamIndex++;
278 }
279 
280 void moXmlConfig::PrevParam()
281 {
282  if(m_ParamIndex!=MO_PARAM_NOT_SEL && m_ParamIndex>0)
283  m_ParamIndex--;
284 }
285 
286 int moXmlConfig::GetParamIndex( char* name)
287 {
288  for( int i=0; i<paramcount; i++)
289  {
290  if( nameparam[i]== name)
291  return i;
292  }
293 
294  return MO_PARAM_NOT_FOUND;
295 }
296 
297 moText moXmlConfig::GetParamName( int nroparam)
298 {
299  if(0<=nroparam && nroparam<paramcount)
300  return nameparam[nroparam];
301  else
302  {
303  printf("Par�etro fuera de rango.\n");
304  return moText("");
305  }
306 
307  return moText("");
308 }
309 
310 
311 void moXmlConfig::AddValue( int nroparam, char* valueparam)
312 {
313  if(valuecount[nroparam] == 0)
314  {
315  param[nroparam] = new moParam[MO_MAX_VALOR];
316  if(!param[nroparam])
317  {
318  printf("Insuficiente memoria para la configuracion.\n");
319  exit(1);
320  }
321  }
322  currentvalue[nroparam] = valuecount[nroparam];
323  valuecount[nroparam]++;
324  param[nroparam][currentvalue[nroparam]].SetValue( valueparam);
325 
326 }
327 
328 int moXmlConfig::GetValueCount( int nroparam)
329 {
330 
331  if(0<=nroparam && nroparam<paramcount)
332  return valuecount[nroparam];
333  else
334  return 0;
335 }
336 
337 int moXmlConfig::GetCurrentValue( int nroparam)
338 {
339  if(0<=nroparam && nroparam<paramcount)
340  return currentvalue[nroparam];
341  else
342  return MO_PARAM_NOT_FOUND;
343 }
344 
345 void moXmlConfig::SetCurrentValue( int nroparam, int nroopcion)
346 {
347  if(0<=nroparam && nroparam<paramcount && 0<=nroopcion && nroopcion<valuecount[nroparam])
348  currentvalue[nroparam]=nroopcion;
349 
350 }
351 
352 void moXmlConfig::FirstValue()
353 {
354  if(currentvalue[currentparam] != MO_PARAM_NOT_SEL && valuecount[currentparam] > 0)
355  currentvalue[currentparam]=0;
356 
357 }
358 
359 void moXmlConfig::NextValue()
360 {
361  if(currentvalue[currentparam] != MO_PARAM_NOT_SEL && currentvalue[currentparam] < valuecount[currentparam]-1)
362  currentvalue[currentparam]++;
363 
364 }
365 
366 void moXmlConfig::PreviousValue()
367 {
368  if(currentvalue[currentparam] != MO_PARAM_NOT_SEL && currentvalue[currentparam] > 0)
369  currentvalue[currentparam]--;
370 
371 }
372 
373 */