src/XMLDocumentConstructor.h
branchv_0
changeset 36 c97810ccfdef
parent 35 5bfd1d389d5f
child 37 cae9eedf4180
equal deleted inserted replaced
35:5bfd1d389d5f 36:c97810ccfdef
    56 	 * number of remainin items in the fixed-size container (map or array) at current tree-level
    56 	 * number of remainin items in the fixed-size container (map or array) at current tree-level
    57 	 */
    57 	 */
    58 	std::vector<ssize_t> remainingItems;
    58 	std::vector<ssize_t> remainingItems;
    59 #define INDEFINITE -1
    59 #define INDEFINITE -1
    60 
    60 
       
    61 	std::stringstream currentIndefiniteString;
       
    62 
    61 	cbor_callbacks callbacks = cbor_empty_callbacks;
    63 	cbor_callbacks callbacks = cbor_empty_callbacks;
    62 
    64 
    63 	/**
    65 	/**
    64 	 * Both CBOR and XML strings are in UTF-8.
    66 	 * Both CBOR and XML strings are in UTF-8.
    65 	 */
    67 	 */
    95 			current->set_attribute("value-type", cborType);
    97 			current->set_attribute("value-type", cborType);
    96 			current = parentOrSelf(current);
    98 			current = parentOrSelf(current);
    97 			mode.pop_back();
    99 			mode.pop_back();
    98 		} else if (mode.back() == Mode::ROOT) {
   100 		} else if (mode.back() == Mode::ROOT) {
    99 			current->add_child_text(value);
   101 			current->add_child_text(value);
       
   102 		} else if (mode.back() == Mode::BYTE_STRING || mode.back() == Mode::CHAR_STRING) {
       
   103 			currentIndefiniteString << value;
   100 		} else {
   104 		} else {
   101 			// TODO: process YAML_SCALAR_EVENT
   105 			// TODO: process YAML_SCALAR_EVENT
   102 		}
   106 		}
   103 
   107 
   104 		checkRemainingItems();
   108 		checkRemainingItems();
   134 
   138 
   135 		mode.push_back(Mode::MAP_KEY);
   139 		mode.push_back(Mode::MAP_KEY);
   136 		remainingItems.push_back(size);
   140 		remainingItems.push_back(size);
   137 	}
   141 	}
   138 
   142 
       
   143 	void flushCurrentIndefiniteString(Glib::ustring cborType) {
       
   144 		mode.pop_back();
       
   145 		appendScalarValue(currentIndefiniteString.str(), cborType);
       
   146 		currentIndefiniteString = std::stringstream();
       
   147 	}
       
   148 
   139 	void containerEnd() {
   149 	void containerEnd() {
   140 		remainingItems.pop_back();
   150 		remainingItems.pop_back();
   141 		if (mode.back() == Mode::MAP_KEY || mode.back() == Mode::MAP_VALUE) current = parentOrSelf(current);
   151 		if (mode.back() == Mode::MAP_KEY || mode.back() == Mode::MAP_VALUE) current = parentOrSelf(current);
   142 		mode.pop_back(); // TODO: assert map/array
   152 		else if (mode.back() == Mode::BYTE_STRING) flushCurrentIndefiniteString("byte-string");
       
   153 		else if (mode.back() == Mode::CHAR_STRING) flushCurrentIndefiniteString("string");
       
   154 		else mode.pop_back(); // TODO: assert map/array
   143 	}
   155 	}
   144 
   156 
   145 public:
   157 public:
   146 
   158 
   147 	XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) {
   159 	XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) {
   173 
   185 
   174 		callbacks.byte_string_start = [](void* context) {
   186 		callbacks.byte_string_start = [](void* context) {
   175 			CBOR_CALLBACK_START
   187 			CBOR_CALLBACK_START
   176 			instance->mode.push_back(Mode::BYTE_STRING);
   188 			instance->mode.push_back(Mode::BYTE_STRING);
   177 			instance->remainingItems.push_back(INDEFINITE);
   189 			instance->remainingItems.push_back(INDEFINITE);
   178 			// TODO: implement
       
   179 			xmlpp::Element* element = instance->current->add_child("byte-string-start");
       
   180 			CBOR_CALLBACK_END
   190 			CBOR_CALLBACK_END
   181 		};
   191 		};
   182 
   192 
   183 		callbacks.float2 = NUMERIC_CALLBACK(float, "float2");
   193 		callbacks.float2 = NUMERIC_CALLBACK(float, "float2");
   184 		callbacks.float4 = NUMERIC_CALLBACK(float, "float4");
   194 		callbacks.float4 = NUMERIC_CALLBACK(float, "float4");
   227 
   237 
   228 		callbacks.string_start = [](void* context) {
   238 		callbacks.string_start = [](void* context) {
   229 			CBOR_CALLBACK_START
   239 			CBOR_CALLBACK_START
   230 			instance->mode.push_back(Mode::CHAR_STRING);
   240 			instance->mode.push_back(Mode::CHAR_STRING);
   231 			instance->remainingItems.push_back(INDEFINITE);
   241 			instance->remainingItems.push_back(INDEFINITE);
   232 			// TODO: implement
       
   233 			xmlpp::Element* element = instance->current->add_child("string-start");
       
   234 			CBOR_CALLBACK_END
   242 			CBOR_CALLBACK_END
   235 		};
   243 		};
   236 
   244 
   237 		callbacks.tag = [](void* context, uint64_t value) {
   245 		callbacks.tag = [](void* context, uint64_t value) {
   238 			CBOR_CALLBACK_START
   246 			CBOR_CALLBACK_START