OpenASIP
2.0
|
#include <XMLSerializer.hh>
Public Member Functions | |
XMLSerializer () | |
virtual | ~XMLSerializer () |
void | setSourceFile (const std::string &fileName) |
void | setSourceString (const std::string &source) |
void | setDestinationFile (const std::string &fileName) |
void | setDestinationString (std::string &destination) |
void | setSchemaFile (const std::string &fileName) |
void | setUseSchema (bool useSchema) |
void | setXMLNamespace (std::string nsUri) |
virtual ObjectState * | readState () |
virtual void | writeState (const ObjectState *rootState) |
Public Member Functions inherited from TCETools::Serializer | |
virtual | ~Serializer () |
Protected Member Functions | |
std::string | sourceFile () const |
Private Member Functions | |
XMLSerializer (const XMLSerializer &) | |
Copying forbidden. More... | |
XMLSerializer & | operator= (const XMLSerializer &) |
Assignment forbidden. More... | |
void | initializeParser () |
virtual ObjectState * | readFile (const std::string &fileName) |
virtual ObjectState * | readString (const std::string &source) |
virtual void | writeFile (const std::string &fileName, const ObjectState *rootState) |
virtual void | writeString (std::string &target, const ObjectState *rootState) |
DOMDocument * | createDOMDocument (const ObjectState *state) const |
void | ensureValidStream (const std::string &fileName) const |
DOMElement * | createDOM (ObjectState *state, DOMDocument *doc) const |
ObjectState * | createState (const DOMNode *node) const |
bool | hasChildElementNodes (const DOMNode *node) const |
Private Attributes | |
std::string | sourceFile_ |
Source file path. More... | |
std::string | destinationFile_ |
Destination file path. More... | |
std::string | schemaFile_ |
Schema file path. More... | |
bool | useSchema_ |
Indicates if xml file is validated using schema. More... | |
DOMBuilder * | parser_ |
The parser that checks the XML file for errors with the Schema. More... | |
DOMImplementation * | domImplementation_ |
Implementation of the DOM. More... | |
const std::string * | sourceString_ |
Source string to read. More... | |
std::string * | destinationString_ |
Destination string to write. More... | |
std::string | nsUri_ |
XML namespace URI. More... | |
This class is used to read and write XML. This is a base class for different kind of XML serializers.
Definition at line 62 of file XMLSerializer.hh.
XMLSerializer::XMLSerializer | ( | ) |
Constructor.
Definition at line 78 of file XMLSerializer.cc.
References domImplementation_, and parser_.
|
virtual |
|
private |
Copying forbidden.
|
private |
Creates DOM tree from the given ObjectState tree.
state | Root node of the ObjectState tree. |
doc | The DOMDocument to which the created DOM tree belongs. |
Definition at line 609 of file XMLSerializer.cc.
References ObjectState::attribute(), ObjectState::attributeCount(), ObjectState::child(), ObjectState::childCount(), ObjectState::Attribute::name, ObjectState::name(), ObjectState::stringValue(), Conversion::toXMLCh(), and ObjectState::Attribute::value.
Referenced by createDOMDocument().
|
private |
Creates a DOM tree according to the given ObjectState tree.
state | Root node of the ObjectState tree. |
Definition at line 537 of file XMLSerializer.cc.
References ObjectState::attribute(), ObjectState::attributeCount(), ObjectState::child(), ObjectState::childCount(), createDOM(), domImplementation_, ObjectState::Attribute::name, ObjectState::name(), nsUri_, ObjectState::stringValue(), Conversion::toXMLCh(), and ObjectState::Attribute::value.
Referenced by writeFile(), and writeString().
|
private |
Creates a one-to-one ObjectState object (tree) according to the given DOMNode.
node | DOMNode from which the ObjectState is created. |
Definition at line 653 of file XMLSerializer.cc.
References ObjectState::addChild(), hasChildElementNodes(), ObjectState::setAttribute(), ObjectState::setValue(), and Conversion::XMLChToString().
Referenced by readFile(), and readString().
|
private |
Checks that the file is OK for reading.
fileName | Name of the XML file. |
UnreachableStream | If the given file cannot be read. |
Definition at line 587 of file XMLSerializer.cc.
Referenced by initializeParser(), and readFile().
|
private |
Returns true if the given node has child elements.
node | Node. |
Definition at line 695 of file XMLSerializer.cc.
Referenced by createState().
|
private |
Initializes the XML parser.
Definition at line 234 of file XMLSerializer.cc.
References __func__, FileSystem::currentWorkingDir(), FileSystem::DIRECTORY_SEPARATOR, ensureValidStream(), Exception::errorMessage(), FileSystem::isRelativePath(), parser_, schemaFile_, Exception::setCause(), Conversion::toXMLCh(), and useSchema_.
Referenced by readFile(), and readString().
|
private |
Assignment forbidden.
|
privatevirtual |
Reads current XML file set and creates an ObjectState tree according to it.
The XML file is validated with the current schema file if the setting is on.
SerializerException | If an error occurs while reading. |
Definition at line 368 of file XMLSerializer.cc.
References __func__, createState(), ensureValidStream(), DOMBuilderErrorHandler::errorCount(), DOMBuilderErrorHandler::errorLog(), Exception::errorMessage(), initializeParser(), parser_, and sourceFile().
Referenced by readState().
|
virtual |
Reads object state from a file or string.
File is read if a source file is set with setSourceFile(). String is read if a source string is set with setSourceString(). Only the last file/string set will be read.
Implements TCETools::Serializer.
Reimplemented in GUIOptionsSerializer, IPXactSerializer, ADFSerializer, IDF::IDFSerializer, and BEMSerializer.
Definition at line 200 of file XMLSerializer.cc.
References __func__, readFile(), readString(), sourceFile_, and sourceString_.
Referenced by BlocksModel::BlocksModel(), BEMSerializer::readState(), IDF::IDFSerializer::readState(), OSEdOptionsSerializer::readState(), OperationSerializer::readState(), ADFSerializer::readState(), and GUIOptionsSerializer::readState().
|
privatevirtual |
Reads object state from an xml string.
XML | to read as an string containing the entire xml document. |
SerializerException | If an error occurs while reading. |
Definition at line 301 of file XMLSerializer.cc.
References __func__, createState(), DOMBuilderErrorHandler::errorCount(), DOMBuilderErrorHandler::errorLog(), initializeParser(), and parser_.
Referenced by readState().
void XMLSerializer::setDestinationFile | ( | const std::string & | fileName | ) |
Sets the destination file used when writeState is called.
Previously set destination file or string is unset.
fileName | Relative or absolute path of the destination file, e.g. /home/openasip/file.xml or ./file.xml. |
Definition at line 142 of file XMLSerializer.cc.
References destinationFile_, and destinationString_.
Referenced by CompileTools::compileAsC(), CompileTools::compileAsLLVM(), SaveOptionsCmd::Do(), ProximQuitCmd::Do(), ProcessorImplementationWindow::doSaveIDF(), main(), GenerateProcessorDialog::onOK(), MDFDocument::OnSaveDocument(), DesignSpaceExplorer::schedule(), OSEdOptionsSerializer::setDestinationFile(), OperationSerializer::setDestinationFile(), DSDBManager::writeArchitectureToFile(), DSDBManager::writeImplementationToFile(), IPXactFileGenerator::writeProjectFiles(), TTAMachine::Machine::writeToADF(), and DataDependenceGraph::writeToXMLFile().
void XMLSerializer::setDestinationString | ( | std::string & | target | ) |
Sets the destination string used when writeState is called.
Previously set destination file or string is unset.
target | Target string to write. |
Definition at line 156 of file XMLSerializer.cc.
References destinationFile_, and destinationString_.
Referenced by DSDBManager::addArchitecture(), DSDBManager::addImplementation(), TTAMachine::Machine::hash(), and TDGen::writeBackendCode().
void XMLSerializer::setSchemaFile | ( | const std::string & | fileName | ) |
Sets the schema file used to validate xml files.
fileName | Relative or absolute path of the schema file, e.g. /home/openasip/schema.xsd or ./schema.xsd. |
Definition at line 168 of file XMLSerializer.cc.
References schemaFile_.
Referenced by ADFSerializer::ADFSerializer(), BEMSerializer::BEMSerializer(), IDF::IDFSerializer::IDFSerializer(), Proxim::loadOptions(), ProDe::OnInit(), OSEdOptionsSerializer::setSchemaFile(), and OperationSerializer::setSchemaFile().
void XMLSerializer::setSourceFile | ( | const std::string & | fileName | ) |
Sets the source file used when readState is called.
Previously set source file or string is unset.
fileName | Relative or absolute path of the source file, e.g. /home/openasip/file.xml or ./file.xml. |
Definition at line 115 of file XMLSerializer.cc.
References sourceFile_, and sourceString_.
Referenced by BlocksModel::BlocksModel(), AddFUArchFromADFCmd::Do(), loadBEM(), ProGe::ProGeUI::loadBinaryEncoding(), TTAMachine::Machine::loadFromADF(), IDF::MachineImplementation::loadFromIDF(), loadInputs(), loadMachine(), ProGe::ProGeUI::loadMachine(), SimulatorFrontend::loadMachine(), ProGe::ProGeUI::loadMachineImplementation(), Proxim::loadOptions(), ProGe::ProGeUI::loadProcessorConfiguration(), main(), Model::Model(), GenerateProcessorDialog::onBrowseBEMLoad(), ProDe::OnInit(), ProcessorImplementationWindow::onLoadIDF(), readAdf(), readIdf(), OSEdOptionsSerializer::setSourceFile(), and OperationSerializer::setSourceFile().
void XMLSerializer::setSourceString | ( | const std::string & | source | ) |
Sets the source string used when readState is called.
Previously set source file or string is unset.
source | Source string to read. |
Definition at line 128 of file XMLSerializer.cc.
References sourceFile_, and sourceString_.
Referenced by DSDBManager::architecture(), llvm::TCETargetMachine::createMachine(), DSDBManager::implementation(), llvm::TCEStubTargetMachine::TCEStubTargetMachine(), DSDBManager::writeArchitectureToFile(), and DSDBManager::writeImplementationToFile().
void XMLSerializer::setUseSchema | ( | bool | useSchema | ) |
Sets/unsets validation of xml files using xml schema.
useSchema | True sets and false unsets validation. Default value is false. |
Definition at line 179 of file XMLSerializer.cc.
References useSchema_.
Referenced by ADFSerializer::ADFSerializer(), BEMSerializer::BEMSerializer(), IDF::IDFSerializer::IDFSerializer(), IPXactSerializer::IPXactSerializer(), Proxim::loadOptions(), ProDe::OnInit(), OSEdOptionsSerializer::setUseSchema(), and OperationSerializer::setUseSchema().
void XMLSerializer::setXMLNamespace | ( | std::string | nsUri | ) |
Sets the XML namespace URI to be used when creating a DOM document
Definition at line 188 of file XMLSerializer.cc.
References nsUri_.
Referenced by IPXactSerializer::writeState().
|
protected |
Returns the source file that is set.
Definition at line 526 of file XMLSerializer.cc.
References sourceFile_.
Referenced by readFile(), and IDF::IDFSerializer::readState().
|
privatevirtual |
Writes the given ObjectState tree into the current XML file set.
rootState | The root object of the ObjectState tree. |
SerializerException | If the destination file cannot be written. |
Definition at line 435 of file XMLSerializer.cc.
References __func__, createDOMDocument(), domImplementation_, FileSystem::fileIsCreatable(), and FileSystem::fileIsWritable().
Referenced by writeState().
|
virtual |
Writes the given object state to a file or string.
File is written if a destiantion file is set with setDestinationFile(). String is written if a destination string is set with setDestinationString(). Only the last file/string set will be written.
Implements TCETools::Serializer.
Reimplemented in IDF::IDFSerializer, BEMSerializer, GUIOptionsSerializer, ADFSerializer, and IPXactSerializer.
Definition at line 219 of file XMLSerializer.cc.
References __func__, destinationFile_, destinationString_, writeFile(), and writeString().
Referenced by IPXactSerializer::writeState(), OSEdOptionsSerializer::writeState(), BEMSerializer::writeState(), IDF::IDFSerializer::writeState(), ADFSerializer::writeState(), OperationSerializer::writeState(), GUIOptionsSerializer::writeState(), and DataDependenceGraph::writeToXMLFile().
|
privatevirtual |
Writes the given ObjectState tree to a target string.
rootState | The root object of the ObjectState tree. |
SerializerException | If the destination file cannot be written. |
Definition at line 485 of file XMLSerializer.cc.
References __func__, createDOMDocument(), and domImplementation_.
Referenced by writeState().
|
private |
Destination file path.
Definition at line 114 of file XMLSerializer.hh.
Referenced by setDestinationFile(), setDestinationString(), and writeState().
|
private |
Destination string to write.
Definition at line 131 of file XMLSerializer.hh.
Referenced by setDestinationFile(), setDestinationString(), and writeState().
|
private |
Implementation of the DOM.
Definition at line 126 of file XMLSerializer.hh.
Referenced by createDOMDocument(), writeFile(), writeString(), and XMLSerializer().
|
private |
XML namespace URI.
Definition at line 134 of file XMLSerializer.hh.
Referenced by createDOMDocument(), and setXMLNamespace().
|
private |
The parser that checks the XML file for errors with the Schema.
Definition at line 123 of file XMLSerializer.hh.
Referenced by initializeParser(), readFile(), readString(), XMLSerializer(), and ~XMLSerializer().
|
private |
Schema file path.
Definition at line 116 of file XMLSerializer.hh.
Referenced by initializeParser(), and setSchemaFile().
|
private |
Source file path.
Definition at line 112 of file XMLSerializer.hh.
Referenced by readState(), setSourceFile(), setSourceString(), and sourceFile().
|
private |
Source string to read.
Definition at line 129 of file XMLSerializer.hh.
Referenced by readState(), setSourceFile(), and setSourceString().
|
private |
Indicates if xml file is validated using schema.
Definition at line 118 of file XMLSerializer.hh.
Referenced by initializeParser(), and setUseSchema().