The XML reader class This is an important helper class for the store and retrieval system of objects in FreeCAD. More...
#include <Reader.h>
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< FileEntry > | FileList |
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 |
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.
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"); }
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"); }
Definition at line 115 of file Reader.h.
typedef std::map<std::string,std::string> Base::XMLReader::AttrMapType [protected] |
anonymous enum [protected] |
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.
const char * Base::XMLReader::addFile | ( | const char * | Name, | |
Base::Persistence * | Object | |||
) |
add a read request of a persistent object
Definition at line 316 of file Reader.cpp.
References FileList, Base::XMLReader::FileEntry::FileName, FileNames, and Base::XMLReader::FileEntry::Object.
Referenced by Part::PropertyFilletEdges::Restore(), Part::PropertyPartShape::Restore(), App::PropertyColorList::Restore(), App::PropertyFloatList::Restore(), App::PropertyPythonObject::Restore(), Points::PropertyPointKernel::Restore(), App::PropertyVectorList::Restore(), App::PropertyFileIncluded::Restore(), Points::PropertyCurvatureList::Restore(), Points::PointKernel::Restore(), Mesh::PropertyMeshKernel::Restore(), Mesh::PropertyCurvatureList::Restore(), Gui::MergeDocuments::Restore(), Fem::PropertyFemMesh::Restore(), and Gui::Document::Restore().
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 |
return the named attribute as a double floating point (does type checking)
Definition at line 162 of file Reader.cpp.
References AttrMap, and RobotExample::pos.
Referenced by Gui::MergeDocuments::importObjects(), Gui::Document::importObjects(), App::Document::importObjects(), Robot::Waypoint::Restore(), Part::PropertyFilletEdges::Restore(), Part::PropertyPartShape::Restore(), App::PropertyColorList::Restore(), App::PropertyBool::Restore(), App::PropertyStringList::Restore(), App::PropertyString::Restore(), App::PropertyFloatList::Restore(), App::PropertyEnumeration::Restore(), App::PropertyPath::Restore(), App::PropertyPythonObject::Restore(), Points::PropertyPointKernel::Restore(), App::PropertyLinkSubList::Restore(), App::PropertyLinkList::Restore(), App::PropertyLinkSub::Restore(), App::PropertyLink::Restore(), Part::PropertyGeometryList::Restore(), App::PropertyVectorList::Restore(), App::PropertyFileIncluded::Restore(), App::PropertyContainer::Restore(), Points::PropertyCurvatureList::Restore(), Points::PointKernel::Restore(), Mesh::PropertyMeshKernel::Restore(), Mesh::PropertyCurvatureList::Restore(), Fem::PropertyFemMesh::Restore(), Part::Box::Restore(), App::DynamicProperty::Restore(), App::Document::Restore(), Sketcher::Constraint::Restore(), Gui::MergeDocuments::RestoreDocFile(), and Gui::Document::RestoreDocFile().
double Base::XMLReader::getAttributeAsFloat | ( | const char * | AttrName | ) | const |
return the named attribute as a double floating point (does type checking)
Definition at line 149 of file Reader.cpp.
References AttrMap, and RobotExample::pos.
Referenced by MeshCore::MeshInput::LoadXML(), Robot::Waypoint::Restore(), Robot::Robot6Axis::Restore(), App::PropertyMaterial::Restore(), App::PropertyFloat::Restore(), App::PropertyPlacement::Restore(), App::PropertyMatrix::Restore(), App::PropertyVector::Restore(), Part::GeomLineSegment::Restore(), Part::GeomLine::Restore(), Part::GeomArcOfCircle::Restore(), Part::GeomCircle::Restore(), Part::GeomPoint::Restore(), and Sketcher::Constraint::Restore().
long Base::XMLReader::getAttributeAsInteger | ( | const char * | AttrName | ) | const |
return the named attribute as an interer (does type checking)
Definition at line 123 of file Reader.cpp.
References AttrMap, and RobotExample::pos.
Referenced by Gui::MergeDocuments::importObjects(), Gui::Document::importObjects(), App::Document::importObjects(), MeshCore::MeshInput::LoadXML(), Robot::Waypoint::Restore(), Robot::Trajectory::Restore(), App::PropertyStringList::Restore(), App::PropertyIntegerList::Restore(), App::PropertyEnumeration::Restore(), App::PropertyInteger::Restore(), App::PropertyLinkSubList::Restore(), App::PropertyLinkList::Restore(), App::PropertyLinkSub::Restore(), Part::PropertyGeometryList::Restore(), App::PropertyContainer::Restore(), Sketcher::PropertyConstraintList::Restore(), Part::Geometry::Restore(), Part::Box::Restore(), App::DynamicProperty::Restore(), App::Document::Restore(), Sketcher::Constraint::Restore(), Gui::MergeDocuments::RestoreDocFile(), and Gui::Document::RestoreDocFile().
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 |
check if the read element has a special attribute
Definition at line 175 of file Reader.cpp.
References AttrMap.
Referenced by Robot::Robot6Axis::Restore(), App::PropertyColorList::Restore(), App::PropertyEnumeration::Restore(), App::PropertyPythonObject::Restore(), App::DynamicProperty::Restore(), and Sketcher::Constraint::Restore().
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.
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 |
) |
read until an end element is found (with special name if given)
Definition at line 243 of file Reader.cpp.
References EndElement, LocalName, read(), and ReadType.
Referenced by Gui::MergeDocuments::importObjects(), Gui::Document::importObjects(), App::Document::importObjects(), MeshCore::MeshInput::LoadXML(), App::PropertyStringList::Restore(), App::PropertyIntegerList::Restore(), App::PropertyEnumeration::Restore(), App::PropertyLinkSubList::Restore(), App::PropertyLinkList::Restore(), App::PropertyLinkSub::Restore(), Part::PropertyGeometryList::Restore(), App::PropertyContainer::Restore(), Sketcher::PropertyConstraintList::Restore(), Part::Box::Restore(), App::DynamicProperty::Restore(), App::Document::Restore(), Gui::MergeDocuments::RestoreDocFile(), and Gui::Document::RestoreDocFile().
void Base::XMLReader::readFiles | ( | zipios::ZipInputStream & | zipstream | ) | const |
process the requested file writes
Definition at line 258 of file Reader.cpp.
References Base::Console(), Base::ConsoleSingleton::Error(), FileList, and zipios::ZipInputStream::getNextEntry().
Referenced by Gui::MergeDocuments::importObjects(), App::Document::importObjects(), and Gui::Document::RestoreDocFile().
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.
FileInfo Base::XMLReader::_File [protected] |
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] |
Definition at line 193 of file Reader.h.
Referenced by getAttribute(), getAttributeAsFloat(), getAttributeAsInteger(), getAttributeAsUnsigned(), getAttributeCount(), hasAttribute(), startElement(), and Gui::XMLMergeReader::startElement().
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().
Schema Version of the document.
Definition at line 163 of file Reader.h.
Referenced by Gui::MergeDocuments::importObjects(), App::Document::importObjects(), Points::PropertyPointKernel::Restore(), Points::PointKernel::Restore(), and App::Document::Restore().
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] |
Definition at line 189 of file Reader.h.
Referenced by endElement(), Gui::XMLMergeReader::endElement(), localName(), readElement(), readEndElement(), startElement(), and Gui::XMLMergeReader::startElement().
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] |
Referenced by characters(), endElement(), read(), readElement(), readEndElement(), and startElement().
XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken Base::XMLReader::token [protected] |
Definition at line 207 of file Reader.h.
Referenced by read(), and XMLReader().