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
 
wxLocale * m_wxLocale
 

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

Constructor & Destructor Documentation

◆ LOCALE_IO()

LOCALE_IO::LOCALE_IO ( )

Definition at line 227 of file common.cpp.

227  : m_wxLocale( nullptr )
228 {
229  // use thread safe, atomic operation
230  if( m_c_count++ == 0 )
231  {
232 #if USE_WXLOCALE
233  m_wxLocale = new wxLocale( "C", "C", "C", false );
234 #else
235  // Store the user locale name, to restore this locale later, in dtor
236  m_user_locale = setlocale( LC_NUMERIC, nullptr );
237 #if defined( _WIN32 ) && defined( DEBUG )
238  // Disable wxWidgets alerts
239  wxSetAssertHandler( KiAssertFilter );
240 #endif
241  // Switch the locale to C locale, to read/write files with fp numbers
242  setlocale( LC_NUMERIC, "C" );
243 #endif
244  }
245 }
wxLocale * m_wxLocale
Definition: common.h:229
static std::atomic< unsigned int > m_c_count
Definition: common.h:224
std::string m_user_locale
Definition: common.h:228

References m_c_count, m_user_locale, and m_wxLocale.

◆ ~LOCALE_IO()

LOCALE_IO::~LOCALE_IO ( )

Definition at line 248 of file common.cpp.

249 {
250  // use thread safe, atomic operation
251  if( --m_c_count == 0 )
252  {
253  // revert to the user locale
254 #if USE_WXLOCALE
255  delete m_wxLocale; // Deleting m_wxLocale restored previous locale
256  m_wxLocale = nullptr;
257 #else
258  setlocale( LC_NUMERIC, m_user_locale.c_str() );
259 #if defined( _WIN32 ) && defined( DEBUG )
260  // Enable wxWidgets alerts
261  wxSetDefaultAssertHandler();
262 #endif
263 #endif
264  }
265 }
wxLocale * m_wxLocale
Definition: common.h:229
static std::atomic< unsigned int > m_c_count
Definition: common.h:224
std::string m_user_locale
Definition: common.h:228

References m_c_count, m_user_locale, and m_wxLocale.

Member Data Documentation

◆ m_c_count

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

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

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

◆ m_wxLocale

wxLocale* LOCALE_IO::m_wxLocale
private

Definition at line 229 of file common.h.

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


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