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
moConfig.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moConfig.h
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 
29 *******************************************************************************/
30 
31 #ifndef __MO_CONFIG_H__
32 #define __MO_CONFIG_H__
33 
34 #include "moTypes.h"
35 #include "moText.h"
36 #include "moParam.h"
37 #include "moArray.h"
38 #include "moPreConfig.h"
39 
40 #define MO_PARAM_NOT_SEL -1
41 #define MO_PARAM_NOT_FOUND -1
42 #define MO_CONFIGFILE_NOT_FOUND -1
43 #define MO_CONFIG_OK 0
44 #define MO_SELECTED -1
45 
47 
58 {
59  public:
60 
63 
65  virtual ~moConfigDefinition();
66 
68  moConfigDefinition( const moConfigDefinition& p_src );
69 
72 
74 
81  void Add( const moText& p_name, moParamType p_type, int p_index=-1, const moValue& p_defaultvalue = moValue("INVALID",MO_VALUE_UNDEFINED), const moText& p_OptionsStr = moText("") );
82 
84 
88  moParamDefinitions* GetParamDefinitions() {
89  return &m_ParamDefinitions;
90  }
91 
93 
97  moParamIndexes& ParamIndexes() { return m_ParamIndexes; }
98 
100 
106  void Set( moText p_objectname, moText p_objectclass ) {
107  m_ObjectName = p_objectname;
108  m_ObjectClass = p_objectclass;
109  }
110 
112 
117  return m_ObjectName;
118  }
119 
121 
126  return m_ObjectClass;
127  }
128 
130 
140  bool SetParamIndex( int defined_array_index, moParamIndex paramindex );
141  bool SetIndex( moText p_name, MOint p_index);
142 
144 
151  bool Exists( moText p_name );
152 
153  const moParamDefinition& GetParamDefinition( const moText& p_param_name );
154 
156  const moText& ToJSON();
157 
158  private:
159 
160  moParamDefinitions m_ParamDefinitions;
161 
162  moParamIndexes m_ParamIndexes;
163 
164  moText m_ObjectName;
165  moText m_ObjectClass;
166 
167  moText m_FullJSON;
168 };
169 
176 #define moDefineParamIndex(X,Y) if ( m_Config.GetConfigDefinition()!=NULL) {\
177  int pidx = (MOint)m_Config.GetParamIndex(Y);\
178  if (pidx>-1) {\
179  if (!m_Config.GetConfigDefinition()->SetParamIndex( (int)X, moParamIndex(pidx))) {\
180  MODebug2->Warning( "<"+m_Config.GetObjectClass()+">["+m_Config.GetObjectName()+"]::Init()_moDefineParamIndex > Config parameter \"" + moText(Y) + moText("\" warning. Bad indexation could cause errors."));\
181  }\
182  } else MODebug2->Error( m_Config.GetObjectClass()+": "+m_Config.GetObjectName()+ " parameter \"" + moText(Y) + moText("\" not found."));\
183  }
184 
194 {
195  public:
196 
198  moConfig();
199 
201  virtual ~moConfig();
202 
204 
210  void Set( moText p_objectname, moText p_objectclass ) {
211  m_ConfigDefinition.Set( p_objectname, p_objectclass);
212  }
213 
215 
220  return m_ConfigDefinition.GetObjectName();
221  }
222 
224 
229  return m_ConfigDefinition.GetObjectClass();
230  }
231 
233 
234  const moText& GetName() { return m_FileName; }
235 
237 
238  moParams& GetParams();
239 
240 
242 
243  MOboolean IsConfigLoaded();
244 
246 
247  int LoadConfig( moText p_filename );
248 
250 
257  void FixConfig();
258 
260 
265  void Indexation();
266 
268 
272  MOboolean CreateDefault( const moText &p_fullconfigfilename );
273 
275 
278  void UnloadConfig();
279 
281 
283  int SaveConfig( moText p_filename = moText(""));
284 
285 
287  void DeleteConfig();
288 
290 
291  moText GetFullText();
292 
294 
296  MOuint GetValuesCount( int p_paramindex );
297 
299 
302  moValue& GetValue( moText nameparam, int indexvalue = -1 );//el valor seleccionado del parametro
303 
305 
308  moValue& GetValue( int indexparam, int indexvalue = -1 );//el valor seleccionado del parametro
309 
310 
312 
314  MOint Int( moParamReference p_paramreference );
315  MOint Int( moText p_param_name );
316 
318 
320  MOdouble Double( moParamReference p_paramreference );
321  MOdouble Double( moText p_param_name );
322 
324 
326  moText Text( moParamReference p_paramreference );
327  moText Text( moText p_param_name );
328  moText Text( int p_param_index );
329 
331 
333  MOdouble Eval( moParamReference p_paramreference, double x, ... );
334  MOdouble Eval( moParamReference p_paramreference);
335  MOdouble Eval( moText p_param_name, double x, ... );
336  MOdouble Eval( moText p_param_name );
337 
338  moVector4d EvalColor( moParamReference p_paramreference );
339  moVector4d EvalColor( moParamReference p_paramreference, double x, ... );
340 
342 
344  GLint GetGLId( moParamReference p_paramreference, MOfloat p_cycle, MOfloat p_fade, const moTextFilterParam &p_filterparam );
345  GLint GetGLId( moParamReference p_paramreference, moTempo *p_tempo, MOfloat p_fade, const moTextFilterParam &p_filterparam );
346  GLint GetGLId( moParamReference p_paramreference, MOuint p_i, MOfloat p_fade, const moTextFilterParam &p_filterparam );
347  GLint GetGLId( moParamReference p_paramreference, MOfloat p_fade, const moTextFilterParam &p_filterparam );
348 
349  GLint GetGLId( moParamReference p_paramreference, MOfloat p_cycle);
350  GLint GetGLId( moParamReference p_paramreference, moTempo *p_tempo );
351  GLint GetGLId( moParamReference p_paramreference, MOuint p_i );
352  GLint GetGLId( moParamReference p_paramreference );
353 
354 
356  moMathFunction& Fun( moParamReference p_paramreference );
357  const moFont& Font( moParamReference p_paramreference );
358  const moTextureBuffer& TextureBuffer( moParamReference p_paramreference );
359  const moSceneNode& Model( moParamReference p_paramreference );
360  const moVector2d& Vector2d( moParamReference p_paramreference );
361  const moVector2i& Vector2i( moParamReference p_paramreference );
362  const moVector3d& Vector3d( moParamReference p_paramreference );
363  const moVector3i& Vector3i( moParamReference p_paramreference );
364  const moVector4d& Vector4d( moParamReference p_paramreference );
365  const moVector4i& Vector4i( moParamReference p_paramreference );
366  const moDataMessage& Message( moParamReference p_paramreference );
367  const moDataMessages& Messages( moParamReference p_paramreference );
368  moSound& Sound( moParamReference p_paramreference );
369  const moTexture& Texture( moParamReference p_paramreference );
370 
371 
373 
375  moParam& operator [] ( MOint p_paramindex ) {
376  return GetParam( p_paramindex );
377  }
378 
380 
382  moParam& operator [] ( moText p_paramname ) {
383  return GetParam( p_paramname );
384  }
385 
387 
389  moParam& operator [] ( moParamIndex p_paramindex ) {
390  return GetParam(p_paramindex.index );
391  }
392 
394 
396  moParam& operator [] ( moParamReference p_paramreference ) {
397  return GetParam( m_ConfigDefinition.ParamIndexes().Get(p_paramreference.reference) );
398  }
399 
401 
402  moParam& GetCurrentParam();
403 
405 
407  moParam& GetParam( MOint p_paramindex = -1 );
408 
410 
412  moParam& GetParam( moText p_paramname );
413 
415 
417  moParam& GetParam( moParamIndex p_paramindex ) {
418  return GetParam(p_paramindex.index );
419  }
420 
422 
424  moParam& GetParam( moParamReference p_paramreference ) {
425  return GetParam( m_ConfigDefinition.ParamIndexes().Get(p_paramreference.reference) );
426  }
427 
428 
430 
431  int GetParamsCount();
432 
434 
436  int GetCurrentValueIndex( MOint p_paramindex );
437 
439 
441  int GetParamIndex( moText p_paramname);
442 
444 
445  int GetCurrentParamIndex() const;
446 
448 
449  bool SetCurrentParamIndex( int);
450 
451  bool SetCurrentParam( const moText& p_param_name ) {
452  return SetCurrentParamIndex( GetParamIndex( p_param_name ) );
453  }
454 
456  void FirstParam();
457 
459  void NextParam();
460 
462  void PrevParam();
463 
465 
467  void SetCurrentValueIndex( int p_paramindex, int p_valueindex );
468 
470 
471  moValue& GetCurrentValue();
472 
474  bool FirstValue();
475 
477  bool NextValue();
478 
480  bool PreviousValue();
481 
483 
484  moConfigDefinition* GetConfigDefinition();
485 
486 
488 
489  MOint GetPreConfCount();
490 
492 
493  MOint GetCurrentPreConf();
494 
496 
497  void SetCurrentPreConf( MOint p_actual );
498 
500  void PreConfFirst();
501 
503  void PreConfNext();
504 
506  void PreConfPrev();
507 
508 
509 
510 
511 
513  void AddValue( int paramindex, moValue& p_value );
514 
516  void InsertValue( int paramindex, int valueindex, moValue& p_value );
517 
519  void SetValue( int paramindex, int valueindex, moValue& p_value );
520 
522  void DeleteValue( int paramindex, int valueindex );
523 
524 
526  const moPreConfig& GetPreconfig( int valueindex );
527 
529  void AddPreconfig( moPreconfigIndexes& p_preconfindexes );
530 
532  void AddPreconfig( int preconfig_index);
533 
535  void InsertPreconfig( int valueindex, moPreconfigIndexes& p_preconfindexes );
536 
538  void SetPreconfig( int valueindex, moPreconfigIndexes& p_preconfindexes );
539 
541  void DeletePreconfig( int valueindex );
542 
544  const moText& ToJSON();
545 
546  private:
547 
548  MOboolean m_ConfigLoaded;
549  moParams m_Params;//los parametros del config
550  moPreConfigs m_PreConfigs;
551  moConfigDefinition m_ConfigDefinition;
552 
553  MOint m_MajorVersion;
554  MOint m_MinorVersion;
555  moText m_FileName;
556 
557  int m_CurrentParam;// el indice que indica cual es el parametro actual.
558  MOint m_PreconfParamNum;
559  MOint m_PreconfActual;
560 
562  static moFont* m_pFont;
563  static moMathFunction* m_pFun;
564  static moTextureBuffer* m_pTextureBuffer;
565  static moSceneNode* m_pModel;
566  static moVector2d* m_pVector2d;
567  static moVector2i* m_pVector2i;
568  static moVector3d* m_pVector3d;
569  static moVector3i* m_pVector3i;
570  static moVector4d* m_pVector4d;
571  static moVector4i* m_pVector4i;
572  static moDataMessage* m_pMessage;
573  static moDataMessages* m_pMessages;
574  static moSound* m_pSound;
575  static moTexture* m_pTexture;
576 
577 
578  void CreateParam( moParamDefinition& p_ParamDef );
579 
580  moText m_FullJSON;
581 };
582 
583 #endif
584 
Valor de un Parámetro.
Definition: moValue.h:501
const moText & GetName()
Devuelve el nombre del archivo de configuración
Definition: moConfig.h:234
const moText & GetObjectClass()
Devuelve el nombre de la clase del objeto asociado a este config.
Definition: moConfig.h:125
const moText & GetObjectClass()
Devuelve el nombre de la clase del objeto asociado a este config.
Definition: moConfig.h:228
Tempo, beat, ritmo.
Definition: moTempo.h:44
clase base para una fuente 3d o 2d
Definition: moFontManager.h:63
moParamType
Definition: moParam.h:40
void Set(moText p_objectname, moText p_objectclass)
Fija el nombre y la clase del objeto a configurar.
Definition: moConfig.h:106
moDatas moDataMessage
Definition: moValue.h:149
#define MOboolean
Definition: moTypes.h:385
MOlong index
Definition: moParam.h:124
const moText & GetObjectName()
Devuelve el nombre del objeto asociado a este config.
Definition: moConfig.h:116
Clase base abstracta de donde deben derivar los objetos [virtual pura].
Definition: moAbstract.h:191
moParam & GetParam(moParamIndex p_paramindex)
Devuelve el parámetro por estructura de índice (moParamIndex)
Definition: moConfig.h:417
#define LIBMOLDEO_API
Definition: moTypes.h:180
definición de todos los parámetros a encontrar o a crear dentro del moConfig
Definition: moConfig.h:57
#define MOfloat
Definition: moTypes.h:403
clase de para manejar textos
Definition: moText.h:75
moParamIndexes & ParamIndexes()
Devuelve el puntero al arreglo de índices de los parámetros.
Definition: moConfig.h:97
moText0 moText
Definition: moText.h:291
#define MOint
Definition: moTypes.h:388
bool SetCurrentParam(const moText &p_param_name)
Definition: moConfig.h:451
clase base para el manejo de una textura
Definition: moTexture.h:78
void Set(moText p_objectname, moText p_objectclass)
Fija el nombre y la clase del objeto a configurar.
Definition: moConfig.h:210
Clase base de sonido.
MOlong reference
Definition: moParam.h:98
moParam & GetParam(moParamReference p_paramreference)
Devuelve el parámetro por referencia de parámetro (moParamReference)
Definition: moConfig.h:424
#define MOdouble
Definition: moTypes.h:404
moMatrix3 & operator=(const moMatrix3 &rkM)
#define MOuint
Definition: moTypes.h:387
const moText & GetObjectName()
Devuelve el nombre del objeto asociado a este config.
Definition: moConfig.h:219
moParamDefinitions * GetParamDefinitions()
Devuelve el puntero al arreglo de definciones de parámetros.
Definition: moConfig.h:88
moMathFunction
almacena la configuración de los parámetros de un objeto en un archivo XML
Definition: moConfig.h:193
const Real * operator[](int iRow) const