NLGEORGES::CForm Class Reference

#include <form.h>

Inheritance diagram for NLGEORGES::CForm:

NLGEORGES::UForm NLMISC::CRefCount

Detailed Description

This class implement a georges form.

Definition at line 44 of file form.h.

Public Types

enum  { HeldElementCount = 4 }

Public Member Functions

 CForm ()
void clean ()
void clearParents ()
const std::string & getComment () const
void getDependencies (std::set< std::string > &dependencies) const
const std::string & getFilename () const
uint getNumParent () const
 Get a mutable pointer on the root element of the form. It is a struct node.

CFormgetParent (uint parent) const
uint getParentCount () const
const std::string & getParentFilename (uint parent) const
UFormgetParentForm (uint parent) const
 Get a mutable pointer on the root element of the form. It is a struct node.

const sintgetRefCount () const
const UFormElmgetRootNode () const
 Get a const pointer on the root element of the form. It is a struct node.

UFormElmgetRootNode ()
 Get a mutable pointer on the root element of the form. It is a struct node.

bool insertParent (uint before, const char *filename, CForm *parent)
void removeParent (uint parent)
void warning (bool exception, const char *function, const char *format,...) const
void write (xmlDocPtr doc, const char *filename, bool georges4CVS)
void write (class NLMISC::IStream &stream, bool georges4CVS)
 ~CForm ()

Data Fields

sint crefs
CFormElmStruct Elements
 Vector of CFormElm*.

CFileHeader Header
CFormElmStructHeldElements [HeldElementCount]
 Backup slots.

CPtrInfo * pinfo

Static Public Attributes

CPtrInfo NullPtrInfo

Private Member Functions

void read (xmlNodePtr node, CFormLoader &loader, CFormDfn *dfn, const char *filename)
void readParent (const char *parent, CFormLoader &loader)

Private Attributes

std::string _Filename
std::vector< CParentParentList
 Pointer on the parent.


Friends

class CFormLoader
bool convertFormFile (const char *oldFileName, const char *newFileName)
struct CPtrInfo


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
HeldElementCount 

Definition at line 50 of file form.h.

00050 { HeldElementCount = 4 };


Constructor & Destructor Documentation

NLGEORGES::CForm::CForm  ) 
 

Definition at line 94 of file form.cpp.

References HeldElementCount, HeldElements, and uint.

00094               : Elements (this, NULL, NULL, 0xffffffff)
00095 {
00096         uint i;
00097         for (i=0; i<HeldElementCount; i++)
00098         {
00099                 HeldElements[i] = new CFormElmStruct (this, NULL, NULL, 0xffffffff);
00100         }
00101 }

NLGEORGES::CForm::~CForm  ) 
 

Definition at line 105 of file form.cpp.

References HeldElementCount, HeldElements, and uint.

00106 {
00107         uint i;
00108         for (i=0; i<HeldElementCount; i++)
00109         {
00110                 delete HeldElements[i];
00111         }
00112 }


Member Function Documentation

void NLGEORGES::CForm::clean  ) 
 

Definition at line 337 of file form.cpp.

References clearParents().

Referenced by read().

00338 {
00339         clearParents ();
00340 }

void NLGEORGES::CForm::clearParents  ) 
 

Definition at line 344 of file form.cpp.

References ParentList.

Referenced by clean().

00345 {
00346         ParentList.clear ();
00347 }

const std::string & NLGEORGES::CForm::getComment  )  const [virtual]
 

Get the comment

Implements NLGEORGES::UForm.

Definition at line 264 of file form.cpp.

References NLGEORGES::CFileHeader::Comments, and Header.

00265 {
00266         return Header.Comments;
00267 }

void NLGEORGES::CForm::getDependencies std::set< std::string > &  dependencies  )  const [virtual]
 

Get dependency files

Implements NLGEORGES::UForm.

Definition at line 373 of file form.cpp.

References _Filename, NLGEORGES::CFormElmStruct::getDependencies(), ParentList, NLMISC::strlwr(), and uint.

00374 {
00375         // Add me
00376         if (dependencies.insert (strlwr(CFile::getFilename (_Filename))).second)
00377         {
00378                 // Add parents
00379                 uint i;
00380                 for (i=0; i<ParentList.size (); i++)
00381                 {
00382                         if (ParentList[i].Parent)
00383                         {
00384                                 ParentList[i].Parent->getDependencies (dependencies);
00385                         }
00386                 }
00387 
00388                 // Add elements
00389                 Elements.getDependencies (dependencies);
00390         }
00391 }

const std::string & NLGEORGES::CForm::getFilename  )  const
 

Definition at line 351 of file form.cpp.

References _Filename.

Referenced by NLGEORGES::CMyEvalNumExpr::evalValue(), NLGEORGES::CFormElm::getIternalNodeByName(), NLGEORGES::CFormElmAtom::warning(), NLGEORGES::CFormElmArray::warning(), NLGEORGES::CFormElmVirtualStruct::warning(), NLGEORGES::CFormElmStruct::warning(), and NLGEORGES::CFormElm::warning().

00352 {
00353         return _Filename;
00354 }

uint NLGEORGES::CForm::getNumParent  )  const [virtual]
 

Get a mutable pointer on the root element of the form. It is a struct node.

Access form parents

Implements NLGEORGES::UForm.

Definition at line 395 of file form.cpp.

References getParentCount(), and uint.

00396 {
00397         return getParentCount();
00398 }

CForm * NLGEORGES::CForm::getParent uint  parent  )  const
 

Definition at line 316 of file form.cpp.

References ParentList, and uint.

Referenced by NLGEORGES::CFormElm::getIternalNodeByName(), and getParentForm().

00317 {
00318         return ParentList[parent].Parent;
00319 }

uint NLGEORGES::CForm::getParentCount  )  const
 

Definition at line 330 of file form.cpp.

References ParentList, and uint.

Referenced by NLGEORGES::CFormElm::getIternalNodeByName(), getNumParent(), and readParent().

00331 {
00332         return ParentList.size ();
00333 }

const std::string & NLGEORGES::CForm::getParentFilename uint  parent  )  const
 

Definition at line 323 of file form.cpp.

References ParentList, and uint.

00324 {
00325         return ParentList[parent].ParentFilename;
00326 }

UForm * NLGEORGES::CForm::getParentForm uint  parent  )  const [virtual]
 

Get a mutable pointer on the root element of the form. It is a struct node.

Implements NLGEORGES::UForm.

Definition at line 402 of file form.cpp.

References getParent(), and uint.

00403 {
00404         CForm *form = getParent (parent);
00405         return form;
00406 }

const sint& NLMISC::CRefCount::getRefCount  )  const [inline, inherited]
 

Definition at line 70 of file smart_ptr.h.

References NLMISC::CRefCount::crefs, and sint.

00071         {
00072                 return  crefs;
00073         }

const UFormElm & NLGEORGES::CForm::getRootNode  )  const [virtual]
 

Get a const pointer on the root element of the form. It is a struct node.

Implements NLGEORGES::UForm.

Definition at line 85 of file form.cpp.

00086 {
00087         return Elements;
00088 }

UFormElm & NLGEORGES::CForm::getRootNode  )  [virtual]
 

Get a mutable pointer on the root element of the form. It is a struct node.

Access form nodes

Implements NLGEORGES::UForm.

Definition at line 78 of file form.cpp.

Referenced by NLGEORGES::CMyEvalNumExpr::evalValue(), and NLGEORGES::CFormElm::getIternalNodeByName().

00079 {
00080         return Elements;
00081 }

bool NLGEORGES::CForm::insertParent uint  before,
const char *  filename,
CForm parent
 

Definition at line 283 of file form.cpp.

References Elements, NLGEORGES::CFormElmStruct::FormDfn, nlassert, ParentList, uint, and warning().

Referenced by readParent().

00284 {
00285         // Set or reset ?
00286         nlassert (parent);
00287 
00288         // Must have the same DFN
00289         if (parent->Elements.FormDfn == Elements.FormDfn)
00290         {
00291                 // Set members
00292                 std::vector<CParent>::iterator ite = ParentList.insert (ParentList.begin() + before);
00293                 ite->Parent = parent;
00294                 ite->ParentFilename = filename;
00295 
00296                 return true;
00297         }
00298         else
00299         {
00300                 // Output an error
00301                 warning (false, "insertParent", "Can't insert parent form (%s) that has not the same DFN.", filename);
00302         }
00303 
00304         return false;
00305 }

void NLGEORGES::CForm::read xmlNodePtr  node,
CFormLoader loader,
CFormDfn dfn,
const char *  filename
[private]
 

Definition at line 188 of file form.cpp.

References _Filename, NLGEORGES::CFormElmStruct::build(), clean(), Header, HeldElementCount, HeldElements, index, ParentList, NLGEORGES::CFileHeader::read(), NLGEORGES::CFormElmStruct::read(), readParent(), uint, and warning().

00189 {
00190         // Save the filename
00191         _Filename = CFile::getFilename (filename);
00192 
00193         // Reset form
00194         clean ();
00195 
00196         // Check node name
00197         if ( ((const char*)node->name == NULL) || (strcmp ((const char*)node->name, "FORM") != 0) )
00198         {
00199                 // Make an error message
00200                 warning (true, "read", "XML Syntax error in block line %d, node (%s) should be FORM.", 
00201                         (int)node->content, node->name);
00202         }
00203 
00204         // Get first struct node
00205         xmlNodePtr child = CIXml::getFirstChildNode (node, "STRUCT");
00206         if (child == NULL)
00207         {
00208                 // Throw exception
00209                 warning (true, "read", "Syntax error in block line %d, node (%s) should have a STRUCT child node.", 
00210                         (int)node->content, node->name);
00211         }
00212 
00213         // Read the struct
00214         Elements.read (child, loader, dfn, this);
00215 
00216         // Get next struct node
00217         child = CIXml::getNextChildNode (node, "STRUCT");
00218         uint index = 0;
00219         while ( (child != NULL) && (index < HeldElementCount))
00220         {
00221                 HeldElements[index]->read (child, loader, dfn, this);
00222                 index++;
00223         }
00224         while (index < HeldElementCount)
00225         {
00226                 // Build the Form
00227                 HeldElements[index]->build (dfn);
00228                 index++;
00229         }
00230 
00231         // Get the old parent parameter
00232         const char *parent = (const char*)xmlGetProp (node, (xmlChar*)"Parent");
00233         if (parent)
00234         {
00235                 // Add a parent, xmlFree is done by readParent
00236                 readParent (parent, loader);
00237         }
00238 
00239         // Read the new parent nodes
00240         uint parentCount = CIXml::countChildren (node, "PARENT");
00241 
00242         // Reserve some parents
00243         ParentList.reserve (ParentList.size () + parentCount);
00244 
00245         // Enum children node
00246         child = CIXml::getFirstChildNode (node, "PARENT");
00247         while (child)
00248         {
00249                 parent = (const char*)xmlGetProp (child, (xmlChar*)"Filename");
00250 
00251                 // Add a parent, xmlFree is done by readParent
00252                 readParent (parent, loader);
00253 
00254                 // Next node <PARENT>
00255                 child = CIXml::getNextChildNode (child, "PARENT");
00256         }
00257 
00258         // Read the header
00259         Header.read (node);
00260 }

void NLGEORGES::CForm::readParent const char *  parent,
CFormLoader loader
[private]
 

Definition at line 154 of file form.cpp.

References getParentCount(), insertParent(), NLGEORGES::CFormLoader::loadForm(), and warning().

Referenced by read().

00155 {
00156         // Load the parent
00157         CForm *theParent = (CForm*)loader.loadForm (parent);
00158         if (theParent != NULL)
00159         {
00160                 // Set the parent
00161                 if (!insertParent (getParentCount (), parent, theParent))
00162                 {
00163                         // Make an error message
00164                         std::string parentName = parent;
00165 
00166                         // Delete the value
00167                         xmlFree ((void*)parent);
00168 
00169                         // Throw exception
00170                         warning (true, "readParent", "Can't set the parent FORM named (%s). Check if it is the same form or if it use a differnt formDfn.", parentName.c_str ());
00171                 }
00172         }
00173         else
00174         {
00175                 // Make an error message
00176                 std::string parentName = parent;
00177 
00178                 // Delete the value
00179                 xmlFree ((void*)parent);
00180 
00181                 // Throw exception
00182                 warning (true, "readParent", "Can't load the parent FORM named (%s).", parentName.c_str ());
00183         }
00184 }

void NLGEORGES::CForm::removeParent uint  parent  ) 
 

Definition at line 309 of file form.cpp.

References ParentList, and uint.

00310 {
00311         ParentList.erase (ParentList.begin() + parent);
00312 }

void NLGEORGES::CForm::warning bool  exception,
const char *  function,
const char *  format,
... 
const
 

Definition at line 358 of file form.cpp.

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

Referenced by insertParent(), read(), and readParent().

00359 {
00360         // Make a buffer string
00361         va_list args;
00362         va_start( args, format );
00363         char buffer[1024];
00364         vsnprintf( buffer, 1024, format, args );
00365         va_end( args );
00366 
00367         // Set the warning
00368         NLGEORGES::warning (exception, "(CForm::%s) in form (%s) : %s", function, _Filename.c_str (), buffer);
00369 }

void NLGEORGES::CForm::write xmlDocPtr  doc,
const char *  filename,
bool  georges4CVS
 

Definition at line 116 of file form.cpp.

References _Filename, Header, HeldElementCount, HeldElements, ParentList, uint, NLGEORGES::CFileHeader::write(), and NLGEORGES::CFormElmStruct::write().

00117 {
00118         // Save the filename
00119         if (filename)
00120                 _Filename = CFile::getFilename (filename);
00121 
00122         // Create the first node
00123         xmlNodePtr node = xmlNewDocNode (doc, NULL, (const xmlChar*)"FORM", NULL);
00124         xmlDocSetRootElement (doc, node);
00125 
00126         // List of parent
00127         for (uint parent=0; parent<ParentList.size (); parent++)
00128         {
00129                 // Parent name not empty ?
00130                 if (!(ParentList[parent].ParentFilename.empty()))
00131                 {
00132                         // Add a parent node
00133                         xmlNodePtr parentNode = xmlNewChild ( node, NULL, (const xmlChar*)"PARENT", NULL );
00134                         xmlSetProp (parentNode, (const xmlChar*)"Filename", (const xmlChar*)ParentList[parent].ParentFilename.c_str());
00135                 }
00136         }
00137 
00138         // Write elements
00139         Elements.write (node, this, NULL, true);
00140 
00141         // Write held elements
00142         uint i;
00143         for (i=0; i<HeldElementCount; i++)
00144         {
00145                 HeldElements[i]->write (node, this, NULL, true);
00146         }
00147 
00148         // Header
00149         Header.write (node, georges4CVS);
00150 }

void NLGEORGES::CForm::write class NLMISC::IStream stream,
bool  georges4CVS
[virtual]
 

Write the form in a stream.

Parameters:
stream is the stream used to write the form
georges4CVS should be true if you use Georges with CVS false else

Implements NLGEORGES::UForm.

Definition at line 271 of file form.cpp.

References NLMISC::COXml::getDocument(), and NLMISC::COXml::init().

00272 {
00273         // Xml stream
00274         COXml xmlStream;
00275         xmlStream.init (&stream);
00276 
00277         // Write the file
00278         write (xmlStream.getDocument (), NULL, georges4CVS);
00279 }


Friends And Related Function Documentation

friend class CFormLoader [friend]
 

Definition at line 46 of file form.h.

bool convertFormFile const char *  oldFileName,
const char *  newFileName
[friend]
 

friend struct CPtrInfo [friend, inherited]
 

Definition at line 67 of file smart_ptr.h.


Field Documentation

std::string NLGEORGES::CForm::_Filename [private]
 

Definition at line 132 of file form.h.

Referenced by getDependencies(), getFilename(), read(), warning(), and write().

sint NLMISC::CRefCount::crefs [mutable, inherited]
 

Definition at line 79 of file smart_ptr.h.

Referenced by NLMISC::CRefCount::CRefCount(), NLMISC::CRefCount::getRefCount(), and NLMISC::CRefCount::~CRefCount().

CFormElmStruct NLGEORGES::CForm::Elements
 

Vector of CFormElm*.

Definition at line 78 of file form.h.

Referenced by insertParent().

CFileHeader NLGEORGES::CForm::Header
 

Definition at line 73 of file form.h.

Referenced by getComment(), read(), and write().

CFormElmStruct* NLGEORGES::CForm::HeldElements[HeldElementCount]
 

Backup slots.

Definition at line 81 of file form.h.

Referenced by CForm(), read(), write(), and ~CForm().

CRefCount::CPtrInfo NLMISC::CRefCount::NullPtrInfo [static, inherited]
 

Referenced by NLMISC::CRefCount::CRefCount().

std::vector<CParent> NLGEORGES::CForm::ParentList [private]
 

Pointer on the parent.

Definition at line 122 of file form.h.

Referenced by clearParents(), getDependencies(), getParent(), getParentCount(), getParentFilename(), insertParent(), read(), removeParent(), and write().

CPtrInfo* NLMISC::CRefCount::pinfo [mutable, inherited]
 

Definition at line 80 of file smart_ptr.h.

Referenced by NLMISC::CRefCount::CRefCount(), and NLMISC::CRefCount::~CRefCount().


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