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[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
92 std::string(payload->info.platformID) :
94 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
95 std::string(payload->info.manufacturerName) :
97 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
98 std::string(payload->info.manufacturerUrl) :
100 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
101 std::string(payload->info.modelNumber) :
103 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
104 std::string(payload->info.dateOfManufacture) :
106 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
107 std::string(payload->info.platformVersion) :
109 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
110 std::string(payload->info.operatingSystemVersion) :
112 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
113 std::string(payload->info.hardwareVersion) :
115 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
116 std::string(payload->info.firmwareVersion) :
118 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
119 std::string(payload->info.supportUrl) :
121 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
122 std::string(payload->info.systemTime) :
125 m_reps.push_back(std::move(rep));
128 void MessageContainer::setPayload(const OCRepPayload* payload)
130 const OCRepPayload* pl = payload;
133 OCRepresentation cur;
137 this->addRepresentation(cur);
141 OCRepPayload* MessageContainer::getPayload() const
143 OCRepPayload* root = nullptr;
144 for(const auto& r : representations())
148 root = r.getPayload();
152 OCRepPayloadAppend(root, r.getPayload());
159 const std::vector<OCRepresentation>& MessageContainer::representations() const
164 void MessageContainer::addRepresentation(const OCRepresentation& rep)
166 m_reps.push_back(rep);
172 struct get_payload_array: boost::static_visitor<>
175 void operator()(T& /*arr*/)
177 throw std::logic_error("Invalid calc_dimensions_visitor type");
181 void operator()(std::vector<T>& arr)
184 dimensions[0] = arr.size();
187 dimTotal = calcDimTotal(dimensions);
189 array = (void*)OICMalloc(dimTotal * root_size);
191 for(size_t i = 0; i < dimensions[0]; ++i)
193 copy_to_array(arr[i], array, i);
198 void operator()(std::vector<std::vector<T>>& arr)
201 dimensions[0] = arr.size();
204 for(size_t i = 0; i < arr.size(); ++i)
206 dimensions[1] = std::max(dimensions[1], arr[i].size());
208 dimTotal = calcDimTotal(dimensions);
209 array = (void*)OICCalloc(1, dimTotal * root_size);
211 for(size_t i = 0; i < dimensions[0]; ++i)
213 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
215 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
220 void operator()(std::vector<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 for(size_t j = 0; j < arr[i].size(); ++j)
232 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
236 dimTotal = calcDimTotal(dimensions);
237 array = (void*)OICCalloc(1, dimTotal * root_size);
239 for(size_t i = 0; i < dimensions[0]; ++i)
241 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
243 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
245 copy_to_array(arr[i][j][k], array,
247 dimensions[2] * dimensions[1] * i +
255 void root_size_calc()
257 root_size = sizeof(T);
261 void copy_to_array(T item, void* array, size_t pos)
263 ((T*)array)[pos] = item;
266 size_t dimensions[MAX_REP_ARRAY_DEPTH];
273 void get_payload_array::root_size_calc<int>()
275 root_size = sizeof(int64_t);
279 void get_payload_array::root_size_calc<std::string>()
281 root_size = sizeof(char*);
285 void get_payload_array::root_size_calc<OC::OCRepresentation>()
287 root_size = sizeof(OCRepPayload*);
291 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
293 ((int64_t*)array)[pos] = item;
297 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
299 ((bool*)array)[pos] = static_cast<bool>(br);
303 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
305 ((char**)array)[pos] = OICStrdup(item.c_str());
309 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
311 ((char**)array)[pos] = OICStrdup(item.c_str());
315 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
317 ((char**)array)[pos] = OICStrdup(item.c_str());
321 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
323 ((OCRepPayload**)array)[pos] = item.getPayload();
326 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
327 const OCRepresentation::AttributeItem& item) const
329 get_payload_array vis{};
330 boost::apply_visitor(vis, m_values[item.attrname()]);
333 switch(item.base_type())
335 case AttributeType::Integer:
336 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
340 case AttributeType::Double:
341 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
345 case AttributeType::Boolean:
346 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
350 case AttributeType::String:
351 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
355 case AttributeType::OCRepresentation:
356 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
357 (OCRepPayload**)vis.array, vis.dimensions);
360 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
361 std::to_string((int)item.base_type()));
365 OCRepPayload* OCRepresentation::getPayload() const
367 OCRepPayload* root = OCRepPayloadCreate();
370 throw std::bad_alloc();
373 OCRepPayloadSetUri(root, getUri().c_str());
375 for(const std::string& type : getResourceTypes())
377 OCRepPayloadAddResourceType(root, type.c_str());
380 for(const std::string& iface : getResourceInterfaces())
382 OCRepPayloadAddInterface(root, iface.c_str());
385 for(auto& val : *this)
389 case AttributeType::Null:
390 OCRepPayloadSetNull(root, val.attrname().c_str());
392 case AttributeType::Integer:
393 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
395 case AttributeType::Double:
396 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
397 val.getValue<double>());
399 case AttributeType::Boolean:
400 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
402 case AttributeType::String:
403 OCRepPayloadSetPropString(root, val.attrname().c_str(),
404 static_cast<std::string>(val).c_str());
406 case AttributeType::OCRepresentation:
407 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
408 static_cast<OCRepresentation>(val).getPayload());
410 case AttributeType::Vector:
411 getPayloadArray(root, val);
414 throw std::logic_error(std::string("Getpayload: Not Implemented") +
415 std::to_string((int)val.type()));
423 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
425 if(dimensions[0] == 0)
427 throw std::logic_error("invalid calcArrayDepth");
429 else if(dimensions[1] == 0)
433 else if (dimensions[2] == 0)
444 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
446 throw std::logic_error("payload_array_helper_copy: unsupported type");
449 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
451 return pl->arr.iArray[index];
454 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
456 return pl->arr.dArray[index];
459 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
461 return pl->arr.bArray[index];
464 std::string OCRepresentation::payload_array_helper_copy<std::string>(
465 size_t index, const OCRepPayloadValue* pl)
467 if (pl->arr.strArray[index])
469 return std::string(pl->arr.strArray[index]);
473 return std::string{};
477 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
478 size_t index, const OCRepPayloadValue* pl)
481 if (pl->arr.objArray[index])
483 r.setPayload(pl->arr.objArray[index]);
489 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
493 std::vector<T> val(pl->arr.dimensions[0]);
495 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
497 val[i] = payload_array_helper_copy<T>(i, pl);
499 this->setValue(std::string(pl->name), val);
503 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
504 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
506 val[i].resize(pl->arr.dimensions[1]);
507 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
509 val[i][j] = payload_array_helper_copy<T>(
510 i * pl->arr.dimensions[1] + j, pl);
513 this->setValue(std::string(pl->name), val);
517 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
518 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
520 val[i].resize(pl->arr.dimensions[1]);
521 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
523 val[i][j].resize(pl->arr.dimensions[2]);
524 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
526 val[i][j][k] = payload_array_helper_copy<T>(
527 pl->arr.dimensions[2] * j +
528 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
534 this->setValue(std::string(pl->name), val);
538 throw std::logic_error("Invalid depth in payload_array_helper");
542 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
548 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
550 case OCREP_PROP_DOUBLE:
551 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
553 case OCREP_PROP_BOOL:
554 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
556 case OCREP_PROP_STRING:
557 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
559 case OCREP_PROP_OBJECT:
560 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
563 throw std::logic_error("setPayload array invalid type");
568 void OCRepresentation::setPayload(const OCRepPayload* pl)
572 OCStringLL* ll = pl->types;
575 addResourceType(ll->value);
582 addResourceInterface(ll->value);
586 OCRepPayloadValue* val = pl->values;
592 case OCREP_PROP_NULL:
596 setValue<int>(val->name, val->i);
598 case OCREP_PROP_DOUBLE:
599 setValue<double>(val->name, val->d);
601 case OCREP_PROP_BOOL:
602 setValue<bool>(val->name, val->b);
604 case OCREP_PROP_STRING:
605 setValue<std::string>(val->name, val->str);
607 case OCREP_PROP_OBJECT:
609 OCRepresentation cur;
610 cur.setPayload(val->obj);
611 setValue<OCRepresentation>(val->name, cur);
614 case OCREP_PROP_ARRAY:
615 setPayloadArray(val);
618 throw std::logic_error(std::string("Not Implemented!") +
619 std::to_string((int)val->type));
626 void OCRepresentation::addChild(const OCRepresentation& rep)
628 m_children.push_back(rep);
631 void OCRepresentation::clearChildren()
636 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
641 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
643 m_children = children;
646 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
648 std::ostringstream ss;
649 if (m_devAddr.flags & OC_SECURE)
653 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
661 if (m_devAddr.flags & OC_IP_USE_V6)
663 ss << '[' << m_devAddr.addr << ']';
667 ss << m_devAddr.addr;
671 ss << ':' << m_devAddr.port;
676 const std::string OCRepresentation::getHost() const
681 void OCRepresentation::setUri(const char* uri)
683 m_uri = uri ? uri : "";
686 void OCRepresentation::setUri(const std::string& uri)
691 std::string OCRepresentation::getUri() const
696 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
698 return m_resourceTypes;
701 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
703 m_resourceTypes = resourceTypes;
706 void OCRepresentation::addResourceType(const std::string& str)
708 m_resourceTypes.push_back(str);
711 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
716 void OCRepresentation::addResourceInterface(const std::string& str)
718 m_interfaces.push_back(str);
721 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
723 m_interfaces = resourceInterfaces;
726 bool OCRepresentation::hasAttribute(const std::string& str) const
728 return m_values.find(str) != m_values.end();
731 bool OCRepresentation::emptyData() const
733 // This logic is meant to determine whether based on the JSON serialization rules
734 // if this object will result in empty JSON. URI is only serialized if there is valid
735 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
736 // child of a default or link item.
737 // Our values array is only printed in the if we are the child of a Batch resource,
738 // the parent in a 'default' situation, or not in a child/parent relationship.
743 else if ((m_interfaceType == InterfaceType::None
744 || m_interfaceType==InterfaceType::DefaultChild
745 || m_interfaceType==InterfaceType::LinkChild)
746 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
750 else if((m_interfaceType == InterfaceType::None
751 || m_interfaceType == InterfaceType::BatchChild
752 || m_interfaceType == InterfaceType::DefaultParent)
753 && m_values.size()>0)
758 if(m_children.size() > 0)
766 int OCRepresentation::numberOfAttributes() const
768 return m_values.size();
771 bool OCRepresentation::erase(const std::string& str)
773 return m_values.erase(str);
776 void OCRepresentation::setNULL(const std::string& str)
778 m_values[str] = OC::NullType();
781 bool OCRepresentation::isNULL(const std::string& str) const
783 auto x = m_values.find(str);
785 if(m_values.end() != x)
787 return x->second.which() == AttributeValueNullIndex;
791 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
798 std::ostream& operator <<(std::ostream& os, const AttributeType at)
802 case AttributeType::Null:
805 case AttributeType::Integer:
808 case AttributeType::Double:
811 case AttributeType::Boolean:
814 case AttributeType::String:
817 case AttributeType::OCRepresentation:
818 os << "OCRepresentation";
820 case AttributeType::Vector:
828 // STL Container For OCRepresentation
831 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
832 std::map<std::string, AttributeValue>& vals):
833 m_attrName(name), m_values(vals){}
835 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
837 OCRepresentation::AttributeItem attr{key, m_values};
838 return std::move(attr);
841 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
843 OCRepresentation::AttributeItem attr{key, m_values};
844 return std::move(attr);
847 const std::string& OCRepresentation::AttributeItem::attrname() const
852 template<typename T, typename = void>
855 // contains the actual type
857 // contains the inner most vector-type
859 // contains the AttributeType for this item
860 constexpr static AttributeType enum_type =
861 AttributeTypeConvert<T>::type;
862 // contains the AttributeType for this base-type
863 constexpr static AttributeType enum_base_type =
864 AttributeTypeConvert<T>::type;
865 // depth of the vector
866 constexpr static size_t depth = 0;
870 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
873 typedef typename type_info<typename T::value_type>::base_type base_type;
874 constexpr static AttributeType enum_type = AttributeType::Vector;
875 constexpr static AttributeType enum_base_type =
876 type_info<typename T::value_type>::enum_base_type;
877 constexpr static size_t depth = 1 +
878 type_info<typename T::value_type>::depth;
881 struct type_introspection_visitor : boost::static_visitor<>
884 AttributeType base_type;
887 type_introspection_visitor() : boost::static_visitor<>(),
888 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
890 template <typename T>
891 void operator()(T const& /*item*/)
893 type = type_info<T>::enum_type;
894 base_type = type_info<T>::enum_base_type;
895 depth = type_info<T>::depth;
899 AttributeType OCRepresentation::AttributeItem::type() const
901 type_introspection_visitor vis;
902 boost::apply_visitor(vis, m_values[m_attrName]);
906 AttributeType OCRepresentation::AttributeItem::base_type() const
908 type_introspection_visitor vis;
909 boost::apply_visitor(vis, m_values[m_attrName]);
910 return vis.base_type;
913 size_t OCRepresentation::AttributeItem::depth() const
915 type_introspection_visitor vis;
916 boost::apply_visitor(vis, m_values[m_attrName]);
920 OCRepresentation::iterator OCRepresentation::begin()
922 return OCRepresentation::iterator(m_values.begin(), m_values);
925 OCRepresentation::const_iterator OCRepresentation::begin() const
927 return OCRepresentation::const_iterator(m_values.begin(), m_values);
930 OCRepresentation::const_iterator OCRepresentation::cbegin() const
932 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
935 OCRepresentation::iterator OCRepresentation::end()
937 return OCRepresentation::iterator(m_values.end(), m_values);
940 OCRepresentation::const_iterator OCRepresentation::end() const
942 return OCRepresentation::const_iterator(m_values.end(), m_values);
945 OCRepresentation::const_iterator OCRepresentation::cend() const
947 return OCRepresentation::const_iterator(m_values.cend(), m_values);
950 size_t OCRepresentation::size() const
952 return m_values.size();
955 bool OCRepresentation::empty() const
957 return m_values.empty();
960 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
962 return m_iterator == rhs.m_iterator;
965 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
967 return m_iterator != rhs.m_iterator;
970 bool OCRepresentation::const_iterator::operator==(
971 const OCRepresentation::const_iterator& rhs) const
973 return m_iterator == rhs.m_iterator;
976 bool OCRepresentation::const_iterator::operator!=(
977 const OCRepresentation::const_iterator& rhs) const
979 return m_iterator != rhs.m_iterator;
982 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
987 OCRepresentation::const_iterator::const_reference
988 OCRepresentation::const_iterator::operator*() const
993 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
998 OCRepresentation::const_iterator::const_pointer
999 OCRepresentation::const_iterator::operator->() const
1004 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1007 if(m_iterator != m_item.m_values.end())
1009 m_item.m_attrName = m_iterator->first;
1013 m_item.m_attrName = "";
1018 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1021 if(m_iterator != m_item.m_values.end())
1023 m_item.m_attrName = m_iterator->first;
1027 m_item.m_attrName = "";
1032 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1034 OCRepresentation::iterator itr(*this);
1039 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1041 OCRepresentation::const_iterator itr(*this);
1046 struct to_string_visitor : boost::static_visitor<>
1049 template <typename T>
1050 void operator()(T const& item)
1052 str = boost::lexical_cast<std::string>(item);
1055 template <typename T>
1056 void operator()(std::vector<T> const& item)
1058 to_string_visitor vis;
1059 std::ostringstream stream;
1062 for(const auto& i : item)
1065 stream << vis.str << " ";
1073 void to_string_visitor::operator()(bool const& item)
1075 str = item ? "true" : "false";
1079 void to_string_visitor::operator()(std::string const& item)
1085 void to_string_visitor::operator()(NullType const& /*item*/)
1091 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1093 str = "OC::OCRepresentation";
1096 std::string OCRepresentation::getValueToString(const std::string& key) const
1098 auto x = m_values.find(key);
1099 if(x != m_values.end())
1101 to_string_visitor vis;
1102 boost::apply_visitor(vis, x->second);
1103 return std::move(vis.str);
1109 std::string OCRepresentation::AttributeItem::getValueToString() const
1111 to_string_visitor vis;
1112 boost::apply_visitor(vis, m_values[m_attrName]);
1113 return std::move(vis.str);
1116 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1118 os << ai.getValueToString();