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
 

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 177 of file common.h.

Constructor & Destructor Documentation

◆ LOCALE_IO()

LOCALE_IO::LOCALE_IO ( )

Definition at line 83 of file common.cpp.

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

References m_c_count, and m_user_locale.

◆ ~LOCALE_IO()

LOCALE_IO::~LOCALE_IO ( )

Definition at line 100 of file common.cpp.

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

References m_c_count, and m_user_locale.

Member Data Documentation

◆ m_c_count

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

Definition at line 185 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 189 of file common.h.

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


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