Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _DBW_FCA_CAN_PLATFORM_MAP_H
00036 #define _DBW_FCA_CAN_PLATFORM_MAP_H
00037
00038
00039 #include <dbw_fca_can/ModuleVersion.h>
00040 #include <dbw_fca_can/PlatformVersion.h>
00041
00042
00043 #include <vector>
00044 #include <map>
00045
00046 namespace dbw_fca_can
00047 {
00048
00049 class PlatformMap {
00050 public:
00051 PlatformMap() {};
00052 PlatformMap(Platform p, Module m, ModuleVersion v) { insert(p, m, v); };
00053 PlatformMap(const PlatformVersion &x) { insert(x); };
00054 PlatformMap(const std::vector<PlatformVersion> &vec) {
00055 for (size_t i = 0; i < vec.size(); i++) {
00056 insert(vec[i]);
00057 }
00058 };
00059 void insert(Platform p, Module m, ModuleVersion v) {
00060 map[p][m] = v;
00061 }
00062 void insert(const PlatformVersion &x) {
00063 map[x.p][x.m] = x.v;
00064 }
00065 ModuleVersion findModule(Module m) const {
00066 for (Map::const_iterator it_p = map.begin(); it_p != map.end(); it_p++) {
00067 const MapM &map_m = it_p->second;
00068 MapM::const_iterator it_m = map_m.find(m);
00069 if (it_m != map_m.end()) {
00070 return it_m->second;
00071 }
00072 }
00073 return ModuleVersion();
00074 }
00075 ModuleVersion findModule(Platform p, Module m) const {
00076 MapP::const_iterator it_p = map.find(p);
00077 if (it_p != map.end()) {
00078 const MapM &map_m = it_p->second;
00079 MapM::const_iterator it_m = map_m.find(m);
00080 if (it_m != map_m.end()) {
00081 return it_m->second;
00082 }
00083 }
00084 return ModuleVersion();
00085 }
00086 ModuleVersion findModule(const PlatformVersion &x) const {
00087 return findModule(x.p, x.m);
00088 }
00089 PlatformVersion findPlatform(Module m) const {
00090 for (Map::const_iterator it_p = map.begin(); it_p != map.end(); it_p++) {
00091 const MapM &map_m = it_p->second;
00092 MapM::const_iterator it_m = map_m.find(m);
00093 if (it_m != map_m.end()) {
00094 return PlatformVersion(it_p->first, it_m->first, it_m->second);
00095 }
00096 }
00097 return PlatformVersion();
00098 }
00099 PlatformVersion findPlatform(const PlatformVersion &x) const {
00100 return findPlatform(x.m);
00101 }
00102 private:
00103 typedef std::map<Module, ModuleVersion> MapM;
00104 typedef std::map<Platform, MapM> MapP;
00105 typedef MapP Map;
00106 Map map;
00107 };
00108
00109 static bool operator< (const PlatformVersion& x, const PlatformMap& map) { return x < map.findModule(x); }
00110 static bool operator> (const PlatformVersion& x, const PlatformMap& map) { return x > map.findModule(x); }
00111 static bool operator<=(const PlatformVersion& x, const PlatformMap& map) { return x <= map.findModule(x); }
00112 static bool operator>=(const PlatformVersion& x, const PlatformMap& map) { return x >= map.findModule(x); }
00113 static bool operator==(const PlatformVersion& x, const PlatformMap& map) { return x == map.findModule(x); }
00114 static bool operator!=(const PlatformVersion& x, const PlatformMap& map) { return x != map.findModule(x); }
00115
00116 }
00117
00118 #endif // _DBW_FCA_CAN_PLATFORM_MAP_H
00119