17 #ifndef COMMONVALUE_HPP_
18 #define COMMONVALUE_HPP_
22 #ifdef KAA_USE_CONFIGURATION
26 #include <boost/ref.hpp>
34 template <
typename T, CommonValueType CVT>
35 class CommonValue :
public ICommonValue {
38 typedef T * value_ptr;
39 typedef T & value_ref;
40 typedef const T & value_cref;
42 typedef std::shared_ptr<T> shared_ptr;
44 CommonValue(value_cref value, std::size_t len = 0);
45 CommonValue(
const CommonValue<T, CVT> &r);
48 const boost::any getValue()
const {
return boost::cref(value_).get(); }
49 avro::GenericDatum toAvro()
const;
50 std::string toString()
const;
53 std::size_t valLength_;
57 CommonValue<std::uint8_t *, CommonValueType::COMMON_BYTES>::~CommonValue()
62 template <
typename T, CommonValueType CVT>
63 CommonValue<T, CVT>::CommonValue(value_cref value, std::size_t len) : ICommonValue(CVT), value_(value), valLength_(len)
68 template <
typename T, CommonValueType CVT>
69 CommonValue<T, CVT>::CommonValue(
const CommonValue<T, CVT> &r) : ICommonValue(CVT), value_(r.value_), valLength_(r.valLength_)
73 template <
typename T, CommonValueType CVT>
74 CommonValue<T, CVT>::~CommonValue()
79 template <
typename T, CommonValueType CVT>
80 std::string CommonValue<T, CVT>::toString()
const
88 std::string CommonValue<std::string, CommonValueType::COMMON_STRING>::toString()
const
91 ss <<
"\"" << value_ <<
"\"";
96 std::string CommonValue<std::vector<std::uint8_t>, CommonValueType::COMMON_BYTES>::toString()
const
99 for (
auto it = value_.begin(); it != value_.end();) {
100 ss << std::setw(2) << std::setfill(
'0') << std::hex << (int)*it << std::dec;
101 if (++it != value_.end()) {
108 template <
typename T, CommonValueType CVT>
109 avro::GenericDatum CommonValue<T, CVT>::toAvro()
const
111 avro::GenericDatum datum(value_);
116 CommonValue<std::uint8_t *, CommonValueType::COMMON_BYTES>::CommonValue(value_cref value, std::size_t len)
118 , value_(new std::uint8_t[len])
121 std::copy(value, value + len, value_);
125 CommonValue<std::uint8_t *, CommonValueType::COMMON_BYTES>::CommonValue(
const CommonValue<std::uint8_t *, CommonValueType::COMMON_BYTES> &r)
127 , value_(new std::uint8_t[r.valLength_])
128 , valLength_(r.valLength_)
130 std::copy(r.value_, r.value_ + valLength_, value_);
134 std::string CommonValue<std::uint8_t *, CommonValueType::COMMON_BYTES>::toString()
const
136 std::stringstream ss;
137 for (std::size_t i = 0; i < valLength_; ) {
138 ss << std::setw(2) << std::setfill(
'0') << std::hex << (int)value_[i] << std::dec;
139 if (++i != valLength_) {