19 #include "ICSerializerRapid.hpp"
20 #include <tobicore/TCException.hpp>
21 #include <tobicore/TCTools.hpp>
23 #include <tobicore/rapidxml.hpp>
24 #include <tobicore/rapidxml_print.hpp>
32 using namespace rapidxml;
36 const bool declaration)
49 throw TCException(
"iC message not set, cannot serialize");
55 std::string xml_as_string;
56 std::string xml_no_indent;
60 xml_node<>* decl = doc.allocate_node(node_declaration);
61 decl->append_attribute(doc.allocate_attribute(
"version",
"1.0"));
62 decl->append_attribute(doc.allocate_attribute(
"encoding",
"utf-8"));
63 doc.append_node(decl);
71 std::string timestamp, reference;
76 xml_node<>* root = doc.allocate_node(node_element, ICMESSAGE_ROOTNODE);
77 root->append_attribute(doc.allocate_attribute(ICMESSAGE_VERSIONNODE,
79 root->append_attribute(doc.allocate_attribute(ICMESSAGE_FRAMENODE,
81 root->append_attribute(doc.allocate_attribute(ICMESSAGE_TIMESTAMPNODE,
83 root->append_attribute(doc.allocate_attribute(ICMESSAGE_REFERENCENODE,
85 doc.append_node(root);
93 char* ptr_vtype = NULL;
94 char* ptr_ltype = NULL;
95 xml_node<>* cnode = NULL;
96 xml_node<>* knode = NULL;
100 cptr = (*cit).second;
101 cnode = doc.allocate_node(node_element, ICMESSAGE_CLASSISIFERNODE);
102 cnode->append_attribute(doc.allocate_attribute(ICMESSAGE_NAMENODE,
104 cnode->append_attribute(doc.allocate_attribute(ICMESSAGE_DESCNODE,
106 root->append_node(cnode);
111 ptr_vtype = (
char*)ICTYPES_ENTRY_UNDEF;
114 ptr_vtype = (
char*)ICTYPES_ENTRY_PROB;
117 ptr_vtype = (
char*)ICTYPES_ENTRY_DIST;
120 ptr_vtype = (
char*)ICTYPES_ENTRY_CLBL;
123 ptr_vtype = (
char*)ICTYPES_ENTRY_RCOE;
126 cnode->append_attribute(doc.allocate_attribute(ICMESSAGE_VTYPENODE,
132 ptr_ltype = (
char*)ICTYPES_LABEL_CLASS;
135 ptr_ltype = (
char*)ICTYPES_LABEL_UNDEF;
138 ptr_ltype = (
char*)ICTYPES_LABEL_BIOSIG;
141 ptr_ltype = (
char*)ICTYPES_LABEL_CUSTOM;
144 cnode->append_attribute(doc.allocate_attribute(ICMESSAGE_LTYPENODE,
150 kptr = (*kit).second;
151 knode = doc.allocate_node(node_element, ICMESSAGE_CLASSNODE,
153 knode->append_attribute(doc.allocate_attribute(ICMESSAGE_LABELNODE,
155 cnode->append_node(knode);
165 print(std::back_inserter(*buffer), doc);
167 print(std::back_inserter(*buffer), doc, print_no_indenting);
176 std::vector<char> xml_copy(buffer->begin(), buffer->end());
177 xml_copy.push_back(
'\0');
178 doc.parse<parse_declaration_node | parse_no_data_nodes>(&xml_copy[0]);
181 xml_node<>* rootnode = doc.first_node(ICMESSAGE_ROOTNODE);
182 if(rootnode == NULL) {
193 cache = rootnode->first_attribute(ICMESSAGE_VERSIONNODE)->value();
194 if(cache.compare(ICMESSAGE_VERSION) != 0) {
195 std::string info(
"iC version mismatch: ");
196 info.append(ICMESSAGE_VERSION);
209 cache = rootnode->first_attribute(ICMESSAGE_FRAMENODE)->value();
213 cache = rootnode->first_attribute(ICMESSAGE_TIMESTAMPNODE)->value();
215 cache = rootnode->first_attribute(ICMESSAGE_REFERENCENODE)->value();
219 xml_node<>* cnode = NULL;
220 xml_node<>* knode = NULL;
226 cnode = rootnode->first_node(ICMESSAGE_CLASSISIFERNODE);
227 while(cnode != NULL) {
228 std::string cname, cdesc, tvtype, tltype;
233 cname = cnode->first_attribute(ICMESSAGE_NAMENODE)->value();
235 cdesc = cnode->first_attribute(ICMESSAGE_DESCNODE)->value();
236 tvtype = cnode->first_attribute(ICMESSAGE_VTYPENODE)->value();
237 tltype = cnode->first_attribute(ICMESSAGE_LTYPENODE)->value();
253 knode = cnode->first_node(ICMESSAGE_CLASSNODE);
254 while(knode != NULL) {
256 knode->first_attribute(ICMESSAGE_LABELNODE)->value();
257 std::string tvalue = knode->value();
268 knode = knode->next_sibling(ICMESSAGE_CLASSNODE);
272 cnode = cnode->next_sibling(ICMESSAGE_CLASSISIFERNODE);