It's freeware, but closed source. I use Borland C++Builder and there are some specifically types and methods. By me my property system is not universal. It's not possible to use it outside from this application. I just started to write any improvements.
By me in C++ you can't avoid casting of types, when you create any property list. It's impossible. OK, let's see some variants of this task. For example if you use C++Builder you can use their property system like:
example
Code: Select all
class PropertyExample : public TObject{
private:
int Fx,Fy;
float Fcells[100][100];
protected:
__fastcall int readX() { return(Fx); }
__fastcall void writeX(int newFx) { Fx = newFx; }
__fastcall double computeZ() {
// Do some computation and return a floating point value...
return(0.0);
}
__fastcall float cellValue(int row, int col) { return(Fcells[row][col]); }
public:
PropertyExample()
{
Fx = 666;
}
__published:
__property int prX = { read=readX, write=writeX };
__property int Y = { read=Fy };
__property double Z = { read=computeZ };
__property float Cells[int row][int col] = { read=cellValue };
};
Code: Select all
void TestFunction()
{
PropertyExample * myPropertyExample = new PropertyExample();
derivedPropertyExample * myderivedPropertyExample = new derivedPropertyExample();
TTypeKinds TypeKinds;
TTypeInfo *ptypeinfo=(TTypeInfo *)myderivedPropertyExample->ClassInfo();
int Count=(GetTypeData(ptypeinfo))->PropCount;
PPropList PropList=(PPropList)new Pointer[Count];
TypeKinds<<tkInteger<<tkString<<tkLString<<tkEnumeration<<tkClass;//...
int Count2=GetPropList(ptypeinfo,TypeKinds, PropList);
ListBox1->Clear();
for(int i=0; i < Count2; i++)
{
ListBox1->Items->Add(PropList[i]->Name);
ShowMessage((*(PropList[i]->PropType))->Kind);
ShowMessage((*(PropList[i]->PropType))->Name);
if((*(PropList[i]->PropType))->Kind ==7)//class
PropList[i]->GetProc;
if((*(PropList[i]->PropType))->Kind ==1)//int
{
int a = (int)PropList[i]->GetProc;
ShowMessage(a);
}
ShowMessage(GetOrdProp(myderivedPropertyExample, "prM"));
PropertyExample* prObj = (PropertyExample*)GetObjectPropClass(myderivedPropertyExample,"prObj");
prObj->prX = 69;
ShowMessage(prObj->prX);
}
}
You can see that here also any cast is needed. Also if you use their property system you must to derive all your classes from TObject - base class.
Similar are things with MS property system but I'm not familiar with it. In both casses /Borland or Microsoft/ you are forced to use or TObject or MS Common Object Model /COM/
Another variant is writing of compiler and IDE independent property template class like:
template<class Container, class ValueType, int nPropType>
class PropTest;
Property<PropTest,std::tring,READ_WRITE> MyProperty1;
Property<PropTest,int,READ_WRITE> MyProperty2;
With this method you will be able to add properties
even outside of any class. Seems easy, flexible,...but... We want any property list for each instance of any class. But in this case each property is from different type. Try typeid for testing. So, for collecting of propertyes we can use or any heterogeneous container /not implemented in C++/ or any list with void objects. In both cases any typecast is needed when properties are extracted from container.
My opinion is that property class must be independent from compiler and IDE, therefore will choice second /template/ method with container /list/ to void values. Yes, any enumeration for property types is compulsory.
I don't know many about Niko's plans, but he was planned Scene serialization for Irrlicht and I suppose that he will implement any property system for Irrlicht, but I can mistake. I know that if you have property system you can very easy to save each instance of any class. So, if Niko is planned this our efforts can be for nothing, because he is master in C++ and will able to implement this with better issue.