KiCad PCB EDA Suite
LOCALE_IO Class Reference

Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting exceptions to be thrown. More...

#include <common.h>

Public Member Functions

 LOCALE_IO ()
 
 ~LOCALE_IO ()
 

Private Member Functions

void setUserLocale (const char *aUserLocale)
 

Private Attributes

std::string m_user_locale
 

Static Private Attributes

static std::atomic< unsigned int > m_c_count
 

Detailed Description

Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting exceptions to be thrown.

Its constructor set a "C" laguage locale option, to read/print files with fp numbers. Its destructor insures that the default locale is restored if an exception is thrown, or not.

Definition at line 166 of file common.h.

Constructor & Destructor Documentation

LOCALE_IO::LOCALE_IO ( )

Definition at line 70 of file common.cpp.

References m_c_count, and m_user_locale.

71 {
72  // use thread safe, atomic operation
73  if( m_c_count++ == 0 )
74  {
75  // Store the user locale name, to restore this locale later, in dtor
76  m_user_locale = setlocale( LC_ALL, 0 );
77  // Switch the locale to C locale, to read/write files with fp numbers
78  setlocale( LC_ALL, "C" );
79  }
80 }
static std::atomic< unsigned int > m_c_count
Definition: common.h:176
std::string m_user_locale
Definition: common.h:180
LOCALE_IO::~LOCALE_IO ( )

Definition at line 82 of file common.cpp.

References m_c_count, and m_user_locale.

83 {
84  // use thread safe, atomic operation
85  if( --m_c_count == 0 )
86  {
87  // revert to the user locale
88  setlocale( LC_ALL, m_user_locale.c_str() );
89  }
90 }
static std::atomic< unsigned int > m_c_count
Definition: common.h:176
std::string m_user_locale
Definition: common.h:180

Member Function Documentation

void LOCALE_IO::setUserLocale ( const char *  aUserLocale)
private

Member Data Documentation

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

Definition at line 176 of file common.h.

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

std::string LOCALE_IO::m_user_locale
private

Definition at line 180 of file common.h.

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


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