20 #ifndef DATA_H_09E4D8E5
21 #define DATA_H_09E4D8E5
27 #include "uscxml/config.h"
42 static int _dataIndentation = 1;
51 Data() : node(NULL), type(INTERPRETED) {}
53 Data(
const char* data,
size_t size,
const std::string& mimeType,
bool adopt =
false);
56 Data(
bool atom) : node(NULL), type(VERBATIM) {
68 Data(T value,
typename std::enable_if<! std::is_base_of<Data, T>::value>::type* =
nullptr)
69 : node(NULL), atom(toStr(value)), type(VERBATIM) {}
71 Data(T value, Type type,
typename std::enable_if<! std::is_base_of<Data, T>::value>::type* =
nullptr)
72 : node(NULL), atom(toStr(value)), type(type) {}
77 bool hasContent = (atom.length() > 0 || !compound.empty() || !array.empty() || binary || node);
81 bool operator<(
const Data& other)
const {
82 if (other.atom != atom)
83 return other.atom < atom;
84 if (other.array != array)
85 return other.array < array;
86 if (other.compound != compound)
87 return other.compound < compound;
88 if (other.node != node)
89 return other.node < node;
90 if (other.binary != binary)
91 return other.binary < binary;
92 if (other.type != type)
93 return other.type < type;
98 void merge(
const Data& other);
100 bool hasKey(
const std::string& key)
const {
101 return (!compound.empty() && compound.find(key) != compound.end());
104 Data& operator[](
const std::string& key) {
105 return operator[](key.c_str());
108 const Data& operator[](
const std::string& key)
const {
109 return operator[](key.c_str());
112 Data& operator[](
const char* key) {
113 return compound[key];
116 const Data& operator[](
const char* key)
const {
117 return compound.at(key);
120 Data& operator[](
const size_t index) {
121 while(array.size() < index) {
122 array.push_back(
Data(
"", Data::VERBATIM));
124 std::list<Data>::iterator arrayIter = array.begin();
125 for (
size_t i = 0; i < index; i++, arrayIter++) {}
129 const Data at(
const std::string& key)
const {
130 return at(key.c_str());
133 const Data at(
const char* key)
const {
135 return compound.at(key);
140 const Data item(
const size_t index)
const {
141 if (array.size() > index) {
142 std::list<Data>::const_iterator arrayIter = array.begin();
143 for (
size_t i = 0; i < index; i++, arrayIter++) {}
150 void put(std::string key,
const Data& data) {
151 compound[key] = data;
154 void put(
size_t index,
const Data& data) {
158 bool operator==(
const Data &other)
const {
159 return (*
this < other || other < *
this);
162 bool operator!=(
const Data &other)
const {
163 return !(*
this == other);
166 operator std::string()
const {
170 operator std::map<std::string, Data>() {
174 operator std::list<Data>() {
178 static Data fromJSON(
const std::string& jsonString);
179 static std::string toJSON(
const Data& data);
180 std::string asJSON()
const;
183 std::map<std::string, Data> getCompound() {
186 void setCompound(
const std::map<std::string, Data>& compound) {
187 this->compound = compound;
190 std::list<Data> getArray() {
193 void setArray(
const std::list<Data>& array) {
197 std::string getAtom()
const {
200 void setAtom(
const std::string& atom) {
207 void setBinary(
const Blob& binary) {
208 this->binary = binary;
214 void setType(
const Type type) {
222 XERCESC_NS::DOMNode* node;
223 std::shared_ptr<XERCESC_NS::DOMDocument*> adoptedDoc;
224 std::map<std::string, Data> compound;
225 std::list<Data> array;
231 friend USCXML_API std::ostream& operator<< (std::ostream& os,
const Data& data);
234 USCXML_API std::ostream& operator<< (std::ostream& os,
const Data& data);
Definition: InterpreterIssue.cpp:33
Definition: InterpreterIssue.h:31