OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
LocaleSettingsSwitch.h
Go to the documentation of this file.
1#pragma once
2#include <locale>
4{
5public:
6 LocaleSettingsSwitch(const char intendedDecimalSeparator)
7 {
8 const char currentSeparator = *std::localeconv()->decimal_point;
9 if (intendedDecimalSeparator != currentSeparator)
10 {
11 _reset = true;
12 char* local = std::setlocale(LC_NUMERIC, nullptr);
13 if (local == nullptr)
14 {
15 throw std::exception("Failed to determine active locale settings for decimal separator.");
16 }
17 else
18 {
19 _oldLocale = std::string(local);
20 }
21 if (intendedDecimalSeparator == '.')
22 {
23 std::setlocale(LC_NUMERIC, "en_US.UTF8");
24 }
25 else if(intendedDecimalSeparator == ',')
26 {
27 std::setlocale(LC_NUMERIC, "de_DE.UTF-8");
28 }
29 else
30 {
31 throw std::exception("Intended decimal separator is not supported.");
32 }
33 }
34 }
36 {
37 if (_reset)
38 {
39 std::setlocale(LC_NUMERIC, _oldLocale.c_str());
40 }
41 }
42private:
43 std::string _oldLocale = "";
44 bool _reset = false;
45};
Definition LocaleSettingsSwitch.h:4
LocaleSettingsSwitch(const char intendedDecimalSeparator)
Definition LocaleSettingsSwitch.h:6
~LocaleSettingsSwitch()
Definition LocaleSettingsSwitch.h:35