# 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_dfn.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_DFN_H
00027 #define _NLGEORGES__FORM_DFN_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/georges/u_form_dfn.h"
00032 #include "nel/georges/u_form_elm.h"
00033 #include "header.h"
00034 #include "georges/type.h"
00035 
00036 bool convertDfnFile (const char *oldFileName, const char *newFileName);
00037 
00038 namespace NLGEORGES
00039 {
00040 
00041 class CFormLoader;
00042 
00046 class CFormDfn : public UFormDfn
00047 {
00048         friend class CForm;
00049         friend class CType;
00050         friend class CFormElm;
00051         friend class CFormLoader;
00052         friend class CFormElmStruct;
00053         friend bool convertDfnFile (const char *oldFileName, const char *newFileName);
00054 public:
00055 
00056         // Default cstr
00057         CFormDfn ()
00058         {
00059                 Round = 0xffffffff;
00060         }
00061 
00062         // A form defnition entry
00063         class CEntry
00064         {
00065                 friend class CType;
00066                 friend class CForm;
00067                 friend class CFormElm;
00068                 friend class CFormDfn;
00069                 friend class CFormElmStruct;
00070                 friend bool convertDfnFile (const char *oldFileName, const char *newFileName);
00071         public:
00072 
00073                 CEntry ()
00074                 {
00075                         TypeElement = EntryType;
00076                         FilenameExt = "*.*";
00077                 }
00078 
00079                 // Get the type
00080                 class CType                                     *getTypePtr ();
00081 
00082                 // Get the type
00083                 const CType                                     *getTypePtr () const;
00084 
00085                 // Get the dfn
00086                 CFormDfn                                        *getDfnPtr ();
00087 
00088                 // Get the dfn
00089                 const CFormDfn                          *getDfnPtr () const;
00090 
00091                 // Get type flag
00092                 TEntryType                                      getType () const;
00093 
00094                 // Set as a type
00095                 void                                            setType (CFormLoader &loader, const char *filename);
00096 
00097                 // Set as a dfn
00098                 void                                            setDfn (CFormLoader &loader, const char *filename);
00099 
00100                 // Set as a dfn pointer
00101                 void                                            setDfnPointer ();
00102 
00103                 // Get element Name
00104                 const std::string                       &getName () const;
00105 
00106                 // Set element Name
00107                 void                                            setName (const char *name);
00108 
00109                 // Get the filename
00110                 const std::string                       &getFilename() const;
00111 
00112                 // Get the filename extension
00113                 const std::string                       &getFilenameExt() const;
00114 
00115                 // Set the filename
00116                 void                                            setFilename (const char *def);
00117 
00118                 // Set the filename extension
00119                 void                                            setFilenameExt (const char *ext);
00120 
00121                 // Get default value
00122                 const std::string                       &getDefault () const;
00123 
00124                 // Set default value
00125                 void                                            setDefault (const char *def);
00126 
00127                 // Set array flag
00128                 void                                            setArrayFlag (bool flag);
00129 
00130                 // Get array flag
00131                 bool                                            getArrayFlag () const;
00132 
00133         private:
00134                 // Entry name
00135                 std::string                                     Name;
00136 
00137                 // What is the type of the element ?
00138                 TEntryType                                      TypeElement;
00139 
00140                 // Is an array of this type ?
00141                 bool                                            Array;
00142 
00143                 // The filename
00144                 std::string                                     Filename;
00145 
00146                 // The default value for atom
00147                 std::string                                     Default;
00148 
00149                 // The filename
00150                 std::string                                     FilenameExt;
00151 
00152                 // Smart ptr on the type or the dfn
00153                 NLMISC::CSmartPtr<CType>        Type;
00154 
00155                 // Smart ptr on the type or the dfn
00156                 NLMISC::CSmartPtr<CFormDfn>     Dfn;
00157         };
00158 
00159         // Parent DFN
00160         class CParent
00161         {
00162         public:
00163                 // The parent filename
00164                 std::string                                             ParentFilename;
00165 
00166                 // The parent smart
00167                 NLMISC::CSmartPtr<CFormDfn>     Parent;
00168         };
00169 
00170         // ** IO functions
00171         void                                                    write (xmlDocPtr root, const char *filename, bool georges4CVS);
00172 
00173         // Count parent DFN
00174         uint                                                    countParentDfn (uint32 round=UFormElm::LastRound++) const;
00175 
00176         // Get parent DFN
00177         void                                                    getParentDfn (std::vector<CFormDfn*> &array, uint32 round=UFormElm::LastRound++);
00178 
00179         // Get parent DFN
00180         void                                                    getParentDfn (std::vector<const CFormDfn*> &array, uint32 round=UFormElm::LastRound++) const;
00181 
00182         // Get num parent
00183         uint                                                    getNumParent () const;
00184 
00185         // Get parent count
00186         void                                                    setNumParent (uint size);
00187 
00188         // Set a parent
00189         void                                                    setParent (uint parent, CFormLoader &loader, const char *filename);
00190 
00191         // Get a parent
00192         CFormDfn                                                *getParent (uint parent) const;
00193 
00194         // Get a parent string
00195         const std::string                               &getParentFilename (uint parent) const;
00196 
00197         // Get num entry
00198         uint                                                    getNumEntry () const;
00199 
00200         // Set num entry
00201         void                                                    setNumEntry (uint size);
00202 
00203         // Get an entry
00204         const CEntry                                    &getEntry (uint entry) const;
00205 
00206         // Get an entry
00207         CEntry                                                  &getEntry (uint entry);
00208 
00209         // Form UFormDfn
00210         bool                                                    getEntryType (uint entry, TEntryType &type, bool &array) const;
00211         bool                                                    getEntryName (uint entry, std::string &name) const;
00212         bool                                                    getEntryDfn (uint entry, UFormDfn **dfn);
00213         bool                                                    getEntryType (uint entry, UType **type);
00214         uint                                                    getNumParents () const;
00215         bool                                                    getParent (uint parent, UFormDfn **parentRet);
00216         const std::string                               &getComment (std::string &comment) const;
00217         bool                                                    getEntryFilename (uint entry, std::string& filename) const;
00218         bool                                                    getParentFilename (uint parent, std::string &filename) const;
00219 
00220         // Get the sub dfn of a dfn
00221         CFormDfn                                                *getSubDfn (uint index, uint &dfnIndex);
00222         const CFormDfn                                  *getSubDfn (uint index, uint &dfnIndex) const;
00223 
00224         // Header
00225         CFileHeader                                             Header;
00226 
00227         // Error handling
00228         void                                                    warning (bool exception, const char *function, const char *format, ... ) const;
00229 
00230 private:
00231         // The parents array
00232         std::vector<CParent>                    Parents;
00233 
00234         // A vector of entries
00235         std::vector<CEntry>                             Entries;
00236 
00237         // Recurcive call count
00238         mutable uint32                                  Round;
00239 
00240         // The form DFN filename
00241         std::string                                             _Filename;
00242 
00243 private:
00244         // Read method called by the form loader
00245         void                                                    read (xmlNodePtr doc, CFormLoader &loader, bool forceLoad, const char *filename);
00246 };
00247 
00248 } // NLGEORGES
00249 
00250 #endif // _NLGEORGES__FORM_DFN_H
00251