1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the implementation of classes and its members related
25 * to OCRepresentation.
29 #include <OCRepresentation.h>
31 #include <boost/lexical_cast.hpp>
33 #include "ocpayload.h"
35 #include "oic_malloc.h"
36 #include "oic_string.h"
40 static const char COAP[] = "coap://";
41 static const char COAPS[] = "coaps://";
42 static const char COAP_TCP[] = "coap+tcp://";
44 void MessageContainer::setPayload(const OCPayload* rep)
53 case PAYLOAD_TYPE_REPRESENTATION:
54 setPayload(reinterpret_cast<const OCRepPayload*>(rep));
56 case PAYLOAD_TYPE_DEVICE:
57 setPayload(reinterpret_cast<const OCDevicePayload*>(rep));
59 case PAYLOAD_TYPE_PLATFORM:
60 setPayload(reinterpret_cast<const OCPlatformPayload*>(rep));
63 throw OC::OCException("Invalid Payload type in setPayload");
68 void MessageContainer::setPayload(const OCDevicePayload* payload)
70 if (payload == nullptr)
76 rep[OC_RSRVD_DEVICE_ID] = (payload->sid) ?
77 std::string(payload->sid) :
79 rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
80 std::string(payload->deviceName) :
82 rep[OC_RSRVD_SPEC_VERSION] = payload->specVersion ?
83 std::string(payload->specVersion) :
85 for (OCStringLL *strll = payload->dataModelVersions; strll; strll = strll->next)
87 rep.addDataModelVersion(strll->value);
89 for (OCStringLL *strll = payload->types; strll; strll = strll->next)
91 rep.addResourceType(strll->value);
93 m_reps.push_back(std::move(rep));
96 void MessageContainer::setPayload(const OCPlatformPayload* payload)
98 if (payload == nullptr)
103 OCRepresentation rep;
104 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
105 std::string(payload->info.platformID) :
107 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
108 std::string(payload->info.manufacturerName) :
110 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
111 std::string(payload->info.manufacturerUrl) :
113 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
114 std::string(payload->info.modelNumber) :
116 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
117 std::string(payload->info.dateOfManufacture) :
119 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
120 std::string(payload->info.platformVersion) :
122 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
123 std::string(payload->info.operatingSystemVersion) :
125 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
126 std::string(payload->info.hardwareVersion) :
128 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
129 std::string(payload->info.firmwareVersion) :
131 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
132 std::string(payload->info.supportUrl) :
134 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
135 std::string(payload->info.systemTime) :
138 for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
140 rep.addResourceType(strll->value);
142 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
144 rep.addResourceInterface(strll->value);
147 m_reps.push_back(std::move(rep));
150 void MessageContainer::setPayload(const OCRepPayload* payload)
152 const OCRepPayload* pl = payload;
155 OCRepresentation cur;
159 this->addRepresentation(cur);
163 OCRepPayload* MessageContainer::getPayload() const
165 OCRepPayload* root = nullptr;
166 for(const auto& r : representations())
170 root = r.getPayload();
174 OCRepPayloadAppend(root, r.getPayload());
181 const std::vector<OCRepresentation>& MessageContainer::representations() const
186 void MessageContainer::addRepresentation(const OCRepresentation& rep)
188 m_reps.push_back(rep);
194 struct get_payload_array: boost::static_visitor<>
197 void operator()(T& /*arr*/)
199 throw std::logic_error("Invalid calc_dimensions_visitor type");
203 void operator()(std::vector<T>& arr)
206 dimensions[0] = arr.size();
209 dimTotal = calcDimTotal(dimensions);
211 array = (void*)OICMalloc(dimTotal * root_size);
213 for(size_t i = 0; i < dimensions[0]; ++i)
215 copy_to_array(arr[i], array, i);
220 void operator()(std::vector<std::vector<T>>& arr)
223 dimensions[0] = arr.size();
226 for(size_t i = 0; i < arr.size(); ++i)
228 dimensions[1] = std::max(dimensions[1], arr[i].size());
230 dimTotal = calcDimTotal(dimensions);
231 array = (void*)OICCalloc(1, dimTotal * root_size);
233 for(size_t i = 0; i < dimensions[0]; ++i)
235 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
237 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
242 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
245 dimensions[0] = arr.size();
248 for(size_t i = 0; i < arr.size(); ++i)
250 dimensions[1] = std::max(dimensions[1], arr[i].size());
252 for(size_t j = 0; j < arr[i].size(); ++j)
254 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
258 dimTotal = calcDimTotal(dimensions);
259 array = (void*)OICCalloc(1, dimTotal * root_size);
261 for(size_t i = 0; i < dimensions[0]; ++i)
263 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
265 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
267 copy_to_array(arr[i][j][k], array,
269 dimensions[2] * dimensions[1] * i +
277 void root_size_calc()
279 root_size = sizeof(T);
283 void copy_to_array(T item, void* array, size_t pos)
285 ((T*)array)[pos] = item;
288 size_t dimensions[MAX_REP_ARRAY_DEPTH];
295 void get_payload_array::root_size_calc<int>()
297 root_size = sizeof(int64_t);
301 void get_payload_array::root_size_calc<std::string>()
303 root_size = sizeof(char*);
307 void get_payload_array::root_size_calc<OC::OCRepresentation>()
309 root_size = sizeof(OCRepPayload*);
313 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
315 ((int64_t*)array)[pos] = item;
319 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
321 ((bool*)array)[pos] = static_cast<bool>(br);
325 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
327 ((char**)array)[pos] = OICStrdup(item.c_str());
331 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
333 ((char**)array)[pos] = OICStrdup(item.c_str());
337 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
339 ((char**)array)[pos] = OICStrdup(item.c_str());
343 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
345 ((OCRepPayload**)array)[pos] = item.getPayload();
348 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
349 const OCRepresentation::AttributeItem& item) const
351 get_payload_array vis{};
352 boost::apply_visitor(vis, m_values[item.attrname()]);
355 switch(item.base_type())
357 case AttributeType::Integer:
358 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
362 case AttributeType::Double:
363 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
367 case AttributeType::Boolean:
368 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
372 case AttributeType::String:
373 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
377 case AttributeType::OCRepresentation:
378 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
379 (OCRepPayload**)vis.array, vis.dimensions);
382 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
383 std::to_string((int)item.base_type()));
387 OCRepPayload* OCRepresentation::getPayload() const
389 OCRepPayload* root = OCRepPayloadCreate();
392 throw std::bad_alloc();
395 OCRepPayloadSetUri(root, getUri().c_str());
397 for(const std::string& type : getResourceTypes())
399 OCRepPayloadAddResourceType(root, type.c_str());
402 for(const std::string& iface : getResourceInterfaces())
404 OCRepPayloadAddInterface(root, iface.c_str());
407 for(auto& val : *this)
411 case AttributeType::Null:
412 OCRepPayloadSetNull(root, val.attrname().c_str());
414 case AttributeType::Integer:
415 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
417 case AttributeType::Double:
418 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
419 val.getValue<double>());
421 case AttributeType::Boolean:
422 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
424 case AttributeType::String:
425 OCRepPayloadSetPropString(root, val.attrname().c_str(),
426 static_cast<std::string>(val).c_str());
428 case AttributeType::OCRepresentation:
429 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
430 static_cast<OCRepresentation>(val).getPayload());
432 case AttributeType::Vector:
433 getPayloadArray(root, val);
436 throw std::logic_error(std::string("Getpayload: Not Implemented") +
437 std::to_string((int)val.type()));
445 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
447 if (dimensions[0] == 0)
449 throw std::logic_error("invalid calcArrayDepth");
451 else if (dimensions[1] == 0)
455 else if (dimensions[2] == 0)
466 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
468 throw std::logic_error("payload_array_helper_copy: unsupported type");
471 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
473 return pl->arr.iArray[index];
476 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
478 return pl->arr.dArray[index];
481 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
483 return pl->arr.bArray[index];
486 std::string OCRepresentation::payload_array_helper_copy<std::string>(
487 size_t index, const OCRepPayloadValue* pl)
489 if (pl->arr.strArray[index])
491 return std::string(pl->arr.strArray[index]);
495 return std::string{};
499 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
500 size_t index, const OCRepPayloadValue* pl)
503 if (pl->arr.objArray[index])
505 r.setPayload(pl->arr.objArray[index]);
511 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
515 std::vector<T> val(pl->arr.dimensions[0]);
517 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
519 val[i] = payload_array_helper_copy<T>(i, pl);
521 this->setValue(std::string(pl->name), val);
525 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
526 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
528 val[i].resize(pl->arr.dimensions[1]);
529 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
531 val[i][j] = payload_array_helper_copy<T>(
532 i * pl->arr.dimensions[1] + j, pl);
535 this->setValue(std::string(pl->name), val);
539 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
540 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
542 val[i].resize(pl->arr.dimensions[1]);
543 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
545 val[i][j].resize(pl->arr.dimensions[2]);
546 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
548 val[i][j][k] = payload_array_helper_copy<T>(
549 pl->arr.dimensions[2] * j +
550 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
556 this->setValue(std::string(pl->name), val);
560 throw std::logic_error("Invalid depth in payload_array_helper");
564 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
570 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
572 case OCREP_PROP_DOUBLE:
573 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
575 case OCREP_PROP_BOOL:
576 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
578 case OCREP_PROP_STRING:
579 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
581 case OCREP_PROP_OBJECT:
582 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
585 throw std::logic_error("setPayload array invalid type");
590 void OCRepresentation::setPayload(const OCRepPayload* pl)
594 OCStringLL* ll = pl->types;
597 addResourceType(ll->value);
604 addResourceInterface(ll->value);
608 OCRepPayloadValue* val = pl->values;
614 case OCREP_PROP_NULL:
618 setValue<int>(val->name, val->i);
620 case OCREP_PROP_DOUBLE:
621 setValue<double>(val->name, val->d);
623 case OCREP_PROP_BOOL:
624 setValue<bool>(val->name, val->b);
626 case OCREP_PROP_STRING:
627 setValue<std::string>(val->name, val->str);
629 case OCREP_PROP_OBJECT:
631 OCRepresentation cur;
632 cur.setPayload(val->obj);
633 setValue<OCRepresentation>(val->name, cur);
636 case OCREP_PROP_ARRAY:
637 setPayloadArray(val);
640 throw std::logic_error(std::string("Not Implemented!") +
641 std::to_string((int)val->type));
648 void OCRepresentation::addChild(const OCRepresentation& rep)
650 m_children.push_back(rep);
653 void OCRepresentation::clearChildren()
658 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
663 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
665 m_children = children;
668 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
670 std::ostringstream ss;
671 if (m_devAddr.flags & OC_SECURE)
675 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
683 if (m_devAddr.flags & OC_IP_USE_V6)
685 ss << '[' << m_devAddr.addr << ']';
689 ss << m_devAddr.addr;
693 ss << ':' << m_devAddr.port;
698 const std::string OCRepresentation::getHost() const
703 void OCRepresentation::setUri(const char* uri)
705 m_uri = uri ? uri : "";
708 void OCRepresentation::setUri(const std::string& uri)
713 std::string OCRepresentation::getUri() const
718 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
720 return m_resourceTypes;
723 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
725 m_resourceTypes = resourceTypes;
728 void OCRepresentation::addResourceType(const std::string& str)
730 m_resourceTypes.push_back(str);
733 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
738 void OCRepresentation::addResourceInterface(const std::string& str)
740 m_interfaces.push_back(str);
743 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
745 m_interfaces = resourceInterfaces;
748 const std::vector<std::string>& OCRepresentation::getDataModelVersions() const
750 return m_dataModelVersions;
753 void OCRepresentation::addDataModelVersion(const std::string& str)
755 m_dataModelVersions.push_back(str);
758 bool OCRepresentation::hasAttribute(const std::string& str) const
760 return m_values.find(str) != m_values.end();
763 bool OCRepresentation::emptyData() const
765 // This logic is meant to determine whether based on the JSON serialization rules
766 // if this object will result in empty JSON. URI is only serialized if there is valid
767 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
768 // child of a default or link item.
769 // Our values array is only printed in the if we are the child of a Batch resource,
770 // the parent in a 'default' situation, or not in a child/parent relationship.
775 else if ((m_interfaceType == InterfaceType::None
776 || m_interfaceType==InterfaceType::DefaultChild
777 || m_interfaceType==InterfaceType::LinkChild)
778 && (m_resourceTypes.size()>0 || m_interfaces.size()>0
779 || m_dataModelVersions.size()>0))
783 else if ((m_interfaceType == InterfaceType::None
784 || m_interfaceType == InterfaceType::BatchChild
785 || m_interfaceType == InterfaceType::DefaultParent)
786 && m_values.size()>0)
791 if (m_children.size() > 0)
799 int OCRepresentation::numberOfAttributes() const
801 return m_values.size();
804 bool OCRepresentation::erase(const std::string& str)
806 return m_values.erase(str);
809 void OCRepresentation::setNULL(const std::string& str)
811 m_values[str] = OC::NullType();
814 bool OCRepresentation::isNULL(const std::string& str) const
816 auto x = m_values.find(str);
818 if (m_values.end() != x)
820 return x->second.which() == AttributeValueNullIndex;
824 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
831 std::ostream& operator <<(std::ostream& os, const AttributeType at)
835 case AttributeType::Null:
838 case AttributeType::Integer:
841 case AttributeType::Double:
844 case AttributeType::Boolean:
847 case AttributeType::String:
850 case AttributeType::OCRepresentation:
851 os << "OCRepresentation";
853 case AttributeType::Vector:
861 // STL Container For OCRepresentation
864 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
865 std::map<std::string, AttributeValue>& vals):
866 m_attrName(name), m_values(vals){}
868 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
870 OCRepresentation::AttributeItem attr{key, m_values};
871 return std::move(attr);
874 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
876 OCRepresentation::AttributeItem attr{key, m_values};
877 return std::move(attr);
880 const std::string& OCRepresentation::AttributeItem::attrname() const
885 template<typename T, typename = void>
888 // contains the actual type
890 // contains the inner most vector-type
892 // contains the AttributeType for this item
893 constexpr static AttributeType enum_type =
894 AttributeTypeConvert<T>::type;
895 // contains the AttributeType for this base-type
896 constexpr static AttributeType enum_base_type =
897 AttributeTypeConvert<T>::type;
898 // depth of the vector
899 constexpr static size_t depth = 0;
903 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
906 typedef typename type_info<typename T::value_type>::base_type base_type;
907 constexpr static AttributeType enum_type = AttributeType::Vector;
908 constexpr static AttributeType enum_base_type =
909 type_info<typename T::value_type>::enum_base_type;
910 constexpr static size_t depth = 1 +
911 type_info<typename T::value_type>::depth;
914 struct type_introspection_visitor : boost::static_visitor<>
917 AttributeType base_type;
920 type_introspection_visitor() : boost::static_visitor<>(),
921 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
923 template <typename T>
924 void operator()(T const& /*item*/)
926 type = type_info<T>::enum_type;
927 base_type = type_info<T>::enum_base_type;
928 depth = type_info<T>::depth;
932 AttributeType OCRepresentation::AttributeItem::type() const
934 type_introspection_visitor vis;
935 boost::apply_visitor(vis, m_values[m_attrName]);
939 AttributeType OCRepresentation::AttributeItem::base_type() const
941 type_introspection_visitor vis;
942 boost::apply_visitor(vis, m_values[m_attrName]);
943 return vis.base_type;
946 size_t OCRepresentation::AttributeItem::depth() const
948 type_introspection_visitor vis;
949 boost::apply_visitor(vis, m_values[m_attrName]);
953 OCRepresentation::iterator OCRepresentation::begin()
955 return OCRepresentation::iterator(m_values.begin(), m_values);
958 OCRepresentation::const_iterator OCRepresentation::begin() const
960 return OCRepresentation::const_iterator(m_values.begin(), m_values);
963 OCRepresentation::const_iterator OCRepresentation::cbegin() const
965 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
968 OCRepresentation::iterator OCRepresentation::end()
970 return OCRepresentation::iterator(m_values.end(), m_values);
973 OCRepresentation::const_iterator OCRepresentation::end() const
975 return OCRepresentation::const_iterator(m_values.end(), m_values);
978 OCRepresentation::const_iterator OCRepresentation::cend() const
980 return OCRepresentation::const_iterator(m_values.cend(), m_values);
983 size_t OCRepresentation::size() const
985 return m_values.size();
988 bool OCRepresentation::empty() const
990 return m_values.empty();
993 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
995 return m_iterator == rhs.m_iterator;
998 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
1000 return m_iterator != rhs.m_iterator;
1003 bool OCRepresentation::const_iterator::operator==(
1004 const OCRepresentation::const_iterator& rhs) const
1006 return m_iterator == rhs.m_iterator;
1009 bool OCRepresentation::const_iterator::operator!=(
1010 const OCRepresentation::const_iterator& rhs) const
1012 return m_iterator != rhs.m_iterator;
1015 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
1020 OCRepresentation::const_iterator::const_reference
1021 OCRepresentation::const_iterator::operator*() const
1026 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1031 OCRepresentation::const_iterator::const_pointer
1032 OCRepresentation::const_iterator::operator->() const
1037 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1040 if (m_iterator != m_item.m_values.end())
1042 m_item.m_attrName = m_iterator->first;
1046 m_item.m_attrName = "";
1051 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1054 if (m_iterator != m_item.m_values.end())
1056 m_item.m_attrName = m_iterator->first;
1060 m_item.m_attrName = "";
1065 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1067 OCRepresentation::iterator itr(*this);
1072 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1074 OCRepresentation::const_iterator itr(*this);
1079 struct to_string_visitor : boost::static_visitor<>
1082 template <typename T>
1083 void operator()(T const& item)
1085 str = boost::lexical_cast<std::string>(item);
1088 template <typename T>
1089 void operator()(std::vector<T> const& item)
1091 to_string_visitor vis;
1092 std::ostringstream stream;
1095 for(const auto& i : item)
1098 stream << vis.str << " ";
1106 void to_string_visitor::operator()(bool const& item)
1108 str = item ? "true" : "false";
1112 void to_string_visitor::operator()(std::string const& item)
1118 void to_string_visitor::operator()(NullType const& /*item*/)
1124 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1126 str = "OC::OCRepresentation";
1129 std::string OCRepresentation::getValueToString(const std::string& key) const
1131 auto x = m_values.find(key);
1132 if (x != m_values.end())
1134 to_string_visitor vis;
1135 boost::apply_visitor(vis, x->second);
1136 return std::move(vis.str);
1142 std::string OCRepresentation::AttributeItem::getValueToString() const
1144 to_string_visitor vis;
1145 boost::apply_visitor(vis, m_values[m_attrName]);
1146 return std::move(vis.str);
1149 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1151 os << ai.getValueToString();