KiCad PCB EDA Suite
UTIL Namespace Reference

Namespaces

 DETAIL
 

Classes

class  LINK
 
class  OBSERVABLE
 

Typedefs

template<typename T >
using CFG_MAP = std::vector< std::pair< T, long > >
 A config value table is a list of native values (usually enums) to a different set of values, for example, the values used to represent the enum in a config file, or the index used to represent it in a selection list. More...
 
template<typename MAP >
using CFG_NATIVE_VAL = typename MAP::value_type::first_type
 The "native" type of a CFG_MAP: probably an enum type. More...
 

Functions

template<typename MAP >
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 (probably enum) value. More...
 
template<typename MAP >
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 in the mapping table. More...
 

Typedef Documentation

template<typename T >
using UTIL::CFG_MAP = typedef std::vector<std::pair<T, long> >

A config value table is a list of native values (usually enums) to a different set of values, for example, the values used to represent the enum in a config file, or the index used to represent it in a selection list.

It can be important to decouple from the internal representation, especially in the case of persistent config files, as adding, removing or modifying the order of items internally can easily result in configs being read incorrectly, and, even if otherwise carefully managed, results in obsolete values being kept in enums as placeholders.

The first item in the list is used default if no matching value is found during lookup.

Definition at line 49 of file config_map.h.

template<typename MAP >
using UTIL::CFG_NATIVE_VAL = typedef typename MAP::value_type::first_type

The "native" type of a CFG_MAP: probably an enum type.

Definition at line 55 of file config_map.h.

Function Documentation

template<typename MAP >
static long UTIL::GetConfigForVal ( const MAP &  aMap,
CFG_NATIVE_VAL< MAP >  aVal 
)
static

Get the mapped config value (the one to write to file, or use in an index) from the given native (probably enum) value.

The default (first item) is returned if the value is not found in the list.

Parameters
aMapthe value-config mapping table
aValthe value to look up

Definition at line 69 of file config_map.h.

Referenced by DIALOG_DISPLAY_OPTIONS::TransferDataToWindow(), GAL_OPTIONS_PANEL::TransferDataToWindow(), and KIGFX::GAL_DISPLAY_OPTIONS::WriteConfig().

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 }
template<typename MAP >
static CFG_NATIVE_VAL<MAP> UTIL::GetValFromConfig ( const MAP &  aMap,
long  aConf 
)
static

Get the native value corresponding to the config value (read from file or UI, probably) and find it in the mapping table.

The default item is returned if the mapping fails.

Parameters
aMapthe value-config mapping table
aValthe config value to look up

Definition at line 96 of file config_map.h.

Referenced by KIGFX::GAL_DISPLAY_OPTIONS::ReadConfig(), DIALOG_DISPLAY_OPTIONS::TransferDataFromWindow(), and GAL_OPTIONS_PANEL::TransferDataFromWindow().

98 {
99  // default is first entry
100  CFG_NATIVE_VAL<MAP> aVal = aMap[0].first;
101 
102  for( const auto& mapping : aMap )
103  {
104  if( mapping.second == aConf )
105  {
106  aVal = mapping.first;
107  break;
108  }
109  }
110 
111  return aVal;
112 }