16 #ifndef __OMNETPP_ANY_PTR_H
17 #define __OMNETPP_ANY_PTR_H
21 #include "simkerneldefs.h"
22 #include "cexception.h"
65 const std::type_info *type;
67 void checkType(
const std::type_info& asType)
const;
71 explicit any_ptr(std::nullptr_t) : ptr(
nullptr), type(&
typeid(std::nullptr_t)) {}
74 explicit any_ptr(T *ptr) : ptr(ptr), type(&
typeid(T*)) {}
79 any_ptr(
void *ptr,
const std::type_info& type) : ptr(ptr), type(&type) {}
81 any_ptr(
const any_ptr &other) : ptr(other.ptr), type(other.type) {}
83 const any_ptr& operator=(
const any_ptr& other) {ptr=other.ptr; type=other.type;
return *
this;}
85 bool operator==(
const any_ptr& other)
const {
return ptr==other.ptr && (ptr==
nullptr || type==other.type);}
86 bool operator!=(
const any_ptr& other)
const {
return !operator==(other);}
88 bool operator==(std::nullptr_t)
const {
return ptr==
nullptr;}
89 bool operator!=(std::nullptr_t)
const {
return ptr!=
nullptr;}
92 bool contains()
const {
return typeid(T*) == *type;}
94 void *raw()
const {
return ptr;}
95 const std::type_info& pointerType()
const {
return *type;}
96 const char *pointerTypeName()
const {
return opp_typename(*type);}
97 const char *typeName()
const;
100 T *get() { checkType(
typeid(T*));
return reinterpret_cast<T*
>(ptr); }
103 const T *get()
const { checkType(
typeid(T*));
return reinterpret_cast<const T*
>(ptr);}
105 std::string str()
const;
111 T *fromAnyPtr(
any_ptr object) =
delete;
116 inline any_ptr toAnyPtr(
const cObject *obj) {
return any_ptr(
const_cast<cObject*
>(obj)); }