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://";
43 void MessageContainer::setPayload(const OCPayload* rep)
47 case PAYLOAD_TYPE_REPRESENTATION:
48 setPayload(reinterpret_cast<const OCRepPayload*>(rep));
50 case PAYLOAD_TYPE_DEVICE:
51 setPayload(reinterpret_cast<const OCDevicePayload*>(rep));
53 case PAYLOAD_TYPE_PLATFORM:
54 setPayload(reinterpret_cast<const OCPlatformPayload*>(rep));
57 throw OC::OCException("Invalid Payload type in setPayload");
62 void MessageContainer::setPayload(const OCDevicePayload* payload)
65 rep.setUri(payload->uri);
66 char uuidString[UUID_STRING_SIZE];
67 if(payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString))
69 rep[OC_RSRVD_DEVICE_ID] = std::string(uuidString);
73 rep[OC_RSRVD_DEVICE_ID] = std::string();
75 rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
76 std::string(payload->deviceName) :
78 rep[OC_RSRVD_SPEC_VERSION] = payload->specVersion ?
79 std::string(payload->specVersion) :
81 rep[OC_RSRVD_DATA_MODEL_VERSION] = payload->dataModelVersion ?
82 std::string(payload->dataModelVersion) :
84 m_reps.push_back(std::move(rep));
87 void MessageContainer::setPayload(const OCPlatformPayload* payload)
90 rep.setUri(payload->uri);
92 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
93 std::string(payload->info.platformID) :
95 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
96 std::string(payload->info.manufacturerName) :
98 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
99 std::string(payload->info.manufacturerUrl) :
101 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
102 std::string(payload->info.modelNumber) :
104 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
105 std::string(payload->info.dateOfManufacture) :
107 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
108 std::string(payload->info.platformVersion) :
110 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
111 std::string(payload->info.operatingSystemVersion) :
113 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
114 std::string(payload->info.hardwareVersion) :
116 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
117 std::string(payload->info.firmwareVersion) :
119 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
120 std::string(payload->info.supportUrl) :
122 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
123 std::string(payload->info.systemTime) :
126 m_reps.push_back(std::move(rep));
129 void MessageContainer::setPayload(const OCRepPayload* payload)
131 const OCRepPayload* pl = payload;
134 OCRepresentation cur;
138 this->addRepresentation(cur);
142 OCRepPayload* MessageContainer::getPayload() const
144 OCRepPayload* root = nullptr;
145 for(const auto& r : representations())
149 root = r.getPayload();
153 OCRepPayloadAppend(root, r.getPayload());
160 const std::vector<OCRepresentation>& MessageContainer::representations() const
165 void MessageContainer::addRepresentation(const OCRepresentation& rep)
167 m_reps.push_back(rep);
173 struct get_payload_array: boost::static_visitor<>
176 void operator()(T& /*arr*/)
178 throw std::logic_error("Invalid calc_dimensions_visitor type");
182 void operator()(std::vector<T>& arr)
185 dimensions[0] = arr.size();
188 dimTotal = calcDimTotal(dimensions);
190 array = (void*)OICMalloc(dimTotal * root_size);
192 for(size_t i = 0; i < dimensions[0]; ++i)
194 copy_to_array(arr[i], array, i);
199 void operator()(std::vector<std::vector<T>>& arr)
202 dimensions[0] = arr.size();
205 for(size_t i = 0; i < arr.size(); ++i)
207 dimensions[1] = std::max(dimensions[1], arr[i].size());
209 dimTotal = calcDimTotal(dimensions);
210 array = (void*)OICCalloc(1, dimTotal * root_size);
212 for(size_t i = 0; i < dimensions[0]; ++i)
214 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
216 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
221 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
224 dimensions[0] = arr.size();
227 for(size_t i = 0; i < arr.size(); ++i)
229 dimensions[1] = std::max(dimensions[1], arr[i].size());
231 for(size_t j = 0; j < arr[i].size(); ++j)
233 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
237 dimTotal = calcDimTotal(dimensions);
238 array = (void*)OICCalloc(1, dimTotal * root_size);
240 for(size_t i = 0; i < dimensions[0]; ++i)
242 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
244 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
246 copy_to_array(arr[i][j][k], array,
248 dimensions[2] * dimensions[1] * i +
256 void root_size_calc()
258 root_size = sizeof(T);
262 void copy_to_array(T item, void* array, size_t pos)
264 ((T*)array)[pos] = item;
267 size_t dimensions[MAX_REP_ARRAY_DEPTH];
274 void get_payload_array::root_size_calc<int>()
276 root_size = sizeof(int64_t);
280 void get_payload_array::root_size_calc<std::string>()
282 root_size = sizeof(char*);
286 void get_payload_array::root_size_calc<OC::OCRepresentation>()
288 root_size = sizeof(OCRepPayload*);
292 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
294 ((int64_t*)array)[pos] = item;
298 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
300 ((bool*)array)[pos] = static_cast<bool>(br);
304 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
306 ((char**)array)[pos] = OICStrdup(item.c_str());
310 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
312 ((char**)array)[pos] = OICStrdup(item.c_str());
316 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
318 ((char**)array)[pos] = OICStrdup(item.c_str());
322 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
324 ((OCRepPayload**)array)[pos] = item.getPayload();
327 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
328 const OCRepresentation::AttributeItem& item) const
330 get_payload_array vis{};
331 boost::apply_visitor(vis, m_values[item.attrname()]);
334 switch(item.base_type())
336 case AttributeType::Integer:
337 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
341 case AttributeType::Double:
342 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
346 case AttributeType::Boolean:
347 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
351 case AttributeType::String:
352 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
356 case AttributeType::OCRepresentation:
357 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
358 (OCRepPayload**)vis.array, vis.dimensions);
361 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
362 std::to_string((int)item.base_type()));
366 OCRepPayload* OCRepresentation::getPayload() const
368 OCRepPayload* root = OCRepPayloadCreate();
371 throw std::bad_alloc();
374 OCRepPayloadSetUri(root, getUri().c_str());
376 for(const std::string& type : getResourceTypes())
378 OCRepPayloadAddResourceType(root, type.c_str());
381 for(const std::string& iface : getResourceInterfaces())
383 OCRepPayloadAddInterface(root, iface.c_str());
386 for(auto& val : *this)
390 case AttributeType::Null:
391 OCRepPayloadSetNull(root, val.attrname().c_str());
393 case AttributeType::Integer:
394 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
396 case AttributeType::Double:
397 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
398 val.getValue<double>());
400 case AttributeType::Boolean:
401 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
403 case AttributeType::String:
404 OCRepPayloadSetPropString(root, val.attrname().c_str(),
405 static_cast<std::string>(val).c_str());
407 case AttributeType::OCRepresentation:
408 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
409 static_cast<OCRepresentation>(val).getPayload());
411 case AttributeType::Vector:
412 getPayloadArray(root, val);
415 throw std::logic_error(std::string("Getpayload: Not Implemented") +
416 std::to_string((int)val.type()));
424 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
426 if(dimensions[0] == 0)
428 throw std::logic_error("invalid calcArrayDepth");
430 else if(dimensions[1] == 0)
434 else if (dimensions[2] == 0)
445 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
447 throw std::logic_error("payload_array_helper_copy: unsupported type");
450 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
452 return pl->arr.iArray[index];
455 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
457 return pl->arr.dArray[index];
460 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
462 return pl->arr.bArray[index];
465 std::string OCRepresentation::payload_array_helper_copy<std::string>(
466 size_t index, const OCRepPayloadValue* pl)
468 if (pl->arr.strArray[index])
470 return std::string(pl->arr.strArray[index]);
474 return std::string{};
478 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
479 size_t index, const OCRepPayloadValue* pl)
482 if (pl->arr.objArray[index])
484 r.setPayload(pl->arr.objArray[index]);
490 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
494 std::vector<T> val(pl->arr.dimensions[0]);
496 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
498 val[i] = payload_array_helper_copy<T>(i, pl);
500 this->setValue(std::string(pl->name), val);
504 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
505 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
507 val[i].resize(pl->arr.dimensions[1]);
508 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
510 val[i][j] = payload_array_helper_copy<T>(
511 i * pl->arr.dimensions[1] + j, pl);
514 this->setValue(std::string(pl->name), val);
518 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
519 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
521 val[i].resize(pl->arr.dimensions[1]);
522 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
524 val[i][j].resize(pl->arr.dimensions[2]);
525 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
527 val[i][j][k] = payload_array_helper_copy<T>(
528 pl->arr.dimensions[2] * j +
529 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
535 this->setValue(std::string(pl->name), val);
539 throw std::logic_error("Invalid depth in payload_array_helper");
543 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
549 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
551 case OCREP_PROP_DOUBLE:
552 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
554 case OCREP_PROP_BOOL:
555 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
557 case OCREP_PROP_STRING:
558 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
560 case OCREP_PROP_OBJECT:
561 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
564 throw std::logic_error("setPayload array invalid type");
569 void OCRepresentation::setPayload(const OCRepPayload* pl)
573 OCStringLL* ll = pl->types;
576 addResourceType(ll->value);
583 addResourceInterface(ll->value);
587 OCRepPayloadValue* val = pl->values;
593 case OCREP_PROP_NULL:
597 setValue<int>(val->name, val->i);
599 case OCREP_PROP_DOUBLE:
600 setValue<double>(val->name, val->d);
602 case OCREP_PROP_BOOL:
603 setValue<bool>(val->name, val->b);
605 case OCREP_PROP_STRING:
606 setValue<std::string>(val->name, val->str);
608 case OCREP_PROP_OBJECT:
610 OCRepresentation cur;
611 cur.setPayload(val->obj);
612 setValue<OCRepresentation>(val->name, cur);
615 case OCREP_PROP_ARRAY:
616 setPayloadArray(val);
619 throw std::logic_error(std::string("Not Implemented!") +
620 std::to_string((int)val->type));
627 void OCRepresentation::addChild(const OCRepresentation& rep)
629 m_children.push_back(rep);
632 void OCRepresentation::clearChildren()
637 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
642 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
644 m_children = children;
647 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
649 std::ostringstream ss;
650 if (m_devAddr.flags & OC_SECURE)
655 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
664 if (m_devAddr.flags & OC_IP_USE_V6)
666 ss << '[' << m_devAddr.addr << ']';
670 ss << m_devAddr.addr;
674 ss << ':' << m_devAddr.port;
679 const std::string OCRepresentation::getHost() const
684 void OCRepresentation::setUri(const char* uri)
686 m_uri = uri ? uri : "";
689 void OCRepresentation::setUri(const std::string& uri)
694 std::string OCRepresentation::getUri() const
699 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
701 return m_resourceTypes;
704 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
706 m_resourceTypes = resourceTypes;
709 void OCRepresentation::addResourceType(const std::string& str)
711 m_resourceTypes.push_back(str);
714 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
719 void OCRepresentation::addResourceInterface(const std::string& str)
721 m_interfaces.push_back(str);
724 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
726 m_interfaces = resourceInterfaces;
729 bool OCRepresentation::hasAttribute(const std::string& str) const
731 return m_values.find(str) != m_values.end();
734 bool OCRepresentation::emptyData() const
736 // This logic is meant to determine whether based on the JSON serialization rules
737 // if this object will result in empty JSON. URI is only serialized if there is valid
738 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
739 // child of a default or link item.
740 // Our values array is only printed in the if we are the child of a Batch resource,
741 // the parent in a 'default' situation, or not in a child/parent relationship.
746 else if ((m_interfaceType == InterfaceType::None
747 || m_interfaceType==InterfaceType::DefaultChild
748 || m_interfaceType==InterfaceType::LinkChild)
749 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
753 else if((m_interfaceType == InterfaceType::None
754 || m_interfaceType == InterfaceType::BatchChild
755 || m_interfaceType == InterfaceType::DefaultParent)
756 && m_values.size()>0)
761 if(m_children.size() > 0)
769 int OCRepresentation::numberOfAttributes() const
771 return m_values.size();
774 bool OCRepresentation::erase(const std::string& str)
776 return m_values.erase(str);
779 void OCRepresentation::setNULL(const std::string& str)
781 m_values[str] = OC::NullType();
784 bool OCRepresentation::isNULL(const std::string& str) const
786 auto x = m_values.find(str);
788 if(m_values.end() != x)
790 return x->second.which() == AttributeValueNullIndex;
794 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
801 std::ostream& operator <<(std::ostream& os, const AttributeType at)
805 case AttributeType::Null:
808 case AttributeType::Integer:
811 case AttributeType::Double:
814 case AttributeType::Boolean:
817 case AttributeType::String:
820 case AttributeType::OCRepresentation:
821 os << "OCRepresentation";
823 case AttributeType::Vector:
831 // STL Container For OCRepresentation
834 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
835 std::map<std::string, AttributeValue>& vals):
836 m_attrName(name), m_values(vals){}
838 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
840 OCRepresentation::AttributeItem attr{key, m_values};
841 return std::move(attr);
844 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
846 OCRepresentation::AttributeItem attr{key, m_values};
847 return std::move(attr);
850 const std::string& OCRepresentation::AttributeItem::attrname() const
855 template<typename T, typename = void>
858 // contains the actual type
860 // contains the inner most vector-type
862 // contains the AttributeType for this item
863 constexpr static AttributeType enum_type =
864 AttributeTypeConvert<T>::type;
865 // contains the AttributeType for this base-type
866 constexpr static AttributeType enum_base_type =
867 AttributeTypeConvert<T>::type;
868 // depth of the vector
869 constexpr static size_t depth = 0;
873 struct type_info<T, typename std::enable_if<is_vector<T>::value>::type>
876 typedef typename type_info<typename T::value_type>::base_type base_type;
877 constexpr static AttributeType enum_type = AttributeType::Vector;
878 constexpr static AttributeType enum_base_type =
879 type_info<typename T::value_type>::enum_base_type;
880 constexpr static size_t depth = 1 +
881 type_info<typename T::value_type>::depth;
884 struct type_introspection_visitor : boost::static_visitor<>
887 AttributeType base_type;
890 type_introspection_visitor() : boost::static_visitor<>(),
891 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
893 template <typename T>
894 void operator()(T const& /*item*/)
896 type = type_info<T>::enum_type;
897 base_type = type_info<T>::enum_base_type;
898 depth = type_info<T>::depth;
902 AttributeType OCRepresentation::AttributeItem::type() const
904 type_introspection_visitor vis;
905 boost::apply_visitor(vis, m_values[m_attrName]);
909 AttributeType OCRepresentation::AttributeItem::base_type() const
911 type_introspection_visitor vis;
912 boost::apply_visitor(vis, m_values[m_attrName]);
913 return vis.base_type;
916 size_t OCRepresentation::AttributeItem::depth() const
918 type_introspection_visitor vis;
919 boost::apply_visitor(vis, m_values[m_attrName]);
923 OCRepresentation::iterator OCRepresentation::begin()
925 return OCRepresentation::iterator(m_values.begin(), m_values);
928 OCRepresentation::const_iterator OCRepresentation::begin() const
930 return OCRepresentation::const_iterator(m_values.begin(), m_values);
933 OCRepresentation::const_iterator OCRepresentation::cbegin() const
935 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
938 OCRepresentation::iterator OCRepresentation::end()
940 return OCRepresentation::iterator(m_values.end(), m_values);
943 OCRepresentation::const_iterator OCRepresentation::end() const
945 return OCRepresentation::const_iterator(m_values.end(), m_values);
948 OCRepresentation::const_iterator OCRepresentation::cend() const
950 return OCRepresentation::const_iterator(m_values.cend(), m_values);
953 size_t OCRepresentation::size() const
955 return m_values.size();
958 bool OCRepresentation::empty() const
960 return m_values.empty();
963 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
965 return m_iterator == rhs.m_iterator;
968 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
970 return m_iterator != rhs.m_iterator;
973 bool OCRepresentation::const_iterator::operator==(
974 const OCRepresentation::const_iterator& rhs) const
976 return m_iterator == rhs.m_iterator;
979 bool OCRepresentation::const_iterator::operator!=(
980 const OCRepresentation::const_iterator& rhs) const
982 return m_iterator != rhs.m_iterator;
985 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
990 OCRepresentation::const_iterator::const_reference
991 OCRepresentation::const_iterator::operator*() const
996 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1001 OCRepresentation::const_iterator::const_pointer
1002 OCRepresentation::const_iterator::operator->() const
1007 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1010 if(m_iterator != m_item.m_values.end())
1012 m_item.m_attrName = m_iterator->first;
1016 m_item.m_attrName = "";
1021 OCRepresentation::const_iterator& OCRepresentation::const_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::iterator OCRepresentation::iterator::operator++(int)
1037 OCRepresentation::iterator itr(*this);
1042 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1044 OCRepresentation::const_iterator itr(*this);
1049 struct to_string_visitor : boost::static_visitor<>
1052 template <typename T>
1053 void operator()(T const& item)
1055 str = boost::lexical_cast<std::string>(item);
1058 template <typename T>
1059 void operator()(std::vector<T> const& item)
1061 to_string_visitor vis;
1062 std::ostringstream stream;
1065 for(const auto& i : item)
1068 stream << vis.str << " ";
1076 void to_string_visitor::operator()(bool const& item)
1078 str = item ? "true" : "false";
1082 void to_string_visitor::operator()(std::string const& item)
1088 void to_string_visitor::operator()(NullType const& /*item*/)
1094 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1096 str = "OC::OCRepresentation";
1099 std::string OCRepresentation::getValueToString(const std::string& key) const
1101 auto x = m_values.find(key);
1102 if(x != m_values.end())
1104 to_string_visitor vis;
1105 boost::apply_visitor(vis, x->second);
1106 return std::move(vis.str);
1112 std::string OCRepresentation::AttributeItem::getValueToString() const
1114 to_string_visitor vis;
1115 boost::apply_visitor(vis, m_values[m_attrName]);
1116 return std::move(vis.str);
1119 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1121 os << ai.getValueToString();