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 m_reps.push_back(std::move(rep));
91 void MessageContainer::setPayload(const OCPlatformPayload* payload)
93 if (payload == nullptr)
99 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
100 std::string(payload->info.platformID) :
102 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
103 std::string(payload->info.manufacturerName) :
105 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
106 std::string(payload->info.manufacturerUrl) :
108 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
109 std::string(payload->info.modelNumber) :
111 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
112 std::string(payload->info.dateOfManufacture) :
114 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
115 std::string(payload->info.platformVersion) :
117 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
118 std::string(payload->info.operatingSystemVersion) :
120 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
121 std::string(payload->info.hardwareVersion) :
123 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
124 std::string(payload->info.firmwareVersion) :
126 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
127 std::string(payload->info.supportUrl) :
129 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
130 std::string(payload->info.systemTime) :
135 rep.addResourceType(payload->rt);
137 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
139 rep.addResourceInterface(strll->value);
142 m_reps.push_back(std::move(rep));
145 void MessageContainer::setPayload(const OCRepPayload* payload)
147 const OCRepPayload* pl = payload;
150 OCRepresentation cur;
154 this->addRepresentation(cur);
158 OCRepPayload* MessageContainer::getPayload() const
160 OCRepPayload* root = nullptr;
161 for(const auto& r : representations())
165 root = r.getPayload();
169 OCRepPayloadAppend(root, r.getPayload());
176 const std::vector<OCRepresentation>& MessageContainer::representations() const
181 void MessageContainer::addRepresentation(const OCRepresentation& rep)
183 m_reps.push_back(rep);
189 struct get_payload_array: boost::static_visitor<>
192 void operator()(T& /*arr*/)
194 throw std::logic_error("Invalid calc_dimensions_visitor type");
198 void operator()(std::vector<T>& arr)
201 dimensions[0] = arr.size();
204 dimTotal = calcDimTotal(dimensions);
206 array = (void*)OICMalloc(dimTotal * root_size);
208 for(size_t i = 0; i < dimensions[0]; ++i)
210 copy_to_array(arr[i], array, i);
215 void operator()(std::vector<std::vector<T>>& arr)
218 dimensions[0] = arr.size();
221 for(size_t i = 0; i < arr.size(); ++i)
223 dimensions[1] = std::max(dimensions[1], arr[i].size());
225 dimTotal = calcDimTotal(dimensions);
226 array = (void*)OICCalloc(1, dimTotal * root_size);
228 for(size_t i = 0; i < dimensions[0]; ++i)
230 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
232 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
237 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
240 dimensions[0] = arr.size();
243 for(size_t i = 0; i < arr.size(); ++i)
245 dimensions[1] = std::max(dimensions[1], arr[i].size());
247 for(size_t j = 0; j < arr[i].size(); ++j)
249 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
253 dimTotal = calcDimTotal(dimensions);
254 array = (void*)OICCalloc(1, dimTotal * root_size);
256 for(size_t i = 0; i < dimensions[0]; ++i)
258 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
260 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
262 copy_to_array(arr[i][j][k], array,
264 dimensions[2] * dimensions[1] * i +
272 void root_size_calc()
274 root_size = sizeof(T);
278 void copy_to_array(T item, void* array, size_t pos)
280 ((T*)array)[pos] = item;
283 size_t dimensions[MAX_REP_ARRAY_DEPTH];
290 void get_payload_array::root_size_calc<int>()
292 root_size = sizeof(int64_t);
296 void get_payload_array::root_size_calc<std::string>()
298 root_size = sizeof(char*);
302 void get_payload_array::root_size_calc<OC::OCRepresentation>()
304 root_size = sizeof(OCRepPayload*);
308 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
310 ((int64_t*)array)[pos] = item;
314 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
316 ((bool*)array)[pos] = static_cast<bool>(br);
320 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
322 ((char**)array)[pos] = OICStrdup(item.c_str());
326 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
328 ((char**)array)[pos] = OICStrdup(item.c_str());
332 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
334 ((char**)array)[pos] = OICStrdup(item.c_str());
338 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
340 ((OCRepPayload**)array)[pos] = item.getPayload();
343 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
344 const OCRepresentation::AttributeItem& item) const
346 get_payload_array vis{};
347 boost::apply_visitor(vis, m_values[item.attrname()]);
350 switch(item.base_type())
352 case AttributeType::Integer:
353 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
357 case AttributeType::Double:
358 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
362 case AttributeType::Boolean:
363 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
367 case AttributeType::String:
368 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
372 case AttributeType::OCRepresentation:
373 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
374 (OCRepPayload**)vis.array, vis.dimensions);
377 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
378 std::to_string((int)item.base_type()));
382 OCRepPayload* OCRepresentation::getPayload() const
384 OCRepPayload* root = OCRepPayloadCreate();
387 throw std::bad_alloc();
390 OCRepPayloadSetUri(root, getUri().c_str());
392 for(const std::string& type : getResourceTypes())
394 OCRepPayloadAddResourceType(root, type.c_str());
397 for(const std::string& iface : getResourceInterfaces())
399 OCRepPayloadAddInterface(root, iface.c_str());
402 for(auto& val : *this)
406 case AttributeType::Null:
407 OCRepPayloadSetNull(root, val.attrname().c_str());
409 case AttributeType::Integer:
410 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
412 case AttributeType::Double:
413 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
414 val.getValue<double>());
416 case AttributeType::Boolean:
417 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
419 case AttributeType::String:
420 OCRepPayloadSetPropString(root, val.attrname().c_str(),
421 static_cast<std::string>(val).c_str());
423 case AttributeType::OCRepresentation:
424 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
425 static_cast<OCRepresentation>(val).getPayload());
427 case AttributeType::Vector:
428 getPayloadArray(root, val);
431 throw std::logic_error(std::string("Getpayload: Not Implemented") +
432 std::to_string((int)val.type()));
440 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
442 if (dimensions[0] == 0)
444 throw std::logic_error("invalid calcArrayDepth");
446 else if (dimensions[1] == 0)
450 else if (dimensions[2] == 0)
461 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
463 throw std::logic_error("payload_array_helper_copy: unsupported type");
466 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
468 return pl->arr.iArray[index];
471 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
473 return pl->arr.dArray[index];
476 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
478 return pl->arr.bArray[index];
481 std::string OCRepresentation::payload_array_helper_copy<std::string>(
482 size_t index, const OCRepPayloadValue* pl)
484 if (pl->arr.strArray[index])
486 return std::string(pl->arr.strArray[index]);
490 return std::string{};
494 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
495 size_t index, const OCRepPayloadValue* pl)
498 if (pl->arr.objArray[index])
500 r.setPayload(pl->arr.objArray[index]);
506 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
510 std::vector<T> val(pl->arr.dimensions[0]);
512 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
514 val[i] = payload_array_helper_copy<T>(i, pl);
516 this->setValue(std::string(pl->name), val);
520 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
521 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
523 val[i].resize(pl->arr.dimensions[1]);
524 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
526 val[i][j] = payload_array_helper_copy<T>(
527 i * pl->arr.dimensions[1] + j, pl);
530 this->setValue(std::string(pl->name), val);
534 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
535 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
537 val[i].resize(pl->arr.dimensions[1]);
538 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
540 val[i][j].resize(pl->arr.dimensions[2]);
541 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
543 val[i][j][k] = payload_array_helper_copy<T>(
544 pl->arr.dimensions[2] * j +
545 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
551 this->setValue(std::string(pl->name), val);
555 throw std::logic_error("Invalid depth in payload_array_helper");
559 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
565 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
567 case OCREP_PROP_DOUBLE:
568 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
570 case OCREP_PROP_BOOL:
571 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
573 case OCREP_PROP_STRING:
574 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
576 case OCREP_PROP_OBJECT:
577 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
580 throw std::logic_error("setPayload array invalid type");
585 void OCRepresentation::setPayload(const OCRepPayload* pl)
589 OCStringLL* ll = pl->types;
592 addResourceType(ll->value);
599 addResourceInterface(ll->value);
603 OCRepPayloadValue* val = pl->values;
609 case OCREP_PROP_NULL:
613 setValue<int>(val->name, val->i);
615 case OCREP_PROP_DOUBLE:
616 setValue<double>(val->name, val->d);
618 case OCREP_PROP_BOOL:
619 setValue<bool>(val->name, val->b);
621 case OCREP_PROP_STRING:
622 setValue<std::string>(val->name, val->str);
624 case OCREP_PROP_OBJECT:
626 OCRepresentation cur;
627 cur.setPayload(val->obj);
628 setValue<OCRepresentation>(val->name, cur);
631 case OCREP_PROP_ARRAY:
632 setPayloadArray(val);
635 throw std::logic_error(std::string("Not Implemented!") +
636 std::to_string((int)val->type));
643 void OCRepresentation::addChild(const OCRepresentation& rep)
645 m_children.push_back(rep);
648 void OCRepresentation::clearChildren()
653 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
658 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
660 m_children = children;
663 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
665 std::ostringstream ss;
666 if (m_devAddr.flags & OC_SECURE)
670 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
678 if (m_devAddr.flags & OC_IP_USE_V6)
680 ss << '[' << m_devAddr.addr << ']';
684 ss << m_devAddr.addr;
688 ss << ':' << m_devAddr.port;
693 const std::string OCRepresentation::getHost() const
698 void OCRepresentation::setUri(const char* uri)
700 m_uri = uri ? uri : "";
703 void OCRepresentation::setUri(const std::string& uri)
708 std::string OCRepresentation::getUri() const
713 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
715 return m_resourceTypes;
718 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
720 m_resourceTypes = resourceTypes;
723 void OCRepresentation::addResourceType(const std::string& str)
725 m_resourceTypes.push_back(str);
728 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
733 void OCRepresentation::addResourceInterface(const std::string& str)
735 m_interfaces.push_back(str);
738 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
740 m_interfaces = resourceInterfaces;
743 bool OCRepresentation::hasAttribute(const std::string& str) const
745 return m_values.find(str) != m_values.end();
748 bool OCRepresentation::emptyData() const
750 // This logic is meant to determine whether based on the JSON serialization rules
751 // if this object will result in empty JSON. URI is only serialized if there is valid
752 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
753 // child of a default or link item.
754 // Our values array is only printed in the if we are the child of a Batch resource,
755 // the parent in a 'default' situation, or not in a child/parent relationship.
760 else if ((m_interfaceType == InterfaceType::None
761 || m_interfaceType==InterfaceType::DefaultChild
762 || m_interfaceType==InterfaceType::LinkChild)
763 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
767 else if ((m_interfaceType == InterfaceType::None
768 || m_interfaceType == InterfaceType::BatchChild
769 || m_interfaceType == InterfaceType::DefaultParent)
770 && m_values.size()>0)
775 if (m_children.size() > 0)
783 int OCRepresentation::numberOfAttributes() const
785 return m_values.size();
788 bool OCRepresentation::erase(const std::string& str)
790 return m_values.erase(str);
793 void OCRepresentation::setNULL(const std::string& str)
795 m_values[str] = OC::NullType();
798 bool OCRepresentation::isNULL(const std::string& str) const
800 auto x = m_values.find(str);
802 if (m_values.end() != x)
804 return x->second.which() == AttributeValueNullIndex;
808 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
815 std::ostream& operator <<(std::ostream& os, const AttributeType at)
819 case AttributeType::Null:
822 case AttributeType::Integer:
825 case AttributeType::Double:
828 case AttributeType::Boolean:
831 case AttributeType::String:
834 case AttributeType::OCRepresentation:
835 os << "OCRepresentation";
837 case AttributeType::Vector:
845 // STL Container For OCRepresentation
848 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
849 std::map<std::string, AttributeValue>& vals):
850 m_attrName(name), m_values(vals){}
852 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
854 OCRepresentation::AttributeItem attr{key, m_values};
855 return std::move(attr);
858 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
860 OCRepresentation::AttributeItem attr{key, m_values};
861 return std::move(attr);
864 const std::string& OCRepresentation::AttributeItem::attrname() const
869 template<typename T, typename = void>
872 // contains the actual type
874 // contains the inner most vector-type
876 // contains the AttributeType for this item
877 constexpr static AttributeType enum_type =
878 AttributeTypeConvert<T>::type;
879 // contains the AttributeType for this base-type
880 constexpr static AttributeType enum_base_type =
881 AttributeTypeConvert<T>::type;
882 // depth of the vector
883 constexpr static size_t depth = 0;
887 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
890 typedef typename type_info<typename T::value_type>::base_type base_type;
891 constexpr static AttributeType enum_type = AttributeType::Vector;
892 constexpr static AttributeType enum_base_type =
893 type_info<typename T::value_type>::enum_base_type;
894 constexpr static size_t depth = 1 +
895 type_info<typename T::value_type>::depth;
898 struct type_introspection_visitor : boost::static_visitor<>
901 AttributeType base_type;
904 type_introspection_visitor() : boost::static_visitor<>(),
905 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
907 template <typename T>
908 void operator()(T const& /*item*/)
910 type = type_info<T>::enum_type;
911 base_type = type_info<T>::enum_base_type;
912 depth = type_info<T>::depth;
916 AttributeType OCRepresentation::AttributeItem::type() const
918 type_introspection_visitor vis;
919 boost::apply_visitor(vis, m_values[m_attrName]);
923 AttributeType OCRepresentation::AttributeItem::base_type() const
925 type_introspection_visitor vis;
926 boost::apply_visitor(vis, m_values[m_attrName]);
927 return vis.base_type;
930 size_t OCRepresentation::AttributeItem::depth() const
932 type_introspection_visitor vis;
933 boost::apply_visitor(vis, m_values[m_attrName]);
937 OCRepresentation::iterator OCRepresentation::begin()
939 return OCRepresentation::iterator(m_values.begin(), m_values);
942 OCRepresentation::const_iterator OCRepresentation::begin() const
944 return OCRepresentation::const_iterator(m_values.begin(), m_values);
947 OCRepresentation::const_iterator OCRepresentation::cbegin() const
949 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
952 OCRepresentation::iterator OCRepresentation::end()
954 return OCRepresentation::iterator(m_values.end(), m_values);
957 OCRepresentation::const_iterator OCRepresentation::end() const
959 return OCRepresentation::const_iterator(m_values.end(), m_values);
962 OCRepresentation::const_iterator OCRepresentation::cend() const
964 return OCRepresentation::const_iterator(m_values.cend(), m_values);
967 size_t OCRepresentation::size() const
969 return m_values.size();
972 bool OCRepresentation::empty() const
974 return m_values.empty();
977 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
979 return m_iterator == rhs.m_iterator;
982 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
984 return m_iterator != rhs.m_iterator;
987 bool OCRepresentation::const_iterator::operator==(
988 const OCRepresentation::const_iterator& rhs) const
990 return m_iterator == rhs.m_iterator;
993 bool OCRepresentation::const_iterator::operator!=(
994 const OCRepresentation::const_iterator& rhs) const
996 return m_iterator != rhs.m_iterator;
999 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
1004 OCRepresentation::const_iterator::const_reference
1005 OCRepresentation::const_iterator::operator*() const
1010 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1015 OCRepresentation::const_iterator::const_pointer
1016 OCRepresentation::const_iterator::operator->() const
1021 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1024 if (m_iterator != m_item.m_values.end())
1026 m_item.m_attrName = m_iterator->first;
1030 m_item.m_attrName = "";
1035 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1038 if (m_iterator != m_item.m_values.end())
1040 m_item.m_attrName = m_iterator->first;
1044 m_item.m_attrName = "";
1049 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1051 OCRepresentation::iterator itr(*this);
1056 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1058 OCRepresentation::const_iterator itr(*this);
1063 struct to_string_visitor : boost::static_visitor<>
1066 template <typename T>
1067 void operator()(T const& item)
1069 str = boost::lexical_cast<std::string>(item);
1072 template <typename T>
1073 void operator()(std::vector<T> const& item)
1075 to_string_visitor vis;
1076 std::ostringstream stream;
1079 for(const auto& i : item)
1082 stream << vis.str << " ";
1090 void to_string_visitor::operator()(bool const& item)
1092 str = item ? "true" : "false";
1096 void to_string_visitor::operator()(std::string const& item)
1102 void to_string_visitor::operator()(NullType const& /*item*/)
1108 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1110 str = "OC::OCRepresentation";
1113 std::string OCRepresentation::getValueToString(const std::string& key) const
1115 auto x = m_values.find(key);
1116 if (x != m_values.end())
1118 to_string_visitor vis;
1119 boost::apply_visitor(vis, x->second);
1120 return std::move(vis.str);
1126 std::string OCRepresentation::AttributeItem::getValueToString() const
1128 to_string_visitor vis;
1129 boost::apply_visitor(vis, m_values[m_attrName]);
1130 return std::move(vis.str);
1133 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1135 os << ai.getValueToString();