PlatformMap.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018-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_FCA_CAN_PLATFORM_MAP_H
36 #define _DBW_FCA_CAN_PLATFORM_MAP_H
37 
38 // Version classes
41 
42 // Standard libraries
43 #include <vector>
44 #include <map>
45 
46 namespace dbw_fca_can
47 {
48 
49 class PlatformMap {
50 public:
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  };
60  map[p][m] = v;
61  }
62  void insert(const PlatformVersion &x) {
63  map[x.p][x.m] = x.v;
64  }
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  }
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  }
87  return findModule(x.p, x.m);
88  }
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  }
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_fca_can
117 
118 #endif // _DBW_FCA_CAN_PLATFORM_MAP_H
119 
PlatformVersion findPlatform(Module m) const
Definition: PlatformMap.h:89
void insert(const PlatformVersion &x)
Definition: PlatformMap.h:62
static bool operator==(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:113
static bool operator<(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:109
ModuleVersion findModule(Platform p, Module m) const
Definition: PlatformMap.h:75
std::map< Platform, MapM > MapP
Definition: PlatformMap.h:104
ModuleVersion findModule(Module m) const
Definition: PlatformMap.h:65
static bool operator<=(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:111
PlatformMap(Platform p, Module m, ModuleVersion v)
Definition: PlatformMap.h:52
static bool operator>(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:110
PlatformVersion findPlatform(const PlatformVersion &x) const
Definition: PlatformMap.h:99
ModuleVersion findModule(const PlatformVersion &x) const
Definition: PlatformMap.h:86
static bool operator!=(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:114
std::map< Module, ModuleVersion > MapM
Definition: PlatformMap.h:103
PlatformMap(const PlatformVersion &x)
Definition: PlatformMap.h:53
void insert(Platform p, Module m, ModuleVersion v)
Definition: PlatformMap.h:59
PlatformMap(const std::vector< PlatformVersion > &vec)
Definition: PlatformMap.h:54
static bool operator>=(const PlatformVersion &x, const PlatformMap &map)
Definition: PlatformMap.h:112


dbw_fca_can
Author(s): Kevin Hallenbeck
autogenerated on Wed May 12 2021 02:14:05