20 #ifndef DATA_H_09E4D8E5
21 #define DATA_H_09E4D8E5
26 #include <type_traits>
42 static unsigned int _dataIndentation = 1;
51 Data() : node(NULL), type(INTERPRETED) {
53 (void)_dataIndentation;
56 explicit Data(
const char* data,
size_t size,
const std::string& mimeType,
bool adopt =
false);
67 explicit Data(XERCESC_NS::DOMNode* node_) : node(node_) {}
69 explicit Data(
const std::string& value) : node(NULL), atom(toStr(value)), type(VERBATIM) {}
76 typename =
typename std::enable_if<std::is_arithmetic<T>::value, T>::type
78 explicit Data(T value)
79 : node(NULL), atom(toStr(value)), type(INTERPRETED) {}
83 explicit Data(T value, Type type) : node(NULL), atom(toStr(value)), type(type) {}
98 bool hasContent = (atom.length() > 0 || !compound.empty() || !array.empty() || binary || node);
102 bool operator<(
const Data& other)
const {
103 if (other.atom != atom)
104 return other.atom < atom;
105 if (other.array != array)
106 return other.array < array;
107 if (other.compound != compound)
108 return other.compound < compound;
109 if (other.node != node)
110 return other.node < node;
111 if (other.binary != binary)
112 return other.binary < binary;
113 if (other.type != type)
114 return other.type < type;
119 void merge(
const Data& other);
121 bool hasKey(
const std::string& key)
const {
122 return (!compound.empty() && compound.find(key) != compound.end());
127 Data& operator[](
const std::string& key) {
128 return compound[key];
131 Data& operator[](
const char* key) {
132 return compound[key];
135 const Data& operator[](
const std::string& key)
const {
136 return compound.at(key);
139 const Data& operator[](
const char* key)
const {
140 return compound.at(key);
143 Data& operator[](
const size_t index) {
144 while(array.size() < index) {
145 array.push_back(Data(
"", Data::VERBATIM));
147 std::list<Data>::iterator arrayIter = array.begin();
148 for (
size_t i = 0; i < index; i++, arrayIter++) {}
153 const Data at(
const std::string& key)
const {
154 return at(key.c_str());
157 const Data at(
const char* key)
const {
159 return compound.at(key);
164 const Data item(
const size_t index)
const {
165 if (array.size() > index) {
166 std::list<Data>::const_iterator arrayIter = array.begin();
167 for (
size_t i = 0; i < index; i++, arrayIter++) {}
174 void put(std::string key,
const Data& data) {
175 compound[key] = data;
178 void put(
size_t index,
const Data& data) {
182 bool operator==(
const Data &other)
const {
183 return !(*
this != other);
186 bool operator!=(
const Data &other)
const {
187 return (*
this < other || other < *
this);
190 operator std::string()
const {
194 operator std::map<std::string, Data>() {
198 operator std::list<Data>() {
202 static Data fromJSON(
const std::string& jsonString);
203 static std::string toJSON(
const Data& data);
204 std::string asJSON()
const;
206 std::list<Data> getArray() {
209 void setArray(
const std::list<Data>& array) {
213 std::string getAtom()
const {
216 void setAtom(
const std::string& atom) {
223 void setBinary(
const Blob& binary) {
224 this->binary = binary;
230 void setType(
const Type type) {
235 std::map<std::string, uscxml::Data> getCompound() {
239 void setCompound(
const std::map<std::string, uscxml::Data>& compound) {
240 this->compound = compound;
247 XERCESC_NS::DOMNode* node;
249 std::map<std::string, Data> compound;
250 std::list<Data> array;
256 static std::string jsonEscape(
const std::string& expr);
257 static std::string jsonUnescape(
const std::string& expr);
258 friend USCXML_API std::ostream& operator<< (std::ostream& os,
const Data& data);
262 USCXML_API std::ostream& operator<< (std::ostream& os,
const Data& data);
Definition: Breakpoint.cpp:26
Definition: Breakpoint.h:30