Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
mitk::LocaleSwitch Struct Reference

Convenience class to temporarily change the current locale. More...

#include <mitkLocaleSwitch.h>

Public Member Functions

 LocaleSwitch (const char *newLocale)
 
 ~LocaleSwitch ()
 
 LocaleSwitch (LocaleSwitch &)=delete
 
LocaleSwitch operator= (LocaleSwitch &)=delete
 

Detailed Description

Convenience class to temporarily change the current locale.

This helper class can be used to switch to a specific locale for a couple of operations. Once the class is destroyed, the previous locale will be restored. This avoids calling or forgetting to call setlocale() in multiple return locations.

Typically this is used to switch to a "C" locale when parsing or printing numbers, in order to consistently get "." and not "," as a decimal separator.

WARNING: Please be aware that using setlocale and there for is not thread safe. So use this class with care (see task T24295 for more information. This switch is especially use full if you have to deal with third party code where you have to control the locale via set locale

{
mitk::LocaleSwitch localeSwitch("C");// installs C locale until the end of the function
ExternalLibraryCall(); //that might throw or what ever.
}

If you just want to control you own stringstream operations use imbue instead, as it is threadsafe. E.G.:

std::string toString(int number)
{
std::ostringstream parser;
parser.imbue(std::locale("C"));
parser << number;
return parser.str();
}

Definition at line 57 of file mitkLocaleSwitch.h.

Constructor & Destructor Documentation

◆ LocaleSwitch() [1/2]

mitk::LocaleSwitch::LocaleSwitch ( const char *  newLocale)
explicit

◆ ~LocaleSwitch()

mitk::LocaleSwitch::~LocaleSwitch ( )

◆ LocaleSwitch() [2/2]

mitk::LocaleSwitch::LocaleSwitch ( LocaleSwitch )
delete

Member Function Documentation

◆ operator=()

LocaleSwitch mitk::LocaleSwitch::operator= ( LocaleSwitch )
delete

The documentation for this struct was generated from the following file:
mitk::LocaleSwitch
Convenience class to temporarily change the current locale.
Definition: mitkLocaleSwitch.h:57