Commit cd991428 authored by Martin Marinov's avatar Martin Marinov
Browse files

Fixed a bug in BASE_THROW_ERROR_TODO_if; Moved LocaleSession to...

Fixed a bug in  BASE_THROW_ERROR_TODO_if; Moved LocaleSession to System::Environment. Changed LocaleSession to use std::locale::global() instead of ::set_locale().
parent 32e3f78b
......@@ -45,7 +45,7 @@ protected:
#define BASE_THROW_ERROR_if(COND, INDEX) { if (COND) THROW_ERROR(INDEX); }
#define BASE_THROW_ERROR_TODO(MSG) { THROW_ERROR_TODO_MODULE(Base, MSG); }
#define BASE_THROW_ERROR_TODO_if(COND, MSG) { if (COND) THROW_ERROR_TODO(MSG); }
#define BASE_THROW_ERROR_TODO_if(COND, MSG) { if (COND) BASE_THROW_ERROR_TODO(MSG); }
#endif//BASE_ERROR_HH_INCLUDED
......
......@@ -2,7 +2,11 @@
#include "Base/Security/Mandatory.hh"
#include "Environment.hh"
#include "Base/Debug/DebOut.hh"
#include <cstdlib>
#include <locale.h>
#include <locale>
namespace System {
namespace Environment {
......@@ -26,5 +30,22 @@ bool variable(const char* _vrbl_name, std::string& _vrbl)
return true;
}
//default session locale is "C" (i.e., "." is the decimal point)
LocaleSession::LocaleSession(const char* const _ssn_lcle)
{
lcl_bckp_ = std::locale::global(std::locale(_ssn_lcle));
auto* lcle = ::setlocale(LC_ALL, nullptr);
DEB_error_if(lcle == nullptr,
"std::locale::global() failed to set " << _ssn_lcle);
DEB_error_if(lcle != nullptr && strcmp(lcle, _ssn_lcle) != 0,
"set_locale() was asked to set " << _ssn_lcle <<
", but actually set " << lcle);
}
LocaleSession::~LocaleSession()
{
std::locale::global(lcl_bckp_);
}
}//namespace Environment
}//namespace System
......@@ -4,6 +4,7 @@
#define BASE_ENVIRONMENT_HH_INCLUDED
#include <string>
#include <locale>
namespace System {
namespace Environment {
......@@ -33,6 +34,20 @@ inline std::string variable(const char* _vrbl_name, const char* _vrbl_dflt)
return vrbl;
}
/*!
Define a "scoped" custom locale session.
*/
class LocaleSession
{
public:
//default session locale is "C" (i.e., "." is the decimal point)
LocaleSession(const char* const _ssn_lcle = "C");
~LocaleSession();
private:
std::locale lcl_bckp_;
};
}//namespace Environment
}//namespace System
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment