NLGEORGES::CFileHeader Class Reference

#include <header.h>


Public Types

enum  TState { Modified = 0, Checked, StateCount }

Public Member Functions

void addLog (const char *log)
 Add a log.

 CFileHeader ()
 Default constructor.

void read (xmlNodePtr root)
 ** IO functions

void setComments (const char *comments)
 Set the comment.

void warning (bool exception, const char *function, const char *format,...) const
void write (xmlNodePtr node, bool georges4CVS) const

Static Public Member Functions

const char * getStateString (TState state)

Data Fields

std::string Comments
 Comments of the form.

std::string Log
 Log of the form.

uint32 MajorVersion
 Major version number.

uint32 MinorVersion
 Minor version number.

std::string Revision
 CVS Revision string.

TState State
 State of the form.


Member Enumeration Documentation

enum NLGEORGES::CFileHeader::TState
 

Enumeration values:
Modified 
Checked 
StateCount 

Definition at line 41 of file header.h.

00042         {
00043                 Modified =0,
00044                 Checked,
00045                 StateCount,
00046         };


Constructor & Destructor Documentation

NLGEORGES::CFileHeader::CFileHeader  ) 
 

Default constructor.

Definition at line 44 of file header.cpp.

References MajorVersion, MinorVersion, and Revision.

00045 {
00046         MajorVersion = 0;
00047         MinorVersion = 0;
00048         State = Modified;
00049         Revision = "$R";
00050         Revision += "evision$";
00051 }


Member Function Documentation

void NLGEORGES::CFileHeader::addLog const char *  log  ) 
 

Add a log.

Definition at line 98 of file header.cpp.

References Log, and t.

00099 {
00100         time_t t;
00101         time (&t);
00102         if (!Log.empty())
00103                 Log += "\n";
00104         Log += ctime(&t);
00105         Log.resize (Log.size()-1);
00106         Log += " (";
00107         Log += IThread::getCurrentThread ()->getUserName ();
00108         Log += ") ";
00109         Log += log;
00110 }

const char * NLGEORGES::CFileHeader::getStateString TState  state  )  [static]
 

Definition at line 240 of file header.cpp.

00241 {
00242         if (state == Modified)
00243                 return "Modified";
00244         else
00245                 return "Checked";
00246 }

void NLGEORGES::CFileHeader::read xmlNodePtr  root  ) 
 

** IO functions

Definition at line 121 of file header.cpp.

References Checked, Comments, Log, MajorVersion, MinorVersion, Revision, value, and warning().

Referenced by NLGEORGES::CType::read(), NLGEORGES::CFormDfn::read(), and NLGEORGES::CForm::read().

00122 {
00123         // Get the version
00124         const char *value = (const char*)xmlGetProp (root, (xmlChar*)"Version");
00125         if (value)
00126         {
00127                 // Read the version
00128                 if (sscanf (value, "%d.%d", &MajorVersion, &MinorVersion) != 2)
00129                 {
00130                         // Delete the value
00131                         xmlFree ((void*)value);
00132 
00133                         // Throw exception
00134                         warning (true, "read", "XML Syntax error in TYPE block line %d, the Version argument is invalid.", 
00135                                 (int)root->content);
00136                 }
00137 
00138                 // Delete the value
00139                 xmlFree ((void*)value);
00140         }
00141         else
00142         {
00143                 // Set default
00144                 MajorVersion = 0;
00145                 MinorVersion = 0;
00146         }
00147 
00148         // Get the revision
00149         value = (const char*)xmlGetProp (root, (xmlChar*)"Revision");
00150         if (value)
00151         {
00152                 // Set the value
00153                 Revision = value;
00154 
00155                 // Delete the value
00156                 xmlFree ((void*)value);
00157         }
00158         else
00159         {
00160                 // Set default
00161                 Revision = "$R";
00162                 Revision += "evision$";
00163         }
00164 
00165         // Get the version
00166         value = (const char*)xmlGetProp (root, (xmlChar*)"State");
00167         if (value)
00168         {
00169                 // Read the version
00170                 if (strcmp (value, "modified") == 0)
00171                 {
00172                         State = Modified;
00173                 }
00174                 else if (strcmp (value, "checked") == 0)
00175                 {
00176                         State = Checked;
00177                 }
00178                 else 
00179                 {
00180                         // Delete the value
00181                         xmlFree ((void*)value);
00182 
00183                         // Throw exception
00184                         warning (true, "read", "XML Syntax error in TYPE block line %d, the State argument is invalid.", 
00185                                 (int)root->content);
00186                 }
00187 
00188                 // Delete the value
00189                 xmlFree ((void*)value);
00190         }
00191         else
00192         {
00193                 // Set default
00194                 State = Modified;
00195         }
00196 
00197         // Look for the comment node
00198         Comments = "";
00199         xmlNodePtr node = CIXml::getFirstChildNode (root, "COMMENTS");
00200         if (node)
00201         {
00202                 // Get a text node
00203                 if ((node = CIXml::getFirstChildNode (node, XML_TEXT_NODE)))
00204                 {
00205                         // Get content
00206                         const char *comments = (const char*)xmlNodeGetContent (node);
00207                         if (comments)
00208                         {
00209                                 Comments = comments;
00210 
00211                                 // Delete the value
00212                                 xmlFree ((void*)comments);
00213                         }
00214                 }
00215         }
00216 
00217         // Look for the log node
00218         Log = "";
00219         node = CIXml::getFirstChildNode (root, "LOG");
00220         if (node)
00221         {
00222                 // Get a text node
00223                 if ((node = CIXml::getFirstChildNode (node, XML_TEXT_NODE)))
00224                 {
00225                         // Get content
00226                         const char *log = (const char*)xmlNodeGetContent (node);
00227                         if (log)
00228                         {
00229                                 Log = log;
00230 
00231                                 // Delete the value
00232                                 xmlFree ((void*)log);
00233                         }
00234                 }
00235         }
00236 }

void NLGEORGES::CFileHeader::setComments const char *  comments  ) 
 

Set the comment.

Definition at line 114 of file header.cpp.

References Comments.

00115 {
00116         Comments = comments;
00117 }

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

Definition at line 250 of file header.cpp.

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

Referenced by read().

00251 {
00252         // Make a buffer string
00253         va_list args;
00254         va_start( args, format );
00255         char buffer[1024];
00256         vsnprintf( buffer, 1024, format, args );
00257         va_end( args );
00258 
00259         // Set the warning
00260         NLGEORGES::warning (exception, "(CFileHeader::%s) : %s", function, buffer);
00261 }

void NLGEORGES::CFileHeader::write xmlNodePtr  node,
bool  georges4CVS
const
 

Definition at line 55 of file header.cpp.

References Comments, Log, MajorVersion, MinorVersion, Revision, and NLMISC::smprintf().

Referenced by NLGEORGES::CType::write(), NLGEORGES::CFormDfn::write(), and NLGEORGES::CForm::write().

00056 {
00057         // Version for CVS ?
00058         if (georges4CVS)
00059         {
00060                 // Georges version system
00061                 xmlSetProp (node, (const xmlChar*)"Revision", (const xmlChar*)Revision.c_str ());
00062         }
00063         else
00064         {
00065                 // Georges version system
00066                 char tmp[512];
00067                 smprintf (tmp, 512, "%d.%d", MajorVersion, MinorVersion);
00068                 xmlSetProp (node, (const xmlChar*)"Version", (const xmlChar*)tmp);
00069         }
00070 
00071         // State
00072         if (State == Modified)
00073                 xmlSetProp (node, (const xmlChar*)"State", (const xmlChar*)"modified");
00074         else
00075                 xmlSetProp (node, (const xmlChar*)"State", (const xmlChar*)"checked");
00076 
00077         // Comments of the form
00078         if (!Comments.empty ())
00079         {
00080                 // Create a new node
00081                 xmlNodePtr child = xmlNewChild ( node, NULL, (const xmlChar*)"COMMENTS", NULL);
00082                 xmlNodePtr textNode = xmlNewText ((const xmlChar *)Comments.c_str());
00083                 xmlAddChild (child, textNode);
00084         }
00085 
00086         // Logs
00087         if (!Log.empty ())
00088         {
00089                 // Create a new node
00090                 xmlNodePtr child = xmlNewChild ( node, NULL, (const xmlChar*)"LOG", NULL);
00091                 xmlNodePtr textNode = xmlNewText ((const xmlChar *)Log.c_str());
00092                 xmlAddChild (child, textNode);
00093         }
00094 }


Field Documentation

std::string NLGEORGES::CFileHeader::Comments
 

Comments of the form.

Definition at line 67 of file header.h.

Referenced by NLGEORGES::CType::getComment(), NLGEORGES::CFormDfn::getComment(), NLGEORGES::CForm::getComment(), read(), setComments(), and write().

std::string NLGEORGES::CFileHeader::Log
 

Log of the form.

Definition at line 70 of file header.h.

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

uint32 NLGEORGES::CFileHeader::MajorVersion
 

Major version number.

Definition at line 55 of file header.h.

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

uint32 NLGEORGES::CFileHeader::MinorVersion
 

Minor version number.

Definition at line 58 of file header.h.

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

std::string NLGEORGES::CFileHeader::Revision
 

CVS Revision string.

Definition at line 64 of file header.h.

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

TState NLGEORGES::CFileHeader::State
 

State of the form.

Definition at line 61 of file header.h.


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