11
11
// / A classdesc descriptor to generate virtual xrap processing calls
12
12
#include " function.h"
13
13
#include " multiArray.h"
14
+ #include " object.h"
14
15
#include < map>
15
16
#include < stdexcept>
16
17
@@ -24,6 +25,12 @@ namespace classdesc
24
25
// / interface for the REST processor
25
26
class RESTProcessBase
26
27
{
28
+ protected:
29
+ // / implementation of upcasting to a classdesc::object
30
+ template <class T > typename enable_if<is_base_of<object,T>, object*>::T
31
+ getClassdescObjectImpl (T& obj) {return &obj;}
32
+ template <class T > typename enable_if<Not<is_base_of<object,T>>, object*>::T
33
+ getClassdescObjectImpl (T& obj) {return nullptr ;}
27
34
public:
28
35
virtual ~RESTProcessBase () {}
29
36
// / perform the REST operation, with \a remainder being the query string and \a arguments as body text
@@ -38,6 +45,8 @@ namespace classdesc
38
45
template <class F > REST_PROCESS_BUFFER functionSignature () const ;
39
46
// / returns a pointer to the underlying object if it is one of type T, otherwise null
40
47
template <class T > T* getObject ();
48
+ // / returns a classdesc object is referring to an object derived from classdesc::object
49
+ virtual object* getClassdescObject () {return nullptr ;}
41
50
// / true if this is an object, not a function
42
51
virtual bool isObject () const {return false ;}
43
52
// / true if this is a const object, a const member function or static/free function
@@ -325,6 +334,7 @@ namespace classdesc
325
334
REST_PROCESS_BUFFER signature () const override ;
326
335
REST_PROCESS_BUFFER list () const override ;
327
336
REST_PROCESS_BUFFER type () const override {return REST_PROCESS_BUFFER (typeName<T>());}
337
+ object* getClassdescObject () override {return getClassdescObjectImpl (obj);}
328
338
bool isObject () const override {return true ;}
329
339
bool isConst () const override {return std::is_const<T>::value;}
330
340
};
@@ -711,6 +721,7 @@ namespace classdesc
711
721
return REST_PROCESS_BUFFER (json5_parser::mArray ());
712
722
}
713
723
REST_PROCESS_BUFFER type () const override {return REST_PROCESS_BUFFER (typeName<T>());}
724
+ object* getClassdescObject () override {return ptr? getClassdescObjectImpl (*ptr): nullptr ;}
714
725
};
715
726
716
727
template <class T >
@@ -726,6 +737,7 @@ namespace classdesc
726
737
else return REST_PROCESS_BUFFER (json5_parser::mArray ());
727
738
}
728
739
REST_PROCESS_BUFFER type () const override {return REST_PROCESS_BUFFER (typeName<std::weak_ptr<T> >());}
740
+ object* getClassdescObject () override {return ptr? getClassdescObjectImpl (*ptr): nullptr ;}
729
741
};
730
742
731
743
0 commit comments