PlatformMap.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015-2019, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _DBW_MKZ_CAN_PLATFORM_MAP_H
36 #define _DBW_MKZ_CAN_PLATFORM_MAP_H
37 
38 // Version classes
41 
42 // Standard libraries
43 #include <vector>
44 #include <map>
45 
46 namespace dbw_mkz_can
47 {
48 
49 class PlatformMap {
50 public:
51  PlatformMap() {};
52  PlatformMap(Platform p, Module m, ModuleVersion v) { insert(p, m, v); };
53  PlatformMap(const PlatformVersion &x) { insert(x); };
54  PlatformMap(const std::vector<PlatformVersion> &vec) {
55  for (size_t i = 0; i < vec.size(); i++) {
56  insert(vec[i]);
57  }
58  };
59  void insert(Platform p, Module m, ModuleVersion v) {
60  map[p][m] = v;
61  }
62  void insert(const PlatformVersion &x) {
63  map[x.p][x.m] = x.v;
64  }
65  ModuleVersion findModule(Module m) const {
66  for (Map::const_iterator it_p = map.begin(); it_p != map.end(); it_p++) {
67  const MapM &map_m = it_p->second;
68  MapM::const_iterator it_m = map_m.find(m);
69  if (it_m != map_m.end()) {
70  return it_m->second;
71  }
72  }
73  return ModuleVersion();
74  }
75  ModuleVersion findModule(Platform p, Module m) const {
76  MapP::const_iterator it_p = map.find(p);
77  if (it_p != map.end()) {
78  const MapM &map_m = it_p->second;
79  MapM::const_iterator it_m = map_m.find(m);
80  if (it_m != map_m.end()) {
81  return it_m->second;
82  }
83  }
84  return ModuleVersion();
85  }
86  ModuleVersion findModule(const PlatformVersion &x) const {
87  return findModule(x.p, x.m);
88  }
89  PlatformVersion findPlatform(Module m) const {
90  for (Map::const_iterator it_p = map.begin(); it_p != map.end(); it_p++) {
91  const MapM &map_m = it_p->second;
92  MapM::const_iterator it_m = map_m.find(m);
93  if (it_m != map_m.end()) {
94  return PlatformVersion(it_p->first, it_m->first, it_m->second);
95  }
96  }
97  return PlatformVersion();
98  }
99  PlatformVersion findPlatform(const PlatformVersion &x) const {
100  return findPlatform(x.m);
101  }
102 private:
103  typedef std::map<Module, ModuleVersion> MapM;
104  typedef std::map<Platform, MapM> MapP;
105  typedef MapP Map;
106  Map map;
107 };
108 
109 static bool operator< (const PlatformVersion& x, const PlatformMap& map) { return x < map.findModule(x); }
110 static bool operator> (const PlatformVersion& x, const PlatformMap& map) { return x > map.findModule(x); }
111 static bool operator<=(const PlatformVersion& x, const PlatformMap& map) { return x <= map.findModule(x); }
112 static bool operator>=(const PlatformVersion& x, const PlatformMap& map) { return x >= map.findModule(x); }
113 static bool operator==(const PlatformVersion& x, const PlatformMap& map) { return x == map.findModule(x); }
114 static bool operator!=(const PlatformVersion& x, const PlatformMap& map) { return x != map.findModule(x); }
115 
116 } // namespace dbw_mkz_can
117 
118 #endif // _DBW_MKZ_CAN_PLATFORM_MAP_H
119 
dbw_mkz_can::x
float x
Definition: sonar_lut.h:107
PlatformVersion.h
dbw_mkz_can::PlatformMap::Map
MapP Map
Definition: PlatformMap.h:169
Module
Module
dbw_mkz_can::PlatformMap::MapM
std::map< Module, ModuleVersion > MapM
Definition: PlatformMap.h:167
dbw_mkz_can::PlatformMap::findPlatform
PlatformVersion findPlatform(Module m) const
Definition: PlatformMap.h:153
dbw_mkz_can::operator>=
static bool operator>=(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:144
dbw_mkz_can::PlatformMap::findModule
ModuleVersion findModule(Module m) const
Definition: PlatformMap.h:129
dbw_mkz_can::operator<
static bool operator<(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:141
dbw_mkz_can::PlatformMap::map
Map map
Definition: PlatformMap.h:170
Platform
Platform
dbw_mkz_can::operator<=
static bool operator<=(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:143
dbw_mkz_can
Definition: dispatch.h:39
dbw_mkz_can::operator==
static bool operator==(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:145
dbw_mkz_can::PlatformMap::insert
void insert(Platform p, Module m, ModuleVersion v)
Definition: PlatformMap.h:123
dbw_mkz_can::PlatformMap::MapP
std::map< Platform, MapM > MapP
Definition: PlatformMap.h:168
ModuleVersion.h
dbw_mkz_can::operator!=
static bool operator!=(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:146
dbw_mkz_can::operator>
static bool operator>(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:142
dbw_mkz_can::PlatformMap::PlatformMap
PlatformMap()
Definition: PlatformMap.h:115


dbw_mkz_can
Author(s): Kevin Hallenbeck
autogenerated on Thu Jan 4 2024 03:46:24