Medical Imaging Interaction Toolkit  2022.04.99-01b95b17
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 tast T24295 for more information. This switch is especially use full if you have to deal with third party code where you have to controll 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 << number;
return parser.str();

Definition at line 57 of file mitkLocaleSwitch.h.

Constructor & Destructor Documentation

◆ LocaleSwitch() [1/2]

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

◆ ~LocaleSwitch()

mitk::LocaleSwitch::~LocaleSwitch ( )

◆ LocaleSwitch() [2/2]

mitk::LocaleSwitch::LocaleSwitch ( LocaleSwitch )

Member Function Documentation

◆ operator=()

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

The documentation for this struct was generated from the following file: