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 char uuidString[UUID_STRING_SIZE];
77 if (payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString))
79 rep[OC_RSRVD_DEVICE_ID] = std::string(uuidString);
83 rep[OC_RSRVD_DEVICE_ID] = std::string();
85 rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
86 std::string(payload->deviceName) :
88 rep[OC_RSRVD_SPEC_VERSION] = payload->specVersion ?
89 std::string(payload->specVersion) :
91 rep[OC_RSRVD_DATA_MODEL_VERSION] = payload->dataModelVersion ?
92 std::string(payload->dataModelVersion) :
94 m_reps.push_back(std::move(rep));
97 void MessageContainer::setPayload(const OCPlatformPayload* payload)
99 if (payload == nullptr)
104 OCRepresentation rep;
105 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
106 std::string(payload->info.platformID) :
108 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
109 std::string(payload->info.manufacturerName) :
111 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
112 std::string(payload->info.manufacturerUrl) :
114 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
115 std::string(payload->info.modelNumber) :
117 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
118 std::string(payload->info.dateOfManufacture) :
120 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
121 std::string(payload->info.platformVersion) :
123 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
124 std::string(payload->info.operatingSystemVersion) :
126 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
127 std::string(payload->info.hardwareVersion) :
129 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
130 std::string(payload->info.firmwareVersion) :
132 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
133 std::string(payload->info.supportUrl) :
135 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
136 std::string(payload->info.systemTime) :
139 m_reps.push_back(std::move(rep));
142 void MessageContainer::setPayload(const OCRepPayload* payload)
144 const OCRepPayload* pl = payload;
147 OCRepresentation cur;
151 this->addRepresentation(cur);
155 OCRepPayload* MessageContainer::getPayload() const
157 OCRepPayload* root = nullptr;
158 for(const auto& r : representations())
162 root = r.getPayload();
166 OCRepPayloadAppend(root, r.getPayload());
173 const std::vector<OCRepresentation>& MessageContainer::representations() const
178 void MessageContainer::addRepresentation(const OCRepresentation& rep)
180 m_reps.push_back(rep);
186 struct get_payload_array: boost::static_visitor<>
189 void operator()(T& /*arr*/)
191 throw std::logic_error("Invalid calc_dimensions_visitor type");
195 void operator()(std::vector<T>& arr)
198 dimensions[0] = arr.size();
201 dimTotal = calcDimTotal(dimensions);
203 array = (void*)OICMalloc(dimTotal * root_size);
205 for(size_t i = 0; i < dimensions[0]; ++i)
207 copy_to_array(arr[i], array, i);
212 void operator()(std::vector<std::vector<T>>& arr)
215 dimensions[0] = arr.size();
218 for(size_t i = 0; i < arr.size(); ++i)
220 dimensions[1] = std::max(dimensions[1], arr[i].size());
222 dimTotal = calcDimTotal(dimensions);
223 array = (void*)OICCalloc(1, dimTotal * root_size);
225 for(size_t i = 0; i < dimensions[0]; ++i)
227 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
229 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
234 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
237 dimensions[0] = arr.size();
240 for(size_t i = 0; i < arr.size(); ++i)
242 dimensions[1] = std::max(dimensions[1], arr[i].size());
244 for(size_t j = 0; j < arr[i].size(); ++j)
246 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
250 dimTotal = calcDimTotal(dimensions);
251 array = (void*)OICCalloc(1, dimTotal * root_size);
253 for(size_t i = 0; i < dimensions[0]; ++i)
255 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
257 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
259 copy_to_array(arr[i][j][k], array,
261 dimensions[2] * dimensions[1] * i +
269 void root_size_calc()
271 root_size = sizeof(T);
275 void copy_to_array(T item, void* array, size_t pos)
277 ((T*)array)[pos] = item;
280 size_t dimensions[MAX_REP_ARRAY_DEPTH];
287 void get_payload_array::root_size_calc<int>()
289 root_size = sizeof(int64_t);
293 void get_payload_array::root_size_calc<std::string>()
295 root_size = sizeof(char*);
299 void get_payload_array::root_size_calc<OC::OCRepresentation>()
301 root_size = sizeof(OCRepPayload*);
305 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
307 ((int64_t*)array)[pos] = item;
311 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
313 ((bool*)array)[pos] = static_cast<bool>(br);
317 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
319 ((char**)array)[pos] = OICStrdup(item.c_str());
323 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
325 ((char**)array)[pos] = OICStrdup(item.c_str());
329 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
331 ((char**)array)[pos] = OICStrdup(item.c_str());
335 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
337 ((OCRepPayload**)array)[pos] = item.getPayload();
340 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
341 const OCRepresentation::AttributeItem& item) const
343 get_payload_array vis{};
344 boost::apply_visitor(vis, m_values[item.attrname()]);
347 switch(item.base_type())
349 case AttributeType::Integer:
350 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
354 case AttributeType::Double:
355 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
359 case AttributeType::Boolean:
360 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
364 case AttributeType::String:
365 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
369 case AttributeType::OCRepresentation:
370 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
371 (OCRepPayload**)vis.array, vis.dimensions);
374 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
375 std::to_string((int)item.base_type()));
379 OCRepPayload* OCRepresentation::getPayload() const
381 OCRepPayload* root = OCRepPayloadCreate();
384 throw std::bad_alloc();
387 OCRepPayloadSetUri(root, getUri().c_str());
389 for(const std::string& type : getResourceTypes())
391 OCRepPayloadAddResourceType(root, type.c_str());
394 for(const std::string& iface : getResourceInterfaces())
396 OCRepPayloadAddInterface(root, iface.c_str());
399 for(auto& val : *this)
403 case AttributeType::Null:
404 OCRepPayloadSetNull(root, val.attrname().c_str());
406 case AttributeType::Integer:
407 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
409 case AttributeType::Double:
410 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
411 val.getValue<double>());
413 case AttributeType::Boolean:
414 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
416 case AttributeType::String:
417 OCRepPayloadSetPropString(root, val.attrname().c_str(),
418 static_cast<std::string>(val).c_str());
420 case AttributeType::OCRepresentation:
421 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
422 static_cast<OCRepresentation>(val).getPayload());
424 case AttributeType::Vector:
425 getPayloadArray(root, val);
428 throw std::logic_error(std::string("Getpayload: Not Implemented") +
429 std::to_string((int)val.type()));
437 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
439 if (dimensions[0] == 0)
441 throw std::logic_error("invalid calcArrayDepth");
443 else if (dimensions[1] == 0)
447 else if (dimensions[2] == 0)
458 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
460 throw std::logic_error("payload_array_helper_copy: unsupported type");
463 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
465 return pl->arr.iArray[index];
468 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
470 return pl->arr.dArray[index];
473 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
475 return pl->arr.bArray[index];
478 std::string OCRepresentation::payload_array_helper_copy<std::string>(
479 size_t index, const OCRepPayloadValue* pl)
481 if (pl->arr.strArray[index])
483 return std::string(pl->arr.strArray[index]);
487 return std::string{};
491 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
492 size_t index, const OCRepPayloadValue* pl)
495 if (pl->arr.objArray[index])
497 r.setPayload(pl->arr.objArray[index]);
503 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
507 std::vector<T> val(pl->arr.dimensions[0]);
509 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
511 val[i] = payload_array_helper_copy<T>(i, pl);
513 this->setValue(std::string(pl->name), val);
517 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] = payload_array_helper_copy<T>(
524 i * pl->arr.dimensions[1] + j, pl);
527 this->setValue(std::string(pl->name), val);
531 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
532 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
534 val[i].resize(pl->arr.dimensions[1]);
535 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
537 val[i][j].resize(pl->arr.dimensions[2]);
538 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
540 val[i][j][k] = payload_array_helper_copy<T>(
541 pl->arr.dimensions[2] * j +
542 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
548 this->setValue(std::string(pl->name), val);
552 throw std::logic_error("Invalid depth in payload_array_helper");
556 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
562 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
564 case OCREP_PROP_DOUBLE:
565 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
567 case OCREP_PROP_BOOL:
568 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
570 case OCREP_PROP_STRING:
571 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
573 case OCREP_PROP_OBJECT:
574 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
577 throw std::logic_error("setPayload array invalid type");
582 void OCRepresentation::setPayload(const OCRepPayload* pl)
586 OCStringLL* ll = pl->types;
589 addResourceType(ll->value);
596 addResourceInterface(ll->value);
600 OCRepPayloadValue* val = pl->values;
606 case OCREP_PROP_NULL:
610 setValue<int>(val->name, val->i);
612 case OCREP_PROP_DOUBLE:
613 setValue<double>(val->name, val->d);
615 case OCREP_PROP_BOOL:
616 setValue<bool>(val->name, val->b);
618 case OCREP_PROP_STRING:
619 setValue<std::string>(val->name, val->str);
621 case OCREP_PROP_OBJECT:
623 OCRepresentation cur;
624 cur.setPayload(val->obj);
625 setValue<OCRepresentation>(val->name, cur);
628 case OCREP_PROP_ARRAY:
629 setPayloadArray(val);
632 throw std::logic_error(std::string("Not Implemented!") +
633 std::to_string((int)val->type));
640 void OCRepresentation::addChild(const OCRepresentation& rep)
642 m_children.push_back(rep);
645 void OCRepresentation::clearChildren()
650 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
655 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
657 m_children = children;
660 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
662 std::ostringstream ss;
663 if (m_devAddr.flags & OC_SECURE)
667 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
675 if (m_devAddr.flags & OC_IP_USE_V6)
677 ss << '[' << m_devAddr.addr << ']';
681 ss << m_devAddr.addr;
685 ss << ':' << m_devAddr.port;
690 const std::string OCRepresentation::getHost() const
695 void OCRepresentation::setUri(const char* uri)
697 m_uri = uri ? uri : "";
700 void OCRepresentation::setUri(const std::string& uri)
705 std::string OCRepresentation::getUri() const
710 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
712 return m_resourceTypes;
715 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
717 m_resourceTypes = resourceTypes;
720 void OCRepresentation::addResourceType(const std::string& str)
722 m_resourceTypes.push_back(str);
725 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
730 void OCRepresentation::addResourceInterface(const std::string& str)
732 m_interfaces.push_back(str);
735 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
737 m_interfaces = resourceInterfaces;
740 bool OCRepresentation::hasAttribute(const std::string& str) const
742 return m_values.find(str) != m_values.end();
745 bool OCRepresentation::emptyData() const
747 // This logic is meant to determine whether based on the JSON serialization rules
748 // if this object will result in empty JSON. URI is only serialized if there is valid
749 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
750 // child of a default or link item.
751 // Our values array is only printed in the if we are the child of a Batch resource,
752 // the parent in a 'default' situation, or not in a child/parent relationship.
757 else if ((m_interfaceType == InterfaceType::None
758 || m_interfaceType==InterfaceType::DefaultChild
759 || m_interfaceType==InterfaceType::LinkChild)
760 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
764 else if ((m_interfaceType == InterfaceType::None
765 || m_interfaceType == InterfaceType::BatchChild
766 || m_interfaceType == InterfaceType::DefaultParent)
767 && m_values.size()>0)
772 if (m_children.size() > 0)
780 int OCRepresentation::numberOfAttributes() const
782 return m_values.size();
785 bool OCRepresentation::erase(const std::string& str)
787 return m_values.erase(str);
790 void OCRepresentation::setNULL(const std::string& str)
792 m_values[str] = OC::NullType();
795 bool OCRepresentation::isNULL(const std::string& str) const
797 auto x = m_values.find(str);
799 if (m_values.end() != x)
801 return x->second.which() == AttributeValueNullIndex;
805 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
812 std::ostream& operator <<(std::ostream& os, const AttributeType at)
816 case AttributeType::Null:
819 case AttributeType::Integer:
822 case AttributeType::Double:
825 case AttributeType::Boolean:
828 case AttributeType::String:
831 case AttributeType::OCRepresentation:
832 os << "OCRepresentation";
834 case AttributeType::Vector:
842 // STL Container For OCRepresentation
845 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
846 std::map<std::string, AttributeValue>& vals):
847 m_attrName(name), m_values(vals){}
849 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
851 OCRepresentation::AttributeItem attr{key, m_values};
852 return std::move(attr);
855 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
857 OCRepresentation::AttributeItem attr{key, m_values};
858 return std::move(attr);
861 const std::string& OCRepresentation::AttributeItem::attrname() const
866 template<typename T, typename = void>
869 // contains the actual type
871 // contains the inner most vector-type
873 // contains the AttributeType for this item
874 constexpr static AttributeType enum_type =
875 AttributeTypeConvert<T>::type;
876 // contains the AttributeType for this base-type
877 constexpr static AttributeType enum_base_type =
878 AttributeTypeConvert<T>::type;
879 // depth of the vector
880 constexpr static size_t depth = 0;
884 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
887 typedef typename type_info<typename T::value_type>::base_type base_type;
888 constexpr static AttributeType enum_type = AttributeType::Vector;
889 constexpr static AttributeType enum_base_type =
890 type_info<typename T::value_type>::enum_base_type;
891 constexpr static size_t depth = 1 +
892 type_info<typename T::value_type>::depth;
895 struct type_introspection_visitor : boost::static_visitor<>
898 AttributeType base_type;
901 type_introspection_visitor() : boost::static_visitor<>(),
902 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
904 template <typename T>
905 void operator()(T const& /*item*/)
907 type = type_info<T>::enum_type;
908 base_type = type_info<T>::enum_base_type;
909 depth = type_info<T>::depth;
913 AttributeType OCRepresentation::AttributeItem::type() const
915 type_introspection_visitor vis;
916 boost::apply_visitor(vis, m_values[m_attrName]);
920 AttributeType OCRepresentation::AttributeItem::base_type() const
922 type_introspection_visitor vis;
923 boost::apply_visitor(vis, m_values[m_attrName]);
924 return vis.base_type;
927 size_t OCRepresentation::AttributeItem::depth() const
929 type_introspection_visitor vis;
930 boost::apply_visitor(vis, m_values[m_attrName]);
934 OCRepresentation::iterator OCRepresentation::begin()
936 return OCRepresentation::iterator(m_values.begin(), m_values);
939 OCRepresentation::const_iterator OCRepresentation::begin() const
941 return OCRepresentation::const_iterator(m_values.begin(), m_values);
944 OCRepresentation::const_iterator OCRepresentation::cbegin() const
946 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
949 OCRepresentation::iterator OCRepresentation::end()
951 return OCRepresentation::iterator(m_values.end(), m_values);
954 OCRepresentation::const_iterator OCRepresentation::end() const
956 return OCRepresentation::const_iterator(m_values.end(), m_values);
959 OCRepresentation::const_iterator OCRepresentation::cend() const
961 return OCRepresentation::const_iterator(m_values.cend(), m_values);
964 size_t OCRepresentation::size() const
966 return m_values.size();
969 bool OCRepresentation::empty() const
971 return m_values.empty();
974 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
976 return m_iterator == rhs.m_iterator;
979 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
981 return m_iterator != rhs.m_iterator;
984 bool OCRepresentation::const_iterator::operator==(
985 const OCRepresentation::const_iterator& rhs) const
987 return m_iterator == rhs.m_iterator;
990 bool OCRepresentation::const_iterator::operator!=(
991 const OCRepresentation::const_iterator& rhs) const
993 return m_iterator != rhs.m_iterator;
996 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
1001 OCRepresentation::const_iterator::const_reference
1002 OCRepresentation::const_iterator::operator*() const
1007 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1012 OCRepresentation::const_iterator::const_pointer
1013 OCRepresentation::const_iterator::operator->() const
1018 OCRepresentation::iterator& OCRepresentation::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::const_iterator& OCRepresentation::const_iterator::operator++()
1035 if (m_iterator != m_item.m_values.end())
1037 m_item.m_attrName = m_iterator->first;
1041 m_item.m_attrName = "";
1046 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1048 OCRepresentation::iterator itr(*this);
1053 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1055 OCRepresentation::const_iterator itr(*this);
1060 struct to_string_visitor : boost::static_visitor<>
1063 template <typename T>
1064 void operator()(T const& item)
1066 str = boost::lexical_cast<std::string>(item);
1069 template <typename T>
1070 void operator()(std::vector<T> const& item)
1072 to_string_visitor vis;
1073 std::ostringstream stream;
1076 for(const auto& i : item)
1079 stream << vis.str << " ";
1087 void to_string_visitor::operator()(bool const& item)
1089 str = item ? "true" : "false";
1093 void to_string_visitor::operator()(std::string const& item)
1099 void to_string_visitor::operator()(NullType const& /*item*/)
1105 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1107 str = "OC::OCRepresentation";
1110 std::string OCRepresentation::getValueToString(const std::string& key) const
1112 auto x = m_values.find(key);
1113 if (x != m_values.end())
1115 to_string_visitor vis;
1116 boost::apply_visitor(vis, x->second);
1117 return std::move(vis.str);
1123 std::string OCRepresentation::AttributeItem::getValueToString() const
1125 to_string_visitor vis;
1126 boost::apply_visitor(vis, m_values[m_attrName]);
1127 return std::move(vis.str);
1130 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1132 os << ai.getValueToString();