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)
48 case PAYLOAD_TYPE_REPRESENTATION:
49 setPayload(reinterpret_cast<const OCRepPayload*>(rep));
51 case PAYLOAD_TYPE_DEVICE:
52 setPayload(reinterpret_cast<const OCDevicePayload*>(rep));
54 case PAYLOAD_TYPE_PLATFORM:
55 setPayload(reinterpret_cast<const OCPlatformPayload*>(rep));
58 throw OC::OCException("Invalid Payload type in setPayload");
63 void MessageContainer::setPayload(const OCDevicePayload* payload)
66 rep.setUri(payload->uri);
67 char uuidString[UUID_STRING_SIZE];
68 if(payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString))
70 rep[OC_RSRVD_DEVICE_ID] = std::string(uuidString);
74 rep[OC_RSRVD_DEVICE_ID] = std::string();
76 rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
77 std::string(payload->deviceName) :
79 rep[OC_RSRVD_SPEC_VERSION] = payload->specVersion ?
80 std::string(payload->specVersion) :
82 rep[OC_RSRVD_DATA_MODEL_VERSION] = payload->dataModelVersion ?
83 std::string(payload->dataModelVersion) :
85 m_reps.push_back(std::move(rep));
88 void MessageContainer::setPayload(const OCPlatformPayload* payload)
91 rep.setUri(payload->uri);
93 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
94 std::string(payload->info.platformID) :
96 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
97 std::string(payload->info.manufacturerName) :
99 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
100 std::string(payload->info.manufacturerUrl) :
102 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
103 std::string(payload->info.modelNumber) :
105 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
106 std::string(payload->info.dateOfManufacture) :
108 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
109 std::string(payload->info.platformVersion) :
111 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
112 std::string(payload->info.operatingSystemVersion) :
114 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
115 std::string(payload->info.hardwareVersion) :
117 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
118 std::string(payload->info.firmwareVersion) :
120 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
121 std::string(payload->info.supportUrl) :
123 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
124 std::string(payload->info.systemTime) :
127 m_reps.push_back(std::move(rep));
130 void MessageContainer::setPayload(const OCRepPayload* payload)
132 const OCRepPayload* pl = payload;
135 OCRepresentation cur;
139 this->addRepresentation(cur);
143 OCRepPayload* MessageContainer::getPayload() const
145 OCRepPayload* root = nullptr;
146 for(const auto& r : representations())
150 root = r.getPayload();
154 OCRepPayloadAppend(root, r.getPayload());
161 const std::vector<OCRepresentation>& MessageContainer::representations() const
166 void MessageContainer::addRepresentation(const OCRepresentation& rep)
168 m_reps.push_back(rep);
174 struct get_payload_array: boost::static_visitor<>
177 void operator()(T& /*arr*/)
179 throw std::logic_error("Invalid calc_dimensions_visitor type");
183 void operator()(std::vector<T>& arr)
186 dimensions[0] = arr.size();
189 dimTotal = calcDimTotal(dimensions);
191 array = (void*)OICMalloc(dimTotal * root_size);
193 for(size_t i = 0; i < dimensions[0]; ++i)
195 copy_to_array(arr[i], array, i);
200 void operator()(std::vector<std::vector<T>>& arr)
203 dimensions[0] = arr.size();
206 for(size_t i = 0; i < arr.size(); ++i)
208 dimensions[1] = std::max(dimensions[1], arr[i].size());
210 dimTotal = calcDimTotal(dimensions);
211 array = (void*)OICCalloc(1, dimTotal * root_size);
213 for(size_t i = 0; i < dimensions[0]; ++i)
215 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
217 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
222 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
225 dimensions[0] = arr.size();
228 for(size_t i = 0; i < arr.size(); ++i)
230 dimensions[1] = std::max(dimensions[1], arr[i].size());
232 for(size_t j = 0; j < arr[i].size(); ++j)
234 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
238 dimTotal = calcDimTotal(dimensions);
239 array = (void*)OICCalloc(1, dimTotal * root_size);
241 for(size_t i = 0; i < dimensions[0]; ++i)
243 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
245 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
247 copy_to_array(arr[i][j][k], array,
249 dimensions[2] * dimensions[1] * i +
257 void root_size_calc()
259 root_size = sizeof(T);
263 void copy_to_array(T item, void* array, size_t pos)
265 ((T*)array)[pos] = item;
268 size_t dimensions[MAX_REP_ARRAY_DEPTH];
275 void get_payload_array::root_size_calc<int>()
277 root_size = sizeof(int64_t);
281 void get_payload_array::root_size_calc<std::string>()
283 root_size = sizeof(char*);
287 void get_payload_array::root_size_calc<OC::OCRepresentation>()
289 root_size = sizeof(OCRepPayload*);
293 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
295 ((int64_t*)array)[pos] = item;
299 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
301 ((bool*)array)[pos] = static_cast<bool>(br);
305 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
307 ((char**)array)[pos] = OICStrdup(item.c_str());
311 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
313 ((char**)array)[pos] = OICStrdup(item.c_str());
317 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
319 ((char**)array)[pos] = OICStrdup(item.c_str());
323 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
325 ((OCRepPayload**)array)[pos] = item.getPayload();
328 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
329 const OCRepresentation::AttributeItem& item) const
331 get_payload_array vis{};
332 boost::apply_visitor(vis, m_values[item.attrname()]);
335 switch(item.base_type())
337 case AttributeType::Integer:
338 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
342 case AttributeType::Double:
343 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
347 case AttributeType::Boolean:
348 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
352 case AttributeType::String:
353 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
357 case AttributeType::OCRepresentation:
358 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
359 (OCRepPayload**)vis.array, vis.dimensions);
362 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
363 std::to_string((int)item.base_type()));
367 OCRepPayload* OCRepresentation::getPayload() const
369 OCRepPayload* root = OCRepPayloadCreate();
372 throw std::bad_alloc();
375 OCRepPayloadSetUri(root, getUri().c_str());
377 for(const std::string& type : getResourceTypes())
379 OCRepPayloadAddResourceType(root, type.c_str());
382 for(const std::string& iface : getResourceInterfaces())
384 OCRepPayloadAddInterface(root, iface.c_str());
387 for(auto& val : *this)
391 case AttributeType::Null:
392 OCRepPayloadSetNull(root, val.attrname().c_str());
394 case AttributeType::Integer:
395 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
397 case AttributeType::Double:
398 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
399 val.getValue<double>());
401 case AttributeType::Boolean:
402 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
404 case AttributeType::String:
405 OCRepPayloadSetPropString(root, val.attrname().c_str(),
406 static_cast<std::string>(val).c_str());
408 case AttributeType::OCRepresentation:
409 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
410 static_cast<OCRepresentation>(val).getPayload());
412 case AttributeType::Vector:
413 getPayloadArray(root, val);
416 throw std::logic_error(std::string("Getpayload: Not Implemented") +
417 std::to_string((int)val.type()));
425 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
427 if(dimensions[0] == 0)
429 throw std::logic_error("invalid calcArrayDepth");
431 else if(dimensions[1] == 0)
435 else if (dimensions[2] == 0)
446 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
448 throw std::logic_error("payload_array_helper_copy: unsupported type");
451 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
453 return pl->arr.iArray[index];
456 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
458 return pl->arr.dArray[index];
461 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
463 return pl->arr.bArray[index];
466 std::string OCRepresentation::payload_array_helper_copy<std::string>(
467 size_t index, const OCRepPayloadValue* pl)
469 if (pl->arr.strArray[index])
471 return std::string(pl->arr.strArray[index]);
475 return std::string{};
479 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
480 size_t index, const OCRepPayloadValue* pl)
483 if (pl->arr.objArray[index])
485 r.setPayload(pl->arr.objArray[index]);
491 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
495 std::vector<T> val(pl->arr.dimensions[0]);
497 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
499 val[i] = payload_array_helper_copy<T>(i, pl);
501 this->setValue(std::string(pl->name), val);
505 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
506 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
508 val[i].resize(pl->arr.dimensions[1]);
509 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
511 val[i][j] = payload_array_helper_copy<T>(
512 i * pl->arr.dimensions[1] + j, pl);
515 this->setValue(std::string(pl->name), val);
519 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
520 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
522 val[i].resize(pl->arr.dimensions[1]);
523 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
525 val[i][j].resize(pl->arr.dimensions[2]);
526 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
528 val[i][j][k] = payload_array_helper_copy<T>(
529 pl->arr.dimensions[2] * j +
530 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
536 this->setValue(std::string(pl->name), val);
540 throw std::logic_error("Invalid depth in payload_array_helper");
544 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
550 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
552 case OCREP_PROP_DOUBLE:
553 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
555 case OCREP_PROP_BOOL:
556 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
558 case OCREP_PROP_STRING:
559 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
561 case OCREP_PROP_OBJECT:
562 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
565 throw std::logic_error("setPayload array invalid type");
570 void OCRepresentation::setPayload(const OCRepPayload* pl)
574 OCStringLL* ll = pl->types;
577 addResourceType(ll->value);
584 addResourceInterface(ll->value);
588 OCRepPayloadValue* val = pl->values;
594 case OCREP_PROP_NULL:
598 setValue<int>(val->name, val->i);
600 case OCREP_PROP_DOUBLE:
601 setValue<double>(val->name, val->d);
603 case OCREP_PROP_BOOL:
604 setValue<bool>(val->name, val->b);
606 case OCREP_PROP_STRING:
607 setValue<std::string>(val->name, val->str);
609 case OCREP_PROP_OBJECT:
611 OCRepresentation cur;
612 cur.setPayload(val->obj);
613 setValue<OCRepresentation>(val->name, cur);
616 case OCREP_PROP_ARRAY:
617 setPayloadArray(val);
620 throw std::logic_error(std::string("Not Implemented!") +
621 std::to_string((int)val->type));
628 void OCRepresentation::addChild(const OCRepresentation& rep)
630 m_children.push_back(rep);
633 void OCRepresentation::clearChildren()
638 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
643 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
645 m_children = children;
648 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
650 std::ostringstream ss;
651 if (m_devAddr.flags & OC_SECURE)
655 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
663 if (m_devAddr.flags & OC_IP_USE_V6)
665 ss << '[' << m_devAddr.addr << ']';
669 ss << m_devAddr.addr;
673 ss << ':' << m_devAddr.port;
678 const std::string OCRepresentation::getHost() const
683 void OCRepresentation::setUri(const char* uri)
685 m_uri = uri ? uri : "";
688 void OCRepresentation::setUri(const std::string& uri)
693 std::string OCRepresentation::getUri() const
698 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
700 return m_resourceTypes;
703 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
705 m_resourceTypes = resourceTypes;
708 void OCRepresentation::addResourceType(const std::string& str)
710 m_resourceTypes.push_back(str);
713 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
718 void OCRepresentation::addResourceInterface(const std::string& str)
720 m_interfaces.push_back(str);
723 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
725 m_interfaces = resourceInterfaces;
728 bool OCRepresentation::hasAttribute(const std::string& str) const
730 return m_values.find(str) != m_values.end();
733 bool OCRepresentation::emptyData() const
735 // This logic is meant to determine whether based on the JSON serialization rules
736 // if this object will result in empty JSON. URI is only serialized if there is valid
737 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
738 // child of a default or link item.
739 // Our values array is only printed in the if we are the child of a Batch resource,
740 // the parent in a 'default' situation, or not in a child/parent relationship.
745 else if ((m_interfaceType == InterfaceType::None
746 || m_interfaceType==InterfaceType::DefaultChild
747 || m_interfaceType==InterfaceType::LinkChild)
748 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
752 else if((m_interfaceType == InterfaceType::None
753 || m_interfaceType == InterfaceType::BatchChild
754 || m_interfaceType == InterfaceType::DefaultParent)
755 && m_values.size()>0)
760 if(m_children.size() > 0)
768 int OCRepresentation::numberOfAttributes() const
770 return m_values.size();
773 bool OCRepresentation::erase(const std::string& str)
775 return m_values.erase(str);
778 void OCRepresentation::setNULL(const std::string& str)
780 m_values[str] = OC::NullType();
783 bool OCRepresentation::isNULL(const std::string& str) const
785 auto x = m_values.find(str);
787 if(m_values.end() != x)
789 return x->second.which() == AttributeValueNullIndex;
793 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
800 std::ostream& operator <<(std::ostream& os, const AttributeType at)
804 case AttributeType::Null:
807 case AttributeType::Integer:
810 case AttributeType::Double:
813 case AttributeType::Boolean:
816 case AttributeType::String:
819 case AttributeType::OCRepresentation:
820 os << "OCRepresentation";
822 case AttributeType::Vector:
830 // STL Container For OCRepresentation
833 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
834 std::map<std::string, AttributeValue>& vals):
835 m_attrName(name), m_values(vals){}
837 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
839 OCRepresentation::AttributeItem attr{key, m_values};
840 return std::move(attr);
843 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
845 OCRepresentation::AttributeItem attr{key, m_values};
846 return std::move(attr);
849 const std::string& OCRepresentation::AttributeItem::attrname() const
854 template<typename T, typename = void>
857 // contains the actual type
859 // contains the inner most vector-type
861 // contains the AttributeType for this item
862 constexpr static AttributeType enum_type =
863 AttributeTypeConvert<T>::type;
864 // contains the AttributeType for this base-type
865 constexpr static AttributeType enum_base_type =
866 AttributeTypeConvert<T>::type;
867 // depth of the vector
868 constexpr static size_t depth = 0;
872 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
875 typedef typename type_info<typename T::value_type>::base_type base_type;
876 constexpr static AttributeType enum_type = AttributeType::Vector;
877 constexpr static AttributeType enum_base_type =
878 type_info<typename T::value_type>::enum_base_type;
879 constexpr static size_t depth = 1 +
880 type_info<typename T::value_type>::depth;
883 struct type_introspection_visitor : boost::static_visitor<>
886 AttributeType base_type;
889 type_introspection_visitor() : boost::static_visitor<>(),
890 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
892 template <typename T>
893 void operator()(T const& /*item*/)
895 type = type_info<T>::enum_type;
896 base_type = type_info<T>::enum_base_type;
897 depth = type_info<T>::depth;
901 AttributeType OCRepresentation::AttributeItem::type() const
903 type_introspection_visitor vis;
904 boost::apply_visitor(vis, m_values[m_attrName]);
908 AttributeType OCRepresentation::AttributeItem::base_type() const
910 type_introspection_visitor vis;
911 boost::apply_visitor(vis, m_values[m_attrName]);
912 return vis.base_type;
915 size_t OCRepresentation::AttributeItem::depth() const
917 type_introspection_visitor vis;
918 boost::apply_visitor(vis, m_values[m_attrName]);
922 OCRepresentation::iterator OCRepresentation::begin()
924 return OCRepresentation::iterator(m_values.begin(), m_values);
927 OCRepresentation::const_iterator OCRepresentation::begin() const
929 return OCRepresentation::const_iterator(m_values.begin(), m_values);
932 OCRepresentation::const_iterator OCRepresentation::cbegin() const
934 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
937 OCRepresentation::iterator OCRepresentation::end()
939 return OCRepresentation::iterator(m_values.end(), m_values);
942 OCRepresentation::const_iterator OCRepresentation::end() const
944 return OCRepresentation::const_iterator(m_values.end(), m_values);
947 OCRepresentation::const_iterator OCRepresentation::cend() const
949 return OCRepresentation::const_iterator(m_values.cend(), m_values);
952 size_t OCRepresentation::size() const
954 return m_values.size();
957 bool OCRepresentation::empty() const
959 return m_values.empty();
962 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
964 return m_iterator == rhs.m_iterator;
967 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
969 return m_iterator != rhs.m_iterator;
972 bool OCRepresentation::const_iterator::operator==(
973 const OCRepresentation::const_iterator& rhs) const
975 return m_iterator == rhs.m_iterator;
978 bool OCRepresentation::const_iterator::operator!=(
979 const OCRepresentation::const_iterator& rhs) const
981 return m_iterator != rhs.m_iterator;
984 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
989 OCRepresentation::const_iterator::const_reference
990 OCRepresentation::const_iterator::operator*() const
995 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1000 OCRepresentation::const_iterator::const_pointer
1001 OCRepresentation::const_iterator::operator->() const
1006 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1009 if(m_iterator != m_item.m_values.end())
1011 m_item.m_attrName = m_iterator->first;
1015 m_item.m_attrName = "";
1020 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1023 if(m_iterator != m_item.m_values.end())
1025 m_item.m_attrName = m_iterator->first;
1029 m_item.m_attrName = "";
1034 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1036 OCRepresentation::iterator itr(*this);
1041 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1043 OCRepresentation::const_iterator itr(*this);
1048 struct to_string_visitor : boost::static_visitor<>
1051 template <typename T>
1052 void operator()(T const& item)
1054 str = boost::lexical_cast<std::string>(item);
1057 template <typename T>
1058 void operator()(std::vector<T> const& item)
1060 to_string_visitor vis;
1061 std::ostringstream stream;
1064 for(const auto& i : item)
1067 stream << vis.str << " ";
1075 void to_string_visitor::operator()(bool const& item)
1077 str = item ? "true" : "false";
1081 void to_string_visitor::operator()(std::string const& item)
1087 void to_string_visitor::operator()(NullType const& /*item*/)
1093 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1095 str = "OC::OCRepresentation";
1098 std::string OCRepresentation::getValueToString(const std::string& key) const
1100 auto x = m_values.find(key);
1101 if(x != m_values.end())
1103 to_string_visitor vis;
1104 boost::apply_visitor(vis, x->second);
1105 return std::move(vis.str);
1111 std::string OCRepresentation::AttributeItem::getValueToString() const
1113 to_string_visitor vis;
1114 boost::apply_visitor(vis, m_values[m_attrName]);
1115 return std::move(vis.str);
1118 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1120 os << ai.getValueToString();