KiCad PCB EDA Suite
Loading...
Searching...
No Matches
config_map.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef CONFIG_MAP__H_
21#define CONFIG_MAP__H_
22
23#include <map>
24
25namespace UTIL
26{
27
44template<typename T>
45using CFG_MAP = std::vector<std::pair<T, long> >;
46
50template<typename MAP>
51using CFG_NATIVE_VAL = typename MAP::value_type::first_type;
52
53
64template<typename MAP>
65static long GetConfigForVal( const MAP& aMap, CFG_NATIVE_VAL<MAP> aVal )
66{
67 // default is first entry
68 long aConf = aMap[0].second;
69
70 for( const auto& mapping : aMap )
71 {
72 if( mapping.first == aVal )
73 {
74 aConf = mapping.second;
75 break;
76 }
77 }
78
79 return aConf;
80}
81
91template<typename MAP>
92static CFG_NATIVE_VAL<MAP> GetValFromConfig( const MAP& aMap, long aConf )
93{
94 // default is first entry
95 CFG_NATIVE_VAL<MAP> aVal = aMap[0].first;
96
97 for( const auto& mapping : aMap )
98 {
99 if( mapping.second == aConf )
100 {
101 aVal = mapping.first;
102 break;
103 }
104 }
105
106 return aVal;
107}
108
109}
110
111#endif /* CONFIG_MAP__H_ */
A model subscriber implementation using links to represent connections.
typename MAP::value_type::first_type CFG_NATIVE_VAL
The "native" type of a CFG_MAP: probably an enum type.
Definition config_map.h:51
std::vector< std::pair< T, long > > CFG_MAP
A config value table is a list of native values (usually enums) to a different set of values,...
Definition config_map.h:45
static long GetConfigForVal(const MAP &aMap, CFG_NATIVE_VAL< MAP > aVal)
Get the mapped config value (the one to write to file, or use in an index) from the given native (pro...
Definition config_map.h:65
static CFG_NATIVE_VAL< MAP > GetValFromConfig(const MAP &aMap, long aConf)
Get the native value corresponding to the config value (read from file or UI, probably) and find it i...
Definition config_map.h:92