16 #ifndef COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_S 17 #define COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_S 20 #include <Balau/Type/Impl/ToStringImpl.hpp> 22 #include <boost/lexical_cast.hpp> 23 #include <boost/locale.hpp> 26 #include <forward_list> 29 #include <unordered_set> 30 #include <unordered_map> 34 template <
typename P1,
typename P2,
typename ... P>
35 std::string
toString(
const P1 & p1,
const P2 & p2,
const P & ... p);
37 template <
typename P1,
typename P2,
typename ... P>
38 std::u16string
toString16(
const P1 & p1,
const P2 & p2,
const P & ... p);
40 template <
typename P1,
typename P2,
typename ... P>
41 std::u32string
toString32(
const P1 & p1,
const P2 & p2,
const P & ... p);
48 inline std::string
toString(
const std::string & value) {
55 inline std::string
toString(
const std::string_view & value) {
56 return std::string(value);
59 #ifndef BALAU_USE_BOOST_STRING_VIEW 64 inline std::string
toString(
const boost::string_view & value) {
65 return value.to_string();
73 inline std::string
toString(
const std::u16string & value) {
74 return boost::locale::conv::utf_to_utf<char, char16_t>(value);
80 inline std::string
toString(
const std::u16string_view & value) {
81 return boost::locale::conv::utf_to_utf<char, char16_t>(std::u16string(value));
87 inline std::string
toString(
const std::u32string & value) {
88 return boost::locale::conv::utf_to_utf<char, char32_t>(value);
94 inline std::string
toString(
const std::u32string_view & value) {
95 return boost::locale::conv::utf_to_utf<char, char32_t>(std::u32string(value));
129 return Balau::Impl::toString<std::allocator<char>>(
"%d", (int) value);
136 return Balau::Impl::toString<std::allocator<char>>(
"%d", (int) value);
143 return Balau::Impl::toString<std::allocator<char>>(
"%d", value);
150 return Balau::Impl::toString<std::allocator<char>>(
"%ld", value);
157 return Balau::Impl::toString<std::allocator<char>>(
"%lld", value);
164 return Balau::Impl::toString<std::allocator<char>>(
"%u", (
unsigned int) value);
170 inline std::string
toString(
unsigned short value) {
171 return Balau::Impl::toString<std::allocator<char>>(
"%u", (
unsigned int) value);
178 return Balau::Impl::toString<std::allocator<char>>(
"%u", value);
185 return Balau::Impl::toString<std::allocator<char>>(
"%lu", value);
191 inline std::string
toString(
unsigned long long value) {
192 return Balau::Impl::toString<std::allocator<char>>(
"%llu", value);
199 return boost::lexical_cast<std::string>(value);
206 return boost::lexical_cast<std::string>(value);
213 return boost::lexical_cast<std::string>(value);
219 template <
typename T>
inline std::string
toString(
const std::complex<T> & value) {
220 return toString(value.real(),
" + j", value.imag());
227 return value ?
"true" :
"false";
234 return std::string(value);
237 std::u16string
toString16(
const char16_t * value);
238 std::u32string
toString32(
const char32_t * value);
243 inline std::string
toString(
const char16_t * value) {
250 inline std::string
toString(
const char32_t * value) {
277 inline std::string
toString(std::type_index value) {
284 inline std::string
toString(
const std::function<std::string ()> & f) {
291 template <
typename F,
typename S>
292 inline std::string
toString(
const std::pair<F, S> & p) {
293 return std::string(
"{ ") +
toString(p.first) +
", " +
toString(p.second) +
" }";
301 template <
typename ... T,
template <
typename ...>
class C>
303 std::string builder =
"{";
304 std::string prefix =
" ";
307 for (
const auto & e : c) {
325 #define BALAU_CONTAINER1_TO_STRING(CONTAINER_TYPE) \ 326 template <typename T> \ 327 inline std::string toString(const CONTAINER_TYPE<T> & c) { \ 328 return toStringHelper(c); \ 334 #define BALAU_CONTAINER2_TO_STRING(CONTAINER_TYPE) \ 335 template <typename T, typename U> \ 336 inline std::string toString(const CONTAINER_TYPE<T, U> & c) { \ 337 return toStringHelper(c); \ 343 #define BALAU_CONTAINER3_TO_STRING(CONTAINER_TYPE) \ 344 template <typename T, typename U, typename V> \ 345 inline std::string toString(const CONTAINER_TYPE<T, U, V> & c) { \ 346 return toStringHelper(c); \ 352 #define BALAU_CONTAINER4_TO_STRING(CONTAINER_TYPE) \ 353 template <typename T, typename U, typename V, typename W> \ 354 inline std::string toString(const CONTAINER_TYPE<T, U, V, W> & c) { \ 355 return toStringHelper(c); \ 361 #define BALAU_CONTAINER5_TO_STRING(CONTAINER_TYPE) \ 362 template <typename T, typename U, typename V, typename W, typename X> \ 363 inline std::string toString(const CONTAINER_TYPE<T, U, V, W, X> & c) { \ 364 return toStringHelper(c); \ 383 template <
typename T,
size_t N>
inline std::string
toString(
const std::array<T, N> & c) {
398 template <
typename P1,
typename P2,
typename ... P>
399 inline std::string
toString(
const P1 & p1,
const P2 & p2,
const P & ... p) {
408 inline std::u16string
toString16(
const std::string & value) {
409 return boost::locale::conv::utf_to_utf<char16_t, char>(value);
415 inline std::u16string
toString16(
const std::string_view & value) {
419 #ifndef BALAU_USE_BOOST_STRING_VIEW 424 inline std::u16string
toString16(
const boost::string_view & value) {
433 inline std::u16string
toString16(
const std::u16string & value) {
440 inline std::u16string
toString16(
const std::u16string_view & value) {
441 return std::u16string(value);
447 inline std::u16string
toString16(
const std::u32string & value) {
448 return boost::locale::conv::utf_to_utf<char16_t, char32_t>(value);
572 template <
typename T>
inline std::u16string
toString16(
const std::complex<T> & value) {
573 return toString16(value.real(),
" + j", value.imag());
580 return value ? u
"true" : u
"false";
594 return std::u16string(value);
634 inline std::u16string
toString16(
const std::function<std::u16string ()> & f) {
641 template <
typename F,
typename S>
642 inline std::u16string
toString16(
const std::pair<F, S> & p) {
651 template <
typename ... T,
template <
typename ...>
class C>
653 std::u16string builder = u
"{";
654 std::u16string prefix = u
" ";
657 for (
const auto & e : c) {
675 #define BALAU_CONTAINER1_TO_STRING16(CONTAINER_TYPE) \ 676 template <typename T> \ 677 inline std::u16string toString16(const CONTAINER_TYPE<T> & c) { \ 678 return toString16Helper(c); \ 684 #define BALAU_CONTAINER2_TO_STRING16(CONTAINER_TYPE) \ 685 template <typename T, typename U> \ 686 inline std::u16string toString16(const CONTAINER_TYPE<T, U> & c) { \ 687 return toString16Helper(c); \ 693 #define BALAU_CONTAINER3_TO_STRING16(CONTAINER_TYPE) \ 694 template <typename T, typename U, typename V> \ 695 inline std::u16string toString16(const CONTAINER_TYPE<T, U, V> & c) { \ 696 return toString16Helper(c); \ 702 #define BALAU_CONTAINER4_TO_STRING16(CONTAINER_TYPE) \ 703 template <typename T, typename U, typename V, typename W> \ 704 inline std::u16string toString16(const CONTAINER_TYPE<T, U, V, W> & c) { \ 705 return toString16Helper(c); \ 711 #define BALAU_CONTAINER5_TO_STRING16(CONTAINER_TYPE) \ 712 template <typename T, typename U, typename V, typename W, typename X> \ 713 inline std::u16string toString16(const CONTAINER_TYPE<T, U, V, W, X> & c) { \ 714 return toString16Helper(c); \ 733 template <
typename P1,
typename P2,
typename ... P>
740 inline std::u16string
toString16(
const P1 & p1,
const P2 & p2,
const P & ... p) {
749 inline std::u32string
toString32(
const std::string & value) {
750 return boost::locale::conv::utf_to_utf<char32_t, char>(value);
756 inline std::u32string
toString32(
const std::string_view & value) {
760 #ifndef BALAU_USE_BOOST_STRING_VIEW 765 inline std::u32string
toString32(
const boost::string_view & value) {
774 inline std::u32string
toString32(
const std::u16string & value) {
775 return boost::locale::conv::utf_to_utf<char32_t, char16_t>(value);
781 inline std::u32string
toString32(
const std::u32string & value) {
788 inline std::u32string
toString32(
const std::u32string_view & value) {
789 return std::u32string(value);
913 template <
typename T>
inline std::u32string
toString32(
const std::complex<T> & value) {
914 return toString32(value.real(),
" + j", value.imag());
921 return value ? U
"true" : U
"false";
942 return std::u32string(value);
975 inline std::u32string
toString32(
const std::function<std::u32string ()> & f) {
982 template <
typename F,
typename S>
983 inline std::u32string
toString32(
const std::pair<F, S> & p) {
992 template <
typename ... T,
template <
typename ...>
class C>
994 std::u32string builder = U
"{";
995 std::u32string prefix = U
" ";
998 for (
const auto & e : c) {
1016 #define BALAU_CONTAINER1_TO_STRING32(CONTAINER_TYPE) \ 1017 template <typename T> \ 1018 inline std::u32string toString32(const CONTAINER_TYPE<T> & c) { \ 1019 return toString32Helper(c); \ 1025 #define BALAU_CONTAINER2_TO_STRING32(CONTAINER_TYPE) \ 1026 template <typename T, typename U> \ 1027 inline std::u32string toString32(const CONTAINER_TYPE<T, U> & c) { \ 1028 return toString32Helper(c); \ 1034 #define BALAU_CONTAINER3_TO_STRING32(CONTAINER_TYPE) \ 1035 template <typename T, typename U, typename V> \ 1036 inline std::u32string toString32(const CONTAINER_TYPE<T, U, V> & c) { \ 1037 return toString32Helper(c); \ 1043 #define BALAU_CONTAINER4_TO_STRING32(CONTAINER_TYPE) \ 1044 template <typename T, typename U, typename V, typename W> \ 1045 inline std::u32string toString32(const CONTAINER_TYPE<T, U, V, W> & c) { \ 1046 return toString32Helper(c); \ 1052 #define BALAU_CONTAINER5_TO_STRING32(CONTAINER_TYPE) \ 1053 template <typename T, typename U, typename V, typename W, typename X> \ 1054 inline std::u32string toString32(const CONTAINER_TYPE<T, U, V, W, X> & c) { \ 1055 return toString32Helper(c); \ 1074 template <
typename P1,
typename P2,
typename ... P>
1081 inline std::u32string
toString32(
const P1 & p1,
const P2 & p2,
const P & ... p) {
1093 template <
typename T> std::string operator () (
const T &
object)
const {
1104 template <
typename T> std::u16string operator () (
const T &
object)
const {
1115 template <
typename T> std::u32string operator () (
const T &
object)
const {
1120 #endif // COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_S #define BALAU_CONTAINER3_TO_STRING32(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has three template parameters.
Definition: ToStringS.hpp:1034
#define BALAU_CONTAINER5_TO_STRING(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has five template parameters.
Definition: ToStringS.hpp:361
#define BALAU_CONTAINER2_TO_STRING16(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has two template parameters.
Definition: ToStringS.hpp:684
#define BALAU_CONTAINER3_TO_STRING(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has three template parameters.
Definition: ToStringS.hpp:343
#define BALAU_CONTAINER4_TO_STRING32(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has four template parameters.
Definition: ToStringS.hpp:1043
#define BALAU_CONTAINER4_TO_STRING(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has four template parameters.
Definition: ToStringS.hpp:352
#define BALAU_CONTAINER5_TO_STRING16(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has five template parameters.
Definition: ToStringS.hpp:711
std::u32string toString32Helper(const C< T ... > &c)
Helper for container to UTF-8 string functions.
Definition: ToStringS.hpp:993
std::string toStringHelper(const C< T ... > &c)
Helper for container to UTF-8 string functions.
Definition: ToStringS.hpp:302
#define BALAU_CONTAINER4_TO_STRING16(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has four template parameters.
Definition: ToStringS.hpp:702
#define BALAU_CONTAINER5_TO_STRING32(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has five template parameters.
Definition: ToStringS.hpp:1052
Core includes, typedefs and functions.
#define BALAU_CONTAINER3_TO_STRING16(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has three template parameters.
Definition: ToStringS.hpp:693
#define BALAU_CONTAINER2_TO_STRING32(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has two template parameters.
Definition: ToStringS.hpp:1025
std::u32string toString32(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringS.hpp:1081
std::string toString(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringS.hpp:399
#define BALAU_CONTAINER2_TO_STRING(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has two template parameters.
Definition: ToStringS.hpp:334
std::u16string toString16(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringS.hpp:740
Template class based to-string function for use in template classes.
Definition: ToStringA.hpp:1278
std::u16string toString16Helper(const C< T ... > &c)
Helper for container to UTF-16 string functions.
Definition: ToStringS.hpp:652