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) :
137 m_reps.push_back(std::move(rep));
140 void MessageContainer::setPayload(const OCRepPayload* payload)
142 const OCRepPayload* pl = payload;
145 OCRepresentation cur;
149 this->addRepresentation(cur);
153 OCRepPayload* MessageContainer::getPayload() const
155 OCRepPayload* root = nullptr;
156 for(const auto& r : representations())
160 root = r.getPayload();
164 OCRepPayloadAppend(root, r.getPayload());
171 const std::vector<OCRepresentation>& MessageContainer::representations() const
176 void MessageContainer::addRepresentation(const OCRepresentation& rep)
178 m_reps.push_back(rep);
184 struct get_payload_array: boost::static_visitor<>
187 void operator()(T& /*arr*/)
189 throw std::logic_error("Invalid calc_dimensions_visitor type");
193 void operator()(std::vector<T>& arr)
196 dimensions[0] = arr.size();
199 dimTotal = calcDimTotal(dimensions);
201 array = (void*)OICMalloc(dimTotal * root_size);
203 for(size_t i = 0; i < dimensions[0]; ++i)
205 copy_to_array(arr[i], array, i);
210 void operator()(std::vector<std::vector<T>>& arr)
213 dimensions[0] = arr.size();
216 for(size_t i = 0; i < arr.size(); ++i)
218 dimensions[1] = std::max(dimensions[1], arr[i].size());
220 dimTotal = calcDimTotal(dimensions);
221 array = (void*)OICCalloc(1, dimTotal * root_size);
223 for(size_t i = 0; i < dimensions[0]; ++i)
225 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
227 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
232 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
235 dimensions[0] = arr.size();
238 for(size_t i = 0; i < arr.size(); ++i)
240 dimensions[1] = std::max(dimensions[1], arr[i].size());
242 for(size_t j = 0; j < arr[i].size(); ++j)
244 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
248 dimTotal = calcDimTotal(dimensions);
249 array = (void*)OICCalloc(1, dimTotal * root_size);
251 for(size_t i = 0; i < dimensions[0]; ++i)
253 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
255 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
257 copy_to_array(arr[i][j][k], array,
259 dimensions[2] * dimensions[1] * i +
267 void root_size_calc()
269 root_size = sizeof(T);
273 void copy_to_array(T item, void* array, size_t pos)
275 ((T*)array)[pos] = item;
278 size_t dimensions[MAX_REP_ARRAY_DEPTH];
285 void get_payload_array::root_size_calc<int>()
287 root_size = sizeof(int64_t);
291 void get_payload_array::root_size_calc<std::string>()
293 root_size = sizeof(char*);
297 void get_payload_array::root_size_calc<OC::OCRepresentation>()
299 root_size = sizeof(OCRepPayload*);
303 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
305 ((int64_t*)array)[pos] = item;
309 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
311 ((bool*)array)[pos] = static_cast<bool>(br);
315 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
317 ((char**)array)[pos] = OICStrdup(item.c_str());
321 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
323 ((char**)array)[pos] = OICStrdup(item.c_str());
327 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
329 ((char**)array)[pos] = OICStrdup(item.c_str());
333 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
335 ((OCRepPayload**)array)[pos] = item.getPayload();
338 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
339 const OCRepresentation::AttributeItem& item) const
341 get_payload_array vis{};
342 boost::apply_visitor(vis, m_values[item.attrname()]);
345 switch(item.base_type())
347 case AttributeType::Integer:
348 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
352 case AttributeType::Double:
353 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
357 case AttributeType::Boolean:
358 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
362 case AttributeType::String:
363 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
367 case AttributeType::OCRepresentation:
368 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
369 (OCRepPayload**)vis.array, vis.dimensions);
372 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
373 std::to_string((int)item.base_type()));
377 OCRepPayload* OCRepresentation::getPayload() const
379 OCRepPayload* root = OCRepPayloadCreate();
382 throw std::bad_alloc();
385 OCRepPayloadSetUri(root, getUri().c_str());
387 for(const std::string& type : getResourceTypes())
389 OCRepPayloadAddResourceType(root, type.c_str());
392 for(const std::string& iface : getResourceInterfaces())
394 OCRepPayloadAddInterface(root, iface.c_str());
397 for(auto& val : *this)
401 case AttributeType::Null:
402 OCRepPayloadSetNull(root, val.attrname().c_str());
404 case AttributeType::Integer:
405 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
407 case AttributeType::Double:
408 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
409 val.getValue<double>());
411 case AttributeType::Boolean:
412 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
414 case AttributeType::String:
415 OCRepPayloadSetPropString(root, val.attrname().c_str(),
416 static_cast<std::string>(val).c_str());
418 case AttributeType::OCRepresentation:
419 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
420 static_cast<OCRepresentation>(val).getPayload());
422 case AttributeType::Vector:
423 getPayloadArray(root, val);
426 throw std::logic_error(std::string("Getpayload: Not Implemented") +
427 std::to_string((int)val.type()));
435 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
437 if (dimensions[0] == 0)
439 throw std::logic_error("invalid calcArrayDepth");
441 else if (dimensions[1] == 0)
445 else if (dimensions[2] == 0)
456 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
458 throw std::logic_error("payload_array_helper_copy: unsupported type");
461 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
463 return pl->arr.iArray[index];
466 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
468 return pl->arr.dArray[index];
471 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
473 return pl->arr.bArray[index];
476 std::string OCRepresentation::payload_array_helper_copy<std::string>(
477 size_t index, const OCRepPayloadValue* pl)
479 if (pl->arr.strArray[index])
481 return std::string(pl->arr.strArray[index]);
485 return std::string{};
489 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
490 size_t index, const OCRepPayloadValue* pl)
493 if (pl->arr.objArray[index])
495 r.setPayload(pl->arr.objArray[index]);
501 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
505 std::vector<T> val(pl->arr.dimensions[0]);
507 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
509 val[i] = payload_array_helper_copy<T>(i, pl);
511 this->setValue(std::string(pl->name), val);
515 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
516 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
518 val[i].resize(pl->arr.dimensions[1]);
519 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
521 val[i][j] = payload_array_helper_copy<T>(
522 i * pl->arr.dimensions[1] + j, pl);
525 this->setValue(std::string(pl->name), val);
529 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
530 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
532 val[i].resize(pl->arr.dimensions[1]);
533 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
535 val[i][j].resize(pl->arr.dimensions[2]);
536 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
538 val[i][j][k] = payload_array_helper_copy<T>(
539 pl->arr.dimensions[2] * j +
540 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
546 this->setValue(std::string(pl->name), val);
550 throw std::logic_error("Invalid depth in payload_array_helper");
554 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
560 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
562 case OCREP_PROP_DOUBLE:
563 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
565 case OCREP_PROP_BOOL:
566 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
568 case OCREP_PROP_STRING:
569 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
571 case OCREP_PROP_OBJECT:
572 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
575 throw std::logic_error("setPayload array invalid type");
580 void OCRepresentation::setPayload(const OCRepPayload* pl)
584 OCStringLL* ll = pl->types;
587 addResourceType(ll->value);
594 addResourceInterface(ll->value);
598 OCRepPayloadValue* val = pl->values;
604 case OCREP_PROP_NULL:
608 setValue<int>(val->name, val->i);
610 case OCREP_PROP_DOUBLE:
611 setValue<double>(val->name, val->d);
613 case OCREP_PROP_BOOL:
614 setValue<bool>(val->name, val->b);
616 case OCREP_PROP_STRING:
617 setValue<std::string>(val->name, val->str);
619 case OCREP_PROP_OBJECT:
621 OCRepresentation cur;
622 cur.setPayload(val->obj);
623 setValue<OCRepresentation>(val->name, cur);
626 case OCREP_PROP_ARRAY:
627 setPayloadArray(val);
630 throw std::logic_error(std::string("Not Implemented!") +
631 std::to_string((int)val->type));
638 void OCRepresentation::addChild(const OCRepresentation& rep)
640 m_children.push_back(rep);
643 void OCRepresentation::clearChildren()
648 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
653 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
655 m_children = children;
658 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
660 std::ostringstream ss;
661 if (m_devAddr.flags & OC_SECURE)
665 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
673 if (m_devAddr.flags & OC_IP_USE_V6)
675 ss << '[' << m_devAddr.addr << ']';
679 ss << m_devAddr.addr;
683 ss << ':' << m_devAddr.port;
688 const std::string OCRepresentation::getHost() const
693 void OCRepresentation::setUri(const char* uri)
695 m_uri = uri ? uri : "";
698 void OCRepresentation::setUri(const std::string& uri)
703 std::string OCRepresentation::getUri() const
708 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
710 return m_resourceTypes;
713 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
715 m_resourceTypes = resourceTypes;
718 void OCRepresentation::addResourceType(const std::string& str)
720 m_resourceTypes.push_back(str);
723 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
728 void OCRepresentation::addResourceInterface(const std::string& str)
730 m_interfaces.push_back(str);
733 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
735 m_interfaces = resourceInterfaces;
738 bool OCRepresentation::hasAttribute(const std::string& str) const
740 return m_values.find(str) != m_values.end();
743 bool OCRepresentation::emptyData() const
745 // This logic is meant to determine whether based on the JSON serialization rules
746 // if this object will result in empty JSON. URI is only serialized if there is valid
747 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
748 // child of a default or link item.
749 // Our values array is only printed in the if we are the child of a Batch resource,
750 // the parent in a 'default' situation, or not in a child/parent relationship.
755 else if ((m_interfaceType == InterfaceType::None
756 || m_interfaceType==InterfaceType::DefaultChild
757 || m_interfaceType==InterfaceType::LinkChild)
758 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
762 else if ((m_interfaceType == InterfaceType::None
763 || m_interfaceType == InterfaceType::BatchChild
764 || m_interfaceType == InterfaceType::DefaultParent)
765 && m_values.size()>0)
770 if (m_children.size() > 0)
778 int OCRepresentation::numberOfAttributes() const
780 return m_values.size();
783 bool OCRepresentation::erase(const std::string& str)
785 return m_values.erase(str);
788 void OCRepresentation::setNULL(const std::string& str)
790 m_values[str] = OC::NullType();
793 bool OCRepresentation::isNULL(const std::string& str) const
795 auto x = m_values.find(str);
797 if (m_values.end() != x)
799 return x->second.which() == AttributeValueNullIndex;
803 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
810 std::ostream& operator <<(std::ostream& os, const AttributeType at)
814 case AttributeType::Null:
817 case AttributeType::Integer:
820 case AttributeType::Double:
823 case AttributeType::Boolean:
826 case AttributeType::String:
829 case AttributeType::OCRepresentation:
830 os << "OCRepresentation";
832 case AttributeType::Vector:
840 // STL Container For OCRepresentation
843 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
844 std::map<std::string, AttributeValue>& vals):
845 m_attrName(name), m_values(vals){}
847 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
849 OCRepresentation::AttributeItem attr{key, m_values};
850 return std::move(attr);
853 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
855 OCRepresentation::AttributeItem attr{key, m_values};
856 return std::move(attr);
859 const std::string& OCRepresentation::AttributeItem::attrname() const
864 template<typename T, typename = void>
867 // contains the actual type
869 // contains the inner most vector-type
871 // contains the AttributeType for this item
872 constexpr static AttributeType enum_type =
873 AttributeTypeConvert<T>::type;
874 // contains the AttributeType for this base-type
875 constexpr static AttributeType enum_base_type =
876 AttributeTypeConvert<T>::type;
877 // depth of the vector
878 constexpr static size_t depth = 0;
882 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
885 typedef typename type_info<typename T::value_type>::base_type base_type;
886 constexpr static AttributeType enum_type = AttributeType::Vector;
887 constexpr static AttributeType enum_base_type =
888 type_info<typename T::value_type>::enum_base_type;
889 constexpr static size_t depth = 1 +
890 type_info<typename T::value_type>::depth;
893 struct type_introspection_visitor : boost::static_visitor<>
896 AttributeType base_type;
899 type_introspection_visitor() : boost::static_visitor<>(),
900 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
902 template <typename T>
903 void operator()(T const& /*item*/)
905 type = type_info<T>::enum_type;
906 base_type = type_info<T>::enum_base_type;
907 depth = type_info<T>::depth;
911 AttributeType OCRepresentation::AttributeItem::type() const
913 type_introspection_visitor vis;
914 boost::apply_visitor(vis, m_values[m_attrName]);
918 AttributeType OCRepresentation::AttributeItem::base_type() const
920 type_introspection_visitor vis;
921 boost::apply_visitor(vis, m_values[m_attrName]);
922 return vis.base_type;
925 size_t OCRepresentation::AttributeItem::depth() const
927 type_introspection_visitor vis;
928 boost::apply_visitor(vis, m_values[m_attrName]);
932 OCRepresentation::iterator OCRepresentation::begin()
934 return OCRepresentation::iterator(m_values.begin(), m_values);
937 OCRepresentation::const_iterator OCRepresentation::begin() const
939 return OCRepresentation::const_iterator(m_values.begin(), m_values);
942 OCRepresentation::const_iterator OCRepresentation::cbegin() const
944 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
947 OCRepresentation::iterator OCRepresentation::end()
949 return OCRepresentation::iterator(m_values.end(), m_values);
952 OCRepresentation::const_iterator OCRepresentation::end() const
954 return OCRepresentation::const_iterator(m_values.end(), m_values);
957 OCRepresentation::const_iterator OCRepresentation::cend() const
959 return OCRepresentation::const_iterator(m_values.cend(), m_values);
962 size_t OCRepresentation::size() const
964 return m_values.size();
967 bool OCRepresentation::empty() const
969 return m_values.empty();
972 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
974 return m_iterator == rhs.m_iterator;
977 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
979 return m_iterator != rhs.m_iterator;
982 bool OCRepresentation::const_iterator::operator==(
983 const OCRepresentation::const_iterator& rhs) const
985 return m_iterator == rhs.m_iterator;
988 bool OCRepresentation::const_iterator::operator!=(
989 const OCRepresentation::const_iterator& rhs) const
991 return m_iterator != rhs.m_iterator;
994 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
999 OCRepresentation::const_iterator::const_reference
1000 OCRepresentation::const_iterator::operator*() const
1005 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1010 OCRepresentation::const_iterator::const_pointer
1011 OCRepresentation::const_iterator::operator->() const
1016 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1019 if (m_iterator != m_item.m_values.end())
1021 m_item.m_attrName = m_iterator->first;
1025 m_item.m_attrName = "";
1030 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1033 if (m_iterator != m_item.m_values.end())
1035 m_item.m_attrName = m_iterator->first;
1039 m_item.m_attrName = "";
1044 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1046 OCRepresentation::iterator itr(*this);
1051 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1053 OCRepresentation::const_iterator itr(*this);
1058 struct to_string_visitor : boost::static_visitor<>
1061 template <typename T>
1062 void operator()(T const& item)
1064 str = boost::lexical_cast<std::string>(item);
1067 template <typename T>
1068 void operator()(std::vector<T> const& item)
1070 to_string_visitor vis;
1071 std::ostringstream stream;
1074 for(const auto& i : item)
1077 stream << vis.str << " ";
1085 void to_string_visitor::operator()(bool const& item)
1087 str = item ? "true" : "false";
1091 void to_string_visitor::operator()(std::string const& item)
1097 void to_string_visitor::operator()(NullType const& /*item*/)
1103 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1105 str = "OC::OCRepresentation";
1108 std::string OCRepresentation::getValueToString(const std::string& key) const
1110 auto x = m_values.find(key);
1111 if (x != m_values.end())
1113 to_string_visitor vis;
1114 boost::apply_visitor(vis, x->second);
1115 return std::move(vis.str);
1121 std::string OCRepresentation::AttributeItem::getValueToString() const
1123 to_string_visitor vis;
1124 boost::apply_visitor(vis, m_values[m_attrName]);
1125 return std::move(vis.str);
1128 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1130 os << ai.getValueToString();