Skip to content

Commit cfc8bfa

Browse files
Add a getClassdescObject to extract polymorphic objects from the RESTProcess regsitry.
1 parent 357999e commit cfc8bfa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

RESTProcess_base.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/// A classdesc descriptor to generate virtual xrap processing calls
1212
#include "function.h"
1313
#include "multiArray.h"
14+
#include "object.h"
1415
#include <map>
1516
#include <stdexcept>
1617

@@ -24,6 +25,12 @@ namespace classdesc
2425
/// interface for the REST processor
2526
class RESTProcessBase
2627
{
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;}
2734
public:
2835
virtual ~RESTProcessBase() {}
2936
/// perform the REST operation, with \a remainder being the query string and \a arguments as body text
@@ -38,6 +45,8 @@ namespace classdesc
3845
template <class F> REST_PROCESS_BUFFER functionSignature() const;
3946
/// returns a pointer to the underlying object if it is one of type T, otherwise null
4047
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;}
4150
/// true if this is an object, not a function
4251
virtual bool isObject() const {return false;}
4352
/// true if this is a const object, a const member function or static/free function
@@ -325,6 +334,7 @@ namespace classdesc
325334
REST_PROCESS_BUFFER signature() const override;
326335
REST_PROCESS_BUFFER list() const override;
327336
REST_PROCESS_BUFFER type() const override {return REST_PROCESS_BUFFER(typeName<T>());}
337+
object* getClassdescObject() override {return getClassdescObjectImpl(obj);}
328338
bool isObject() const override {return true;}
329339
bool isConst() const override {return std::is_const<T>::value;}
330340
};
@@ -711,6 +721,7 @@ namespace classdesc
711721
return REST_PROCESS_BUFFER(json5_parser::mArray());
712722
}
713723
REST_PROCESS_BUFFER type() const override {return REST_PROCESS_BUFFER(typeName<T>());}
724+
object* getClassdescObject() override {return ptr? getClassdescObjectImpl(*ptr): nullptr;}
714725
};
715726

716727
template <class T>
@@ -726,6 +737,7 @@ namespace classdesc
726737
else return REST_PROCESS_BUFFER(json5_parser::mArray());
727738
}
728739
REST_PROCESS_BUFFER type() const override {return REST_PROCESS_BUFFER(typeName<std::weak_ptr<T> >());}
740+
object* getClassdescObject() override {return ptr? getClassdescObjectImpl(*ptr): nullptr;}
729741
};
730742

731743

0 commit comments

Comments
 (0)