From: Sean P. <sp...@ad...> - 2006-10-11 18:26:11
|
Hi Ralph, This is referred to as "the refinement problem" - Here value_t models a regular type and a controller is a refinement of a regular type - given the regular type, how do you determine if it is a controller? STL uses tag dispatching to do this at compile time - and relies on the fact that the set of tags is fixed (for example, you can't readily add a new category of iterator and have algorithms dispatch to your specializations - that's one problem I'm hoping C++ Concepts will fix [hi Doug ;-) ] ). With runtime concepts (what we are dealing with here with the any_ types) - we run into a double unknown problem - any given type could model an infinite number of concepts, at the point that we hand the type off to an any_ class we capture the operations for a given concept. If later you want to say "does this type model a refined concept" and then recover the interface you can't because the code hasn't been instantiated and you don't have the type information at that point to force an instantiation (you are now runtime - not compile time). I just signed off on an nfs grant proposal to investigate adding runtime concepts to the language - hence why I'm copying Doug, Peter, and Jaakko. In the shorter term - I've been looking at boost::serialization (in the process of replacing the ASL serialization with it now) - boost serialization uses a registration mechanism to force instantiations and place them in a table so they can be retrieved later - an interesting (though somewhat fragile) solution. The mechanism for this is currently entangled with boost::serialization but I'm envisioning a mechanism where I can write something like: namespace { register_model<concept_controller, checkbox_t>::type dummy_ctor; } And then later being able to write (any_regular_t is the new name for value_t) any_regular_t v(some_function()); if (models<concept_controller>(v)) { any_controller_t c(cast<any_controller_t>(v)); //... } Another form of this that wouldn't require the global registration might look like: any_regular_t v(make_any_regular<concept_controller, concept_view> (checkbox_t())); (usage of the value would be the same as above). Eventually I'd like any_regular_t to become: typedef any<concept_regular> any_regular_t; So lots of work to do! We always welcome you help and suggestions :-) Sean On Oct 11, 2006, at 10:08 AM, Ralph Thomas wrote: > Hi, > > I'm not sure if this is possible, but... is there a way to put an > instance of some class into a value_t and then later pull out > regular_interfaces on it? Something like this: > > struct widget { > // from View > void display(const type_t&); > // from Controller > void monitor(monitor_fn_t); > ... > }; > > value_t v(new widget()); > any_view_t* view = v.get<any_view_t*>(); > any_controller_t* controller = v.get<any_controller_t*>(); > > The problems I have where this would be useful are typically wrapping > an API that defines a type for "a group of objects that can be > enumerated" (which I would have to convert to an array_t) and provides > some special operations on the group type (so I'd also have to have > the specific group type available). Of course, I can also solve this > problem by providing a conversion function, but this seemed more > interesting :). > > Thanks, > Ralph > > -- > "i have a dream and it's called a crossbar switch/what this will mean > is no big data glitch" > > ---------------------------------------------------------------------- > --- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Adobe-source-devel mailing list > Ado...@li... > https://lists.sourceforge.net/lists/listinfo/adobe-source-devel |