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 rep[OC_RSRVD_DATA_MODEL_VERSION] = payload->dataModelVersion ?
86 std::string(payload->dataModelVersion) :
88 for (OCStringLL *strll = payload->types; strll; strll = strll->next)
90 rep.addResourceType(strll->value);
92 m_reps.push_back(std::move(rep));
95 void MessageContainer::setPayload(const OCPlatformPayload* payload)
97 if (payload == nullptr)
102 OCRepresentation rep;
103 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
104 std::string(payload->info.platformID) :
106 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
107 std::string(payload->info.manufacturerName) :
109 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
110 std::string(payload->info.manufacturerUrl) :
112 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
113 std::string(payload->info.modelNumber) :
115 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
116 std::string(payload->info.dateOfManufacture) :
118 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
119 std::string(payload->info.platformVersion) :
121 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
122 std::string(payload->info.operatingSystemVersion) :
124 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
125 std::string(payload->info.hardwareVersion) :
127 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
128 std::string(payload->info.firmwareVersion) :
130 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
131 std::string(payload->info.supportUrl) :
133 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
134 std::string(payload->info.systemTime) :
139 rep.addResourceType(payload->rt);
141 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
143 rep.addResourceInterface(strll->value);
146 m_reps.push_back(std::move(rep));
149 void MessageContainer::setPayload(const OCRepPayload* payload)
151 const OCRepPayload* pl = payload;
154 OCRepresentation cur;
158 this->addRepresentation(cur);
162 OCRepPayload* MessageContainer::getPayload() const
164 OCRepPayload* root = nullptr;
165 for(const auto& r : representations())
169 root = r.getPayload();
173 OCRepPayloadAppend(root, r.getPayload());
180 const std::vector<OCRepresentation>& MessageContainer::representations() const
185 void MessageContainer::addRepresentation(const OCRepresentation& rep)
187 m_reps.push_back(rep);
193 struct get_payload_array: boost::static_visitor<>
196 void operator()(T& /*arr*/)
198 throw std::logic_error("Invalid calc_dimensions_visitor type");
202 void operator()(std::vector<T>& arr)
205 dimensions[0] = arr.size();
208 dimTotal = calcDimTotal(dimensions);
210 array = (void*)OICMalloc(dimTotal * root_size);
212 for(size_t i = 0; i < dimensions[0]; ++i)
214 copy_to_array(arr[i], array, i);
219 void operator()(std::vector<std::vector<T>>& arr)
222 dimensions[0] = arr.size();
225 for(size_t i = 0; i < arr.size(); ++i)
227 dimensions[1] = std::max(dimensions[1], arr[i].size());
229 dimTotal = calcDimTotal(dimensions);
230 array = (void*)OICCalloc(1, dimTotal * root_size);
232 for(size_t i = 0; i < dimensions[0]; ++i)
234 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
236 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
241 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
244 dimensions[0] = arr.size();
247 for(size_t i = 0; i < arr.size(); ++i)
249 dimensions[1] = std::max(dimensions[1], arr[i].size());
251 for(size_t j = 0; j < arr[i].size(); ++j)
253 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
257 dimTotal = calcDimTotal(dimensions);
258 array = (void*)OICCalloc(1, dimTotal * root_size);
260 for(size_t i = 0; i < dimensions[0]; ++i)
262 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
264 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
266 copy_to_array(arr[i][j][k], array,
268 dimensions[2] * dimensions[1] * i +
276 void root_size_calc()
278 root_size = sizeof(T);
282 void copy_to_array(T item, void* array, size_t pos)
284 ((T*)array)[pos] = item;
287 size_t dimensions[MAX_REP_ARRAY_DEPTH];
294 void get_payload_array::root_size_calc<int>()
296 root_size = sizeof(int64_t);
300 void get_payload_array::root_size_calc<std::string>()
302 root_size = sizeof(char*);
306 void get_payload_array::root_size_calc<OC::OCRepresentation>()
308 root_size = sizeof(OCRepPayload*);
312 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
314 ((int64_t*)array)[pos] = item;
318 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
320 ((bool*)array)[pos] = static_cast<bool>(br);
324 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
326 ((char**)array)[pos] = OICStrdup(item.c_str());
330 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
332 ((char**)array)[pos] = OICStrdup(item.c_str());
336 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
338 ((char**)array)[pos] = OICStrdup(item.c_str());
342 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
344 ((OCRepPayload**)array)[pos] = item.getPayload();
347 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
348 const OCRepresentation::AttributeItem& item) const
350 get_payload_array vis{};
351 boost::apply_visitor(vis, m_values[item.attrname()]);
354 switch(item.base_type())
356 case AttributeType::Integer:
357 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
361 case AttributeType::Double:
362 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
366 case AttributeType::Boolean:
367 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
371 case AttributeType::String:
372 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
376 case AttributeType::OCRepresentation:
377 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
378 (OCRepPayload**)vis.array, vis.dimensions);
381 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
382 std::to_string((int)item.base_type()));
386 OCRepPayload* OCRepresentation::getPayload() const
388 OCRepPayload* root = OCRepPayloadCreate();
391 throw std::bad_alloc();
394 OCRepPayloadSetUri(root, getUri().c_str());
396 for(const std::string& type : getResourceTypes())
398 OCRepPayloadAddResourceType(root, type.c_str());
401 for(const std::string& iface : getResourceInterfaces())
403 OCRepPayloadAddInterface(root, iface.c_str());
406 for(auto& val : *this)
410 case AttributeType::Null:
411 OCRepPayloadSetNull(root, val.attrname().c_str());
413 case AttributeType::Integer:
414 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
416 case AttributeType::Double:
417 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
418 val.getValue<double>());
420 case AttributeType::Boolean:
421 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
423 case AttributeType::String:
424 OCRepPayloadSetPropString(root, val.attrname().c_str(),
425 static_cast<std::string>(val).c_str());
427 case AttributeType::OCRepresentation:
428 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
429 static_cast<OCRepresentation>(val).getPayload());
431 case AttributeType::Vector:
432 getPayloadArray(root, val);
435 throw std::logic_error(std::string("Getpayload: Not Implemented") +
436 std::to_string((int)val.type()));
444 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
446 if (dimensions[0] == 0)
448 throw std::logic_error("invalid calcArrayDepth");
450 else if (dimensions[1] == 0)
454 else if (dimensions[2] == 0)
465 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
467 throw std::logic_error("payload_array_helper_copy: unsupported type");
470 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
472 return pl->arr.iArray[index];
475 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
477 return pl->arr.dArray[index];
480 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
482 return pl->arr.bArray[index];
485 std::string OCRepresentation::payload_array_helper_copy<std::string>(
486 size_t index, const OCRepPayloadValue* pl)
488 if (pl->arr.strArray[index])
490 return std::string(pl->arr.strArray[index]);
494 return std::string{};
498 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
499 size_t index, const OCRepPayloadValue* pl)
502 if (pl->arr.objArray[index])
504 r.setPayload(pl->arr.objArray[index]);
510 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
514 std::vector<T> val(pl->arr.dimensions[0]);
516 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
518 val[i] = payload_array_helper_copy<T>(i, pl);
520 this->setValue(std::string(pl->name), val);
524 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
525 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
527 val[i].resize(pl->arr.dimensions[1]);
528 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
530 val[i][j] = payload_array_helper_copy<T>(
531 i * pl->arr.dimensions[1] + j, pl);
534 this->setValue(std::string(pl->name), val);
538 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
539 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
541 val[i].resize(pl->arr.dimensions[1]);
542 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
544 val[i][j].resize(pl->arr.dimensions[2]);
545 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
547 val[i][j][k] = payload_array_helper_copy<T>(
548 pl->arr.dimensions[2] * j +
549 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
555 this->setValue(std::string(pl->name), val);
559 throw std::logic_error("Invalid depth in payload_array_helper");
563 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
569 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
571 case OCREP_PROP_DOUBLE:
572 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
574 case OCREP_PROP_BOOL:
575 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
577 case OCREP_PROP_STRING:
578 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
580 case OCREP_PROP_OBJECT:
581 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
584 throw std::logic_error("setPayload array invalid type");
589 void OCRepresentation::setPayload(const OCRepPayload* pl)
593 OCStringLL* ll = pl->types;
596 addResourceType(ll->value);
603 addResourceInterface(ll->value);
607 OCRepPayloadValue* val = pl->values;
613 case OCREP_PROP_NULL:
617 setValue<int>(val->name, val->i);
619 case OCREP_PROP_DOUBLE:
620 setValue<double>(val->name, val->d);
622 case OCREP_PROP_BOOL:
623 setValue<bool>(val->name, val->b);
625 case OCREP_PROP_STRING:
626 setValue<std::string>(val->name, val->str);
628 case OCREP_PROP_OBJECT:
630 OCRepresentation cur;
631 cur.setPayload(val->obj);
632 setValue<OCRepresentation>(val->name, cur);
635 case OCREP_PROP_ARRAY:
636 setPayloadArray(val);
639 throw std::logic_error(std::string("Not Implemented!") +
640 std::to_string((int)val->type));
647 void OCRepresentation::addChild(const OCRepresentation& rep)
649 m_children.push_back(rep);
652 void OCRepresentation::clearChildren()
657 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
662 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
664 m_children = children;
667 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
669 std::ostringstream ss;
670 if (m_devAddr.flags & OC_SECURE)
674 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
682 if (m_devAddr.flags & OC_IP_USE_V6)
684 ss << '[' << m_devAddr.addr << ']';
688 ss << m_devAddr.addr;
692 ss << ':' << m_devAddr.port;
697 const std::string OCRepresentation::getHost() const
702 void OCRepresentation::setUri(const char* uri)
704 m_uri = uri ? uri : "";
707 void OCRepresentation::setUri(const std::string& uri)
712 std::string OCRepresentation::getUri() const
717 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
719 return m_resourceTypes;
722 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
724 m_resourceTypes = resourceTypes;
727 void OCRepresentation::addResourceType(const std::string& str)
729 m_resourceTypes.push_back(str);
732 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
737 void OCRepresentation::addResourceInterface(const std::string& str)
739 m_interfaces.push_back(str);
742 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
744 m_interfaces = resourceInterfaces;
747 bool OCRepresentation::hasAttribute(const std::string& str) const
749 return m_values.find(str) != m_values.end();
752 bool OCRepresentation::emptyData() const
754 // This logic is meant to determine whether based on the JSON serialization rules
755 // if this object will result in empty JSON. URI is only serialized if there is valid
756 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
757 // child of a default or link item.
758 // Our values array is only printed in the if we are the child of a Batch resource,
759 // the parent in a 'default' situation, or not in a child/parent relationship.
764 else if ((m_interfaceType == InterfaceType::None
765 || m_interfaceType==InterfaceType::DefaultChild
766 || m_interfaceType==InterfaceType::LinkChild)
767 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
771 else if ((m_interfaceType == InterfaceType::None
772 || m_interfaceType == InterfaceType::BatchChild
773 || m_interfaceType == InterfaceType::DefaultParent)
774 && m_values.size()>0)
779 if (m_children.size() > 0)
787 int OCRepresentation::numberOfAttributes() const
789 return m_values.size();
792 bool OCRepresentation::erase(const std::string& str)
794 return m_values.erase(str);
797 void OCRepresentation::setNULL(const std::string& str)
799 m_values[str] = OC::NullType();
802 bool OCRepresentation::isNULL(const std::string& str) const
804 auto x = m_values.find(str);
806 if (m_values.end() != x)
808 return x->second.which() == AttributeValueNullIndex;
812 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
819 std::ostream& operator <<(std::ostream& os, const AttributeType at)
823 case AttributeType::Null:
826 case AttributeType::Integer:
829 case AttributeType::Double:
832 case AttributeType::Boolean:
835 case AttributeType::String:
838 case AttributeType::OCRepresentation:
839 os << "OCRepresentation";
841 case AttributeType::Vector:
849 // STL Container For OCRepresentation
852 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
853 std::map<std::string, AttributeValue>& vals):
854 m_attrName(name), m_values(vals){}
856 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
858 OCRepresentation::AttributeItem attr{key, m_values};
859 return std::move(attr);
862 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
864 OCRepresentation::AttributeItem attr{key, m_values};
865 return std::move(attr);
868 const std::string& OCRepresentation::AttributeItem::attrname() const
873 template<typename T, typename = void>
876 // contains the actual type
878 // contains the inner most vector-type
880 // contains the AttributeType for this item
881 constexpr static AttributeType enum_type =
882 AttributeTypeConvert<T>::type;
883 // contains the AttributeType for this base-type
884 constexpr static AttributeType enum_base_type =
885 AttributeTypeConvert<T>::type;
886 // depth of the vector
887 constexpr static size_t depth = 0;
891 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
894 typedef typename type_info<typename T::value_type>::base_type base_type;
895 constexpr static AttributeType enum_type = AttributeType::Vector;
896 constexpr static AttributeType enum_base_type =
897 type_info<typename T::value_type>::enum_base_type;
898 constexpr static size_t depth = 1 +
899 type_info<typename T::value_type>::depth;
902 struct type_introspection_visitor : boost::static_visitor<>
905 AttributeType base_type;
908 type_introspection_visitor() : boost::static_visitor<>(),
909 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
911 template <typename T>
912 void operator()(T const& /*item*/)
914 type = type_info<T>::enum_type;
915 base_type = type_info<T>::enum_base_type;
916 depth = type_info<T>::depth;
920 AttributeType OCRepresentation::AttributeItem::type() const
922 type_introspection_visitor vis;
923 boost::apply_visitor(vis, m_values[m_attrName]);
927 AttributeType OCRepresentation::AttributeItem::base_type() const
929 type_introspection_visitor vis;
930 boost::apply_visitor(vis, m_values[m_attrName]);
931 return vis.base_type;
934 size_t OCRepresentation::AttributeItem::depth() const
936 type_introspection_visitor vis;
937 boost::apply_visitor(vis, m_values[m_attrName]);
941 OCRepresentation::iterator OCRepresentation::begin()
943 return OCRepresentation::iterator(m_values.begin(), m_values);
946 OCRepresentation::const_iterator OCRepresentation::begin() const
948 return OCRepresentation::const_iterator(m_values.begin(), m_values);
951 OCRepresentation::const_iterator OCRepresentation::cbegin() const
953 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
956 OCRepresentation::iterator OCRepresentation::end()
958 return OCRepresentation::iterator(m_values.end(), m_values);
961 OCRepresentation::const_iterator OCRepresentation::end() const
963 return OCRepresentation::const_iterator(m_values.end(), m_values);
966 OCRepresentation::const_iterator OCRepresentation::cend() const
968 return OCRepresentation::const_iterator(m_values.cend(), m_values);
971 size_t OCRepresentation::size() const
973 return m_values.size();
976 bool OCRepresentation::empty() const
978 return m_values.empty();
981 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
983 return m_iterator == rhs.m_iterator;
986 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
988 return m_iterator != rhs.m_iterator;
991 bool OCRepresentation::const_iterator::operator==(
992 const OCRepresentation::const_iterator& rhs) const
994 return m_iterator == rhs.m_iterator;
997 bool OCRepresentation::const_iterator::operator!=(
998 const OCRepresentation::const_iterator& rhs) const
1000 return m_iterator != rhs.m_iterator;
1003 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
1008 OCRepresentation::const_iterator::const_reference
1009 OCRepresentation::const_iterator::operator*() const
1014 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1019 OCRepresentation::const_iterator::const_pointer
1020 OCRepresentation::const_iterator::operator->() const
1025 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1028 if (m_iterator != m_item.m_values.end())
1030 m_item.m_attrName = m_iterator->first;
1034 m_item.m_attrName = "";
1039 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1042 if (m_iterator != m_item.m_values.end())
1044 m_item.m_attrName = m_iterator->first;
1048 m_item.m_attrName = "";
1053 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1055 OCRepresentation::iterator itr(*this);
1060 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1062 OCRepresentation::const_iterator itr(*this);
1067 struct to_string_visitor : boost::static_visitor<>
1070 template <typename T>
1071 void operator()(T const& item)
1073 str = boost::lexical_cast<std::string>(item);
1076 template <typename T>
1077 void operator()(std::vector<T> const& item)
1079 to_string_visitor vis;
1080 std::ostringstream stream;
1083 for(const auto& i : item)
1086 stream << vis.str << " ";
1094 void to_string_visitor::operator()(bool const& item)
1096 str = item ? "true" : "false";
1100 void to_string_visitor::operator()(std::string const& item)
1106 void to_string_visitor::operator()(NullType const& /*item*/)
1112 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1114 str = "OC::OCRepresentation";
1117 std::string OCRepresentation::getValueToString(const std::string& key) const
1119 auto x = m_values.find(key);
1120 if (x != m_values.end())
1122 to_string_visitor vis;
1123 boost::apply_visitor(vis, x->second);
1124 return std::move(vis.str);
1130 std::string OCRepresentation::AttributeItem::getValueToString() const
1132 to_string_visitor vis;
1133 boost::apply_visitor(vis, m_values[m_attrName]);
1134 return std::move(vis.str);
1137 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1139 os << ai.getValueToString();