KiCad PCB EDA Suite
LOCALE_IO Class Reference

Instantiate the current locale within a scope in which you are expecting exceptions to be thrown. More...

#include <common.h>

Public Member Functions

 LOCALE_IO ()
 
 ~LOCALE_IO ()
 

Private Attributes

std::string m_user_locale
 

Static Private Attributes

static std::atomic< unsigned int > m_c_count
 Global variables definitions. More...
 

Detailed Description

Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.

The constructor sets a "C" language locale option, to read/print files with floating point numbers. The destructor insures that the default locale is restored if an exception is thrown or not.

Definition at line 90 of file common.h.

Constructor & Destructor Documentation

◆ LOCALE_IO()

LOCALE_IO::LOCALE_IO ( )

Definition at line 81 of file common.cpp.

82 {
83  // use thread safe, atomic operation
84  if( m_c_count++ == 0 )
85  {
86  // Store the user locale name, to restore this locale later, in dtor
87  m_user_locale = setlocale( LC_NUMERIC, nullptr );
88 #if defined( _WIN32 ) && defined( DEBUG )
89  // Disable wxWidgets alerts
90  wxSetAssertHandler( KiAssertFilter );
91 #endif
92  // Switch the locale to C locale, to read/write files with fp numbers
93  setlocale( LC_NUMERIC, "C" );
94  }
95 }
static std::atomic< unsigned int > m_c_count
Global variables definitions.
Definition: common.h:98
std::string m_user_locale
Definition: common.h:102

References m_c_count, and m_user_locale.

◆ ~LOCALE_IO()

LOCALE_IO::~LOCALE_IO ( )

Definition at line 98 of file common.cpp.

99 {
100  // use thread safe, atomic operation
101  if( --m_c_count == 0 )
102  {
103  // revert to the user locale
104  setlocale( LC_NUMERIC, m_user_locale.c_str() );
105 #if defined( _WIN32 ) && defined( DEBUG )
106  // Enable wxWidgets alerts
107  wxSetDefaultAssertHandler();
108 #endif
109  }
110 }
static std::atomic< unsigned int > m_c_count
Global variables definitions.
Definition: common.h:98
std::string m_user_locale
Definition: common.h:102

References m_c_count, and m_user_locale.

Member Data Documentation

◆ m_c_count

std::atomic< unsigned int > LOCALE_IO::m_c_count
staticprivate

Global variables definitions.

TODO: All of these variables should be moved into the class were they are defined and used. Most of them probably belong in the application class.

Definition at line 98 of file common.h.

Referenced by LOCALE_IO(), and ~LOCALE_IO().

◆ m_user_locale

std::string LOCALE_IO::m_user_locale
private

Definition at line 102 of file common.h.

Referenced by LOCALE_IO(), and ~LOCALE_IO().


The documentation for this class was generated from the following files: