Page 1 of 1

Iterate through registered QxClasses

PostPosted: Thu Aug 25, 2011 3:27 pm
by balsany
Hi,
Is it possible to iterate through registered QxClasses and QClass base classes (through IxClass interface) in runtime?

As far as know it is not possible, but following 3 member functions help to use qxorm presented reflection in runtime to traverse through inheritance tree and registered classes.


In draft form:

In QxClassX:
Code: Select all
static const QxCollection<QString, IxClass *>* getAllClasses();


in IxClass:
Code: Select all
virtual IxClass* getBaseClass()=0;

in QxClass:
Code: Select all
virtual IxClass* getBaseClass() { if(!boost::is_same<type_base_class, qx::trait::no_base_class_defined>::value) return QxClass<type_base_class>::getSingleton();return 0; }


Those are only my suggestion, but these functionalities will be great.

Thanks

Re: Iterate through registered QxClasses

PostPosted: Thu Aug 25, 2011 4:02 pm
by QxOrm admin
Hi,

Thanks very much for your suggestion : this will be included in the next version...

Today, you cannot iterate over all registered classes (but this is very simple to patch), but you can use the reflection engine if you know the class name.
You have to use the following method :
Code: Select all
static IxClass * qx::QxClassX::getClass(const QString & sKey);


Then, when you have your IxClass *, you can iterate over each properties and each functions defined into QxOrm context :
Code: Select all
IxDataMemberX * getDataMemberX() const;
IxFunctionX * getFctMemberX() const;


You can also retrieve the base class name using :
Code: Select all
QString getKeyBaseClass() const;


So, using the base class name, you can iterate over all hierarchy of a class.
Ok it's more simple if I create your method : virtual IxClass* getBaseClass()=0;

Here is a patch if you want to iterate over all classes defined into QxOrm context : in file QxClassX.h, just add the following public method :
Code: Select all
QxCollection<QString, IxClass *> * getAllClasses() { return m_lstClass; }


I think I will add something in the FAQ to explain how the reflection/introspection engine works...
Thanks ;)

Re: Iterate through registered QxClasses

PostPosted: Thu Aug 25, 2011 6:50 pm
by QxOrm admin
I have a question : why do you want to iterate over all classes registered into QxOrm context ?
Do you want to dump all classes ?

Re: Iterate through registered QxClasses

PostPosted: Thu Aug 25, 2011 8:28 pm
by balsany
Hi,
Thanks for the quick response!
I want to use this reflection mechanism to automatically generate GUI for registered classes.
For example i need a functionality to collect subclasses of a given class (through IxClass) in runtime.
Also collect registered data members and functions of classes (i know this is possible :D).

Is it feasible to register, serialize and collect data members of class witch uses Pimpl idiom (like some classes in Qt and some my class :-()?
(I think ability to register setter and getter function and if they were registered use them in serialization and collect datamembers else use original method? Setter and getter method hide the complexity of Pimpl idiom. I am just dreaming! :-D )

Thanks again!

Re: Iterate through registered QxClasses

PostPosted: Fri Aug 26, 2011 7:46 am
by QxOrm admin
i need a functionality to collect subclasses of a given class (through IxClass) in runtime.

This is possible today using :
QString qx::IxClass::getKeyBaseClass() const;
Then, with the base class name :
static IxClass * qx::QxClassX::getClass(const QString & sKey);
With this method you can retrieve all inheritance tree of a class.

Is it feasible to register, serialize and collect data members of class witch uses Pimpl idiom (like some classes in Qt and some my class :-()?

I don't understand what you want. Can you give an example please ?

I want to use this reflection mechanism to automatically generate GUI for registered classes.

This is very interesting !
Would you show your project (some screenshots or source code) when you will finish it please ?

You can submit all patches you want and you need to create your project.
Then, I will try to include them in the next release of QxOrm library...

Re: Iterate through registered QxClasses

PostPosted: Tue Sep 27, 2011 9:13 am
by QxOrm admin
Is it feasible to register, serialize and collect data members of class witch uses Pimpl idiom (like some classes in Qt and some my class :-()?
(I think ability to register setter and getter function and if they were registered use them in serialization and collect datamembers else use original method? Setter and getter method hide the complexity of Pimpl idiom. I am just dreaming! :-D )

No you are not dreaming ! 8-)
The next version of QxOrm will provide a new mechanism to register properties using Q_PROPERTY macro of Qt library (there will be a new entry in the FAQ to explain how it works).
So, there will be a strong integration with Qt introspection/moc engine.
And Pimpl idiom will be available...

QxOrm 1.1.9 will be released in 1 or 2 weeks...