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 (C) 2017 Kicad Developers, see change_log.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef CONFIG_MAP__H_
25#define CONFIG_MAP__H_
26
27#include <map>
28
29namespace UTIL
30{
31
48template<typename T>
49using CFG_MAP = std::vector<std::pair<T, long> >;
50
54template<typename MAP>
55using CFG_NATIVE_VAL = typename MAP::value_type::first_type;
56
57
68template<typename MAP>
69static long GetConfigForVal( const MAP& aMap, CFG_NATIVE_VAL<MAP> aVal )
70{
71 // default is first entry
72 long aConf = aMap[0].second;
73
74 for( const auto& mapping : aMap )
75 {
76 if( mapping.first == aVal )
77 {
78 aConf = mapping.second;
79 break;
80 }
81 }
82
83 return aConf;
84}
85
95template<typename MAP>
96static CFG_NATIVE_VAL<MAP> GetValFromConfig( const MAP& aMap, long aConf )
97{
98 // default is first entry
99 CFG_NATIVE_VAL<MAP> aVal = aMap[0].first;
100
101 for( const auto& mapping : aMap )
102 {
103 if( mapping.second == aConf )
104 {
105 aVal = mapping.first;
106 break;
107 }
108 }
109
110 return aVal;
111}
112
113}
114
115#endif /* CONFIG_MAP__H_ */
A model subscriber implementation using links to represent connections.
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:49
typename MAP::value_type::first_type CFG_NATIVE_VAL
The "native" type of a CFG_MAP: probably an enum type.
Definition: config_map.h:55
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:69
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:96