D:/WorkDir/SugoiProjects/SugoiTools/include/SugoiTools/cl_param.h

00001 /* LICENSE_BEGIN
00002 SutoiTools library supply support for debugging, testing and 
00003 setting good bases for you application. It is part of the 
00004 SugoiEngine project.
00005 Copyright (C) 2006 Allusse Yannick (yannick dot allusse at laposte dot net)
00006 
00007 This program is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU General Public License
00009 as published by the Free Software Foundation; either version 2
00010 of the License, or (at your option) any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020 LICENSE_END
00021 */
00022 
00023 /* \file SG_TLS_cl_param.h
00024  * \brief Supply a template class for storing any kind of variables...[MORE HERE].
00025  * \author Yannick Allusse
00026  */
00027 #ifndef _SG_TLS_CL_PARAM_H
00028 #define _SG_TLS_CL_PARAM_H
00029 
00030 
00031 #include "SugoiTools\config.h"
00032 #include "SugoiTools\cl_base_obj.h"
00033 #include "SugoiTools\cl_xml_mngr.h"
00034 #include "SugoiTools\cl_template_manager.h"
00035 
00036 
00037 
00038 namespace SGE{
00044 template <class C, typename AccessType=std::string> 
00045           class CL_TEMPLATE_PARAM
00046                     : public CL_BASE_OBJ<AccessType>,
00047                     public CL_XML_OBJ
00048 {
00049 private:
00050           C                             value;              
00051 public:
00052 
00053           
00059           _SG_TLS_INLINE 
00060                     CL_TEMPLATE_PARAM(const AccessType ID)
00061                     :CL_BASE_OBJ<AccessType>(ID)
00062                     ,CL_XML_OBJ("templateFlag")
00063           {
00064                     //SG_Assert(_name!="", "CL_TEMPLATE_PARAM<C>::CL_TEMPLATE_PARAM(), the name is NULL");
00065                     //value = _value;
00066           }
00067 
00068           _SG_TLS_INLINE 
00069                     CL_TEMPLATE_PARAM(const AccessType ID, C _value)
00070                     :CL_BASE_OBJ<AccessType>(ID)
00071                     ,CL_XML_OBJ("templateFlag")
00072                     ,value(_value)
00073           {
00074                     //SG_Assert(_name!="", "CL_TEMPLATE_PARAM<C>::CL_TEMPLATE_PARAM(), the name is NULL");
00075                     
00076           }
00077 
00081           _SG_TLS_INLINE
00082                     ~CL_TEMPLATE_PARAM()
00083           {}
00084 
00088           C* GetValuePointer()
00089           {         return &value;}
00090 
00094           C GetValue()
00095           {         return value;}
00096 
00100           void SetValue(C &_value)
00101           {         value=_value;}
00102 
00103 
00107           void SetValue(C *_value)
00108           {         value=*_value;}
00109           
00110 
00111           virtual const std::string               GetValStr()
00112           {
00113                     return ToCharStr(value);
00114           }
00115 
00116           bool AskForValueInput()
00117           {
00118                     cout << endl << "ID: " << GetIDStr() << " => " << GetValStr() << ". Set/Change Value?";
00119                     string input;
00120                     getline(cin, input);
00121                     if (input == "\n")
00122                               return true;//no change
00123                     
00124                     istringstream is(input);
00125                     is >> value;
00126                     return true;
00127           }
00128 
00129 
00130 #if _SG_TLS_XML
00131 
00134           TiXmlElement* XMLLoad(TiXmlElement* XML_ROOT)
00135           {
00136                     XMLReadVal(XML_ROOT, GetIDStr(), value);
00137                     //if (typeid()
00138                     return XML_ROOT;//value.XMLLoad(XML_ROOT);
00139           }
00140 
00141           TiXmlElement* XMLSave(TiXmlElement* XML_ROOT)
00142           {
00143                     //tag already created by the manager
00144                     //we only add attributes...   
00145                     XMLWriteVal(XML_ROOT, GetIDStr(), value);
00146                     //----------------------------------
00147                     return XML_ROOT;
00148           }
00149 #endif
00150 };
00151 
00152 
00153 //================================================================
00154 
00155 
00156 //================================================================
00174 class _SG_TLS_EXPORT CL_PARAM
00175           :public CL_XML_OBJ
00176 {
00177 public:
00178           typedef   CL_TEMPLATE_PARAM <bool>                TypeBoolFlg;
00179           typedef   CL_TEMPLATE_PARAM <int>                           TypeIntFlg;
00180           typedef   CL_TEMPLATE_PARAM <double>              TypeDoubleFlg;
00181           typedef   CL_TEMPLATE_PARAM <std::string> TypeStringFlg;
00182 
00183           typedef   CL_XML_MNGR <TypeBoolFlg>               TypeBoolMngr;
00184           typedef   CL_XML_MNGR <TypeIntFlg>                TypeIntMngr;
00185           typedef CL_XML_MNGR <TypeDoubleFlg>               TypeDoubleMngr;
00186           typedef   CL_XML_MNGR <TypeStringFlg>             TypeStringMngr;
00187 
00188 
00189 
00190 
00191 public:
00192           //object manager of all kind of type
00193           TypeBoolMngr                  *FlagBool;                    
00194           TypeIntMngr                             *FlagInt;           
00195           TypeDoubleMngr                *FlagDouble;        
00196           TypeStringMngr                *FlagString;        
00197           
00198           //==================================
00199           CL_PARAM();
00200           ~CL_PARAM();
00201 
00202           bool AskForValueInput();
00203           _SG_TLS_INLINE void PrintAllObjects();
00204           
00205           
00206 #if _SG_TLS_XML
00207           TiXmlElement* XMLLoad(TiXmlElement* XML_ROOT);
00208           TiXmlElement* XMLSave(TiXmlElement* XML_ROOT);
00209 #endif
00210 };
00211 
00212 };//namespace SGE
00213 #endif//_SG_TLS_CL_PARAM_H

Generated on Mon Mar 19 23:15:10 2007 for SugoiTools by  doxygen 1.4.6-NO