Re: [Boost-users] problem... maybe boost could help
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_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.
[...]
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
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
dispatchEvent (as in the below 2. If i add the base
event type to the variant list, i.e.
typedef boost::variant
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@lists.boost.org 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#a1130... Sent from the Boost - Users mailing list archive at Nabble.com.
If you like, prepare me some simple example and I can correct it or help you at this point. With Kind Regards, Ovanes Markarian On Tue, June 26, 2007 14:56, Lukasz wrote:
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
[...]
That's very kind, but i already tried out my idea and it works :) Variant basically allowed me to keep a list of all my events of different types, which is exactly what i needed. That, combined with my original "derived helper", and the visitor allows me to get pretty much everything i needed. Thanks again, Lukasz K. Ovanes Markarian wrote:
If you like, prepare me some simple example and I can correct it or help you at this point.
With Kind Regards,
Ovanes Markarian
On Tue, June 26, 2007 14:56, Lukasz wrote:
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
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org 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#a1130... Sent from the Boost - Users mailing list archive at Nabble.com.
Hi all, Probably answered before but I have a little problem I use a template class : template<int N> struct A { // Do Something } ; And I would like serialized this in binary file (with template argument). Do you know a solution (with boost library or not) knowing this class must have a integer template argument ? Best Regards, Pierre Soory for my english, it is not very good
Any reason the following wouldn't work? Robert Ramey Pierre Salmon wrote:
Hi all,
Probably answered before but I have a little problem I use a template class :
template<int N> struct A { // Do Something template<class Archive> void serialize(Archive & ar, const unsigned version){ ar & ...; } } ;
And I would like serialized this in binary file (with template argument). Do you know a solution (with boost library or not) knowing this class must have a integer template argument ?
Best Regards, Pierre
Soory for my english, it is not very good
The problem is not when I serialize class (save) but, when I load class, How I can instanciate template class ? Best Regards, Pierre Salmon
Any reason the following wouldn't work?
Robert Ramey
Pierre Salmon wrote:
Hi all,
Probably answered before but I have a little problem I use a template class :
template<int N> struct A { // Do Something
template<class Archive> void serialize(Archive & ar, const unsigned version){ ar & ...; }
} ;
And I would like serialized this in binary file (with template argument). Do you know a solution (with boost library or not) knowing this class must have a integer template argument ?
Best Regards, Pierre
Soory for my english, it is not very good
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
My question remains: Any reason the following wouldn't work? Robert Ramey Pierre Salmon wrote:
The problem is not when I serialize class (save) but, when I load class, How I can instanciate template class ?
Best Regards,
Pierre Salmon
Any reason the following wouldn't work?
Robert Ramey
Pierre Salmon wrote:
Hi all,
Probably answered before but I have a little problem I use a template class :
template<int N> struct A { // Do Something
template<class Archive> void serialize(Archive & ar, const unsigned version){ ar & ...; }
} ;
And I would like serialized this in binary file (with template argument). Do you know a solution (with boost library or not) knowing this class must have a integer template argument ?
Best Regards, Pierre
Soory for my english, it is not very good
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello again,
I actually have another question. Although the solution now works, it's
still not perfect. The problem is the actual variant. Right now, i have a
separate header file which has a typedef for my variant, i.e.
typedef boost::variant
If you like, prepare me some simple example and I can correct it or help you at this point.
With Kind Regards,
Ovanes Markarian
On Tue, June 26, 2007 14:56, Lukasz wrote:
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
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org 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#a1132... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (4)
-
Lukasz
-
Ovanes Markarian
-
Pierre Salmon
-
Robert Ramey