00001 #ifndef METRO_STATION_DATA_H_INCLUDED
00002 #define METRO_STATION_DATA_H_INCLUDED
00003
00004 #include <sstream>
00005 #include <boost/multi_index_container.hpp>
00006 #include <boost/multi_index/member.hpp>
00007 #include <boost/multi_index/mem_fun.hpp>
00008 #include <boost/multi_index/ordered_index.hpp>
00009
00010 namespace metro
00011 {
00012
00013 namespace bmi = boost::multi_index;
00014
00016 typedef unsigned int id_station;
00017
00018 namespace station
00019 {
00020
00024 class Data
00025 {
00026 friend class IdMgr;
00027
00028 std::string m_ligne;
00029 std::string m_nom;
00030 int m_nEtape;
00031 id_station m_id;
00032
00033 public:
00035 static const id_station invalid_id;
00036
00037 Data(const std::string& ligne, const std::string& nom, int nEtape);
00038
00040 std::string key() const;
00041
00043 id_station id() const;
00044
00046 const std::string& nom() const;
00047
00049 const std::string& ligne() const;
00050
00052 int etape() const;
00053
00055 bool operator<(const Data& other);
00056 };
00057
00059 struct id {};
00061 struct key {};
00062
00064 typedef boost::multi_index_container<
00065 Data,
00066 bmi::indexed_by<
00067 bmi::ordered_unique<
00068 bmi::tag<id>, BOOST_MULTI_INDEX_CONST_MEM_FUN(Data, id_station, id)
00069 >,
00070 bmi::ordered_non_unique<
00071 bmi::tag<key>, BOOST_MULTI_INDEX_CONST_MEM_FUN(Data, std::string, key)
00072 >
00073 >
00074 > IdContainer;
00075
00081 struct IdMgr
00082 {
00083 static IdContainer m_idStations;
00084
00086 static id_station get_id(Data& stationData);
00087
00089 static bmi::index<IdContainer, id>::type& get_by_id();
00090 };
00091
00095 id_station get_id(Data& stationData);
00096
00097 typedef bmi::index<IdContainer, id>::type container_by_id_t;
00098 typedef IdContainer::index<id>::type set_by_id_t;
00099
00103 const container_by_id_t& get_by_id();
00104
00105
00106 }
00107
00111 class StationData : public station::Data
00112 {
00113 public:
00114 StationData(const std::string& ligne, const std::string& nom, int nEtape)
00115 : station::Data(ligne, nom, nEtape)
00116 {
00117 station::get_id(*this);
00118 }
00119 };
00120
00121 }
00122
00123 #endif // METRO_STATION_DATA_H_INCLUDED