# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

form_elm.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef _NLGEORGES__FORM_ELT_H
00027 #define _NLGEORGES__FORM_ELT_H
00028 
00029 #include "nel/georges/u_form_elm.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/misc/rgba.h"
00032 
00033 #include "georges/form_dfn.h"
00034 
00035 namespace NLGEORGES
00036 {
00037 
00038 class CType;
00039 class CFormDfn;
00040 class CForm;
00041 
00045 class CFormElm : public UFormElm
00046 {
00047         friend class CForm;
00048         friend class CType;
00049         friend class CFormDfn;
00050 public:
00051 
00052         // Contructor
00053         CFormElm (CForm *form, CFormElm *parentNode, const CFormDfn *parentDfn, uint parentIndex);
00054 
00055         // Destructor
00056         virtual ~CFormElm ();
00057 
00058         // Get the form pointer
00059         CForm                   *getForm () const;
00060 
00061         // Is the element are used by this form ?
00062         virtual bool    isUsed (const CForm *form) const;
00063 
00064         // Get the form name of the element
00065         virtual void    getFormName (std::string &result, const CFormElm *child=NULL) const = 0;
00066 
00067         // From UFormElm
00068         virtual bool    getNodeByName (const UFormElm **result, const char *name, TWhereIsNode *where, bool verbose, uint32 round=0xffffffff) const;
00069         virtual bool    getNodeByName (UFormElm **result, const char *name, TWhereIsNode *where, bool verbose, uint32 round=0xffffffff);
00070         virtual bool    getValueByName (std::string &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00071         virtual bool    getValueByName (sint8 &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00072         virtual bool    getValueByName (uint8 &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00073         virtual bool    getValueByName (sint16 &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00074         virtual bool    getValueByName (uint16 &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00075         virtual bool    getValueByName (sint32 &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00076         virtual bool    getValueByName (uint32 &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00077         virtual bool    getValueByName (float &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00078         virtual bool    getValueByName (double &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00079         virtual bool    getValueByName (bool &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00080         virtual bool    getValueByName (NLMISC::CRGBA &result, const char *name, TEval evaluate, TWhereIsValue *where, uint32 round=0xffffffff) const;
00081         virtual bool    setValueByName (const char *value, const char *name, bool *created);
00082         virtual bool    setValueByName (sint8 value, const char *name, bool *created);
00083         virtual bool    setValueByName (uint8 value, const char *name, bool *created);
00084         virtual bool    setValueByName (sint16 value, const char *name, bool *created);
00085         virtual bool    setValueByName (uint16 value, const char *name, bool *created);
00086         virtual bool    setValueByName (sint32 value, const char *name, bool *created);
00087         virtual bool    setValueByName (uint32 value, const char *name, bool *created);
00088         virtual bool    setValueByName (float value, const char *name, bool *created);
00089         virtual bool    setValueByName (double value, const char *name, bool *created);
00090         virtual bool    setValueByName (bool value, const char *name, bool *created);
00091         virtual bool    setValueByName (NLMISC::CRGBA value, const char *name, bool *created);
00092         virtual UFormElm        *getParent () const;
00093         virtual bool    isArray () const;
00094         virtual bool    getArraySize (uint &size) const;
00095         virtual bool    getArrayNode (const UFormElm **result, uint arrayIndex) const;
00096         virtual bool    getArrayNode (UFormElm **result, uint arrayIndex);
00097         virtual bool    getArrayNodeName (std::string &result, uint arrayIndex) const;
00098         virtual bool    getArrayValue (std::string &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00099         virtual bool    getArrayValue (sint8 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00100         virtual bool    getArrayValue (uint8 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00101         virtual bool    getArrayValue (sint16 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00102         virtual bool    getArrayValue (uint16 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00103         virtual bool    getArrayValue (sint32 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00104         virtual bool    getArrayValue (uint32 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00105         virtual bool    getArrayValue (float &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00106         virtual bool    getArrayValue (double &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00107         virtual bool    getArrayValue (bool &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00108         virtual bool    getArrayValue (NLMISC::CRGBA &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00109         virtual bool    isStruct () const;
00110         virtual bool    isVirtualStruct () const;
00111         virtual bool    getDfnName (std::string &dfnName ) const;
00112         virtual bool    getStructSize (uint &size) const;
00113         virtual bool    getStructNodeName (uint element, std::string &result) const;
00114         virtual bool    getStructNode (uint element, const UFormElm **result) const;
00115         virtual bool    getStructNode (uint element, UFormElm **result);
00116         virtual bool    isAtom () const;
00117         virtual bool    getValue (std::string &resultname, TEval evaluate) const;
00118         virtual bool    getValue (sint8 &resultname, TEval evaluate) const;
00119         virtual bool    getValue (uint8 &resultname, TEval evaluate) const;
00120         virtual bool    getValue (sint16 &resultname, TEval evaluate) const;
00121         virtual bool    getValue (uint16 &resultname, TEval evaluate) const;
00122         virtual bool    getValue (sint32 &resultname, TEval evaluate) const;
00123         virtual bool    getValue (uint32 &resultname, TEval evaluate) const;
00124         virtual bool    getValue (float &resultname, TEval evaluate) const;
00125         virtual bool    getValue (double &resultname, TEval evaluate) const;
00126         virtual bool    getValue (bool &resultname, TEval evaluate) const;
00127         virtual bool    getValue (NLMISC::CRGBA &resultname, TEval evaluate) const;
00128 
00129         // ** Convert functions
00130 
00131         inline bool             convertValue (sint8 &result, const char *value) const;
00132         inline bool             convertValue (uint8 &result, const char *value) const;
00133         inline bool             convertValue (sint16 &result,   const char *value) const;
00134         inline bool             convertValue (uint16 &result,   const char *value) const;
00135         inline bool             convertValue (sint32 &result,   const char *value) const;
00136         inline bool             convertValue (uint32 &result,   const char *value) const;
00137         inline bool             convertValue (float &result, const char *value) const;
00138         inline bool             convertValue (double &result, const char *value) const;
00139         inline bool             convertValue (bool &result, const char *value) const;
00140         inline bool             convertValue (NLMISC::CRGBA &result, const char *value) const;
00141 
00142         // ** Internal node access
00143 
00144         // Create for a node by name. If the node already exist, return it
00145         bool    createNodeByName (const char *name, const CFormDfn **parentDfn, uint &indexDfn, 
00146                                                                                 const CFormDfn **nodeDfn, const CType **nodeType, 
00147                                                                                 CFormElm **node, UFormDfn::TEntryType &type, 
00148                                                                                 bool &array, bool &created);
00149 
00154         bool    deleteNodeByName (const char *name, const CFormDfn **parentDfn, uint &indexDfn, 
00155                                                                                 const CFormDfn **nodeDfn, const CType **nodeType, 
00156                                                                                 CFormElm **node, UFormDfn::TEntryType &type, 
00157                                                                                 bool &array);
00158 
00159         // Search for a node by name
00160         bool    getNodeByName (const char *name, const CFormDfn **parentDfn, uint &indexDfn, 
00161                                                                                 const CFormDfn **nodeDfn, const CType **nodeType, 
00162                                                                                 CFormElm **node, UFormDfn::TEntryType &type, 
00163                                                                                 bool &array, bool &parentVDfnArray, bool verbose, uint32 round) const;
00164 
00169         bool    arrayInsertNodeByName (const char *name, const CFormDfn **parentDfn, uint &indexDfn, 
00170                                                                                 const CFormDfn **nodeDfn, const CType **nodeType, 
00171                                                                                 CFormElm **node, UFormDfn::TEntryType &type, 
00172                                                                                 bool &array, bool verbose, uint arrayIndex) const;
00173 
00178         bool    arrayDeleteNodeByName (const char *name, const CFormDfn **parentDfn, uint &indexDfn, 
00179                                                                                 const CFormDfn **nodeDfn, const CType **nodeType, 
00180                                                                                 CFormElm **node, UFormDfn::TEntryType &type, 
00181                                                                                 bool &array, bool verbose, uint arrayIndex) const;
00182 protected:
00183         
00184         // Action to perform
00185         enum TNodeAction
00186         {
00187                 Return,
00188                 Create,
00189                 Delete,
00190         };
00191 
00200         static bool     getIternalNodeByName (CForm *form, const char *name, const CFormDfn **parentDfn, uint &indexDfn, 
00201                                                                                 const CFormDfn **nodeDfn, const CType **nodeType, 
00202                                                                                 CFormElm **node, UFormDfn::TEntryType &type, 
00203                                                                                 bool &array, TNodeAction action, bool &created, bool &parentVDfnArray, bool verbose, uint32 round);
00204 
00208         virtual void unlink (CFormElm *child);
00209 
00210 public:
00211 
00212         // Get next token, return NULL if last token
00213         static const char* tokenize (const char *name, std::string &str, uint &errorIndex, uint &code);
00214 
00215         // ** IO functions
00216         virtual xmlNodePtr      write (xmlNodePtr node, const CForm *form, const char *structName = NULL, bool forceWrite = false) const = 0;
00217 
00218         // Last value of round
00219         static uint32           LastRound;
00220 
00221 protected:
00222 
00223         // The form of this node
00224         CForm                           *Form;
00225 
00226         // The parent node of this node
00227         CFormElm                        *ParentNode;
00228 
00229         // The parent DFN of this node
00230         const CFormDfn          *ParentDfn;
00231 
00232         // The index in the parent DFN for this node
00233         uint                            ParentIndex;
00234 
00235         // Recurce Tag
00236         uint32                          Round;
00237 
00238         // Error handling
00239         static void                     warning (bool exception, const char *formName, const char *formFileName, const char *function, const char *format, ... );
00240         virtual void            warning (bool exception, const char *function, const char *format, ... ) const;
00241 
00242 private:
00243         // Tokens
00244         enum TToken
00245         {
00246                 TokenString = 0,
00247                 TokenPoint,
00248                 TokenArrayBegin,
00249                 TokenArrayEnd,
00250         };
00251 };
00252 
00259 class CFormElmStruct : public CFormElm
00260 {
00261 public:
00262         // Default constructor
00263         CFormElmStruct (CForm *form, CFormElm *parentNode, const CFormDfn *parentDfn, uint parentIndex);
00264         ~CFormElmStruct ();
00265 
00266         // Clear sub elements
00267         void clean ();
00268 
00269         // Smart pointer on the form definition for this structure
00270         NLMISC::CSmartPtr<CFormDfn>     FormDfn;
00271 
00272         // Pointer on the parent element
00273         //CFormElmStruct                                        *Parent;
00274 
00275         // A struct element
00276         class CFormElmStructElm
00277         {
00278         public:
00279                 CFormElmStructElm ()
00280                 {
00281                         Element = NULL;
00282                 }
00283 
00284                 std::string             Name;
00285                 CFormElm*               Element;
00286         };
00287 
00288 
00289         // Build form a DFN
00290         void                            build (const CFormDfn *dfn);
00291 
00292         // From UFormElm
00293         bool                            isStruct () const;
00294         bool                            getStructSize (uint &size) const;
00295         bool                            getStructNodeName (uint element, std::string &result) const;
00296         bool                            getStructNode (uint element, const UFormElm **result) const;
00297         bool                            getStructNode (uint element, UFormElm **result);
00298 
00299         // From CFormElm
00300         bool                            isUsed (const CForm *form) const;
00301         xmlNodePtr                      write (xmlNodePtr node, const CForm *form, const char *structName, bool forceWrite = false) const;
00302         void                            unlink (CFormElm *child);
00303         void                            getFormName (std::string &result, const CFormElm *child) const;
00304 
00305 
00306         // Call by CFormLoader
00307         void                            read (xmlNodePtr node, CFormLoader &loader, const CFormDfn *dfn, CForm *form);
00308 
00309         // Sub Elements
00310         std::vector<CFormElmStructElm>          Elements;
00311 
00312         // Error handling
00313         virtual void            warning (bool exception, const char *function, const char *format, ... ) const;
00314 };
00315 
00319 class CFormElmVirtualStruct : public CFormElmStruct
00320 {
00321 public:
00322 
00323         CFormElmVirtualStruct (CForm *form, CFormElm *parentNode, const CFormDfn *parentDfn, uint parentIndex);
00324 
00325         // The Dfn filename used by this struct
00326         std::string                     DfnFilename;
00327 
00328         // From UFormElm
00329         bool                            isVirtualStruct () const;
00330         bool                            getDfnName (std::string &dfnName ) const;
00331 
00332         // From CFormElm
00333         bool                            isUsed (const CForm *form) const;
00334         xmlNodePtr                      write (xmlNodePtr node, const CForm *form, const char *structName, bool forceWrite = false) const;
00335 
00336         // Call by CFormLoader
00337         void                            read (xmlNodePtr node, CFormLoader &loader, CForm *form);
00338 
00339         // Error handling
00340         virtual void            warning (bool exception, const char *function, const char *format, ... ) const;
00341 };
00342 
00346 class CFormElmArray : public CFormElm
00347 {
00348 public:
00349         // Default constructor
00350         CFormElmArray (CForm *form, const CFormDfn *formDfn, const CType *type, CFormElm *parentNode, const CFormDfn *parentDfn, uint parentIndex);
00351         ~CFormElmArray ();
00352         void clean ();
00353 
00354         // Smart pointer on the form definition for this structure
00355         NLMISC::CSmartPtr<CFormDfn>     FormDfn;
00356 
00357         // Pointer on the type (the smart pointer in hold by CFormDfn)
00358         const CType                     *Type;
00359 
00360         // From UFormElm
00361         bool                            isArray () const;
00362         bool                            getArraySize (uint &size) const;
00363         bool                            getArrayNode (const UFormElm **result, uint arrayIndex) const;
00364         bool                            getArrayNode (UFormElm **result, uint arrayIndex);
00365         bool                            getArrayNodeName (std::string &result, uint arrayIndex) const;
00366         bool                            getArrayValue (std::string &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00367         bool                            getArrayValue (sint8 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00368         bool                            getArrayValue (uint8 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00369         bool                            getArrayValue (sint16 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00370         bool                            getArrayValue (uint16 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00371         bool                            getArrayValue (sint32 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00372         bool                            getArrayValue (uint32 &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00373         bool                            getArrayValue (float &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00374         bool                            getArrayValue (double &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00375         bool                            getArrayValue (bool &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00376         bool                            getArrayValue (NLMISC::CRGBA &result, uint arrayIndex, TEval evaluate, TWhereIsValue *where) const;
00377 
00378         // From CFormElm
00379         xmlNodePtr                      write (xmlNodePtr node, const CForm *form, const char *structName, bool forceWrite = false) const;
00380         bool                            setParent (CFormElm *parent);
00381         void                            unlink (CFormElm *child);
00382         bool                            isUsed (const CForm *form) const;
00383         void                            getFormName (std::string &result, const CFormElm *child) const;
00384 
00385         // Call by CFormLoader
00386 
00387         // Read an array
00388         void                            read (xmlNodePtr node, CFormLoader &loader, CForm *form);
00389 
00390         // A struct element
00391         class CElement
00392         {
00393         public:
00394                 CElement ()
00395                 {
00396                         Element = NULL;
00397                 }
00398 
00399                 std::string             Name;
00400                 CFormElm*               Element;
00401         };
00402 
00403         // Array of elements
00404         std::vector<CElement>           Elements;
00405 
00406         // Error handling
00407         virtual void            warning (bool exception, const char *function, const char *format, ... ) const;
00408 };
00409 
00413 class CFormElmAtom : public CFormElm
00414 {
00415         friend class CForm;
00416         friend class CFormElm;
00417         friend class CType;
00418 public:
00419         // Default constructor
00420         CFormElmAtom (CForm *form, CFormElm *parentNode, const CFormDfn *parentDfn, uint parentIndex);
00421 
00422         // Pointer on the parent element
00423         //CFormElmAtom                          *Parent;
00424 
00425         // Pointer on the type (the smart pointer in hold by CFormDfn)
00426         const CType                                     *Type;
00427 
00428         // From CFormElm
00429         xmlNodePtr                                      write (xmlNodePtr node, const CForm *form, const char *structName, bool forceWrite = false) const;
00430         bool                                            setParent (CFormElm *parent);
00431         void                                            getFormName (std::string &result, const CFormElm *child) const;
00432 
00433         // Call by CFormLoader
00434         void                                            read (xmlNodePtr node, CFormLoader &loader, const CType *type, CForm *form);
00435 
00436         // From UFormElm
00437         bool                                            isAtom () const;
00438         bool                                            getValue (std::string &resultname, TEval evaluate) const;
00439         bool                                            getValue (sint8 &resultname, TEval evaluate) const;
00440         bool                                            getValue (uint8 &resultname, TEval evaluate) const;
00441         bool                                            getValue (sint16 &resultname, TEval evaluate) const;
00442         bool                                            getValue (uint16 &resultname, TEval evaluate) const;
00443         bool                                            getValue (sint32 &resultname, TEval evaluate) const;
00444         bool                                            getValue (uint32 &resultname, TEval evaluate) const;
00445         bool                                            getValue (float &resultname, TEval evaluate) const;
00446         bool                                            getValue (double &resultname, TEval evaluate) const;
00447         bool                                            getValue (bool &resultname, TEval evaluate) const;
00448         bool                                            getValue (NLMISC::CRGBA &resultname, TEval evaluate) const;
00449 
00450         // Set the value, the elt been used
00451         void                                            setValue (const char *value);
00452 
00453 private:
00454         // The value
00455         std::string                                     Value;
00456 
00457         // Error handling
00458         virtual void            warning (bool exception, const char *function, const char *format, ... ) const;
00459 };
00460 
00461 // ***************************************************************************
00462 // CFormElm inlines
00463 // ***************************************************************************
00464 
00465 inline bool CFormElm::convertValue (sint8 &result, const char *value) const
00466 {
00467         float tmp;
00468         if (sscanf (value, "%f", &tmp) == 1)
00469         {
00470                 NLMISC::clamp (tmp, -128.f, 127.f);
00471                 result = (sint8)tmp;
00472                 return true;
00473         }
00474         else
00475         {
00476                 // Error message
00477                 warning (false, "convertValue", "Can't convert the string \"%s\" in sint8.", value);
00478         }
00479         return false;
00480 }
00481 
00482 // ***************************************************************************
00483 
00484 inline bool CFormElm::convertValue (uint8 &result, const char *value) const
00485 {
00486         float tmp;
00487         if (sscanf (value, "%f", &tmp) == 1)
00488         {
00489                 NLMISC::clamp (tmp, 0.f, 255.f);
00490                 result = (uint8)tmp;
00491                 return true;
00492         }
00493         else
00494         {
00495                 // Error message
00496                 warning (false, "convertValue", "Can't convert the string \"%s\" in uint8.", value);
00497         }
00498         return false;
00499 }
00500 
00501 // ***************************************************************************
00502 
00503 inline bool CFormElm::convertValue (sint16 &result,     const char *value) const
00504 {
00505         float tmp;
00506         if (sscanf (value, "%f", &tmp) == 1)
00507         {
00508                 NLMISC::clamp (tmp, -32768.f, 32767.f);
00509                 result = (sint16)tmp;
00510                 return true;
00511         }
00512         else
00513         {
00514                 // Error message
00515                 warning (false, "convertValue", "Can't convert the string \"%s\" in sint16.", value);
00516         }
00517         return false;
00518 }
00519 
00520 // ***************************************************************************
00521 
00522 inline bool CFormElm::convertValue (uint16 &result,     const char *value) const
00523 {
00524         float tmp;
00525         if (sscanf (value, "%f", &tmp) == 1)
00526         {
00527                 NLMISC::clamp (tmp, 0.f, 65535.f);
00528                 result = (uint16)tmp;
00529                 return true;
00530         }
00531         else
00532         {
00533                 // Error message
00534                 warning (false, "convertValue", "Can't convert the string \"%s\" in uint16.", value);
00535         }
00536         return false;
00537 }
00538 
00539 // ***************************************************************************
00540 
00541 inline bool CFormElm::convertValue (sint32 &result,     const char *value) const
00542 {
00543         float tmp;
00544         if (sscanf (value, "%f", &tmp) == 1)
00545         {
00546                 NLMISC::clamp (tmp, -2147483648.f, 2147483647.f);
00547                 result = (sint32)tmp;
00548                 return true;
00549         }
00550         else
00551         {
00552                 // Error message
00553                 warning (false, "convertValue", "Can't convert the string \"%s\" in sint32.", value);
00554         }
00555         return false;
00556 }
00557 
00558 // ***************************************************************************
00559 
00560 inline bool CFormElm::convertValue (uint32 &result,     const char *value) const
00561 {
00562         float tmp;
00563         if (sscanf (value, "%f", &tmp) == 1)
00564         {
00565                 NLMISC::clamp (tmp, 0.f, 4294967295.f);
00566                 result = (sint32)tmp;
00567                 return true;
00568         }
00569         else
00570         {
00571                 // Error message
00572                 warning (false, "convertValue", "Can't convert the string \"%s\" in uint32.", value);
00573         }
00574         return false;
00575 }
00576 
00577 // ***************************************************************************
00578 
00579 inline bool CFormElm::convertValue (float &result, const char *value) const
00580 {
00581         if (sscanf (value, "%f", &result) == 1)
00582         {
00583                 return true;
00584         }
00585         else
00586         {
00587                 // Error message
00588                 warning (false, "convertValue", "Can't convert the string \"%s\" in float.", value);
00589         }
00590         return false;
00591 }
00592 
00593 // ***************************************************************************
00594 
00595 inline bool CFormElm::convertValue (double &result, const char *value) const
00596 {
00597         float tmp;
00598         if (sscanf (value, "%f", &tmp) == 1)
00599         {
00600                 result = tmp;
00601                 return true;
00602         }
00603         else
00604         {
00605                 // Error message
00606                 warning (false, "convertValue", "Can't convert the string \"%s\" in double.", value);
00607         }
00608         return false;
00609 }
00610 
00611 // ***************************************************************************
00612 
00613 inline bool CFormElm::convertValue (bool &result, const char *value) const
00614 {
00615         int tmp;
00616         if (sscanf (value, "%d", &tmp) == 1)
00617         {
00618                 result = tmp != 0;
00619                 return true;
00620         }
00621         else
00622         {
00623                 std::string temp = value;
00624                 temp = NLMISC::strlwr (temp);
00625                 if (strcmp (temp.c_str (), "true") == 0)
00626                 {
00627                         result  = true;
00628                         return true;
00629                 }
00630                 if (strcmp (temp.c_str (), "false") == 0)
00631                 {
00632                         result  = false;
00633                         return true;
00634                 }
00635         }
00636 
00637         // Error message
00638         warning (false, "convertValue", "Can't convert the string \"%s\" in boolean.", value);
00639         
00640         return false;
00641 }
00642 
00643 // ***************************************************************************
00644 
00645 inline bool CFormElm::convertValue (NLMISC::CRGBA &result, const char *value) const
00646 {
00647         float r, g, b;
00648         if (sscanf (value, "%f,%f,%f", &r, &g, &b) == 3)
00649         {
00650                 NLMISC::clamp (r, 0.f, 255.f);
00651                 NLMISC::clamp (g, 0.f, 255.f);
00652                 NLMISC::clamp (b, 0.f, 255.f);
00653                 result.R = (uint8)r;
00654                 result.G = (uint8)g;
00655                 result.B = (uint8)b;
00656                 return true;
00657         }
00658 
00659         // Error message
00660         warning (false, "convertValue", "Can't convert the string \"%s\" in RGB color.", value);
00661         
00662         return false;
00663 }
00664 
00665 // ***************************************************************************
00666 
00667 } // NLGEORGES
00668 
00669 #endif // _NLGEORGES_FORM_ELM_H
00670