[litwindow-users] Re: Using aggregate/accessors
Status: Alpha
Brought to you by:
hajokirchhoff
From: Hajo K. <mai...@ha...> - 2005-04-19 08:48:27
|
Hi, >>What do you pass to "Items"? > > > I am passing a vector<class MyListData> to Items. > > Specifically, > > RULE("xrcMainList.Items", make_expr<accessor>("m_ListData")) ah, of course. Tiny detail, big effect. I didn't pay close enough attention. You are not passing a vector<>, you are passing an accessor to a vector. Thats the same difference between Type and Type*. The accessor is like Type*. You need to dereference the accessor to get to the vector. On the wxListCtrl side: Items is not a vector<MyListData>, its an accessor, which in your situation currently happens to point at a vector<MyListData> but could point to a totally different data type a few microseconds later. So you have wxListCtrl *pList = wxDynamicCast(event.GetEventObject(), wxListCtrl); aggregate ag(make_aggregate(*pList)); accessor ac(ag["Items"]); ag["Items"] returns an accessor to the property. If the property is of type long, it returns an accessor to a long object. If the property is of type string, it returns an accessor to a string object. In your case, the property is an accessor, so ag["Items"] returns an accessor to an accessor object. To get to the real accessor, the one you are interested in, you must dereference the accessor, much like *ag["Items"]. But accessors are untyped objects, so you need to cast it into a typed accessor first, then dereference it. Here is how: typed_accessor tac=dynamic_cast_accessor<accessor>(ac); accessor the_real_items_accessor=tac.get(); // this is like '*ac' the_real_items_accessor.is_container()==true; I'll rewrite the scenario using pseudo-code and replace accessor with 'void*' to make things more clear. wxListCtrl *pList=wxDynamicCast... aggregate ag(make_aggregate(*pList)); // ag["Items"] returns a void* to the "Items" member property // which is itself of type void* // so ag["Items"] return type is void ** void **ac=ag["Items"]; // ag.Items // cast it so we can get to the data void *tac=*(void*)ac; vector<MyDataStruct> *the_real_items_accessor=(vector<...>*)tac; *** Here is the full version again, that should work now: wxListCtrl *pList = wxDynamicCast(event.GetEventObject(), wxListCtrl); aggregate ag(make_aggregate(*pList)); accessor ac(ag["Items"]); typed_accessor tac=dynamic_cast_accessor<accessor>(ac); accessor the_real_items=tac.get(); if (the_real_items.is_valid() && the_real_items.is_container()) Looks more complicated than it is until you think of accessors as void* pointers with type information, which is exactly what they are by the way :) Hajo |