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 for (OCStringLL *strll = payload->types; strll; strll = strll->next)
90 rep.addResourceType(strll->value);
92 m_reps.push_back(std::move(rep));
95 void MessageContainer::setPayload(const OCPlatformPayload* payload)
97 if (payload == nullptr)
102 OCRepresentation rep;
103 rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
104 std::string(payload->info.platformID) :
106 rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
107 std::string(payload->info.manufacturerName) :
109 rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
110 std::string(payload->info.manufacturerUrl) :
112 rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
113 std::string(payload->info.modelNumber) :
115 rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
116 std::string(payload->info.dateOfManufacture) :
118 rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
119 std::string(payload->info.platformVersion) :
121 rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
122 std::string(payload->info.operatingSystemVersion) :
124 rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
125 std::string(payload->info.hardwareVersion) :
127 rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
128 std::string(payload->info.firmwareVersion) :
130 rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
131 std::string(payload->info.supportUrl) :
133 rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
134 std::string(payload->info.systemTime) :
137 for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
139 rep.addResourceType(strll->value);
141 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
143 rep.addResourceInterface(strll->value);
146 m_reps.push_back(std::move(rep));
149 void MessageContainer::setPayload(const OCRepPayload* payload)
151 const OCRepPayload* pl = payload;
154 OCRepresentation cur;
158 this->addRepresentation(cur);
162 OCRepPayload* MessageContainer::getPayload() const
164 OCRepPayload* root = nullptr;
165 for(const auto& r : representations())
169 root = r.getPayload();
173 OCRepPayloadAppend(root, r.getPayload());
180 const std::vector<OCRepresentation>& MessageContainer::representations() const
185 void MessageContainer::addRepresentation(const OCRepresentation& rep)
187 m_reps.push_back(rep);
193 struct get_payload_array: boost::static_visitor<>
196 void operator()(T& /*arr*/)
198 throw std::logic_error("Invalid calc_dimensions_visitor type");
202 void operator()(std::vector<T>& arr)
205 dimensions[0] = arr.size();
208 dimTotal = calcDimTotal(dimensions);
210 array = (void*)OICMalloc(dimTotal * root_size);
212 for(size_t i = 0; i < dimensions[0]; ++i)
214 copy_to_array(arr[i], array, i);
219 void operator()(std::vector<std::vector<T>>& arr)
222 dimensions[0] = arr.size();
225 for(size_t i = 0; i < arr.size(); ++i)
227 dimensions[1] = std::max(dimensions[1], arr[i].size());
229 dimTotal = calcDimTotal(dimensions);
230 array = (void*)OICCalloc(1, dimTotal * root_size);
232 for(size_t i = 0; i < dimensions[0]; ++i)
234 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
236 copy_to_array(arr[i][j], array, i*dimensions[1] + j);
241 void operator()(std::vector<std::vector<std::vector<T>>>& arr)
244 dimensions[0] = arr.size();
247 for(size_t i = 0; i < arr.size(); ++i)
249 dimensions[1] = std::max(dimensions[1], arr[i].size());
251 for(size_t j = 0; j < arr[i].size(); ++j)
253 dimensions[2] = std::max(dimensions[2], arr[i][j].size());
257 dimTotal = calcDimTotal(dimensions);
258 array = (void*)OICCalloc(1, dimTotal * root_size);
260 for(size_t i = 0; i < dimensions[0]; ++i)
262 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
264 for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
266 copy_to_array(arr[i][j][k], array,
268 dimensions[2] * dimensions[1] * i +
276 void root_size_calc()
278 root_size = sizeof(T);
282 void copy_to_array(T item, void* array, size_t pos)
284 ((T*)array)[pos] = item;
287 size_t dimensions[MAX_REP_ARRAY_DEPTH];
294 void get_payload_array::root_size_calc<int>()
296 root_size = sizeof(int64_t);
300 void get_payload_array::root_size_calc<std::string>()
302 root_size = sizeof(char*);
306 void get_payload_array::root_size_calc<OC::OCRepresentation>()
308 root_size = sizeof(OCRepPayload*);
312 void get_payload_array::copy_to_array(int item, void* array, size_t pos)
314 ((int64_t*)array)[pos] = item;
317 #if !defined(_MSC_VER)
319 void get_payload_array::copy_to_array(std::_Bit_reference br, void* array, size_t pos)
321 ((bool*)array)[pos] = static_cast<bool>(br);
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(std::string& item, void* array, size_t pos)
334 ((char**)array)[pos] = OICStrdup(item.c_str());
338 void get_payload_array::copy_to_array(const std::string& item, void* array, size_t pos)
340 ((char**)array)[pos] = OICStrdup(item.c_str());
344 void get_payload_array::copy_to_array(OC::OCRepresentation item, void* array, size_t pos)
346 ((OCRepPayload**)array)[pos] = item.getPayload();
349 void OCRepresentation::getPayloadArray(OCRepPayload* payload,
350 const OCRepresentation::AttributeItem& item) const
352 get_payload_array vis{};
353 boost::apply_visitor(vis, m_values[item.attrname()]);
356 switch(item.base_type())
358 case AttributeType::Integer:
359 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
363 case AttributeType::Double:
364 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
368 case AttributeType::Boolean:
369 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
373 case AttributeType::String:
374 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
378 case AttributeType::OCRepresentation:
379 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
380 (OCRepPayload**)vis.array, vis.dimensions);
383 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
384 std::to_string((int)item.base_type()));
388 OCRepPayload* OCRepresentation::getPayload() const
390 OCRepPayload* root = OCRepPayloadCreate();
393 throw std::bad_alloc();
396 OCRepPayloadSetUri(root, getUri().c_str());
398 for(const std::string& type : getResourceTypes())
400 OCRepPayloadAddResourceType(root, type.c_str());
403 for(const std::string& iface : getResourceInterfaces())
405 OCRepPayloadAddInterface(root, iface.c_str());
408 for(auto& val : *this)
412 case AttributeType::Null:
413 OCRepPayloadSetNull(root, val.attrname().c_str());
415 case AttributeType::Integer:
416 OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
418 case AttributeType::Double:
419 OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
420 val.getValue<double>());
422 case AttributeType::Boolean:
423 OCRepPayloadSetPropBool(root, val.attrname().c_str(), val.getValue<bool>());
425 case AttributeType::String:
426 OCRepPayloadSetPropString(root, val.attrname().c_str(),
427 static_cast<std::string>(val).c_str());
429 case AttributeType::OCRepresentation:
430 OCRepPayloadSetPropObjectAsOwner(root, val.attrname().c_str(),
431 static_cast<OCRepresentation>(val).getPayload());
433 case AttributeType::Vector:
434 getPayloadArray(root, val);
436 case AttributeType::Binary:
437 OCRepPayloadSetPropByteString(root, val.attrname().c_str(),
438 OCByteString{const_cast<uint8_t*>(val.getValue<std::vector<uint8_t>>().data()),
439 val.getValue<std::vector<uint8_t>>().size()});
442 throw std::logic_error(std::string("Getpayload: Not Implemented") +
443 std::to_string((int)val.type()));
451 size_t calcArrayDepth(const size_t dimensions[MAX_REP_ARRAY_DEPTH])
453 if (dimensions[0] == 0)
455 throw std::logic_error("invalid calcArrayDepth");
457 else if (dimensions[1] == 0)
461 else if (dimensions[2] == 0)
472 T OCRepresentation::payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl)
474 throw std::logic_error("payload_array_helper_copy: unsupported type");
477 int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
479 return pl->arr.iArray[index];
482 double OCRepresentation::payload_array_helper_copy<double>(size_t index, const OCRepPayloadValue* pl)
484 return pl->arr.dArray[index];
487 bool OCRepresentation::payload_array_helper_copy<bool>(size_t index, const OCRepPayloadValue* pl)
489 return pl->arr.bArray[index];
492 std::string OCRepresentation::payload_array_helper_copy<std::string>(
493 size_t index, const OCRepPayloadValue* pl)
495 if (pl->arr.strArray[index])
497 return std::string(pl->arr.strArray[index]);
501 return std::string{};
505 OCRepresentation OCRepresentation::payload_array_helper_copy<OCRepresentation>(
506 size_t index, const OCRepPayloadValue* pl)
509 if (pl->arr.objArray[index])
511 r.setPayload(pl->arr.objArray[index]);
517 void OCRepresentation::payload_array_helper(const OCRepPayloadValue* pl, size_t depth)
521 std::vector<T> val(pl->arr.dimensions[0]);
523 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
525 val[i] = payload_array_helper_copy<T>(i, pl);
527 this->setValue(std::string(pl->name), val);
531 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] = payload_array_helper_copy<T>(
538 i * pl->arr.dimensions[1] + j, pl);
541 this->setValue(std::string(pl->name), val);
545 std::vector<std::vector<std::vector<T>>> val(pl->arr.dimensions[0]);
546 for(size_t i = 0; i < pl->arr.dimensions[0]; ++i)
548 val[i].resize(pl->arr.dimensions[1]);
549 for(size_t j = 0; j < pl->arr.dimensions[1]; ++j)
551 val[i][j].resize(pl->arr.dimensions[2]);
552 for(size_t k = 0; k < pl->arr.dimensions[2]; ++k)
554 val[i][j][k] = payload_array_helper_copy<T>(
555 pl->arr.dimensions[2] * j +
556 pl->arr.dimensions[2] * pl->arr.dimensions[1] * i +
562 this->setValue(std::string(pl->name), val);
566 throw std::logic_error("Invalid depth in payload_array_helper");
570 void OCRepresentation::setPayloadArray(const OCRepPayloadValue* pl)
576 payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
578 case OCREP_PROP_DOUBLE:
579 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
581 case OCREP_PROP_BOOL:
582 payload_array_helper<bool>(pl, calcArrayDepth(pl->arr.dimensions));
584 case OCREP_PROP_STRING:
585 payload_array_helper<std::string>(pl, calcArrayDepth(pl->arr.dimensions));
587 case OCREP_PROP_OBJECT:
588 payload_array_helper<OCRepresentation>(pl, calcArrayDepth(pl->arr.dimensions));
591 throw std::logic_error("setPayload array invalid type");
596 void OCRepresentation::setPayload(const OCRepPayload* pl)
600 OCStringLL* ll = pl->types;
603 addResourceType(ll->value);
610 addResourceInterface(ll->value);
614 OCRepPayloadValue* val = pl->values;
620 case OCREP_PROP_NULL:
624 setValue<int>(val->name, val->i);
626 case OCREP_PROP_DOUBLE:
627 setValue<double>(val->name, val->d);
629 case OCREP_PROP_BOOL:
630 setValue<bool>(val->name, val->b);
632 case OCREP_PROP_STRING:
633 setValue<std::string>(val->name, val->str);
635 case OCREP_PROP_OBJECT:
637 OCRepresentation cur;
638 cur.setPayload(val->obj);
639 setValue<OCRepresentation>(val->name, cur);
642 case OCREP_PROP_ARRAY:
643 setPayloadArray(val);
645 case OCREP_PROP_BYTE_STRING:
648 (val->ocByteStr.bytes, val->ocByteStr.bytes + val->ocByteStr.len)
652 throw std::logic_error(std::string("Not Implemented!") +
653 std::to_string((int)val->type));
660 void OCRepresentation::addChild(const OCRepresentation& rep)
662 m_children.push_back(rep);
665 void OCRepresentation::clearChildren()
670 const std::vector<OCRepresentation>& OCRepresentation::getChildren() const
675 void OCRepresentation::setChildren(const std::vector<OCRepresentation>& children)
677 m_children = children;
680 void OCRepresentation::setDevAddr(const OCDevAddr m_devAddr)
682 std::ostringstream ss;
683 if (m_devAddr.flags & OC_SECURE)
687 else if (m_devAddr.adapter & OC_ADAPTER_TCP)
695 if (m_devAddr.flags & OC_IP_USE_V6)
697 ss << '[' << m_devAddr.addr << ']';
701 ss << m_devAddr.addr;
705 ss << ':' << m_devAddr.port;
710 const std::string OCRepresentation::getHost() const
715 void OCRepresentation::setUri(const char* uri)
717 m_uri = uri ? uri : "";
720 void OCRepresentation::setUri(const std::string& uri)
725 std::string OCRepresentation::getUri() const
730 const std::vector<std::string>& OCRepresentation::getResourceTypes() const
732 return m_resourceTypes;
735 void OCRepresentation::setResourceTypes(const std::vector<std::string>& resourceTypes)
737 m_resourceTypes = resourceTypes;
740 void OCRepresentation::addResourceType(const std::string& str)
742 m_resourceTypes.push_back(str);
745 const std::vector<std::string>& OCRepresentation::getResourceInterfaces() const
750 void OCRepresentation::addResourceInterface(const std::string& str)
752 m_interfaces.push_back(str);
755 void OCRepresentation::setResourceInterfaces(const std::vector<std::string>& resourceInterfaces)
757 m_interfaces = resourceInterfaces;
760 bool OCRepresentation::hasAttribute(const std::string& str) const
762 return m_values.find(str) != m_values.end();
765 bool OCRepresentation::emptyData() const
767 // This logic is meant to determine whether based on the JSON serialization rules
768 // if this object will result in empty JSON. URI is only serialized if there is valid
769 // data, ResourceType and Interfaces are only serialized if we are a nothing, a
770 // child of a default or link item.
771 // Our values array is only printed in the if we are the child of a Batch resource,
772 // the parent in a 'default' situation, or not in a child/parent relationship.
777 else if ((m_interfaceType == InterfaceType::None
778 || m_interfaceType==InterfaceType::DefaultChild
779 || m_interfaceType==InterfaceType::LinkChild)
780 && (m_resourceTypes.size()>0 || m_interfaces.size()>0))
784 else if ((m_interfaceType == InterfaceType::None
785 || m_interfaceType == InterfaceType::BatchChild
786 || m_interfaceType == InterfaceType::DefaultParent)
787 && m_values.size()>0)
792 if (m_children.size() > 0)
800 int OCRepresentation::numberOfAttributes() const
802 return m_values.size();
805 bool OCRepresentation::erase(const std::string& str)
807 return m_values.erase(str);
810 void OCRepresentation::setNULL(const std::string& str)
812 m_values[str] = OC::NullType();
815 bool OCRepresentation::isNULL(const std::string& str) const
817 auto x = m_values.find(str);
819 if (m_values.end() != x)
821 return x->second.which() == AttributeValueNullIndex;
825 throw OCException(OC::Exception::INVALID_ATTRIBUTE+ str);
832 std::ostream& operator <<(std::ostream& os, const AttributeType at)
836 case AttributeType::Null:
839 case AttributeType::Integer:
842 case AttributeType::Double:
845 case AttributeType::Boolean:
848 case AttributeType::String:
851 case AttributeType::OCRepresentation:
852 os << "OCRepresentation";
854 case AttributeType::Vector:
857 case AttributeType::Binary:
864 // STL Container For OCRepresentation
867 OCRepresentation::AttributeItem::AttributeItem(const std::string& name,
868 std::map<std::string, AttributeValue>& vals):
869 m_attrName(name), m_values(vals){}
871 OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key)
873 OCRepresentation::AttributeItem attr{key, m_values};
874 return std::move(attr);
877 const OCRepresentation::AttributeItem OCRepresentation::operator[](const std::string& key) const
879 OCRepresentation::AttributeItem attr{key, m_values};
880 return std::move(attr);
883 const std::string& OCRepresentation::AttributeItem::attrname() const
888 template<typename T, typename = void>
891 // contains the actual type
893 // contains the inner most vector-type
895 // contains the AttributeType for this item
896 BOOST_STATIC_CONSTEXPR AttributeType enum_type =
897 AttributeTypeConvert<T>::type;
898 // contains the AttributeType for this base-type
899 BOOST_STATIC_CONSTEXPR AttributeType enum_base_type =
900 AttributeTypeConvert<T>::type;
901 // depth of the vector
902 BOOST_STATIC_CONSTEXPR size_t depth = 0;
908 typename std::enable_if<
909 is_vector<T>::value &&
910 !std::is_same<uint8_t, typename T::value_type>::value
915 typedef typename type_info<typename T::value_type>::base_type base_type;
916 BOOST_STATIC_CONSTEXPR AttributeType enum_type = AttributeType::Vector;
917 BOOST_STATIC_CONSTEXPR AttributeType enum_base_type =
918 type_info<typename T::value_type>::enum_base_type;
919 BOOST_STATIC_CONSTEXPR size_t depth = 1 +
920 type_info<typename T::value_type>::depth;
923 // special case for binary data, which is a std::vector<uint8_t>
925 struct type_info<std::vector<uint8_t>, void>
927 typedef std::vector<uint8_t> type;
928 typedef std::vector<uint8_t> base_type;
929 BOOST_STATIC_CONSTEXPR AttributeType enum_type = AttributeType::Binary;
930 BOOST_STATIC_CONSTEXPR AttributeType enum_base_type = AttributeType::Binary;
931 BOOST_STATIC_CONSTEXPR size_t depth = 0;
935 struct type_introspection_visitor : boost::static_visitor<>
938 AttributeType base_type;
941 type_introspection_visitor() : boost::static_visitor<>(),
942 type(AttributeType::Null), base_type(AttributeType::Null), depth(0){}
944 template <typename T>
945 void operator()(T const& /*item*/)
947 type = type_info<T>::enum_type;
948 base_type = type_info<T>::enum_base_type;
949 depth = type_info<T>::depth;
953 AttributeType OCRepresentation::AttributeItem::type() const
955 type_introspection_visitor vis;
956 boost::apply_visitor(vis, m_values[m_attrName]);
960 AttributeType OCRepresentation::AttributeItem::base_type() const
962 type_introspection_visitor vis;
963 boost::apply_visitor(vis, m_values[m_attrName]);
964 return vis.base_type;
967 size_t OCRepresentation::AttributeItem::depth() const
969 type_introspection_visitor vis;
970 boost::apply_visitor(vis, m_values[m_attrName]);
974 OCRepresentation::iterator OCRepresentation::begin()
976 return OCRepresentation::iterator(m_values.begin(), m_values);
979 OCRepresentation::const_iterator OCRepresentation::begin() const
981 return OCRepresentation::const_iterator(m_values.begin(), m_values);
984 OCRepresentation::const_iterator OCRepresentation::cbegin() const
986 return OCRepresentation::const_iterator(m_values.cbegin(), m_values);
989 OCRepresentation::iterator OCRepresentation::end()
991 return OCRepresentation::iterator(m_values.end(), m_values);
994 OCRepresentation::const_iterator OCRepresentation::end() const
996 return OCRepresentation::const_iterator(m_values.end(), m_values);
999 OCRepresentation::const_iterator OCRepresentation::cend() const
1001 return OCRepresentation::const_iterator(m_values.cend(), m_values);
1004 size_t OCRepresentation::size() const
1006 return m_values.size();
1009 bool OCRepresentation::empty() const
1011 return m_values.empty();
1014 bool OCRepresentation::iterator::operator==(const OCRepresentation::iterator& rhs) const
1016 return m_iterator == rhs.m_iterator;
1019 bool OCRepresentation::iterator::operator!=(const OCRepresentation::iterator& rhs) const
1021 return m_iterator != rhs.m_iterator;
1024 bool OCRepresentation::const_iterator::operator==(
1025 const OCRepresentation::const_iterator& rhs) const
1027 return m_iterator == rhs.m_iterator;
1030 bool OCRepresentation::const_iterator::operator!=(
1031 const OCRepresentation::const_iterator& rhs) const
1033 return m_iterator != rhs.m_iterator;
1036 OCRepresentation::iterator::reference OCRepresentation::iterator::operator*()
1041 OCRepresentation::const_iterator::const_reference
1042 OCRepresentation::const_iterator::operator*() const
1047 OCRepresentation::iterator::pointer OCRepresentation::iterator::operator->()
1052 OCRepresentation::const_iterator::const_pointer
1053 OCRepresentation::const_iterator::operator->() const
1058 OCRepresentation::iterator& OCRepresentation::iterator::operator++()
1061 if (m_iterator != m_item.m_values.end())
1063 m_item.m_attrName = m_iterator->first;
1067 m_item.m_attrName = "";
1072 OCRepresentation::const_iterator& OCRepresentation::const_iterator::operator++()
1075 if (m_iterator != m_item.m_values.end())
1077 m_item.m_attrName = m_iterator->first;
1081 m_item.m_attrName = "";
1086 OCRepresentation::iterator OCRepresentation::iterator::operator++(int)
1088 OCRepresentation::iterator itr(*this);
1093 OCRepresentation::const_iterator OCRepresentation::const_iterator::operator++(int)
1095 OCRepresentation::const_iterator itr(*this);
1100 struct to_string_visitor : boost::static_visitor<>
1103 template <typename T>
1104 void operator()(T const& item)
1106 str = boost::lexical_cast<std::string>(item);
1109 template <typename T>
1110 void operator()(std::vector<T> const& item)
1112 to_string_visitor vis;
1113 std::ostringstream stream;
1116 for(const auto& i : item)
1119 stream << vis.str << " ";
1127 void to_string_visitor::operator()(bool const& item)
1129 str = item ? "true" : "false";
1133 void to_string_visitor::operator()(std::string const& item)
1139 void to_string_visitor::operator()(NullType const& /*item*/)
1145 void to_string_visitor::operator()(OCRepresentation const& /*item*/)
1147 str = "OC::OCRepresentation";
1150 std::string OCRepresentation::getValueToString(const std::string& key) const
1152 auto x = m_values.find(key);
1153 if (x != m_values.end())
1155 to_string_visitor vis;
1156 boost::apply_visitor(vis, x->second);
1157 return std::move(vis.str);
1163 std::string OCRepresentation::AttributeItem::getValueToString() const
1165 to_string_visitor vis;
1166 boost::apply_visitor(vis, m_values[m_attrName]);
1167 return std::move(vis.str);
1170 std::ostream& operator<<(std::ostream& os, const OCRepresentation::AttributeItem& ai)
1172 os << ai.getValueToString();