WvDBusMsg::is_reply() had an unnecessary hack for message #1.
[wvapps.git] / xplcidl / anytype.h
blob68a5a8a45536a24c252691a3ab2a3becb749230b
1 #ifndef __ANYTYPE_H
2 #define __ANYTYPE_H
4 #include <xplc/delete.h>
5 #include <xplc/uuid.h>
6 #include <xplc/uuidops.h>
7 #include <xplc/ptr.h>
8 #include "wvstring.h"
10 class AnyType
12 public:
13 /// a pointer to any interface of this object
14 void *raw;
16 /// the iid of the above interface
17 UUID iid;
19 /// a pointer to this object's IObject interface, if any
20 IObject *obj;
22 /// a string representing this item (only if all above objects are NULL)
23 WvString str;
25 AnyType(void *_raw, const UUID &_iid, IObject *_obj = NULL)
26 : iid(_iid), obj(_obj)
27 { raw = _raw; if (_obj) _obj->addRef(); }
29 AnyType(WvStringParm _str)
30 : iid(UUID_null), obj(0), str(_str)
31 { raw = 0; }
33 AnyType()
34 : iid(UUID_null), obj(0)
35 { raw = 0; }
37 ~AnyType()
38 { /* automatic via xplc_ptr */ }
40 bool switchto(const UUID &niid)
42 if (iid == niid) return true; // already done!
43 if (iid == UUID_null) return true; // anybody can do that...
44 if (!obj) return false;
46 IObject *n = obj->getInterface(niid);
47 if (n)
49 obj->release();
50 raw = obj = n;
51 return true;
53 return false;
56 template <typename T>
57 T *get()
59 if (switchto(XPLC_IID<T>::get()))
60 return (T *)raw;
61 else
62 return NULL;
65 template <typename T>
66 operator T* ()
67 { return get<T>(); }
71 #endif // __ANYTYPE_H