Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_context_thread_locale.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2013-2018 INRIA
2
// SPDX-License-Identifier: GPL-2.0-or-later
3
4
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
5
#include <windows.h>
6
#endif
// defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
7
#include <locale.h>
8
#ifdef __APPLE__
9
#include <xlocale.h>
10
#endif
11
12
#ifndef KIS_CONTEXT_THREAD_LOCALE_H
13
#define KIS_CONTEXT_THREAD_LOCALE_H
14
15
// Helper class to set the C locale when doing OCIO calls.
16
//
17
// See https://github.com/AcademySoftwareFoundation/OpenColorIO/issues/297#issuecomment-505636123
18
//
19
// Source: https://github.com/NatronGitHub/openfx-io/commit/27a13e00db8bae1a31308d66b4039a3542c14805
20
class
AutoSetAndRestoreThreadLocale
21
{
22
public
:
23
AutoSetAndRestoreThreadLocale
()
24
{
25
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
26
// set locale will only change locale on the current thread
27
previousThreadConfig = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
28
29
// get and store current locale
30
ssaLocale.assign(setlocale(LC_ALL, NULL));
31
32
// set to "C" locale
33
setlocale(LC_ALL,
"C"
);
34
#else
35
// set to C locale, saving the old one (returned from useLocale)
36
currentLocale
= newlocale(LC_ALL_MASK,
"C"
, NULL);
37
oldLocale
= uselocale(
currentLocale
);
38
#endif
39
}
40
41
~AutoSetAndRestoreThreadLocale
()
42
{
43
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
44
// thread specific
45
setlocale(LC_ALL, ssaLocale.c_str());
46
47
// set back to global settings]
48
_configthreadlocale(previousThreadConfig);
49
#else
50
// restore the previous locale and freeing the created locale
51
uselocale(
oldLocale
);
52
freelocale(
currentLocale
);
53
#endif
54
}
55
56
private
:
57
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
58
std::string ssaLocale;
59
int
previousThreadConfig;
60
#else
61
locale_t
oldLocale
;
62
locale_t
currentLocale
;
63
#endif
64
};
65
66
#endif
// KIS_CONTEXT_THREAD_LOCALE_H
AutoSetAndRestoreThreadLocale
Definition
kis_context_thread_locale.h:21
AutoSetAndRestoreThreadLocale::AutoSetAndRestoreThreadLocale
AutoSetAndRestoreThreadLocale()
Definition
kis_context_thread_locale.h:23
AutoSetAndRestoreThreadLocale::~AutoSetAndRestoreThreadLocale
~AutoSetAndRestoreThreadLocale()
Definition
kis_context_thread_locale.h:41
AutoSetAndRestoreThreadLocale::currentLocale
locale_t currentLocale
Definition
kis_context_thread_locale.h:62
AutoSetAndRestoreThreadLocale::oldLocale
locale_t oldLocale
Definition
kis_context_thread_locale.h:61
plugins
dockers
lut
kis_context_thread_locale.h
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52