95 #ifndef _MultiType_H__ 96 #define _MultiType_H__ 103 #include <OgreVector2.h> 104 #include <OgreVector3.h> 105 #include <OgreVector4.h> 106 #include <OgreQuaternion.h> 107 #include <OgreColourValue.h> 174 inline MT_ValueBase(
void* data,
Type type) : type_(type), bLastConversionSuccessful(true), data_(data) {}
179 virtual void reset() = 0;
185 template <
typename T>
typename std::enable_if<!std::is_enum<T>::value,
bool>::type
189 static_assert(
sizeof(
T) !=
sizeof(
T),
"No template specialization available for T");
193 template <
typename T>
typename std::enable_if<std::is_enum<T>::value,
bool>::type
196 return this->isType<typename std::underlying_type<T>::type>();
202 virtual bool setValue(
const char& value) = 0;
203 virtual bool setValue(
const unsigned char& value) = 0;
204 virtual bool setValue(
const short& value) = 0;
205 virtual bool setValue(
const unsigned short& value) = 0;
206 virtual bool setValue(
const int& value) = 0;
207 virtual bool setValue(
const unsigned int& value) = 0;
208 virtual bool setValue(
const long& value) = 0;
209 virtual bool setValue(
const unsigned long& value) = 0;
210 virtual bool setValue(
const long long& value) = 0;
211 virtual bool setValue(
const unsigned long long& value) = 0;
212 virtual bool setValue(
const float& value) = 0;
213 virtual bool setValue(
const double& value) = 0;
214 virtual bool setValue(
const long double& value) = 0;
215 virtual bool setValue(
const bool& value) = 0;
216 virtual bool setValue(
void*
const& value) = 0;
217 virtual bool setValue(
const std::string& value) = 0;
218 virtual bool setValue(
const orxonox::Vector2& value) = 0;
219 virtual bool setValue(
const orxonox::Vector3& value) = 0;
220 virtual bool setValue(
const orxonox::Vector4& value) = 0;
221 virtual bool setValue(
const orxonox::ColourValue& value) = 0;
222 virtual bool setValue(
const orxonox::Quaternion& value) = 0;
223 virtual bool setValue(
const orxonox::Radian& value) = 0;
224 virtual bool setValue(
const orxonox::Degree& value) = 0;
226 virtual bool setValue(
const MultiType& other) = 0;
228 template <
typename T>
typename std::enable_if<!std::is_enum<T>::value,
bool>::type
232 static_assert(
sizeof(
T) !=
sizeof(
T),
"No template specialization available for T");
235 template <
typename T>
typename std::enable_if<std::is_enum<T>::value,
bool>::type
238 typedef typename std::underlying_type<T>::type UnderlyingType;
239 return this->setValue(reinterpret_cast<const UnderlyingType&>(value));
242 virtual bool getValue(
char* value)
const = 0;
243 virtual bool getValue(
unsigned char* value)
const = 0;
244 virtual bool getValue(
short* value)
const = 0;
245 virtual bool getValue(
unsigned short* value)
const = 0;
246 virtual bool getValue(
int* value)
const = 0;
247 virtual bool getValue(
unsigned int* value)
const = 0;
248 virtual bool getValue(
long* value)
const = 0;
249 virtual bool getValue(
unsigned long* value)
const = 0;
250 virtual bool getValue(
long long* value)
const = 0;
251 virtual bool getValue(
unsigned long long* value)
const = 0;
252 virtual bool getValue(
float* value)
const = 0;
253 virtual bool getValue(
double* value)
const = 0;
254 virtual bool getValue(
long double* value)
const = 0;
255 virtual bool getValue(
bool* value)
const = 0;
256 virtual bool getValue(
void** value)
const = 0;
257 virtual bool getValue(
std::string* value)
const = 0;
258 virtual bool getValue(orxonox::Vector2* value)
const = 0;
259 virtual bool getValue(orxonox::Vector3* value)
const = 0;
260 virtual bool getValue(orxonox::Vector4* value)
const = 0;
261 virtual bool getValue(orxonox::ColourValue* value)
const = 0;
262 virtual bool getValue(orxonox::Quaternion* value)
const = 0;
263 virtual bool getValue(orxonox::Radian* value)
const = 0;
264 virtual bool getValue(orxonox::Degree* value)
const = 0;
266 template <
typename T>
typename std::enable_if<!std::is_enum<T>::value,
bool>::type
270 static_assert(
sizeof(
T) !=
sizeof(
T),
"No template specialization available for T");
273 template <
typename T>
typename std::enable_if<std::is_enum<T>::value,
bool>::type
276 typedef typename std::underlying_type<T>::type UnderlyingType;
277 return this->getValue(reinterpret_cast<UnderlyingType*>(value));
280 template <
typename T>
T get()
const 282 if (this->isType<T>())
283 return *reinterpret_cast<const T*>(this->data_);
287 this->getValue(&value);
292 virtual void toString(std::ostream& outstream)
const = 0;
294 virtual void importData(uint8_t*& mem) = 0;
295 virtual void exportData(uint8_t*& mem)
const = 0;
296 virtual uint8_t getSize()
const = 0;
309 template <
typename V>
310 inline MultiType(
const V& value) : value_(nullptr) { this->
set(value); }
317 inline ~MultiType() {
if (this->value_) {
delete this->value_; } }
329 template <
typename V>
inline bool set(
const V& value)
332 return this->value_->setValue(value);
334 this->assignValue(value);
338 template <
typename V>
inline bool set(
V* value)
350 return this->value_->setValue(other);
351 else if (other.value_)
352 this->value_ = other.value_->clone();
357 template <
typename T,
typename V>
inline bool force(
const V& value)
360 return this->
set(value);
377 inline void reset() {
if (this->value_)
delete this->value_; this->value_ =
nullptr; }
381 inline void resetValue() {
if (this->value_) this->value_->reset(); }
384 template <
typename T>
inline bool isType()
const {
return (this->value_ ? this->value_->isType<
T>() :
false); }
391 inline bool null()
const {
return !this->value_; }
394 template <
class T>
operator T()
const {
return this->get<T>(); }
397 template <
typename T>
inline bool getValue(
T* value)
const {
if (this->value_) {
return this->value_->getValue(value); }
return false; }
400 template <
typename T>
typename std::enable_if<!std::is_pointer<T>::value,
T>::type
401 inline get()
const {
return (this->value_ ? this->value_->get<
T>() :
NilValue<T>()); }
403 template <
typename T>
typename std::enable_if<std::is_pointer<T>::value,
T>::type
404 inline get()
const {
return this->value_ ?
static_cast<T>(this->value_->get<
void*>()) :
nullptr; }
413 assert(
sizeof(
Type) <= 8);
414 *
static_cast<uint8_t*
>(mem) = static_cast<uint8_t>(this->getType());
415 mem +=
sizeof(uint8_t);
416 this->value_->exportData(mem);
421 assert(
sizeof(
Type) <= 8);
422 this->setType(static_cast<Type>(*static_cast<uint8_t*>(mem)));
423 mem +=
sizeof(uint8_t);
424 this->value_->importData(mem);
439 assert(this->value_);
440 return this->value_->getSize() +
sizeof(uint8_t);
447 if (this->isType<T>())
448 this->value_->setValue(value);
450 this->changeValueContainer(value);
455 if (this->isType<void*>())
456 this->value_->setValue(static_cast<void*>(value));
458 this->changeValueContainer<void*>(value);
462 inline void setType(
Type type) { this->reset(); this->convert(type); this->resetValue(); }
464 inline Type getType()
const {
return (this->value_) ? this->value_->type_ : Type::Null; }
466 bool convert(
Type type);
473 this->createNewValueContainer(value);
476 template <
typename T>
typename std::enable_if<!std::is_enum<T>::value>::type
480 static_assert(
sizeof(
T) !=
sizeof(
T),
"No template specialization available for T");
483 template <
typename T>
typename std::enable_if<std::is_enum<T>::value>::type
486 typedef typename std::underlying_type<T>::type UnderlyingType;
487 this->createNewValueContainer<UnderlyingType>(
reinterpret_cast<const UnderlyingType&
>(value));
501 template <>
inline bool MultiType::MT_ValueBase::isType<char>()
const {
return this->type_ == Type::Char; }
502 template <>
inline bool MultiType::MT_ValueBase::isType<unsigned char>()
const {
return this->type_ == Type::UnsignedChar; }
503 template <>
inline bool MultiType::MT_ValueBase::isType<short>()
const {
return this->type_ == Type::Short; }
504 template <>
inline bool MultiType::MT_ValueBase::isType<unsigned short>()
const {
return this->type_ == Type::UnsignedShort; }
505 template <>
inline bool MultiType::MT_ValueBase::isType<int>()
const {
return this->type_ == Type::Int; }
506 template <>
inline bool MultiType::MT_ValueBase::isType<unsigned int>()
const {
return this->type_ == Type::UnsignedInt; }
507 template <>
inline bool MultiType::MT_ValueBase::isType<long>()
const {
return this->type_ == Type::Long; }
508 template <>
inline bool MultiType::MT_ValueBase::isType<unsigned long>()
const {
return this->type_ == Type::UnsignedLong; }
509 template <>
inline bool MultiType::MT_ValueBase::isType<long long>()
const {
return this->type_ == Type::LongLong; }
510 template <>
inline bool MultiType::MT_ValueBase::isType<unsigned long long>()
const {
return this->type_ == Type::UnsignedLongLong; }
511 template <>
inline bool MultiType::MT_ValueBase::isType<float>()
const {
return this->type_ ==
Type::Float; }
512 template <>
inline bool MultiType::MT_ValueBase::isType<double>()
const {
return this->type_ ==
Type::Double; }
513 template <>
inline bool MultiType::MT_ValueBase::isType<long double>()
const {
return this->type_ == Type::LongDouble; }
514 template <>
inline bool MultiType::MT_ValueBase::isType<bool>()
const {
return this->type_ == Type::Bool; }
515 template <>
inline bool MultiType::MT_ValueBase::isType<void*>()
const {
return this->type_ == Type::VoidPointer; }
516 template <>
inline bool MultiType::MT_ValueBase::isType<std::string>()
const {
return this->type_ == Type::String; }
517 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::Vector2>()
const {
return this->type_ == Type::Vector2; }
518 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::Vector3>()
const {
return this->type_ == Type::Vector3; }
519 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::Vector4>()
const {
return this->type_ == Type::Vector4; }
520 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::ColourValue>()
const {
return this->type_ == Type::ColourValue; }
521 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::Quaternion>()
const {
return this->type_ == Type::Quaternion; }
522 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::Radian>()
const {
return this->type_ == Type::Radian; }
523 template <>
inline bool MultiType::MT_ValueBase::isType<orxonox::Degree>()
const {
return this->type_ == Type::Degree; }
529 template <>
inline bool MultiType::isType<void>()
const {
return this->null(); }
530 template <>
inline bool MultiType::convert<void>() { this->reset();
return true; }
MT_ValueBase * value_
A pointer to the value container.
Definition: MultiType.h:490
bool bLastConversionSuccessful
True if the last conversion was successful.
Definition: MultiType.h:299
#define _UtilExport
Definition: UtilPrereqs.h:60
uint32_t getNetworkSize() const
Definition: MultiType.h:437
MT_ValueBase(void *data, Type type)
Definition: MultiType.h:174
std::enable_if<!std::is_enum< T >::value >::type createNewValueContainer(const T &value)
Creates a new value container (works only with specialized types).
Definition: MultiType.h:477
MultiType(const MultiType &other)
Copyconstructor: Assigns value and type of the other MultiType.
Definition: MultiType.h:312
void exportData(uint8_t *&mem) const
Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT...
Definition: MultiType.h:411
void changeValueContainer(const T &value)
Changes the value container.
Definition: MultiType.h:469
Provides zero value symbols that can be returned as reference.
Definition: Math.h:223
MultiType(MultiType &&other)
Moveconstructor: Moves the value and its type from the other MultiType.
Definition: MultiType.h:314
bool force(const V &value)
Changes the type to T and assigns the new value (which might be of another type than T - it gets conv...
Definition: MultiType.h:357
::std::string string
Definition: gtest-port.h:756
void * data_
For direct access to the value if the type is known.
Definition: MultiType.h:300
MultiType & operator=(const MultiType &other)
Assigns the value of the other MultiType and converts it to the current type of the MultiType...
Definition: MultiType.h:324
void operator>>(uint8_t *&mem) const
Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT...
Definition: MultiType.h:433
virtual void toString(std::ostream &outstream) const =0
void reset()
Resets the value and changes the internal type to T.
Definition: MultiType.h:379
MultiType & operator=(const V &value)
Assigns a new value. The value will be converted to the current type of the MultiType.
Definition: MultiType.h:320
MultiType & operator=(V *value)
Assigns a pointer.
Definition: MultiType.h:322
MultiType(const V &value)
Constructor: Assigns the given value and sets the type.
Definition: MultiType.h:310
Type type_
The type of the current value.
Definition: MultiType.h:298
std::enable_if< std::is_enum< T >::value, bool >::type setValue(const T &value)
Definition: MultiType.h:236
MultiType()
Default constructor: Assigns no value and no type. The type will be determined by the first assignmen...
Definition: MultiType.h:307
bool convert()
Converts the current value to type T.
Definition: MultiType.h:374
bool getValue(T *value) const
Assigns the value to the given pointer. The value gets converted if the types don't match...
Definition: MultiType.h:397
virtual MT_ValueBase * clone() const =0
~MultiType()
Destructor: Deletes the MT_Value.
Definition: MultiType.h:317
bool set(const V &value)
Assigns the given value and converts it to the current type.
Definition: MultiType.h:329
FloatingPoint< float > Float
Definition: gtest-internal.h:465
FloatingPoint< double > Double
Definition: gtest-internal.h:466
std::enable_if<!std::is_enum< T >::value, bool >::type isType() const
Returns true if the type of the stored value is T. Note: the actual implementations for all supported...
Definition: MultiType.h:186
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
void reset()
Resets value and type. Type will be void afterwards and null() returns true.
Definition: MultiType.h:377
Type
Enum of all possible types of a MultiType.
Definition: MultiType.h:138
bool lastConversionSuccessful() const
Checks whether the last conversion was successful.
Definition: MultiType.h:388
bool null() const
Checks if the MT contains no value.
Definition: MultiType.h:391
UnVolatile< typename UnConst< T >::Result >::Result UnqualifiedType
Definition: TypeTraits.h:256
mbool is a small helper class that acts like a bool, but keeps track of the number of its state chang...
Definition: mbool.h:58
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the util library ...
std::enable_if< std::is_enum< T >::value, bool >::type getValue(T *value) const
Definition: MultiType.h:274
The MultiType can hold a value of many possible types and convert them to other types.
Definition: MultiType.h:130
std::ostream & operator<<(std::ostream &out, const std::set< const Identifier * > &list)
Lists the names of all Identifiers in a std::set<const Identifier*>.
Definition: Identifier.cc:466
static const MultiType Null
Definition: MultiType.h:304
void importData(uint8_t *&mem)
Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of ...
Definition: MultiType.h:419
Declaration and implementation of the orxonox::mbool class.
void setType(Type type)
Resets the value and changes the internal type to the given type.
Definition: MultiType.h:462
Definition: InputPrereqs.h:105
Definition: InputPrereqs.h:78
std::enable_if< std::is_enum< T >::value, bool >::type isType() const
Implementation for enum classes: Returns true if the type of the stored value is the underlying type ...
Definition: MultiType.h:194
void swap(StrongPtr< T > &a, StrongPtr< T > &b)
Swaps the contents of two strong pointers.
Definition: StrongPtr.h:284
std::enable_if< std::is_enum< T >::value >::type createNewValueContainer(const T &value)
Creates a new value container (implementation for enum classes that must be cast to the underlying ty...
Definition: MultiType.h:484
bool isType() const
Returns true if the type of the current value is T.
Definition: MultiType.h:384
void assignValue(const T &value)
Assigns a new value by changing type and creating a new container.
Definition: MultiType.h:445
ReferenceTraits< typename UnVolatile< typename UnConst< T >::Result >::Result >::ReferredType UnqualifiedReferredType
Definition: TypeTraits.h:262
The MT_Value<T> class is used to hold a value of type T within a MultiType.
Definition: MultiTypeValue.h:53
uint8_t *& operator<<(uint8_t *&mem)
Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT...
Definition: MultiType.h:427
void assignValue(T *const &value)
Assigns a new value by changing type and creating a new container (overload for pointers).
Definition: MultiType.h:453
std::enable_if<!std::is_enum< T >::value, bool >::type setValue(const T &value)
Definition: MultiType.h:229
void copy(const MultiType &other)
Copies the other MultiType by assigning value and type.
Definition: MultiType.h:364
virtual ~MT_ValueBase()
Definition: MultiType.h:175
bool lastConversionSuccessful() const
Checks whether the value is a default one.
Definition: MultiType.h:200
const Type & getType() const
Returns the type of the current value.
Definition: MultiType.h:182
MultiType & operator=(MultiType &&other)
Moves the value and the type of the other MultiType to this one.
Definition: MultiType.h:326
std::enable_if<!std::is_enum< T >::value, bool >::type getValue(T *value) const
Definition: MultiType.h:267
MT_ValueBase is an almost pure virtual baseclass of MT_Value<T>, which holds the value of the MultiTy...
Definition: MultiType.h:171
Type getType() const
Returns the current type.
Definition: MultiType.h:464
void resetValue()
Current value gets overridden with default zero value.
Definition: MultiType.h:381