Base::XMLReader Class Reference

The XML reader class This is an important helper class for the store and retrieval system of objects in FreeCAD. More...

#include <Reader.h>

Inheritance diagram for Base::XMLReader:
Gui::XMLMergeReader

List of all members.

Classes

struct  FileEntry

Public Member Functions

bool isValid () const
 XMLReader (const char *FileName, std::istream &)
 open the file and read the first element
 ~XMLReader ()
additional file reading



const char * addFile (const char *Name, Base::Persistence *Object)
 add a read request of a persistent object
const std::vector< std::string > & getFilenames () const
 get all registered file names
bool isRegistered (Base::Persistence *Object) const
void readFiles (zipios::ZipInputStream &zipstream) const
 process the requested file writes
Attribute handling



const char * getAttribute (const char *AttrName) const
 return the named attribute as a double floating point (does type checking)
double getAttributeAsFloat (const char *AttrName) const
 return the named attribute as a double floating point (does type checking)
long getAttributeAsInteger (const char *AttrName) const
 return the named attribute as an interer (does type checking)
unsigned long getAttributeAsUnsigned (const char *AttrName) const
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
Parser handling



const char * localName (void) const
 get the local name of the current Element
void readCharacters (void)
 read until characters are found
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)

Public Attributes

int DocumentSchema
 Schema Version of the document.

Protected Types

enum  {
  None = 0, Chars, StartElement, StartEndElement,
  EndElement
}
typedef std::map< std::string,
std::string > 
AttrMapType

Protected Member Functions

virtual void characters (const XMLCh *const chars, const unsigned int length)
virtual void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
void error (const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &exc)
void fatalError (const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &exc)
virtual void ignorableWhitespace (const XMLCh *const chars, const unsigned int length)
bool read (void)
 read the next element
virtual void resetDocument ()
void resetErrors ()
virtual void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE_QUALIFIER Attributes &attrs)
void warning (const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &exc)

Protected Attributes

FileInfo _File
bool _valid
std::map< std::string,
std::string > 
AttrMap
unsigned int CharacterCount
std::string Characters
std::vector< FileEntryFileList
std::vector< std::string > FileNames
int Level
std::string LocalName
XERCES_CPP_NAMESPACE_QUALIFIER
SAX2XMLReader * 
parser
enum Base::XMLReader:: { ... }  ReadType
XERCES_CPP_NAMESPACE_QUALIFIER
XMLPScanToken 
token

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

Definition at line 115 of file Reader.h.


Member Typedef Documentation

typedef std::map<std::string,std::string> Base::XMLReader::AttrMapType [protected]

Definition at line 194 of file Reader.h.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
None 
Chars 
StartElement 
StartEndElement 
EndElement 

Definition at line 196 of file Reader.h.


Constructor & Destructor Documentation

Base::XMLReader::XMLReader ( const char *  FileName,
std::istream &  str 
)

open the file and read the first element

Definition at line 61 of file Reader.cpp.

References _File, _valid, DrawingExample::file, Base::FileInfo::filePath(), parser, and token.

Base::XMLReader::~XMLReader (  ) 

Definition at line 107 of file Reader.cpp.

References parser.


Member Function Documentation

const char * Base::XMLReader::addFile ( const char *  Name,
Base::Persistence Object 
)
void Base::XMLReader::characters ( const XMLCh *const   chars,
const unsigned int  length 
) [protected, virtual]

Definition at line 374 of file Reader.cpp.

References CharacterCount, Characters, Chars, and ReadType.

void Base::XMLReader::endElement ( const XMLCh *const  uri,
const XMLCh *const   localname,
const XMLCh *const  qname 
) [protected, virtual]

Reimplemented in Gui::XMLMergeReader.

Definition at line 362 of file Reader.cpp.

References EndElement, Level, LocalName, ReadType, StartElement, and StartEndElement.

void Base::XMLReader::error ( const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &  exc  )  [protected]

Definition at line 398 of file Reader.cpp.

void Base::XMLReader::fatalError ( const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &  exc  )  [protected]

Definition at line 408 of file Reader.cpp.

const char * Base::XMLReader::getAttribute ( const char *  AttrName  )  const
double Base::XMLReader::getAttributeAsFloat ( const char *  AttrName  )  const
long Base::XMLReader::getAttributeAsInteger ( const char *  AttrName  )  const
unsigned long Base::XMLReader::getAttributeAsUnsigned ( const char *  AttrName  )  const

Definition at line 136 of file Reader.cpp.

References AttrMap, and RobotExample::pos.

Referenced by App::PropertyMaterial::Restore(), and App::PropertyColor::Restore().

unsigned int Base::XMLReader::getAttributeCount ( void   )  const

get the number of attributes of the current element

Definition at line 118 of file Reader.cpp.

References AttrMap.

const std::vector< std::string > & Base::XMLReader::getFilenames (  )  const

get all registered file names

Definition at line 328 of file Reader.cpp.

References FileNames.

Referenced by Gui::Document::RestoreDocFile().

bool Base::XMLReader::hasAttribute ( const char *  AttrName  )  const
void Base::XMLReader::ignorableWhitespace ( const XMLCh *const  chars,
const unsigned int  length 
) [protected, virtual]

Definition at line 381 of file Reader.cpp.

bool Base::XMLReader::isRegistered ( Base::Persistence Object  )  const

Definition at line 333 of file Reader.cpp.

References FileList.

bool Base::XMLReader::isValid ( void   )  const [inline]

Definition at line 122 of file Reader.h.

const char * Base::XMLReader::localName ( void   )  const

get the local name of the current Element

Definition at line 113 of file Reader.cpp.

References LocalName.

bool Base::XMLReader::read ( void   )  [protected]

read the next element

Definition at line 180 of file Reader.cpp.

References None, parser, ReadType, and token.

Referenced by readElement(), and readEndElement().

void Base::XMLReader::readCharacters ( void   ) 

read until characters are found

Definition at line 254 of file Reader.cpp.

void Base::XMLReader::readElement ( const char *  ElementName = 0  ) 

read until a start element is found (<name>) or start-end element (<name/>) (with special name if given)

Definition at line 227 of file Reader.cpp.

References EndElement, Level, LocalName, read(), ReadType, StartElement, and StartEndElement.

Referenced by Gui::MergeDocuments::importObjects(), Gui::Document::importObjects(), App::Document::importObjects(), MeshCore::MeshInput::LoadXML(), Robot::Waypoint::Restore(), Robot::Trajectory::Restore(), Robot::Robot6Axis::Restore(), Part::PropertyFilletEdges::Restore(), Part::PropertyPartShape::Restore(), App::PropertyMaterial::Restore(), App::PropertyColorList::Restore(), App::PropertyColor::Restore(), App::PropertyBool::Restore(), App::PropertyStringList::Restore(), App::PropertyString::Restore(), App::PropertyFloatList::Restore(), App::PropertyFloat::Restore(), App::PropertyIntegerList::Restore(), App::PropertyEnumeration::Restore(), App::PropertyPath::Restore(), App::PropertyInteger::Restore(), App::PropertyPythonObject::Restore(), Points::PropertyPointKernel::Restore(), App::PropertyLinkSubList::Restore(), App::PropertyLinkList::Restore(), App::PropertyLinkSub::Restore(), App::PropertyLink::Restore(), Part::PropertyGeometryList::Restore(), App::PropertyPlacement::Restore(), App::PropertyMatrix::Restore(), App::PropertyVectorList::Restore(), App::PropertyVector::Restore(), App::PropertyFileIncluded::Restore(), App::PropertyContainer::Restore(), Sketcher::PropertyConstraintList::Restore(), Points::PropertyCurvatureList::Restore(), Points::PointKernel::Restore(), Mesh::PropertyMeshKernel::Restore(), Mesh::PropertyCurvatureList::Restore(), Part::GeomLineSegment::Restore(), Part::GeomLine::Restore(), Part::GeomArcOfCircle::Restore(), Part::GeomCircle::Restore(), Part::GeomPoint::Restore(), Part::Geometry::Restore(), Fem::PropertyFemMesh::Restore(), Part::Box::Restore(), App::DynamicProperty::Restore(), App::Document::Restore(), Sketcher::Constraint::Restore(), Gui::MergeDocuments::RestoreDocFile(), and Gui::Document::RestoreDocFile().

void Base::XMLReader::readEndElement ( const char *  ElementName = 0  ) 
void Base::XMLReader::readFiles ( zipios::ZipInputStream zipstream  )  const
void Base::XMLReader::resetDocument (  )  [protected, virtual]

Definition at line 386 of file Reader.cpp.

void Base::XMLReader::resetErrors (  )  [protected]

Definition at line 428 of file Reader.cpp.

void Base::XMLReader::startElement ( const XMLCh *const  uri,
const XMLCh *const   localname,
const XMLCh *const  qname,
const XERCES_CPP_NAMESPACE_QUALIFIER Attributes &  attrs 
) [protected, virtual]

Reimplemented in Gui::XMLMergeReader.

Definition at line 348 of file Reader.cpp.

References AttrMap, Level, LocalName, ReadType, and StartElement.

void Base::XMLReader::warning ( const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException &  exc  )  [protected]

Definition at line 418 of file Reader.cpp.


Member Data Documentation

Definition at line 205 of file Reader.h.

Referenced by XMLReader().

bool Base::XMLReader::_valid [protected]

Definition at line 208 of file Reader.h.

Referenced by XMLReader().

std::map<std::string,std::string> Base::XMLReader::AttrMap [protected]
unsigned int Base::XMLReader::CharacterCount [protected]

Definition at line 191 of file Reader.h.

Referenced by characters().

std::string Base::XMLReader::Characters [protected]

Definition at line 190 of file Reader.h.

Referenced by characters().

std::vector<FileEntry> Base::XMLReader::FileList [protected]

Definition at line 214 of file Reader.h.

Referenced by addFile(), isRegistered(), and readFiles().

std::vector<std::string> Base::XMLReader::FileNames [protected]

Definition at line 215 of file Reader.h.

Referenced by addFile(), and getFilenames().

int Base::XMLReader::Level [protected]

Definition at line 188 of file Reader.h.

Referenced by endElement(), readElement(), and startElement().

std::string Base::XMLReader::LocalName [protected]
XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* Base::XMLReader::parser [protected]

Definition at line 206 of file Reader.h.

Referenced by read(), XMLReader(), and ~XMLReader().

enum { ... } Base::XMLReader::ReadType [protected]
XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken Base::XMLReader::token [protected]

Definition at line 207 of file Reader.h.

Referenced by read(), and XMLReader().


The documentation for this class was generated from the following files:

Generated on Wed Nov 23 19:01:49 2011 for FreeCAD by  doxygen 1.6.1