map set/get requests into C++ class/structure changes

前端 未结 1 1004
南旧
南旧 2020-11-28 16:38

I\'m trying to figure out what is the best approach here. Basically I have a system where I receive external requests in order to set/get values in my model. The problem is

相关标签:
1条回答
  • 2020-11-28 17:11

    Boost has Property Maps for this purpose.

    • http://www.boost.org/doc/libs/1_57_0/libs/property_map/doc/property_map.html

    The most elementary interface it exposes is

    get(map, key)
    put(pmap, key, val)
    

    For lvalue/readable maps you can also get indexer style access

    pmap[key];
    pmap[key] = newval; // if not const/readonly
    

    You can a existing property map adaptors:

    • identity_property_map and typed_identity_property_map
    • function_property_map
    • iterator_property_map
    • shared_array_property_map
    • associative_property_map
    • const_associative_property_map
    • vector_property_map
    • ref_property_map
    • static_property_map
    • transform_value_property_map
    • compose_property_map

    or write custom ones.

    There is even a dynamic_property_map that looks like this, in practice:

    put("age",properties,fred,new_age);
    put("gpa",properties,fred,new_gpa);
    

    Note that age and gpa could be stored anywhere (even requiring a web-request, perhaps) but the difference in access is abstracted away by the properymap interface that sits in between.


    Samples from my answers:

    • Is it possible to have several edge weight property maps for one graph BOOST?
    • Cut set of a graph, Boost Graph Library using a BiMap and a Boost Multi Index container to store the properties
    0 讨论(0)
提交回复
热议问题