NLGEORGES::CFormLoader Class Reference

#include <form_loader.h>

Inheritance diagram for NLGEORGES::CFormLoader:

NLGEORGES::UFormLoader

Detailed Description

Georges form loader implementation

Author:
Cyril 'Hulud' Corvazier

Nevrax France

Date:
2002

Definition at line 49 of file form_loader.h.

Public Member Functions

UFormloadForm (const char *filename)
CFormDfnloadFormDfn (const char *filename, bool forceLoad)
UFormDfnloadFormDfn (const char *filename)
UTypeloadFormType (const char *filename)
CTypeloadType (const char *filename)

Static Public Member Functions

UFormLoadercreateLoader ()
 Create a form loader.

void releaseLoader (UFormLoader *loader)
 Create a form loader.


Private Types

typedef std::map< std::string,
NLMISC::CRefPtr< CFormDfn > > 
TFormDfnMap
typedef std::map< std::string,
NLMISC::CRefPtr< CForm > > 
TFormMap
typedef std::map< std::string,
NLMISC::CRefPtr< CType > > 
TTypeMap

Private Member Functions

virtual void warning (bool exception, const char *function, const char *format,...) const

Private Attributes

TFormMap _MapForm
TFormDfnMap _MapFormDfn
TTypeMap _MapType


Member Typedef Documentation

typedef std::map<std::string, NLMISC::CRefPtr<CFormDfn> > NLGEORGES::CFormLoader::TFormDfnMap [private]
 

Definition at line 68 of file form_loader.h.

typedef std::map<std::string, NLMISC::CRefPtr<CForm> > NLGEORGES::CFormLoader::TFormMap [private]
 

Definition at line 69 of file form_loader.h.

typedef std::map<std::string, NLMISC::CRefPtr<CType> > NLGEORGES::CFormLoader::TTypeMap [private]
 

Definition at line 67 of file form_loader.h.


Member Function Documentation

UFormLoader * NLGEORGES::UFormLoader::createLoader  )  [static, inherited]
 

Create a form loader.

Definition at line 53 of file form_loader.cpp.

Referenced by NLSOUND::CAudioMixerUser::init(), and loadForm().

00054 {
00055         return new CFormLoader;
00056 }

UForm * NLGEORGES::CFormLoader::loadForm const char *  filename  )  [virtual]
 

Load a form, use NMISC::CPath to find the file.

The pointer on the form must be held in a CSmartPtr<UForm>. Returns NULL if the form can't be loaded.

Implements NLGEORGES::UFormLoader.

Definition at line 205 of file form_loader.cpp.

References _MapForm, file, index, loadFormDfn(), NLMISC::strlwr(), uint, and warning().

Referenced by NLGEORGES::CForm::readParent().

00206 {
00207         // Lower string filename
00208         string lowerStr = strlwr ((string)filename);
00209         lowerStr = CFile::getFilename (lowerStr);
00210 
00211         // Already in the map ?
00212         TFormMap::iterator ite = _MapForm.find (lowerStr);
00213         if (ite != _MapForm.end() && ite->second)
00214         {
00215                 // Return the pointer
00216                 return (CForm*)ite->second;
00217         }
00218         else
00219         {
00220                 // Create the form
00221                 CForm *form = new CForm;
00222 
00223                 // Insert the form first
00224                 _MapForm[lowerStr] = form;
00225 
00226                 // Load the type
00227                 try
00228                 {
00229                         // Get the form DFN filename
00230                         string name = CFile::getFilename (filename);
00231                         uint index = name.rfind ('.');
00232                         if (index == string::npos)
00233                         {
00234                                 // Output error
00235                                 warning (false, "loadForm", "Form name is invalid (%s). It should have the extension of its DFN type.", name.c_str ());
00236 
00237                                 // Delete the form
00238                                 delete form;
00239                                 form = NULL;
00240                                 _MapForm.erase (lowerStr);
00241                         }
00242                         name = name.substr (index+1);
00243                         name += ".dfn";
00244 
00245                         // Load the dfn
00246                         CFormDfn        *dfn = loadFormDfn (name.c_str (), false);
00247                         if (dfn)
00248                         {
00249                                 // Open the file
00250                                 name = CPath::lookup (filename, false, false);
00251                                 if (name.empty())
00252                                         name = filename;
00253                                 CIFile file;
00254                                 if (file.open (name))
00255                                 {
00256                                         // Init an xml stream
00257                                         CIXml read;
00258                                         read.init (file);
00259 
00260                                         // Read the form
00261                                         form->read (read.getRootNode (), *this, dfn, filename);
00262                                 }
00263                                 else
00264                                 {
00265                                         // Output error
00266                                         warning (false, "loadForm", "Can't open the form file (%s).", filename);
00267 
00268                                         // Delete the form
00269                                         delete form;
00270                                         form = NULL;
00271                                         _MapForm.erase (lowerStr);
00272                                 }
00273                         }
00274                         else
00275                         {
00276                                 // Output error
00277                                 warning (false, "loadForm", "Can't open the dfn file (%s).", name.c_str ());
00278 
00279                                 // Delete the form
00280                                 delete form;
00281                                 form = NULL;
00282                                 _MapForm.erase (lowerStr);
00283                         }
00284                 }
00285                 catch (Exception &e)
00286                 {
00287                         // Output error
00288                         warning (false, "loadForm", "Error while loading the form (%s): %s", filename, e.what());
00289 
00290                         // Delete the form
00291                         delete form;
00292                         form = NULL;
00293                         _MapForm.erase (lowerStr);
00294                 }
00295 
00296                 return form;
00297         }
00298 }

CFormDfn * NLGEORGES::CFormLoader::loadFormDfn const char *  filename,
bool  forceLoad
 

Definition at line 139 of file form_loader.cpp.

References _MapFormDfn, file, NLMISC::strlwr(), and warning().

00140 {
00141         // Lower string filename
00142         string lowerStr = strlwr ((string)filename);
00143         lowerStr = CFile::getFilename (lowerStr);
00144 
00145         // Already in the map ?
00146         TFormDfnMap::iterator ite = _MapFormDfn.find (lowerStr);
00147         if (ite != _MapFormDfn.end() && ite->second)
00148         {
00149                 // Return the pointer
00150                 return ite->second;
00151         }
00152         else
00153         {
00154                 // Create the formDfn
00155                 CFormDfn *formDfn = new CFormDfn;
00156 
00157                 // Insert the form first
00158                 _MapFormDfn[lowerStr] = formDfn;
00159 
00160                 // Load the type
00161                 try
00162                 {
00163                         // Open the file
00164                         string name = CPath::lookup (filename, false, false);
00165                         if (name.empty())
00166                                 name = filename;
00167                         CIFile file;
00168                         if (file.open (name))
00169                         {
00170                                 // Init an xml stream
00171                                 CIXml read;
00172                                 read.init (file);
00173 
00174                                 // Read the type
00175                                 formDfn->read (read.getRootNode (), *this, forceLoad, filename);
00176                         }
00177                         else
00178                         {
00179                                 // Output error
00180                                 warning (false, "loadFormDfn", "Can't open the form file (%s).", filename);
00181 
00182                                 // Delete the formDfn
00183                                 delete formDfn;
00184                                 formDfn = NULL;
00185                                 _MapFormDfn.erase (lowerStr);
00186                         }
00187                 }
00188                 catch (Exception &e)
00189                 {
00190                         // Output error
00191                         warning (false, "loadFormDfn", "Error while loading the form (%s): %s", filename, e.what());
00192 
00193                         // Delete the formDfn
00194                         delete formDfn;
00195                         formDfn = NULL;
00196                         _MapFormDfn.erase (lowerStr);
00197                 }
00198 
00199                 return formDfn;
00200         }
00201 }

UFormDfn * NLGEORGES::CFormLoader::loadFormDfn const char *  filename  )  [virtual]
 

Load a DFN, use NMISC::CPath to find the file.

The pointer on the form must be held in a CSmartPtr<UFormDfn>. Returns NULL if the DFN can't be loaded.

Implements NLGEORGES::UFormLoader.

Definition at line 302 of file form_loader.cpp.

Referenced by loadForm(), NLGEORGES::CFormElmVirtualStruct::read(), NLGEORGES::CFormDfn::read(), NLGEORGES::CFormDfn::CEntry::setDfn(), and NLGEORGES::CFormDfn::setParent().

00303 {
00304         return loadFormDfn (filename, false);
00305 }

UType * NLGEORGES::CFormLoader::loadFormType const char *  filename  )  [virtual]
 

Load a type, use NMISC::CPath to find the file.

The pointer on the form must be held in a CSmartPtr<UType>. Returns NULL if the type can't be loaded.

Implements NLGEORGES::UFormLoader.

Definition at line 309 of file form_loader.cpp.

References loadType().

00310 {
00311         return loadType (filename);
00312 }

CType * NLGEORGES::CFormLoader::loadType const char *  filename  ) 
 

Definition at line 69 of file form_loader.cpp.

References _MapType, file, NLMISC::strlwr(), type, and warning().

Referenced by loadFormType(), NLGEORGES::CFormDfn::read(), and NLGEORGES::CFormDfn::CEntry::setType().

00070 {
00071         // Lower string filename
00072         string lowerStr = strlwr ((string)filename);
00073         lowerStr = CFile::getFilename (lowerStr);
00074 
00075         // Already in the map ?
00076         TTypeMap::iterator ite = _MapType.find (lowerStr);
00077         if (ite != _MapType.end() && (ite->second != NULL) )
00078         {
00079                 // Return the pointer
00080                 return ite->second;
00081         }
00082         else
00083         {
00084                 // Create the type
00085                 CType *type = new CType;
00086 
00087                 // Load the type
00088                 try
00089                 {
00090                         // Open the file
00091                         string name = CPath::lookup (filename, false, false);
00092                         if (name.empty())
00093                                 name = filename;
00094                         CIFile file;
00095                         if (file.open (name))
00096                         {
00097                                 // Init an xml stream
00098                                 CIXml read;
00099                                 read.init (file);
00100 
00101                                 // Read the type
00102                                 type->read (read.getRootNode ());
00103                         }
00104                         else
00105                         {
00106                                 // Output error
00107                                 warning (false, "loadType", "Can't open the form file (%s).", filename);
00108 
00109                                 // Delete the type
00110                                 delete type;
00111                                 type = NULL;
00112                         }
00113                 }
00114                 catch (Exception &e)
00115                 {
00116                         // Output error
00117                         warning (false, "loadType", "Error while loading the form (%s): %s", filename, e.what());
00118 
00119                         // Delete the type
00120                         delete type;
00121                         type = NULL;
00122                 }
00123 
00124                 // Loaded ?
00125                 if (type)
00126                 {
00127                         // Insert a new entry
00128                         _MapType[lowerStr]= type;
00129                         ite = _MapType.find (lowerStr);
00130                         //CType *typeType = ite->second;
00131                         //                      int toto = 0;
00132                 }
00133                 return type;
00134         }
00135 }

void NLGEORGES::UFormLoader::releaseLoader UFormLoader loader  )  [static, inherited]
 

Create a form loader.

Definition at line 60 of file form_loader.cpp.

Referenced by NLSOUND::CAudioMixerUser::init(), and loadForm().

00061 {
00062         delete ((CFormLoader*)loader);
00063 }

void NLGEORGES::CFormLoader::warning bool  exception,
const char *  function,
const char *  format,
... 
const [private, virtual]
 

Definition at line 316 of file form_loader.cpp.

References buffer, format, and NLGEORGES::warning().

Referenced by loadForm(), loadFormDfn(), and loadType().

00317 {
00318         // Make a buffer string
00319         va_list args;
00320         va_start( args, format );
00321         char buffer[1024];
00322         vsnprintf( buffer, 1024, format, args );
00323         va_end( args );
00324 
00325         // Set the warning
00326         NLGEORGES::warning (exception, "(CFormLoader::%s) : %s", function, buffer);
00327 }


Field Documentation

TFormMap NLGEORGES::CFormLoader::_MapForm [private]
 

Definition at line 78 of file form_loader.h.

Referenced by loadForm().

TFormDfnMap NLGEORGES::CFormLoader::_MapFormDfn [private]
 

Definition at line 75 of file form_loader.h.

Referenced by loadFormDfn().

TTypeMap NLGEORGES::CFormLoader::_MapType [private]
 

Definition at line 72 of file form_loader.h.

Referenced by loadType().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 12:45:16 2004 for NeL by doxygen 1.3.6