Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Boost UTF backend is currently used?

Tags:

c++

utf-8

boost

Following the boost manual (http://www.boost.org/doc/libs/1_56_0/libs/locale/doc/html/using_localization_backends.html),

I can set a UTF backend using:

boost::locale::localization_backend_manager my = boost::locale::localization_backend_manager::global();
my.select("std");

Is there any way to now check, whether indeed the std backend is used?

I only seem to be able to get all the available backends, but not the currently active one

boost::locale::localization_backend_manager lbm = boost::locale::localization_backend_manager::global();
auto s = lbm.get_all_backends();
for_each(s.begin(), s.end(), [](string& x){ cout << x << endl; });
like image 650
user695652 Avatar asked May 04 '16 14:05

user695652


1 Answers

Not really, no. There isn't a way to get the current back-end for a multitude of reasons:

  • There's no public API function that gives you access to the back-ends used
  • localization_backend uses the pimpl idiom to defer the actual implementation of the back-ends. There's no reflection either in localization_backend or in the back-ends themselves
  • This comment from localization_backend.hpp:

    Backends are usually registered inside the localization backends manager and allow transparent support of different backends, so a user can switch the backend by simply linking the application to the correct one.

    ...

    Each backend can be installed with a different default priotiry so when you work with two different backends, you can specify priotiry so this backend will be chosen according to their priority.

It would needlessly complicate the implementation as on top of the priority feature, specific back-ends can be set for specific locale categories. Boost.Locale is designed to "just work" with whatever back-ends it's configured with, transparency and binary compatibility in mind. As a commenter said, it's not really useful information since you're using this library to abstract away library/platform-specific features.

like image 82
uh oh somebody needs a pupper Avatar answered Nov 06 '22 08:11

uh oh somebody needs a pupper