Go to the documentation of this file.
29 #include <type_traits>
31 #include <IceUtil/Handle.h>
33 #include <ArmarXCore/interface/observers/VariantBase.h>
34 #include <ArmarXCore/interface/observers/VariantContainers.h>
239 typename std::enable_if_t<!(std::is_base_of_v<VariantDataClass, T> ||
240 std::is_pointer_v<T>)>* t =
nullptr)
266 typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>>* t =
nullptr)
281 typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>>* t =
nullptr)
296 typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>>* t =
nullptr)
308 bool validate(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
334 void setInt(
int n,
const Ice::Current&
c = Ice::emptyCurrent)
override;
343 void setLong(
long n,
const Ice::Current&
c = Ice::emptyCurrent)
override;
352 void setFloat(
float f,
const Ice::Current&
c = Ice::emptyCurrent)
override;
361 void setDouble(
double d,
const Ice::Current&
c = Ice::emptyCurrent)
override;
370 void setString(
const std::string&
s,
const Ice::Current&
c = Ice::emptyCurrent)
override;
379 void setBool(
bool b,
const Ice::Current&
c = Ice::emptyCurrent)
override;
388 void setClass(
const VariantDataClassPtr& variantDataClass);
397 void setClass(
const VariantDataClass& variantDataClass);
411 int getInt(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
421 long getLong(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
431 float getFloat(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
441 double getDouble(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
451 std::string
getString(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
461 bool getBool(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
470 template <
class TVariantDataClass>
484 throw InvalidTypeException(
485 "Variant::getClass failed: actual type of value: " +
data->ice_id() +
487 ", desired type: " + GetType<TVariantDataClass>());
505 template <
typename T>
506 typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>>
507 set(
const VariantDataClassPtr& variantDataClass)
522 template <
typename T>
523 typename std::enable_if_t<!std::is_base_of_v<VariantDataClass, T>>
526 static_assert(std::is_base_of_v<VariantData, typename T::element_type>,
527 "Only basic types or from VariantDataClass derived classes can be "
528 "template parameters");
529 static int invType =
hashTypeName(InvalidVariantData::ice_staticId());
537 throw InvalidTypeException();
540 data = T::dynamicCast(
value->ice_clone());
554 template <
typename T>
558 return getClass<T>();
561 template <
typename T>
562 typename std::enable_if_t<std::is_base_of_v<VariantDataClass, typename T::element_type>,
T>
565 return getClass<typename T::element_type>();
577 template <
typename T>
578 typename std::enable_if_t<(std::is_standard_layout_v<T> && std::is_trivial_v<T>) ||
579 std::is_same_v<std::string, T>,
583 static_assert(always_false<T>,
584 "This function must not be called directly, it is only for primitive "
585 "types which have specializations");
602 std::string
getTypeName(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
607 bool getInitialized(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
671 stream <<
"Null VariantPtr";
690 static const std::map<VariantTypeId, std::string>&
getTypes();
702 template <
typename Type>
706 std::string typeName = GetTypeString<Type>();
708 if (typeName.size() > 1)
710 typeName = typeName.substr(0, typeName.size() - 1);
725 void output(std::ostream& stream)
const;
745 static std::map<VariantTypeId, std::string>& types();
757 std::int8_t Variant::get<std::int8_t>()
const;
759 void Variant::set<std::int8_t>(
const std::int8_t&
value);
764 std::int16_t Variant::get<std::int16_t>()
const;
766 void Variant::set<std::int16_t>(
const std::int16_t&
value);
771 std::int32_t Variant::get<std::int32_t>()
const;
773 void Variant::set<std::int32_t>(
const std::int32_t&
value);
778 std::int64_t Variant::get<std::int64_t>()
const;
780 void Variant::set<std::int64_t>(
const std::int64_t&
value);
785 std::uint8_t Variant::get<std::uint8_t>()
const;
787 void Variant::set<std::uint8_t>(
const std::uint8_t&
value);
792 std::uint8_t Variant::get<std::uint8_t>()
const;
794 void Variant::set<std::uint8_t>(
const std::uint8_t&
value);
799 std::uint16_t Variant::get<std::uint16_t>()
const;
801 void Variant::set<std::uint16_t>(
const std::uint16_t&
value);
806 std::uint32_t Variant::get<std::uint32_t>()
const;
808 void Variant::set<std::uint32_t>(
const std::uint32_t&
value);
813 std::uint64_t Variant::get<std::uint64_t>()
const;
815 void Variant::set<std::uint64_t>(
const std::uint64_t&
value);
833 bool Variant::get<bool>()
const;
835 float Variant::get<float>()
const;
837 double Variant::get<double>()
const;
839 std::string Variant::get<std::string>()
const;
842 void Variant::set<bool>(
const bool&
value);
844 void Variant::set<float>(
const float&
value);
846 void Variant::set<double>(
const double&
value);
848 void Variant::set<std::string>(
const std::string&
value);
855 extern template std::int8_t Variant::get<std::int8_t>()
const;
856 extern template void Variant::set<std::int8_t>(
const std::int8_t&
value);
859 extern template std::int16_t Variant::get<std::int16_t>()
const;
860 extern template void Variant::set<std::int16_t>(
const std::int16_t&
value);
863 extern template std::int32_t Variant::get<std::int32_t>()
const;
864 extern template void Variant::set<std::int32_t>(
const std::int32_t&
value);
867 extern template std::int64_t Variant::get<std::int64_t>()
const;
868 extern template void Variant::set<std::int64_t>(
const std::int64_t&
value);
871 extern template std::uint8_t Variant::get<std::uint8_t>()
const;
872 extern template void Variant::set<std::uint8_t>(
const std::uint8_t&
value);
875 extern template std::uint8_t Variant::get<std::uint8_t>()
const;
876 extern template void Variant::set<std::uint8_t>(
const std::uint8_t&
value);
879 extern template std::uint16_t Variant::get<std::uint16_t>()
const;
880 extern template void Variant::set<std::uint16_t>(
const std::uint16_t&
value);
883 extern template std::uint32_t Variant::get<std::uint32_t>()
const;
884 extern template void Variant::set<std::uint32_t>(
const std::uint32_t&
value);
887 extern template std::uint64_t Variant::get<std::uint64_t>()
const;
888 extern template void Variant::set<std::uint64_t>(
const std::uint64_t&
value);
891 extern template float Variant::get<float>()
const;
892 extern template void Variant::set<float>(
const float&
value);
895 extern template double Variant::get<double>()
const;
896 extern template void Variant::set<double>(
const double&
value);
899 extern template bool Variant::get<bool>()
const;
900 extern template void Variant::set<bool>(
const bool&
value);
903 extern template std::string Variant::get<std::string>()
const;
904 extern template void Variant::set<std::string>(
const std::string&
value);
906 std::ostream&
operator<<(std::ostream& stream,
const VariantDataClass& variant);
The Variant class is described here: Variants.
void setClass(const VariantDataClassPtr &variantDataClass)
Sets the Variant's value to variantDataClass.
bool getInitialized(const Ice::Current &c=Ice::emptyCurrent) const override
Tells if the Variant is properly initialized.
const VariantTypeId Float
Variant & operator=(float f)
void setLong(long n, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to n.
double getDouble(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as double.
bool validate(const Ice::Current &c=Ice::emptyCurrent) const override
Checks if the Variant is initialized and the stored value is valid with respect to the Variant's type...
friend std::ostream & operator<<(std::ostream &stream, const Variant &rhs)
std::map< std::string, Variant > StringVariantMap
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's internal type.
Variant & operator=(double d)
std::enable_if_t<(std::is_standard_layout_v< T > &&std::is_trivial_v< T >)||std::is_same_v< std::string, T >, T > get() const
This getter is only called if a wrong template parameter is given (i.e: the type does not inherit fro...
virtual VariantPtr clone() const
Returns a copy of the Variant.
void setString(const std::string &s, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to s.
Variant & operator=(long n)
static const std::map< VariantTypeId, std::string > & getTypes()
Returns the mapping of currently registered types.
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > get() const
Template-based getter for the Variant's value.
std::string getTypeName(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's internal type.
Variant(const IceInternal::Handle< T > &var, typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T >> *t=nullptr)
Construct a Variant from an IceHandle to a VariantDataClass instance.
long getLong(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as long.
void setInt(int n, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to n.
const VariantTypeId Double
void setDouble(double d, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to d.
std::shared_ptr< Value > value()
void setBool(bool b, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to b.
std::string getString(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as string.
const VariantTypeId Invalid
int getInt(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as int.
void setFloat(float f, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to f.
Variant & operator=(int n)
Variant(char const var[])
Construct a Variant from a string.
Variant & operator=(bool b)
std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > set(const VariantDataClassPtr &variantDataClass)
Template-based setter for the Variant's value for VariantDataClass-instances.
std::enable_if_t< std::is_base_of_v< VariantDataClass, typename T::element_type >, T > get() const
static std::string typeToString(VariantTypeId typeId)
Return the name of the registered type typeId.
float getFloat(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as float.
Variant(const T &var, typename std::enable_if_t<!(std::is_base_of_v< VariantDataClass, T >||std::is_pointer_v< T >)> *t=nullptr)
Construct a Variant from a non-VariantDataClass instance, e.g.
virtual std::string getOutputValueOnly() const
Returns the formatted content of the Variant as a string.
constexpr bool always_false
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
bool IsBasicType(VariantTypeId id)
Variant & operator=(const std::string &s)
Variant(const T &var, typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T >> *t=nullptr)
Construct a Variant from a reference to a VariantDataClass instance.
std::enable_if_t<!std::is_base_of_v< VariantDataClass, T > > set(const T &value)
Template-based setter for the Variant's value for non-VariantDataClass-instances.
void setType(VariantTypeId typeId, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's type to typeId.
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
static std::string GetType()
Template-based getter for a type name.
static int hashTypeName(const std::string &typeName)
Compute and return a hash value for a given type name.
Variant(const T *var, typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T >> *t=nullptr)
Construct a Variant from a pointer to a VariantDataClass instance.
void output(std::ostream &stream) const
Outputs a formatted representation of the Variant to stream.
const VariantTypeId String
IceInternal::Handle< TVariantDataClass > getClass() const
Return the Variant's value as TVariantDataClass.
bool getBool(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as bool.
double s(double t, double s0, double v0, double a0, double j)
This file offers overloads of toIce() and fromIce() functions for STL container types.
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.