FreeCAD C++
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Base::XMLReader Class Reference

#include <Base/Reader.h>

Detailed Description

The XML reader class This is an important helper class for the store and retrieval system of objects in FreeCAD. These classes mainly inherit the App::Persitance base class and implement the Restore() method.

The reader gets mainly initialized by the App::Document on retrieving a document out of a file. From there subsequently the Restore() method will by called on all object stored.
A simple example is the Restore of App::PropertyString:
void PropertyString::Save (short indent,std::ostream &str)
{
str << "<String value=\"" << _cValue.c_str() <<"\"/>" ;
}
void PropertyString::Restore(Base::Reader &reader)
{
// read my Element
reader.readElement("String");
// get the value of my Attribute
_cValue = reader.getAttribute("value");
}
An more complicated example is the retrieval of the App::PropertyContainer:
void PropertyContainer::Save (short indent,std::ostream &str)
{
std::map<std::string,Property*> Map;
getPropertyMap(Map);
str << ind(indent) << "<Properties Count=\"" << Map.size() << "\">" << endl;
std::map<std::string,Property*>::iterator it;
for(it = Map.begin(); it != Map.end(); ++it)
{
str << ind(indent+1) << "<Property name=\"" << it->first << "\" type=\"" << it->second->getTypeId().getName() << "\">" ;
it->second->Save(indent+2,str);
str << "</Property>" << endl;
}
str << ind(indent) << "</Properties>" << endl;
}
void PropertyContainer::Restore(Base::Reader &reader)
{
reader.readElement("Properties");
int Cnt = reader.getAttributeAsInteger("Count");
for(int i=0 ;i<Cnt ;i++)
{
reader.readElement("Property");
string PropName = reader.getAttribute("name");
Property* prop = getPropertyByName(PropName.c_str());
if(prop)
prop->Restore(reader);
reader.readEndElement("Property");
}
reader.readEndElement("Properties");
}
See also
Base::Persistence
Author
Juergen Riegel

Public Member Functions

 XMLReader (const char *FileName, std::istream &)
 open the file and read the first element
 
void setPartialRestore (bool on)
 sets simultaneously the global and local PartialRestore bits
 
bool testStatus (ReaderStatus pos) const
 return the status bits
 
void setStatus (ReaderStatus pos, bool on)
 set the status bits
 
Parser handling
const char * localName (void) const
 get the local name of the current Element
 
void readElement (const char *ElementName=0)
 read until a start element is found (<name>) or start-end element (<name/>) (with special name if given)
 
void readEndElement (const char *ElementName=0)
 read until an end element is found (with special name if given)
 
void readCharacters (void)
 read until characters are found
 
void readBinFile (const char *)
 read binary file
 
Attribute handling
unsigned int getAttributeCount (void) const
 get the number of attributes of the current element
 
bool hasAttribute (const char *AttrName) const
 check if the read element has a special attribute
 
long getAttributeAsInteger (const char *AttrName) const
 return the named attribute as an interer (does type checking)
 
unsigned long getAttributeAsUnsigned (const char *AttrName) const
 
double getAttributeAsFloat (const char *AttrName) const
 return the named attribute as a double floating point (does type checking)
 
const char * getAttribute (const char *AttrName) const
 return the named attribute as a double floating point (does type checking)
 
additional file reading
const char * addFile (const char *Name, Base::Persistence *Object)
 add a read request of a persistent object
 
void readFiles (zipios::ZipInputStream &zipstream) const
 process the requested file writes
 
const std::vector< std::string > & getFilenames () const
 get all registered file names
 
bool isRegistered (Base::Persistence *Object) const
 
virtual void addName (const char *, const char *)
 
virtual const char * getName (const char *) const
 
virtual bool doNameMapping () const
 

Public Attributes

int DocumentSchema
 Schema Version of the document.
 
std::string ProgramVersion
 Version of FreeCAD that wrote this document.
 
int FileVersion
 Version of the file format.
 

Protected Member Functions

bool read (void)
 read the next element
 
Content handler
virtual void startDocument ()
 
virtual void endDocument ()
 
virtual void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE_QUALIFIER Attributes &attrs)
 
virtual void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 
virtual void characters (const XMLCh *const chars, const XMLSize_t length)
 
virtual void ignorableWhitespace (const XMLCh *const chars, const XMLSize_t length)
 
Lexical handler
virtual void startCDATA ()
 
virtual void endCDATA ()
 
Document handler
virtual void resetDocument ()
 
Error handler
void warning (const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &exc)
 
void error (const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &exc)
 
void fatalError (const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &exc)
 
void resetErrors ()