Commit 820d35c2 authored by Serrière Guillaume's avatar Serrière Guillaume

Update the new XML interface (remove string, add const)..

Signed-off-by: default avatarSerrière Guillaume <guillaume.serriere@inria.fr>
parent 2285aea7
......@@ -16,7 +16,7 @@ namespace XML
virtual XML::IXMLNode* parseString(const char* sString, const uint32& uiSize)=0;
//XML extraction
virtual XML::boolean writeXMLInFile(IXMLNode &rNode, const char* sPath)=0;
virtual XML::boolean writeXMLInFile(const IXMLNode &rNode, const char* sPath) const =0;
protected:
virtual ~IXMLHandler() { }
......
......@@ -11,25 +11,25 @@ namespace XML
public:
virtual void release(void)=0;
virtual std::string getName()=0;
virtual const char* getName() const =0;
//Attribute
virtual XML::boolean addAttribute(const char* sAttributeName, const char* sAttributeValue)=0;
virtual XML::boolean hasAttribute(const char* sAttributeName)=0;
virtual std::string getAttribute(const char* sAttributeName)=0;
virtual XML::boolean hasAttribute(const char* sAttributeName) const =0;
virtual const char* getAttribute(const char* sAttributeName) const =0;
//PCDATA
virtual void setPCData(const char* childData)=0;
virtual std::string &getPCData(void)=0;
virtual const char* getPCData(void) const =0;
//Child
virtual void addChild(XML::IXMLNode* ChildNode)=0;
virtual XML::IXMLNode* getChild(XML::uint32 iChildIndex)=0;
virtual XML::IXMLNode* getChildByName(const char* sName)=0;
virtual XML::uint32 getChildCount(void)=0;
virtual XML::IXMLNode* getChild(const XML::uint32 iChildIndex) const =0;
virtual XML::IXMLNode* getChildByName(const char* sName) const =0;
virtual XML::uint32 getChildCount(void) const =0;
//XML generation
virtual std::string getXML(XML::uint32 depth=0)=0;
virtual char* getXML(const XML::uint32 depth=0) const =0;
protected:
virtual ~IXMLNode(void) {}
......
#include "IXMLHandler.h"
#include <expat.h>
#include <cstring>
#include <stack>
#include <fstream>
#include <iostream>
......@@ -18,7 +19,7 @@ namespace XML
virtual XML::IXMLNode* parseString(const char* sString, const uint32& uiSize);
//XML extraction
virtual XML::boolean writeXMLInFile(IXMLNode &rNode, const char* sPath);
virtual XML::boolean writeXMLInFile(const IXMLNode &rNode, const char* sPath) const;
//Internal function for parsing
virtual void openChild(const char* sName, const char** sAttributeName, const char** sAttributeValue, uint64 ui64AttributeCount);
......@@ -119,13 +120,15 @@ IXMLNode *IXMLHandlerImpl::parseString(const char *sString, const uint32& uiSize
return m_pRootNode;
}
boolean IXMLHandlerImpl::writeXMLInFile(IXMLNode &rNode, const char *sPath)
boolean IXMLHandlerImpl::writeXMLInFile(const IXMLNode &rNode, const char *sPath) const
{
std::ofstream l_oFile(sPath, ios::binary);
if(l_oFile.is_open())
{
l_oFile.write(rNode.getXML().c_str(), rNode.getXML().length());
char* l_sXML = rNode.getXML();
l_oFile.write(l_sXML, ::strlen(l_sXML));
l_oFile.close();
free(l_sXML);
return true;
}
return false;
......
#include "IXMLNode.h"
#include <string>
#include <cstring>
#include <stdexcept>
#include <stack>
#include <vector>
#include <map>
......@@ -12,34 +14,34 @@ namespace XML
public:
IXMLNodeImpl(const char* sName);
virtual std::string getName();
virtual const char* getName() const;
virtual void release(void);
//Attribute
virtual XML::boolean addAttribute(const char* sAttributeName, const char* sAttributeValue);
virtual XML::boolean hasAttribute(const char* sAttributeName);
virtual std::string getAttribute(const char* sAttributeName);
virtual XML::boolean hasAttribute(const char* sAttributeName) const;
virtual const char* getAttribute(const char* sAttributeName) const;
//PCDATA
virtual void setPCData(const char* childData);
virtual std::string &getPCData(void);
virtual const char* getPCData(void) const;
//Child
virtual void addChild(XML::IXMLNode* pChildNode);
virtual XML::IXMLNode* getChild(XML::uint32 iChildIndex);
virtual XML::IXMLNode* getChildByName(const char* sName);
virtual XML::uint32 getChildCount(void);
virtual XML::IXMLNode* getChild(const XML::uint32 iChildIndex) const;
virtual XML::IXMLNode* getChildByName(const char* sName) const;
virtual XML::uint32 getChildCount(void) const;
//XMl generation
virtual std::string getXML(XML::uint32 depth=0);
virtual char* getXML(const XML::uint32 depth=0) const;
protected:
virtual ~IXMLNodeImpl(void);
private:
std::string sanitize(std::string& sString);
void applyIndentation(std::string &sString, XML::uint32 depth);
std::string sanitize(const std::string& sString) const;
void applyIndentation(std::string &sString, XML::uint32 depth) const;
std::vector<XML::IXMLNode *> m_oNodeVector;
......@@ -74,9 +76,9 @@ IXMLNodeImpl::IXMLNodeImpl(const char *sName):
}
string IXMLNodeImpl::getName()
const char* IXMLNodeImpl::getName() const
{
return m_sNodeName;
return m_sNodeName.c_str();
}
boolean IXMLNodeImpl::addAttribute(const char* sAttributeName, const char* sAttributeValue)
......@@ -85,14 +87,22 @@ boolean IXMLNodeImpl::addAttribute(const char* sAttributeName, const char* sAttr
return true;
}
XML::boolean IXMLNodeImpl::hasAttribute(const char *sAttributeName)
XML::boolean IXMLNodeImpl::hasAttribute(const char *sAttributeName) const
{
return m_mAttibuteMap.count(sAttributeName) != 0;
}
string IXMLNodeImpl::getAttribute(const char *sAttributeName)
const char* IXMLNodeImpl::getAttribute(const char *sAttributeName) const
{
return m_mAttibuteMap[sAttributeName];
const char* res = NULL;
try
{
res = m_mAttibuteMap.at(sAttributeName).c_str();
}
catch (const std::out_of_range& oor)
{
}
return res;
}
void IXMLNodeImpl::setPCData(const char *childData)
......@@ -101,9 +111,9 @@ void IXMLNodeImpl::setPCData(const char *childData)
m_bHasPCData = true;
}
string &IXMLNodeImpl::getPCData(void)
const char* IXMLNodeImpl::getPCData(void) const
{
return m_sPCData;
return m_sPCData.c_str();
}
void IXMLNodeImpl::addChild(IXMLNode *pChildNode)
......@@ -111,29 +121,28 @@ void IXMLNodeImpl::addChild(IXMLNode *pChildNode)
m_oNodeVector.push_back(pChildNode);
}
IXMLNode *IXMLNodeImpl::getChild(XML::uint32 iChildIndex)
IXMLNode *IXMLNodeImpl::getChild(const XML::uint32 iChildIndex) const
{
return m_oNodeVector[iChildIndex];
}
IXMLNode *IXMLNodeImpl::getChildByName(const char *sName)
IXMLNode *IXMLNodeImpl::getChildByName(const char *sName) const
{
string l_sName(sName);
for (vector<XML::IXMLNode*>::iterator it=m_oNodeVector.begin(); it!=m_oNodeVector.end(); ++it)
for (vector<XML::IXMLNode*>::const_iterator it=m_oNodeVector.begin(); it!=m_oNodeVector.end(); ++it)
{
IXMLNode *l_sTempNode = (IXMLNode *)(*it);
if(!l_sTempNode->getName().compare(l_sName))
if(::strcmp(l_sTempNode->getName(), sName) == 0)
return l_sTempNode;
}
return NULL;
}
XML::uint32 IXMLNodeImpl::getChildCount(void)
XML::uint32 IXMLNodeImpl::getChildCount(void) const
{
return m_oNodeVector.size();
}
std::string IXMLNodeImpl::sanitize(string &sString)
std::string IXMLNodeImpl::sanitize(const string &sString) const
{
string::size_type i;
string l_sRes(sString);
......@@ -153,13 +162,13 @@ std::string IXMLNodeImpl::sanitize(string &sString)
return l_sRes;
}
void IXMLNodeImpl::applyIndentation(string &sString, XML::uint32 depth)
void IXMLNodeImpl::applyIndentation(string &sString, XML::uint32 depth) const
{
string l_sIndent(depth, '\t');
sString.append(l_sIndent);
}
string IXMLNodeImpl::getXML(XML::uint32 depth)
char* IXMLNodeImpl::getXML(const XML::uint32 depth) const
{
string l_sRes;
applyIndentation(l_sRes, depth);
......@@ -168,7 +177,7 @@ string IXMLNodeImpl::getXML(XML::uint32 depth)
//Add attributes if we have some
if(!m_mAttibuteMap.empty())
{
for (map<string,string>::iterator it=m_mAttibuteMap.begin(); it!=m_mAttibuteMap.end(); ++it)
for (map<string,string>::const_iterator it=m_mAttibuteMap.begin(); it!=m_mAttibuteMap.end(); ++it)
{
l_sRes = l_sRes + string(" ")+ it->first + string("=\"") + sanitize(it->second) + string("\"");
......@@ -178,7 +187,8 @@ string IXMLNodeImpl::getXML(XML::uint32 depth)
if(!m_bHasPCData && m_oNodeVector.empty())
{
l_sRes = l_sRes + string("/>\n");
return l_sRes;
char* l_pRes = ::strdup(l_sRes.c_str());
return l_pRes;
}
l_sRes = l_sRes + string(">");
......@@ -188,7 +198,7 @@ string IXMLNodeImpl::getXML(XML::uint32 depth)
l_sRes = l_sRes + sanitize(m_sPCData);
}
for (vector<XML::IXMLNode*>::iterator it=m_oNodeVector.begin(); it!=m_oNodeVector.end(); ++it)
for (vector<XML::IXMLNode*>::const_iterator it=m_oNodeVector.begin(); it!=m_oNodeVector.end(); ++it)
{
IXMLNode *l_sTempNode = (IXMLNode *)(*it);
l_sRes = l_sRes + string("\n") + l_sTempNode->getXML(depth+1);
......@@ -200,7 +210,9 @@ string IXMLNodeImpl::getXML(XML::uint32 depth)
applyIndentation(l_sRes, depth);
}
l_sRes = l_sRes + "</" + m_sNodeName + ">";
return l_sRes;
char* l_pRes = ::strdup(l_sRes.c_str());
return l_pRes;
}
OV_API IXMLNode* XML::createNode(const char* sName)
......
......@@ -595,7 +595,7 @@ void CAlgorithmClassifierSVM::loadParamNodeConfiguration(XML::IXMLNode *pParamNo
XML::IXMLNode* l_pTempNode = pParamNode->getChildByName(c_sSvmTypeNodeName);
for(int i =0; get_svm_type(i);i++)
{
if ( strcmp(get_svm_type(i),l_pTempNode->getPCData().c_str())==0)
if ( strcmp(get_svm_type(i),l_pTempNode->getPCData())==0)
{
m_pModel->param.svm_type=i;
}
......@@ -609,7 +609,7 @@ void CAlgorithmClassifierSVM::loadParamNodeConfiguration(XML::IXMLNode *pParamNo
l_pTempNode = pParamNode->getChildByName(c_sKernelTypeNodeName);
for(int i =0; get_kernel_type(i);i++)
{
if ( strcmp(get_kernel_type(i), l_pTempNode->getPCData().c_str())==0)
if ( strcmp(get_kernel_type(i), l_pTempNode->getPCData())==0)
{
m_pModel->param.kernel_type=i;
}
......
......@@ -61,7 +61,7 @@ boolean CBoxAlgorithmClassifierProcessor::initialize(void)
//If the algorithm is still unknown, that means that we face an error
if(l_oAlgorithmClassIdentifier==OV_UndefinedIdentifier)
{
this->getLogManager() << LogLevel_ImportantWarning << "Unknown classifier algorithm [" << l_pTempNode->getPCData().c_str() << "]\n";
this->getLogManager() << LogLevel_ImportantWarning << "Unknown classifier algorithm [" << l_pTempNode->getPCData() << "]\n";
return false;
}
}
......@@ -71,14 +71,14 @@ boolean CBoxAlgorithmClassifierProcessor::initialize(void)
//Load Rejected class label and put it as the entry for class 0
l_pTempNode = l_pStimulationsNode->getChildByName(c_sRejectedClassNodeName);
CString l_sRejectedLabel(l_pTempNode->getPCData().c_str());
CString l_sRejectedLabel(l_pTempNode->getPCData());
m_vStimulation[0]=this->getTypeManager().getEnumerationEntryValueFromName(OV_TypeId_Stimulation, l_sRejectedLabel);
//Now load every stimulation and store them in the map with the right class id
for(uint32 i=1; i<l_pStimulationsNode->getChildCount(); i++)
{
l_pTempNode = l_pStimulationsNode->getChild(i);
CString l_sStimulationName(l_pTempNode->getPCData().c_str());
CString l_sStimulationName(l_pTempNode->getPCData());
OpenViBE::float64 l_f64ClassId;
std::stringstream l_sIdentifierData(l_pTempNode->getAttribute(c_sIdentifierAttributeName));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment