Commit a27f1231 authored by Serrière Guillaume's avatar Serrière Guillaume

Make OneVsAll use the new XML interface.

Signed-off-by: default avatarSerrière Guillaume <guillaume.serriere@inria.fr>
parent fe920d6d
......@@ -63,7 +63,7 @@ void IXMLNodeImpl::release(void)
}
IXMLNodeImpl::IXMLNodeImpl(const char *sName):
m_sNodeName(sName)
m_sNodeName(sName)
,m_sPCData("")
,m_bHasPCData(false)
{
......@@ -77,34 +77,34 @@ string IXMLNodeImpl::getName()
boolean IXMLNodeImpl::addAttribute(const char* sAttributeName, const char* sAttributeValue)
{
m_mAttibuteMap[sAttributeName] = sAttributeValue;
return true;
m_mAttibuteMap[sAttributeName] = sAttributeValue;
return true;
}
XML::boolean IXMLNodeImpl::hasAttribute(const char *sAttributeName)
{
return m_mAttibuteMap.count(sAttributeName) != 0;
return m_mAttibuteMap.count(sAttributeName) != 0;
}
string IXMLNodeImpl::getAttribute(const char *sAttributeName)
{
return m_mAttibuteMap[sAttributeName];
return m_mAttibuteMap[sAttributeName];
}
void IXMLNodeImpl::setPCData(const char *childData)
{
m_sPCData = childData;
m_bHasPCData = true;
m_sPCData = childData;
m_bHasPCData = true;
}
string &IXMLNodeImpl::getPCData(void)
{
return m_sPCData;
return m_sPCData;
}
void IXMLNodeImpl::addChild(IXMLNode *pChildNode)
{
m_oNodeVector.push_back(pChildNode);
m_oNodeVector.push_back(pChildNode);
}
IXMLNode *IXMLNodeImpl::getChild(XML::uint32 iChildIndex)
......@@ -126,79 +126,82 @@ IXMLNode *IXMLNodeImpl::getChildByName(const char *sName)
XML::uint32 IXMLNodeImpl::getChildCount(void)
{
return m_oNodeVector.size();
return m_oNodeVector.size();
}
std::string IXMLNodeImpl::sanitize(string &sString)
{
string::size_type i;
string l_sRes(sString);
if(l_sRes.length()!=0)
{
// mandatory, this one should be the first because the other ones add & symbols
for(i=l_sRes.find("&", 0); i!=string::npos; i=l_sRes.find("&", i+1))
l_sRes.replace(i, 1, "&amp;");
// other escape sequences
for(i=l_sRes.find("\"", 0); i!=string::npos; i=l_sRes.find("\"", i+1))
l_sRes.replace(i, 1, "&quot;");
for(i=l_sRes.find("<", 0); i!=string::npos; i=l_sRes.find("<", i+1))
l_sRes.replace(i, 1, "&lt;");
for(i=l_sRes.find(">", 0); i!=string::npos; i=l_sRes.find(">", i+1))
l_sRes.replace(i, 1, "&gt;");
}
return l_sRes;
string::size_type i;
string l_sRes(sString);
if(l_sRes.length()!=0)
{
// mandatory, this one should be the first because the other ones add & symbols
for(i=l_sRes.find("&", 0); i!=string::npos; i=l_sRes.find("&", i+1))
l_sRes.replace(i, 1, "&amp;");
// other escape sequences
for(i=l_sRes.find("\"", 0); i!=string::npos; i=l_sRes.find("\"", i+1))
l_sRes.replace(i, 1, "&quot;");
for(i=l_sRes.find("<", 0); i!=string::npos; i=l_sRes.find("<", i+1))
l_sRes.replace(i, 1, "&lt;");
for(i=l_sRes.find(">", 0); i!=string::npos; i=l_sRes.find(">", i+1))
l_sRes.replace(i, 1, "&gt;");
}
return l_sRes;
}
void IXMLNodeImpl::applyIndentation(string &sString, XML::uint32 depth)
{
string l_sIndent(depth, '\t');
sString.append(l_sIndent);
string l_sIndent(depth, '\t');
sString.append(l_sIndent);
}
string IXMLNodeImpl::getXML(XML::uint32 depth)
{
string l_sRes;
applyIndentation(l_sRes, depth);
l_sRes = l_sRes + "<" + m_sNodeName;
//Add attributes if we have some
if(!m_mAttibuteMap.empty())
{
for (map<string,string>::iterator it=m_mAttibuteMap.begin(); it!=m_mAttibuteMap.end(); ++it)
{
l_sRes = l_sRes + string(" ")+ it->first + string("=\"") + sanitize(it->second) + string("\"");
}
}
//If we have nothing else to print let's close the node and return
if(!m_bHasPCData && m_oNodeVector.empty())
{
l_sRes = l_sRes + string("/>\n");
return l_sRes;
}
string l_sRes;
applyIndentation(l_sRes, depth);
l_sRes = l_sRes + "<" + m_sNodeName;
//Add attributes if we have some
if(!m_mAttibuteMap.empty())
{
for (map<string,string>::iterator it=m_mAttibuteMap.begin(); it!=m_mAttibuteMap.end(); ++it)
{
l_sRes = l_sRes + string(" ")+ it->first + string("=\"") + sanitize(it->second) + string("\"");
}
}
//If we have nothing else to print let's close the node and return
if(!m_bHasPCData && m_oNodeVector.empty())
{
l_sRes = l_sRes + string("/>\n");
return l_sRes;
}
l_sRes = l_sRes + string(">");
if(m_bHasPCData)
{
if(m_bHasPCData)
{
l_sRes = l_sRes + sanitize(m_sPCData);
}
}
for (vector<XML::IXMLNode*>::iterator it=m_oNodeVector.begin(); it!=m_oNodeVector.end(); ++it)
{
IXMLNode *l_sTempNode = (IXMLNode *)(*it);
for (vector<XML::IXMLNode*>::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);
}
}
if(!m_oNodeVector.empty())
{
l_sRes = l_sRes + "\n";
applyIndentation(l_sRes, depth);
l_sRes = l_sRes + "</" + m_sNodeName + ">\n";
return l_sRes;
}
l_sRes = l_sRes + "</" + m_sNodeName + ">";
return l_sRes;
}
OV_API IXMLNode* XML::createNode(const char* sName)
{
return new IXMLNodeImpl(sName);
return new IXMLNodeImpl(sName);
}
......@@ -10,6 +10,7 @@
#include <xml/IWriter.h>
#include <xml/IReader.h>
#include <xml/IXMLNode.h>
#include <stack>
#include <vector>
......@@ -40,7 +41,7 @@ namespace OpenViBEPlugins
virtual void write(const char* sString); // XML IWriterCallback
virtual void getClassifierConfiguration(OpenViBE::Kernel::IAlgorithmProxy* classifier, OpenViBE::IMemoryBuffer& rConfiguration);
XML::IXMLNode* getClassifierConfiguration(OpenViBE::Kernel::IAlgorithmProxy* classifier);
virtual void openChild(const char* sName, const char** sAttributeName, const char** sAttributeValue, XML::uint64 ui64AttributeCount); // XML IReaderCallback
virtual void processChildData(const char* sData); // XML IReaderCallback
virtual void closeChild(void); // XML ReaderCallback
......@@ -52,10 +53,13 @@ namespace OpenViBEPlugins
OpenViBE::uint64 m_iClassCounter; //This variable is use during configuration loading
OpenViBE::CMemoryBuffer m_oConfiguration;
XML::IXMLNode *m_pConfigurationNode;
private:
void addNewClassifierAtBack(void);
void removeClassifierAtBack(void);
void loadSubClassifierConfiguration(XML::IXMLNode *pSubClassifiersNode);
};
class CAlgorithmClassifierOneVsAllDesc : public OpenViBEToolkit::CAlgorithmPairingStrategyDesc
......
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