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>
34 #include "ocpayload.h"
36 #include "oic_malloc.h"
37 #include "oic_string.h"
41 static const char COAP[] = "coap://";
42 static const char COAPS[] = "coaps://";
43 static const char COAP_TCP[] = "coap+tcp://";
45 void MessageContainer::setPayload(const OCPayload* rep)
54 case PAYLOAD_TYPE_REPRESENTATION:
55 setPayload(reinterpret_cast<const OCRepPayload*>(rep));
58 throw OC::OCException("Invalid Payload type in setPayload");
63 void MessageContainer::setPayload(const OCRepPayload* payload)
65 const OCRepPayload* pl = payload;
72 this->addRepresentation(cur);
76 OCRepPayload* MessageContainer::getPayload() const
78 OCRepPayload* root = nullptr;
79 for(const auto& r : representations())
83 root = r.getPayload();
87 OCRepPayloadAppend(root, r.getPayload());
94 const std::vector<OCRepresentation>& MessageContainer::representations() const
99 void MessageContainer::addRepresentation(const OCRepresentation& rep)
101 m_reps.push_back(rep);
107 struct get_payload_array: boost::static_visitor<>
110 void operator()(T& /*arr*/)
112 throw std::logic_error("Invalid calc_dimensions_visitor type");
116 void operator()(std::vector<T>& arr)
119 dimensions[0] = arr.size();
122 dimTotal = calcDimTotal(dimensions);
124 array = (void*)OICMalloc(dimTotal * root_size);
126 for(size_t i = 0; i < dimensions[0]; ++i)
128 copy_to_array(arr[i], array, i);
133 void operator()(std::vector<std::vector<T>>& arr)
136 dimensions[0] = arr.size();
139 for(size_t i = 0; i < arr.size(); ++i)
141 dimensions[1] = std::max(dimensions[1], arr[i].size());
143 dimTotal = calcDimTotal(dimensions);
144 array = (void*)OICCalloc(1, dimTotal * root_size);
146 for(size_t i = 0; i < dimensions[0]; ++i)
148 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
150 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
155 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
158 dimensions[0] = arr.size();
161 for(size_t i = 0; i < arr.size(); ++i)
163 dimensions[1] = std::max(dimensions[1], arr[i].size());
165 for(size_t j = 0; j < arr[i].size(); ++j)
167 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
171 dimTotal = calcDimTotal(dimensions);
172 array = (void*)OICCalloc(1, dimTotal * root_size);
174 for(size_t i = 0; i < dimensions[0]; ++i)
176 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
178 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
180 copy_to_array(arr[i][j][k], array,
182 dimensions[2] * dimensions[1] * i +
190 void root_size_calc()
192 root_size = sizeof(T);
196 void copy_to_array(T item, void* array, size_t pos)
198 ((T*)array)[pos] = item;
201 size_t dimensions[MAX_REP_ARRAY_DEPTH];
208 void get_payload_array::root_size_calc<int>()
210 root_size = sizeof(int64_t);
214 void get_payload_array::root_size_calc<std::string>()
216 root_size = sizeof(char*);
220 void get_payload_array::root_size_calc<OC::OCRepresentation>()
222 root_size = sizeof(OCRepPayload*);
226 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
228 ((int64_t*)array)[pos] = item;
231 #if !defined(_MSC_VER)
233 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
235 ((bool*)array)[pos] = static_cast<bool>(br);
240 void get_payload_array::copy_to_array(std::string item, void* array, size_t pos)
242 ((char**)array)[pos] = OICStrdup(item.c_str());
246 void get_payload_array::copy_to_array(std::string& item, void* array, size_t pos)
248 ((char**)array)[pos] = OICStrdup(item.c_str());
252 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
254 ((char**)array)[pos] = OICStrdup(item.c_str());
258 void get_payload_array::copy_to_array(OCByteString item, void *array, size_t pos)
260 ((OCByteString *)array)[pos] = item;
264 void get_payload_array::copy_to_array(OCByteString &item, void *array, size_t pos)
266 ((OCByteString *)array)[pos] = item;
270 void get_payload_array::copy_to_array(const OCByteString &item, void *array, size_t pos)
272 ((OCByteString *)array)[pos] = item;
276 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
278 ((OCRepPayload**)array)[pos] = item.getPayload();
281 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
282 const OCRepresentation::AttributeItem& item) const
284 get_payload_array vis{};
285 boost::apply_visitor(vis, m_values[item.attrname()]);
288 switch(item.base_type())
290 case AttributeType::Integer:
291 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
295 case AttributeType::Double:
296 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
300 case AttributeType::Boolean:
301 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
305 case AttributeType::String:
306 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
310 case AttributeType::OCByteString:
311 OCRepPayloadSetByteStringArrayAsOwner(payload, item.attrname().c_str(),
312 (OCByteString *)vis.array, vis.dimensions);
314 case AttributeType::OCRepresentation:
315 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
316 (OCRepPayload**)vis.array, vis.dimensions);
319 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
320 std::to_string((int)item.base_type()));
324 OCRepPayload* OCRepresentation::getPayload() const
326 OCRepPayload* root = OCRepPayloadCreate();
329 throw std::bad_alloc();
332 OCRepPayloadSetUri(root, getUri().c_str());
334 for(const std::string& type : getResourceTypes())
336 OCRepPayloadAddResourceType(root, type.c_str());
339 for(const std::string& iface : getResourceInterfaces())
341 OCRepPayloadAddInterface(root, iface.c_str());
344 for(auto& val : *this)
348 case AttributeType::Null:
349 OCRepPayloadSetNull(root, val.attrname().c_str());
351 case AttributeType::Integer:
352 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
354 case AttributeType::Double:
355 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
356 val.getValue<double>());
358 case AttributeType::Boolean:
359 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
361 case AttributeType::String:
362 OCRepPayloadSetPropString(root, val.attrname().c_str(),
363 static_cast<std::string>(val).c_str());
365 case AttributeType::OCByteString:
366 OCRepPayloadSetPropByteString(root, val.attrname().c_str(), val.getValue<OCByteString>());
368 case AttributeType::OCRepresentation:
369 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
370 static_cast<OCRepresentation>(val).getPayload());
372 case AttributeType::Vector:
373 getPayloadArray(root, val);
375 case AttributeType::Binary:
376 OCRepPayloadSetPropByteString(root, val.attrname().c_str(),
377 OCByteString{const_cast<uint8_t*>(val.getValue<std::vector<uint8_t>>().data()),
378 val.getValue<std::vector<uint8_t>>().size()});
381 throw std::logic_error(std::string("Getpayload: Not Implemented") +
382 std::to_string((int)val.type()));
390 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
392 if (dimensions[0] == 0)
394 throw std::logic_error("invalid calcArrayDepth");
396 else if (dimensions[1] == 0)
400 else if (dimensions[2] == 0)
411 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
413 throw std::logic_error("payload_array_helper_copy: unsupported type");
416 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
418 return pl->arr.iArray[index];
421 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
423 return pl->arr.dArray[index];
426 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
428 return pl->arr.bArray[index];
431 std::string OCRepresentation::payload_array_helper_copy<std::string>(
432 size_t index, const OCRepPayloadValue* pl)
434 if (pl->arr.strArray[index])
436 return std::string(pl->arr.strArray[index]);
440 return std::string{};
445 OCByteString OCRepresentation::payload_array_helper_copy<OCByteString>(
446 size_t index, const OCRepPayloadValue *pl)
448 OCByteString result {NULL, 0};
449 if (pl->arr.ocByteStrArray[index].len)
451 result = (pl->arr.ocByteStrArray[index]);
457 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
458 size_t index, const OCRepPayloadValue* pl)
461 if (pl->arr.objArray[index])
463 r.setPayload(pl->arr.objArray[index]);
469 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
473 std::vector<T> val(pl->arr.dimensions[0]);
475 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
477 val[i] = payload_array_helper_copy<T>(i, pl);
479 this->setValue(std::string(pl->name), val);
483 std::vector<std::vector<T>> val(pl->arr.dimensions[0]);
484 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
486 val[i].resize(pl->arr.dimensions[1]);
487 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
489 val[i][j] = payload_array_helper_copy<T>(
490 i * pl->arr.dimensions[1] + j, pl);
493 this->setValue(std::string(pl->name), val);
497 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
498 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
500 val[i].resize(pl->arr.dimensions[1]);
501 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
503 val[i][j].resize(pl->arr.dimensions[2]);
504 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
506 val[i][j][k] = payload_array_helper_copy<T>(
507 pl->arr.dimensions[2] * j +
508 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
514 this->setValue(std::string(pl->name), val);
518 throw std::logic_error("Invalid depth in payload_array_helper");
522 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
528 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
530 case OCREP_PROP_DOUBLE:
531 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
533 case OCREP_PROP_BOOL:
534 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
536 case OCREP_PROP_STRING:
537 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
539 case OCREP_PROP_BYTE_STRING:
540 payload_array_helper<OCByteString>(pl, calcArrayDepth(pl->arr.dimensions));
542 case OCREP_PROP_OBJECT:
543 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
546 throw std::logic_error("setPayload array invalid type");
551 void OCRepresentation::setPayload(const OCRepPayload* pl)
555 OCStringLL* ll = pl->types;
558 addResourceType(ll->value);
565 addResourceInterface(ll->value);
569 OCRepPayloadValue* val = pl->values;
575 case OCREP_PROP_NULL:
579 setValue<int>(val->name, val->i);
581 case OCREP_PROP_DOUBLE:
582 setValue<double>(val->name, val->d);
584 case OCREP_PROP_BOOL:
585 setValue<bool>(val->name, val->b);
587 case OCREP_PROP_STRING:
588 setValue<std::string>(val->name, val->str);
590 case OCREP_PROP_OBJECT:
592 OCRepresentation cur;
593 cur.setPayload(val->obj);
594 setValue<OCRepresentation>(val->name, cur);
597 case OCREP_PROP_ARRAY:
598 setPayloadArray(val);
600 case OCREP_PROP_BYTE_STRING:
603 (val->ocByteStr.bytes, val->ocByteStr.bytes + val->ocByteStr.len)
607 throw std::logic_error(std::string("Not Implemented!") +
608 std::to_string((int)val->type));
615 void OCRepresentation::addChild(const OCRepresentation& rep)
617 m_children.push_back(rep);
620 void OCRepresentation::clearChildren()
625 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
630 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
632 m_children = children;
635 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
637 std::ostringstream ss;
638 if (m_devAddr.flags & OC_SECURE)
642 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
650 if (m_devAddr.flags & OC_IP_USE_V6)
652 ss << '[' << m_devAddr.addr << ']';
656 ss << m_devAddr.addr;
660 ss << ':' << m_devAddr.port;
665 const std::string OCRepresentation::getHost() const
670 void OCRepresentation::setUri(const char* uri)
672 m_uri = uri ? uri : "";
675 void OCRepresentation::setUri(const std::string& uri)
680 std::string OCRepresentation::getUri() const
685 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
687 return m_resourceTypes;
690 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
692 m_resourceTypes = resourceTypes;
695 void OCRepresentation::addResourceType(const std::string& str)
697 m_resourceTypes.push_back(str);
700 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
705 void OCRepresentation::addResourceInterface(const std::string& str)
707 m_interfaces.push_back(str);
710 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
712 m_interfaces = resourceInterfaces;
715 const std::vector<std::string>& OCRepresentation::getDataModelVersions() const
717 return m_dataModelVersions;
720 void OCRepresentation::addDataModelVersion(const std::string& str)
722 m_dataModelVersions.push_back(str);
725 bool OCRepresentation::hasAttribute(const std::string& str) const
727 return m_values.find(str) != m_values.end();
730 bool OCRepresentation::emptyData() const
732 // This logic is meant to determine whether based on the JSON serialization rules
733 // if this object will result in empty JSON. URI is only serialized if there is valid
734 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
735 // child of a default or link item.
736 // Our values array is only printed in the if we are the child of a Batch resource,
737 // the parent in a 'default' situation, or not in a child/parent relationship.
742 else if ((m_interfaceType == InterfaceType::None
743 || m_interfaceType==InterfaceType::DefaultChild
744 || m_interfaceType==InterfaceType::LinkChild)
745 && (m_resourceTypes.size()>0 || m_interfaces.size()>0
746 || m_dataModelVersions.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::OCByteString:
818 os << "OCByteString";
820 case AttributeType::OCRepresentation:
821 os << "OCRepresentation";
823 case AttributeType::Vector:
826 case AttributeType::Binary:
833 // STL Container For OCRepresentation
836 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
837 std::map<std::string, AttributeValue>& vals):
838 m_attrName(name), m_values(vals){}
840 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
842 OCRepresentation::AttributeItem attr{key, m_values};
843 return std::move(attr);
846 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
848 OCRepresentation::AttributeItem attr{key, m_values};
849 return std::move(attr);
852 const std::string& OCRepresentation::AttributeItem::attrname() const
857 template<typename T, typename = void>
860 // contains the actual type
862 // contains the inner most vector-type
864 // contains the AttributeType for this item
865 BOOST_STATIC_CONSTEXPR AttributeType enum_type =
866 AttributeTypeConvert<T>::type;
867 // contains the AttributeType for this base-type
868 BOOST_STATIC_CONSTEXPR AttributeType enum_base_type =
869 AttributeTypeConvert<T>::type;
870 // depth of the vector
871 BOOST_STATIC_CONSTEXPR size_t depth = 0;
877 typename std::enable_if<
878 is_vector<T>::value &&
879 !std::is_same<uint8_t, typename T::value_type>::value
884 typedef typename type_info<typename T::value_type>::base_type base_type;
885 BOOST_STATIC_CONSTEXPR AttributeType enum_type = AttributeType::Vector;
886 BOOST_STATIC_CONSTEXPR AttributeType enum_base_type =
887 type_info<typename T::value_type>::enum_base_type;
888 BOOST_STATIC_CONSTEXPR size_t depth = 1 +
889 type_info<typename T::value_type>::depth;
892 // special case for binary data, which is a std::vector<uint8_t>
894 struct type_info<std::vector<uint8_t>, void>
896 typedef std::vector<uint8_t> type;
897 typedef std::vector<uint8_t> base_type;
898 BOOST_STATIC_CONSTEXPR AttributeType enum_type = AttributeType::Binary;
899 BOOST_STATIC_CONSTEXPR AttributeType enum_base_type = AttributeType::Binary;
900 BOOST_STATIC_CONSTEXPR size_t depth = 0;
904 struct type_introspection_visitor : boost::static_visitor<>
907 AttributeType base_type;
910 type_introspection_visitor() : boost::static_visitor<>(),
911 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
913 template <typename T>
914 void operator()(T const& /*item*/)
916 type = type_info<T>::enum_type;
917 base_type = type_info<T>::enum_base_type;
918 depth = type_info<T>::depth;
922 AttributeType OCRepresentation::AttributeItem::type() const
924 type_introspection_visitor vis;
925 boost::apply_visitor(vis, m_values[m_attrName]);
929 AttributeType OCRepresentation::AttributeItem::base_type() const
931 type_introspection_visitor vis;
932 boost::apply_visitor(vis, m_values[m_attrName]);
933 return vis.base_type;
936 size_t OCRepresentation::AttributeItem::depth() const
938 type_introspection_visitor vis;
939 boost::apply_visitor(vis, m_values[m_attrName]);
943 OCRepresentation::iterator OCRepresentation::begin()
945 return OCRepresentation::iterator(m_values.begin(), m_values);
948 OCRepresentation::const_iterator OCRepresentation::begin() const
950 return OCRepresentation::const_iterator(m_values.begin(), m_values);
953 OCRepresentation::const_iterator OCRepresentation::cbegin() const
955 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
958 OCRepresentation::iterator OCRepresentation::end()
960 return OCRepresentation::iterator(m_values.end(), m_values);
963 OCRepresentation::const_iterator OCRepresentation::end() const
965 return OCRepresentation::const_iterator(m_values.end(), m_values);
968 OCRepresentation::const_iterator OCRepresentation::cend() const
970 return OCRepresentation::const_iterator(m_values.cend(), m_values);
973 size_t OCRepresentation::size() const
975 return m_values.size();
978 bool OCRepresentation::empty() const
980 return m_values.empty();
983 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
985 return m_iterator == rhs.m_iterator;
988 bool OCRepresentation::iterator::operator!=(const OCRepresentation::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 bool OCRepresentation::const_iterator::operator!=(
1000 const OCRepresentation::const_iterator& rhs) const
1002 return m_iterator != rhs.m_iterator;
1005 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
1010 OCRepresentation::const_iterator::const_reference
1011 OCRepresentation::const_iterator::operator*() const
1016 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1021 OCRepresentation::const_iterator::const_pointer
1022 OCRepresentation::const_iterator::operator->() const
1027 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1030 if (m_iterator != m_item.m_values.end())
1032 m_item.m_attrName = m_iterator->first;
1036 m_item.m_attrName = "";
1041 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1044 if (m_iterator != m_item.m_values.end())
1046 m_item.m_attrName = m_iterator->first;
1050 m_item.m_attrName = "";
1055 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1057 OCRepresentation::iterator itr(*this);
1062 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1064 OCRepresentation::const_iterator itr(*this);
1069 struct to_string_visitor : boost::static_visitor<>
1072 template <typename T>
1073 void operator()(T const& item)
1075 str = boost::lexical_cast<std::string>(item);
1078 template <typename T>
1079 void operator()(std::vector<T> const& item)
1081 to_string_visitor vis;
1082 std::ostringstream stream;
1085 for(const auto& i : item)
1088 stream << vis.str << " ";
1096 void to_string_visitor::operator()(bool const& item)
1098 str = item ? "true" : "false";
1102 void to_string_visitor::operator()(std::string const& item)
1108 void to_string_visitor::operator()(NullType const& /*item*/)
1114 void to_string_visitor::operator()(std::vector<uint8_t> const &item)
1116 std::ostringstream stream;
1117 for (size_t i = 0; i < item.size(); i++ )
1119 stream << "\\x" << std::hex << (int) item[i];
1125 void to_string_visitor::operator()(OCByteString const &item)
1127 std::vector<uint8_t> v(item.bytes, item.bytes + item.len);
1132 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1134 str = "OC::OCRepresentation";
1137 std::string OCRepresentation::getValueToString(const std::string& key) const
1139 auto x = m_values.find(key);
1140 if (x != m_values.end())
1142 to_string_visitor vis;
1143 boost::apply_visitor(vis, x->second);
1144 return std::move(vis.str);
1150 std::string OCRepresentation::AttributeItem::getValueToString() const
1152 to_string_visitor vis;
1153 boost::apply_visitor(vis, m_values[m_attrName]);
1154 return std::move(vis.str);
1157 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1159 os << ai.getValueToString();