1

I need to keep my data in associative table. Something like:

 typedef std::map< point, std::list<h_stat> > hm;

But STL containers do not have a ready serialization methods. It is very sad news. I think, it is not a good idea to link a boost library to my small project.

I program on Windows. Maybe, does windows.h or MFC have a associative table class, that has a serialization method from a box? Or is there another good container for C++ on the Internet?

Thank you in advance.

mihai
  • 37,072
  • 9
  • 60
  • 86
Kirill Golikov
  • 1,354
  • 1
  • 13
  • 27
  • 2
    MFC's `CMap` does support serialization. If I had to choose between MFC and standard library+Boost, I'd prefer the latter though. – Jerry Coffin Nov 02 '14 at 18:31
  • 1
    As a separate point: it looks like your `std::map>` is pretty much equivalent to a `std::multimap`. Depending on how your using it, the `multimap` may well be cleaner though. – Jerry Coffin Nov 02 '14 at 18:38
  • List is sorted by distance h_stat.point from point. I will look, is a multimap support a sorted_insert method. – Kirill Golikov Nov 02 '14 at 18:47
  • If you're sorting on both fields, then you may want something more like: `std::set>`. – Jerry Coffin Nov 02 '14 at 18:49
  • For one point there are many h_stat, the first h_stat in the list is the best. – Kirill Golikov Nov 02 '14 at 18:55
  • when you've sorted on both (as will happen by default with `std::pair`) it's easy to find the first one. – Jerry Coffin Nov 02 '14 at 19:00
  • I do not correctly understand "sorting on both"... It something different to my condition, that the points do not sort in the map.So the point stay at a place, the structs only changing their places in list of one point. – Kirill Golikov Nov 02 '14 at 19:13
  • Why does the serialization routine need to be built in to the container itself? It's not so difficult to write your own serialization routine that iterates over the container as necessary. – Jeremy Friesner Nov 02 '14 at 19:39

2 Answers2

4

With MFC you definitively have an easy way for serialisation with CMap and very easy way to make classes serializable.

However it's not so portable. An alternative is boost, which provides for serialisation also for standard containers (see also this answer to a similar question)

Community
  • 1
  • 1
Christophe
  • 68,716
  • 7
  • 72
  • 138
2

s11n is a C++ serialization library which claims that it...

can easily serialize all manner of PODs (Plain Old Data types), most STL containers, and user-defined Serializable types.

You could consider using it (AFAIK, it serializes containers automatically from serialization of constituents).

Otherwise, since your project is small, you should be able (without s11n) to manually add serialization operations to every class. With C++11 it should be relatively easy (thanks to ranged for loops, auto, lambda-expressions).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Unfortunately, I'm using MS VS 2010, as I know, there is an old C++. – Kirill Golikov Nov 02 '14 at 18:52
  • Honestly, It is too lazy for me to realize methods of dumping map, that dumping list, that dumping h_stat struct and etc. And to link the boost to MS VS is lazy too. I hope to find the silver bullet))) Thank you, I'll look at s11n. Maybe it is. – Kirill Golikov Nov 02 '14 at 18:59