On Tue, Jun 2, 2009 at 10:19 AM, Ryan McConnehey
<mccorywork@gmail.com> wrote:
Zachary Turner wrote:
BEGIN_SERIALIZATION_DECLS()
DECL_SERIALIZAITON_SUPPORT(boost::uint16_t)
DECL_SERIALIZATION_SUPPORT(boost::uint32_t)
END_SERIALIZATION_DECLS()
I like how easy this is to expand for new types. A requirement that didn't seem important at the time, but now may affect this design, is having multiple variable names at different levels. For example, within the level (the levels are only one deep)"Bob" and "Sue" the variable "test1" can exist. They are not required to be the same type though. Since types can change I remove the variable name before I store the new variable at the given level. This means current I have a structure with all my different type maps and then a map of levels (level names as the key) and type structures. I have a shared_ptr, to the current level structure of types, and all inputed variables name and values are placed within the shared_ptr structure.
I don't think the design would need to change but do you see any problem?
First thing is I actually made a slight mistake in my code example, the line "map_type map;" inside the struct declaration should have been "static map_type map;"
Regarding your other question, I'm not totally sure I understand, could you post a short code snippet? If you mean that you want different maps for the same type, for example:
std::map<std::string, boost::uint16_t> uint16map_1;
std::map<std::string, boost::uint16_t> uint16map_2;
std::map<std::string, boost::uint16_t> uint16map_3;
Then the design I mentioned doesn't support this directly, but I think it could be made to support it a number of different ways. The easiest way would be to just add an additional argument to the BEGIN_SERIALIZATION_DECLS() macro and use that argument for the namespace name instead of "serialization". Then you would have:
BEGIN_SERIALIZATION_DECLS(serialization_map1)
DECL_SERIALIZATION_SUPPORT(boost::uint16_t)
DECL_SERIALIZATION_SUPPORT(boost::uint32_t)
END_SERIALIZATION_DECLS()
BEGIN_SERIALIZATION_DECLS(serialization_map2)
DECL_SERIALIZATION_SUPPORT(boost::uint32_t)
DECL_SERIALIZATION_SUPPORT(foo)
END_SERIALIZATION_DECLS()
serialization_map1::kv_map<boost::uint16_t>::map["test1"] = 7;
serialization_map2::kv_map<boost::uint16_t>::map["test1"] = 8;
If you need to provide different storage / retrieval logic for different types then just specialize the store_kv and retrieve_kv functions. When you want to support a new type you only add 1 line of code, a DECL_SERIALIZATION_SUPPORT macro.
If the storage / retrieval logic is customized for different types, how is this only adding one line for a new type? Don't you have to add the one line and the extra storage / retrieval logic for the new type?'