Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Need ideas -> generic storage of type registration with unknown type

Reply
Thread Tools

Need ideas -> generic storage of type registration with unknown type

 
 
Noah Roberts
Guest
Posts: n/a
 
      03-15-2010
I'm using the boost::serialization library for the IO for my objects.
I'd like to come up with a way to register objects with the archive in a
generic manner something like so:

struct type_registrar
{
template < typename T >
static bool register_type()
{
singleton()->register_functions.push_back(boost::bind
(&Archive::register_type<T>, _1));
}
static type_registrar * singleton()
{
static type_registrar * singleton_ = new type_registrar;
return singleton_;
}
static void register_all(Archive & ar)
{
BOOST_FOREACH(boost::function<void(Archive&)> rf, singleton()->
register_functions)
{
rf(ar);
}
}
private:
std::vector< boost::function<void(Archive&)> > register_functions;
};

Then in some .cpp file I'd do this:

namespace { bool reg = type_registrar::register_type<my_local_type>(); }

Then, upon a load/save operation I'd do:

Archive ar; // this isn't how to create one, just illustrating.
type_registrar::register_all(ar);

The problem is that "Archive" needs to be any type (in other words,
"register_all()" needs to be templated by Archive) since I could be:

a) registering with either an input or output archive and each is its
own type or...

b) registering with a binary archive in one example and an xml or text
archive in some other.

I need the former now, the latter is just something that would be in
line with the boost::serialization design.

I can't think of any way to do this. I can answer the former with two
sets of functions for the register_all to go through, but it would be
nice to loose the redundancy if possible.

So I'm asking for ideas.

Thanks.
 
Reply With Quote
 
 
 
 
Noah Roberts
Guest
Posts: n/a
 
      03-15-2010
In article <(E-Mail Removed)>,
http://www.velocityreviews.com/forums/(E-Mail Removed) says...
>
> I'm using the boost::serialization library for the IO for my objects.
> I'd like to come up with a way to register objects with the archive in a
> generic manner something like so:


..... blah blah blah....

I was looking at the wrong place in the code for the problem. There's
already mechanics to do what I needed to do and I was using them, I just
thought it wasn't working.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
not just generic type programming,but also parallism generic syntaxprogramming?? minlearn C++ 2 03-13-2009 05:17 PM
Unknown Storage Size Error for union semun kvnsmnsn@hotmail.com C Programming 5 09-23-2007 07:59 AM
Customer Registration - Temporary data storage Chris ASP .Net 3 01-08-2007 02:56 AM
Assign an unknown value to an unknown variable Vincent Arnoux Ruby 1 08-11-2006 06:12 PM
Registration string - unknown prog Pepper Computer Support 2 01-25-2004 07:49 PM



Advertisments