Move locale_io to kicommon

This commit is contained in:
Marek Roszko 2023-09-10 11:29:06 -04:00
parent 4ac5404822
commit f0987821b5
3 changed files with 23 additions and 23 deletions

View File

@ -44,6 +44,7 @@ add_library( singletop STATIC EXCLUDE_FROM_ALL
# as APIEXPORT
set( KICOMMON_SRCS
exceptions.cpp
locale_io.cpp
richio.cpp
string_utils.cpp
)
@ -54,6 +55,7 @@ add_library( kicommon SHARED
target_link_libraries( kicommon
core
kimath
kiplatform
fmt::fmt
${wxWidgets_LIBRARIES}
@ -408,7 +410,6 @@ set( COMMON_SRCS
lib_table_grid_tricks.cpp
lib_tree_model.cpp
lib_tree_model_adapter.cpp
locale_io.cpp
lset.cpp
marker_base.cpp
markup_parser.cpp

View File

@ -47,14 +47,6 @@
//
// So use wxLocale on Windows and setlocale on unix
// set USE_WXLOCALE 0 to use setlocale, 1 to use wxLocale:
#if defined( _WIN32 )
#define USE_WXLOCALE 1
#else
#define USE_WXLOCALE 0
#endif
// On Windows, when using setlocale, a wx alert is generated
// in some cases (reading a bitmap for instance)
// So we disable alerts during the time a file is read or written
@ -73,12 +65,16 @@ void KiAssertFilter( const wxString &file, int line,
#endif
#endif
std::atomic<unsigned int> LOCALE_IO::m_c_count( 0 );
// allow for nesting of LOCALE_IO instantiations
static std::atomic<unsigned int> locale_count( 0 );
LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr )
LOCALE_IO::LOCALE_IO()
#if USE_WXLOCALE
: m_wxLocale( nullptr )
#endif
{
// use thread safe, atomic operation
if( m_c_count++ == 0 )
if( locale_count++ == 0 )
{
#if USE_WXLOCALE
#define C_LANG "C"
@ -100,7 +96,7 @@ LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr )
LOCALE_IO::~LOCALE_IO()
{
// use thread safe, atomic operation
if( --m_c_count == 0 )
if( --locale_count == 0 )
{
// revert to the user locale
#if USE_WXLOCALE

View File

@ -24,9 +24,17 @@
#ifndef LOCALE_IO_H
#define LOCALE_IO_H
#include <kicommon.h>
#include <atomic>
#include <string>
// set USE_WXLOCALE 0 to use setlocale, 1 to use wxLocale:
#if defined( _WIN32 )
#define USE_WXLOCALE 1
#else
#define USE_WXLOCALE 0
#endif
class wxLocale;
/**
@ -37,25 +45,20 @@ class wxLocale;
* point numbers. The destructor insures that the default locale is restored whether an
* exception is thrown or not.
*/
class LOCALE_IO
class KICOMMON_API LOCALE_IO
{
public:
LOCALE_IO();
~LOCALE_IO();
private:
// allow for nesting of LOCALE_IO instantiations
static std::atomic<unsigned int> m_c_count;
#if USE_WXLOCALE
wxLocale* m_wxLocale;
#else
// The locale in use before switching to the "C" locale
// (the locale can be set by user, and is not always the system locale)
std::string m_user_locale;
#ifndef __clang__
// [[maybe_unused]] attribute is ignored by Gcc but generates a warning.
wxLocale* m_wxLocale;
#else
[[maybe_unused]] wxLocale* m_wxLocale;
#endif
#endif
};
#endif