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#pragma once
21
22#include <map>
23#include <utility>
24#include <vector>
25
26
27namespace UTIL
28{
29
46template<typename T>
47using CFG_MAP = std::vector<std::pair<T, long> >;
48
52template<typename MAP>
53using CFG_NATIVE_VAL = typename MAP::value_type::first_type;
54
55
66template<typename MAP>
67static long GetConfigForVal( const MAP& aMap, CFG_NATIVE_VAL<MAP> aVal )
68{
69 // default is first entry
70 long aConf = aMap[0].second;
71
72 for( const auto& mapping : aMap )
73 {
74 if( mapping.first == aVal )
75 {
76 aConf = mapping.second;
77 break;
78 }
79 }
80
81 return aConf;
82}
83
93template<typename MAP>
94static CFG_NATIVE_VAL<MAP> GetValFromConfig( const MAP& aMap, long aConf )
95{
96 // default is first entry
97 CFG_NATIVE_VAL<MAP> aVal = aMap[0].first;
98
99 for( const auto& mapping : aMap )
100 {
101 if( mapping.second == aConf )
102 {
103 aVal = mapping.first;
104 break;
105 }
106 }
107
108 return aVal;
109}
110
111} // namespace UTIL
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:53
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:47
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:67
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:94