|
Boost Users : |
From: Lukasz (lkudra_at_[hidden])
Date: 2007-06-26 08:56:20
You summed it up very well with the first paragraph. I've been trying to
template this from the beginning, but it just wouldn't fit into the design.
However, i think i'll be able to use variant within one of my maps to store
the "real" type of the event which should work perfectly for my needs.
Thanks for all the input... it really helped to get some ideas together and
variant will probably do the trick (but i still have to fiddle some more
with the idea).
Thanks again.
Lukasz K.
Ovanes Markarian wrote:
>
>
> My idea is based on fact that you (program developer or another developer)
> know what is going to
> be send. What you are trying to do is erasing the type to some base and
> that would not work.
>
> So you send event must handle derived type and put it correctly to
> variant. A possible solution
> would be:
>
> template<class EventType_>
> void sendEvent(EventType_ const& ev)
> {
> m_eventContainer = ev; //<- now compiler knows exactly the type of ev
> m_derivedHelper->dispatchEvent(&m_eventContainer);
> }
>
>
> Best Regards,
> Ovanes
>
> On Fri, June 22, 2007 21:41, Lukasz wrote:
>>
>> Thanks for the fast reply. Your solution looked very good for my problem,
>> so i tried to apply it.
>>However, there seems to be a problem. At the point when i call
dispatchEvent (as in the below
>>example) is when i have the actual event to be sent. But i still only have
a pointer to the base
>>class and by assigning it to the container, it always gets interpreted as
a base event, even when
>>in reality it's some derived type.
>>
>> I tried a couple of approaches. In the first one, my variant contains
>> only the derived type
> (base class is Event, derived is EventTest) , i.e.
>>
>> typedef boost::variant<EventTest> event_container;
>>
>> ....
>> event_container m_eventContainer;
>> ...
>>
>> void sendEvent(Event * event)
>> {
>> // Call Helper to dispatch the event to correct type
>> m_eventContainer = *event;
>> m_derivedHelper->dispatchEvent(&m_eventContainer);
>> }
>>
>> This won't work. The compiler complains that none of the overloads for
>>boost::detail::variant::make_initializer_node::apply can convert parameter
2. If i add the base
>>event type to the variant list, i.e.
>>
>> typedef boost::variant<Event, EventTest> event_container;
>>
>> it will work, but it will always trigger the processEvent with the base
>> class type. I haven't found any information as to how boost::variant
>> treats a case of a pointer to
>>a base class (in this case, i'm not even actually passing the pointer but
an object since for
>>pointers it just doesn't seem to work). Should it be able to automatically
convert the type ? If
>>not, then i guess i'm back to square one, since i still can't cast the
event... unless i maybe
>>misunderstood something ? The code i tried is pretty much what you gave
me, with some minor
>>modifications.
>>
>> Thanks in advance for any further assistance.
>>
>> Lukasz K.
>>
>>
> [...]
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
-- View this message in context: http://www.nabble.com/problem...-maybe-boost-could-help-tf3959613.html#a11305123 Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net