1 #include "xercesc/sax2/SAX2XMLReader.hpp" 2 #include <xercesc/sax2/XMLReaderFactory.hpp> 3 #include "xercesc/sax2/DefaultHandler.hpp" 4 #include "xercesc/sax2/Attributes.hpp" 6 #include <xercesc/framework/MemBufInputSource.hpp> 13 std::unique_ptr<SAX2XMLReader>
parser;
20 if (m_parser!=
nullptr)
delete m_parser;
46 enum { md_Idle, md_Parameter, md_Data } m_mode;
50 xc_Parameter=XMLString::transcode(
"Parameter");
51 xc_Data=XMLString::transcode(
"Data");
52 xc_name=XMLString::transcode(
"name");
53 xc_type=XMLString::transcode(
"type");
54 xc_elements=XMLString::transcode(
"elements");
55 xc_encoding=XMLString::transcode(
"encoding");
67 void startElement (
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const Attributes &attrs)
override;
68 void endElement (
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
69 void characters (
const XMLCh *
const chars,
const XMLSize_t length)
override;
70 void ignorableWhitespace (
const XMLCh *
const chars,
const XMLSize_t length)
override;
73 if (val==
nullptr)
return false;
74 char* tool=XMLString::transcode(val);
79 XMLCh *xc_Parameter, *xc_Data, *xc_name, *xc_type, *xc_elements, *xc_encoding;
90 if (m_mode!=md_Idle)
return;
91 if (!XMLString::compareIString(localname,xc_Parameter)) {
93 if (!cvt2String(attrs.getValue(xc_name),m_pname))
return;
95 if (!cvt2String(attrs.getValue(xc_type),m_ptype))
return;
99 }
else if (!XMLString::compareIString(localname,xc_Data)) {
102 if (!cvt2String(attrs.getValue(xc_elements),strElements))
return;
103 n_elements=atoi(strElements.c_str());
106 cvt2String(attrs.getValue(xc_encoding),m_dataEncoding);
114 if (m_mode==md_Idle)
return;
116 if (m_mode==md_Parameter) {
117 m_parameters[m_pname]=m_text;
118 }
else if (m_mode==md_Data) {
121 for (std::string::iterator
q=m_text.begin();
q!=m_text.end();
q++) {
123 if (entry.empty())
continue;
124 m_items.push_back(entry);
133 if (m_mode==md_Idle)
return;
137 if (m_mode==md_Idle)
return;
139 while (offset<length) {
141 for (i=0; i<length-offset && i<255; i++) m_workx[i]=chars[i+offset];
143 XMLString::transcode(m_workx,m_workc,511);
154 if (m_parser==
nullptr) {
156 m_parser->parser=std::unique_ptr<xercesc::SAX2XMLReader>(xercesc::XMLReaderFactory::createXMLReader());
159 MemBufInputSource
src((
const unsigned char*)xmlDocument.c_str(), xmlDocument.length(),
"hcal::PatternReader");
160 m_parser->parser->setContentHandler(&handler);
161 m_parser->parser->parse(
src);
168 std::vector<std::string>
items;
171 this->
parse(xmlDocument,parameters,items,encoding);
173 if (encoding==
"dec") formatting=10;
174 if (encoding==
"hex") formatting=16;
177 for (std::vector<std::string>::const_iterator
i=items.begin();
i!=items.end();
i++)
178 data.push_back(strtol(
i->c_str(),
nullptr,formatting));
void parse(const std::string &xmlDocument, std::map< std::string, std::string > ¶meters, std::vector< std::string > &items, std::string &encoding)
bool cvt2String(const XMLCh *val, std::string &ou)
std::vector< std::string > & m_items
void characters(const XMLCh *const chars, const XMLSize_t length) override
std::string & m_dataEncoding
std::unique_ptr< SAX2XMLReader > parser
ConfigurationDBHandler(std::map< std::string, std::string > ¶meters, std::vector< std::string > &items, std::string &encoding)
std::map< std::string, std::string > & m_parameters
void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length) override
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) override
char data[epos_bytes_allocation]
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
~ConfigurationDBHandler() override