PlatformMap.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2018-2019, Dataspeed Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Dataspeed Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 #ifndef _DBW_FCA_CAN_PLATFORM_MAP_H
00036 #define _DBW_FCA_CAN_PLATFORM_MAP_H
00037 
00038 // Version classes
00039 #include <dbw_fca_can/ModuleVersion.h>
00040 #include <dbw_fca_can/PlatformVersion.h>
00041 
00042 // Standard libraries
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 } // namespace dbw_fca_can
00117 
00118 #endif // _DBW_FCA_CAN_PLATFORM_MAP_H
00119 


dbw_fca_can
Author(s): Kevin Hallenbeck
autogenerated on Sat May 4 2019 02:40:31