34 #include <unordered_map>
36 template class ::IceInternal::Handle<::armarx::Variant>;
40 template <> Variant::Variant(
const std::int8_t& var,
void*)
44 template<> std::int8_t Variant::get<std::int8_t>()
const
49 return static_cast<std::int8_t
>(i);
51 template<>
void Variant::set<std::int8_t>(
const std::int8_t&
value)
53 setInt(
static_cast<int>(
value));
60 template<> std::int16_t Variant::get<std::int16_t>()
const
65 return static_cast<std::int16_t
>(i);
67 template<>
void Variant::set<std::int16_t>(
const std::int16_t&
value)
69 setInt(
static_cast<int>(
value));
74 data =
new IntVariantData(
static_cast<int>(var));
78 template<> std::int32_t Variant::get<std::int32_t>()
const
83 return static_cast<std::int32_t
>(i);
85 template<>
void Variant::set<std::int32_t>(
const std::int32_t&
value)
87 setInt(
static_cast<int>(
value));
92 data =
new LongVariantData(
static_cast<long>(var));
96 template<> std::int64_t Variant::get<std::int64_t>()
const
99 return static_cast<std::int64_t
>(i);
101 template<>
void Variant::set<std::int64_t>(
const std::int64_t&
value)
103 setLong(
static_cast<long>(
value));
110 template<> std::uint8_t Variant::get<std::uint8_t>()
const
115 return static_cast<std::uint8_t
>(i);
117 template<>
void Variant::set<std::uint8_t>(
const std::uint8_t&
value)
119 setInt(
static_cast<int>(
value));
126 template<> std::uint16_t Variant::get<std::uint16_t>()
const
131 return static_cast<std::uint16_t
>(i);
133 template<>
void Variant::set<std::uint16_t>(
const std::uint16_t&
value)
135 setInt(
static_cast<int>(
value));
141 data =
new IntVariantData(
static_cast<int>(var));
145 template<> std::uint32_t Variant::get<std::uint32_t>()
const
150 return static_cast<std::uint32_t
>(i);
152 template<>
void Variant::set<std::uint32_t>(
const std::uint32_t&
value)
154 setInt(
static_cast<int>(
value));
160 data =
new LongVariantData(
static_cast<long>(var));
164 template<> std::uint64_t Variant::get<std::uint64_t>()
const
168 return static_cast<std::uint64_t
>(i);
170 template<>
void Variant::set<std::uint64_t>(
const std::uint64_t&
value)
173 setLong(
static_cast<long>(
value));
178 data =
new FloatVariantData(var);
184 data =
new DoubleVariantData(var);
190 data =
new BoolVariantData(var);
196 data =
new StringVariantData(var);
201 template<>
bool Variant::get<bool>()
const
205 template<>
float Variant::get<float>()
const
209 template<>
double Variant::get<double>()
const
213 template<> std::string Variant::get<std::string>()
const
218 template<>
void Variant::set<bool>(
const bool&
value)
222 template<>
void Variant::set<float>(
const float&
value)
226 template<>
void Variant::set<double>(
const double&
value)
230 template<>
void Variant::set<std::string>(
const std::string&
value)
249 data = VariantDataPtr::dynamicCast(
source.data->ice_clone());
267 throw LocalException(
"A Variant's type cannot be changed after it was set! Current Variant type: ")
270 this->typeId = typeId;
283 data =
new IntVariantData();
287 IntVariantDataPtr::dynamicCast(this->
data)->n = n;
299 data =
new LongVariantData();
303 LongVariantDataPtr::dynamicCast(this->
data)->n = n;
315 data =
new FloatVariantData();
320 FloatVariantDataPtr::dynamicCast(this->
data)->f = f;
332 data =
new DoubleVariantData();
337 DoubleVariantDataPtr::dynamicCast(this->
data)->d = d;
349 data =
new StringVariantData();
354 StringVariantDataPtr::dynamicCast(this->
data)->s =
s;
366 data =
new BoolVariantData();
371 BoolVariantDataPtr::dynamicCast(this->
data)->b = b;
381 data = variantDataClass;
382 setType(variantDataClass->getType());
392 data = variantDataClass.clone();
393 setType(variantDataClass.getType());
412 IntVariantData* dataPtr =
static_cast<IntVariantData*
>(this->
data.get());
429 LongVariantData* dataPtr =
static_cast<LongVariantData*
>(this->
data.get());
446 FloatVariantData* dataPtr =
static_cast<FloatVariantData*
>(this->
data.get());
464 DoubleVariantData* dataPtr =
static_cast<DoubleVariantData*
>(this->
data.get());
482 StringVariantData* dataPtr =
static_cast<StringVariantData*
>(this->
data.get());
499 BoolVariantData* dataPtr =
static_cast<BoolVariantData*
>(this->
data.get());
507 std::stringstream stream;
508 stream.precision(std::numeric_limits<double>::digits10);
512 stream <<
"Not Initialized";
552 VariantDataClassPtr ptr = VariantDataClassPtr::dynamicCast(this->
data);
560 stream << ptr->output();
587 return "UnknownType";
608 if (
data->ice_id() == VariantData::ice_staticId())
613 VariantDataClassPtr classPtr = VariantDataClassPtr::dynamicCast(
data);
617 return classPtr->validate();
634 data = VariantDataPtr::dynamicCast(prototype.ice_clone());
647 data = VariantDataPtr::dynamicCast(prototype->ice_clone());
660 data = VariantDataPtr::dynamicCast(prototype.data->ice_clone());
679 stream <<
"(UNKNOWNTYPE) ";
684 stream <<
"not Initialized " ;
692 void Variant::invalidate()
694 data =
new InvalidVariantData();
701 static std::unordered_map<std::string, VariantTypeId> idMap;
702 auto it = idMap.find(typeName);
704 if (it != idMap.end())
713 while ((ch = typeName[
index++]))
716 hash = ((hash << 5) + hash) ^ ch;
719 idMap[typeName] = hash;
723 std::map<VariantTypeId, std::string>& Variant::types()
725 static std::map<VariantTypeId, std::string> types = std::map<VariantTypeId, std::string>();
734 auto& typeMap = types();
735 std::map<VariantTypeId, std::string>::iterator it = typeMap.find(type);
738 if (it == types().end())
754 std::pair<unsigned int, std::string> entry;
756 entry.second = typeName;
760 std::map<VariantTypeId, std::string>::iterator it = types().find(hash);
762 if (it != types().end() && typeName != it->second)
764 throw LocalException(
"A Type with the same hash value is already added. It has to be renamed. TypeName: " + typeName);
767 Variant::types().insert(entry);
789 std::ostream&
operator<<(std::ostream& stream,
const VariantDataClass& variant)
791 stream << variant.output();