ToStringA.hpp
Go to the documentation of this file.
1 //
2 // Balau core C++ library
3 //
4 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
5 //
6 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
7 // See the LICENSE file for the full license text.
8 //
9 
15 
16 #ifndef COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_A
17 #define COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_A
18 
19 #include <Balau/Type/StdTypes.hpp>
20 #include <Balau/Type/Impl/ToStringImpl.hpp>
21 #include <Balau/ThirdParty/Boost/Locale/EncodingUtf.hpp>
22 
23 #include <boost/lexical_cast.hpp>
24 #include <boost/locale.hpp>
25 #include <boost/utility/string_view.hpp>
26 
27 #include <forward_list>
28 #include <list>
29 #include <map>
30 #include <unordered_set>
31 #include <unordered_map>
32 #include <stack>
33 #include <queue>
34 
35 namespace Balau {
36 
40 template <typename AllocatorT>
41 using U8String = std::basic_string<char, std::char_traits<char>, AllocatorT>;
42 
46 template <typename AllocatorT>
47 using U16String = std::basic_string<char16_t, std::char_traits<char16_t>, AllocatorT>;
48 
52 template <typename AllocatorT>
53 using U32String = std::basic_string<char32_t, std::char_traits<char32_t>, AllocatorT>;
54 
58 template <typename AllocatorT>
59 using U8OStringStream = std::basic_ostringstream<char, std::char_traits<char>, AllocatorT>;
60 
64 template <typename AllocatorT>
65 using U16OStringStream = std::basic_ostringstream<char16_t, std::char_traits<char16_t>, AllocatorT>;
66 
70 template <typename AllocatorT>
71 using U32OStringStream = std::basic_ostringstream<char32_t, std::char_traits<char32_t>, AllocatorT>;
72 
73 }
74 
75 template <typename AllocatorT, typename P1, typename P2, typename ... P>
76 Balau::U8String<AllocatorT> toString(const P1 & p1, const P2 & p2, const P & ... p);
77 
78 template <typename AllocatorT, typename P1, typename P2, typename ... P>
79 Balau::U16String<AllocatorT> toString16(const P1 & p1, const P2 & p2, const P & ... p);
80 
81 template <typename AllocatorT, typename P1, typename P2, typename ... P>
82 Balau::U32String<AllocatorT> toString32(const P1 & p1, const P2 & p2, const P & ... p);
83 
85 
89 template <typename AllocatorT>
91  return value;
92 }
93 
97 template <typename AllocatorT>
98 inline Balau::U8String<AllocatorT> toString(const std::string & value) {
99  return Balau::U8String<AllocatorT>(value.data(), value.length());
100 }
101 
105 template <typename AllocatorT>
106 inline Balau::U8String<AllocatorT> toString(const std::string_view & value) {
107  return Balau::U8String<AllocatorT>(value);
108 }
109 
110 #ifndef BALAU_USE_BOOST_STRING_VIEW
111 
115 template <typename AllocatorT>
116 inline Balau::U8String<AllocatorT> toString(const boost::string_view & value) {
117  return Balau::U8String<AllocatorT>(value.data(), value.length());
118 }
119 
120 #endif
121 
125 template <typename AllocatorT>
126 inline Balau::U8String<AllocatorT> toString(const std::u16string & value) {
127  return Balau::Boost::Locale::Conv::utf_to_utf<char, char16_t, AllocatorT>(value);
128 }
129 
133 template <typename AllocatorT>
134 inline Balau::U8String<AllocatorT> toString(const std::u16string_view & value) {
135  return Balau::Boost::Locale::Conv::utf_to_utf<char, char16_t, AllocatorT>(std::u16string(value));
136 }
137 
141 template <typename AllocatorT>
142 inline Balau::U8String<AllocatorT> toString(const std::u32string & value) {
143  return Balau::Boost::Locale::Conv::utf_to_utf<char, char32_t, AllocatorT>(value);
144 }
145 
149 template <typename AllocatorT>
150 inline Balau::U8String<AllocatorT> toString(const std::u32string_view & value) {
151  return Balau::Boost::Locale::Conv::utf_to_utf<char, char32_t, AllocatorT>(std::u32string(value));
152 }
153 
157 template <typename AllocatorT>
160  str += value;
161  return str;
162 }
163 
167 template <typename AllocatorT>
168 inline Balau::U8String<AllocatorT> toString(char16_t value) {
170  str += value;
171  return toString<AllocatorT>(str);
172 }
173 
177 template <typename AllocatorT>
178 inline Balau::U8String<AllocatorT> toString(char32_t value) {
179  std::u32string str;
180  str += value;
181  return toString<AllocatorT>(str);
182 }
183 
187 template <typename AllocatorT>
188 inline Balau::U8String<AllocatorT> toString(signed char value) {
189  return Balau::Impl::toString<AllocatorT>("%d", (int) value);
190 }
191 
195 template <typename AllocatorT>
197  return Balau::Impl::toString<AllocatorT>("%d", (int) value);
198 }
199 
203 template <typename AllocatorT>
205  return Balau::Impl::toString<AllocatorT>("%d", (int) value);
206 }
207 
211 template <typename AllocatorT>
213  return Balau::Impl::toString<AllocatorT>("%ld", value);
214 }
215 
219 template <typename AllocatorT>
220 inline Balau::U8String<AllocatorT> toString(long long value) {
221  return Balau::Impl::toString<AllocatorT>("%lld", value);
222 }
223 
227 template <typename AllocatorT>
228 inline Balau::U8String<AllocatorT> toString(unsigned char value) {
229  return Balau::Impl::toString<AllocatorT>("%u", (unsigned int) value);
230 }
231 
235 template <typename AllocatorT>
236 inline Balau::U8String<AllocatorT> toString(unsigned short value) {
237  return Balau::Impl::toString<AllocatorT>("%u", (unsigned int) value);
238 }
239 
243 template <typename AllocatorT>
244 inline Balau::U8String<AllocatorT> toString(unsigned int value) {
245  return Balau::Impl::toString<AllocatorT>("%u", value);
246 }
247 
251 template <typename AllocatorT>
252 inline Balau::U8String<AllocatorT> toString(unsigned long value) {
253  return Balau::Impl::toString<AllocatorT>("%lu", value);
254 }
255 
259 template <typename AllocatorT>
260 inline Balau::U8String<AllocatorT> toString(unsigned long long value) {
261  return Balau::Impl::toString<AllocatorT>("%llu", value);
262 }
263 
267 template <typename AllocatorT>
269  return boost::lexical_cast<Balau::U8String<AllocatorT>>(value);
270 }
271 
275 template <typename AllocatorT>
276 inline Balau::U8String<AllocatorT> toString(double value) {
277  return boost::lexical_cast<Balau::U8String<AllocatorT>>(value);
278 }
279 
283 template <typename AllocatorT>
284 inline Balau::U8String<AllocatorT> toString(long double value) {
285  return boost::lexical_cast<Balau::U8String<AllocatorT>>(value);
286 }
287 
291 template <typename T, typename AllocatorT>
292 inline Balau::U8String<AllocatorT> toString(const std::complex<T> & value) {
293  return toString<AllocatorT>(value.real(), " + j", value.imag());
294 }
295 
299 template <typename AllocatorT>
301  return value ? "true" : "false";
302 }
303 
307 template <typename AllocatorT>
308 inline Balau::U8String<AllocatorT> toString(const char * value) {
309  return Balau::U8String<AllocatorT>(value);
310 }
311 
312 template <typename AllocatorT>
313 std::u16string toString16(const char16_t * value);
314 
315 template <typename AllocatorT>
316 std::u32string toString32(const char32_t * value);
317 
321 template <typename AllocatorT>
322 inline Balau::U8String<AllocatorT> toString(const char16_t * value) {
323  return toString<AllocatorT>(toString16<AllocatorT>(value));
324 }
325 
329 template <typename AllocatorT>
330 inline Balau::U8String<AllocatorT> toString(const char32_t * value) {
331  return toString<AllocatorT>(toString32<AllocatorT>(value));
332 }
333 
340 template <typename AllocatorT>
341 inline Balau::U8String<AllocatorT> toString(const void * ptr) {
342  return toString<AllocatorT>((size_t) ptr);
343 }
344 
351 template <typename AllocatorT>
352 inline Balau::U8String<AllocatorT> toString(std::nullptr_t) {
353  return "0";
354 }
355 
359 template <typename AllocatorT>
360 inline Balau::U8String<AllocatorT> toString(std::type_index value) {
361  return value.name();
362 }
363 
367 template <typename AllocatorT>
369  return f();
370 }
371 
375 template <typename AllocatorT, typename F, typename S>
376 inline Balau::U8String<AllocatorT> toString(const std::pair<F, S> & p) {
377  return Balau::U8String<AllocatorT>("{ ") + toString<AllocatorT>(p.first) + ", " + toString<AllocatorT>(p.second) + " }";
378 }
379 
385 template <typename AllocatorT, typename ... T, template <typename ...> class C>
386 inline Balau::U8String<AllocatorT> toStringHelper(const C<T ...> & c) {
387  Balau::U8String<AllocatorT> builder = "{";
388  Balau::U8String<AllocatorT> prefix = " ";
389  bool empty = true;
390 
391  for (const auto & e : c) {
392  builder += prefix + toString<AllocatorT>(e);
393  prefix = ", ";
394  empty = false;
395  }
396 
397  if (!empty) {
398  builder += " ";
399  }
400 
401  builder += "}";
402 
403  return builder;
404 }
405 
409 #define BALAU_CONTAINER1_TO_STRING_A(CONTAINER_TYPE) \
410  template <typename T, typename AllocatorT> \
411  inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T> & c) { \
412  return toStringHelper<AllocatorT>(c); \
413  }
414 
418 #define BALAU_CONTAINER2_TO_STRING_A(CONTAINER_TYPE) \
419  template <typename AllocatorT, typename T, typename U> \
420  inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U> & c) { \
421  return toStringHelper<AllocatorT>(c); \
422  }
423 
427 #define BALAU_CONTAINER3_TO_STRING_A(CONTAINER_TYPE) \
428  template <typename AllocatorT, typename T, typename U, typename V> \
429  inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U, V> & c) { \
430  return toStringHelper<AllocatorT>(c); \
431  }
432 
436 #define BALAU_CONTAINER4_TO_STRING_A(CONTAINER_TYPE) \
437  template <typename AllocatorT, typename T, typename U, typename V, typename W> \
438  inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U, V, W> & c) { \
439  return toStringHelper<AllocatorT>(c); \
440  }
441 
445 #define BALAU_CONTAINER5_TO_STRING_A(CONTAINER_TYPE) \
446  template <typename AllocatorT, typename T, typename U, typename V, typename W, typename X> \
447  inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U, V, W, X> & c) { \
448  return toStringHelper<AllocatorT>(c); \
449  }
450 
452 BALAU_CONTAINER2_TO_STRING_A(std::forward_list)
455 BALAU_CONTAINER3_TO_STRING_A(std::multiset)
456 BALAU_CONTAINER4_TO_STRING_A(std::multimap)
457 BALAU_CONTAINER3_TO_STRING_A(std::priority_queue)
461 BALAU_CONTAINER5_TO_STRING_A(std::unordered_map)
462 BALAU_CONTAINER5_TO_STRING_A(std::unordered_multimap)
463 BALAU_CONTAINER4_TO_STRING_A(std::unordered_multiset)
464 BALAU_CONTAINER3_TO_STRING_A(std::unordered_set)
465 BALAU_CONTAINER2_TO_STRING_A(std::vector)
466 
467 template <typename AllocatorT, typename T, size_t N>
473 inline Balau::U8String<AllocatorT> toString(const std::array<T, N> & c) {
474  return toStringHelper<AllocatorT>(c);
475 }
476 
483 template <typename AllocatorT, typename P1, typename P2, typename ... P>
484 inline Balau::U8String<AllocatorT> toString(const P1 & p1, const P2 & p2, const P & ... p) {
485  return toString<AllocatorT>(p1) + toString<AllocatorT>(p2) + (Balau::U8String<AllocatorT>() + ... + toString<AllocatorT>(p));
486 }
487 
489 
493 template <typename AllocatorT>
495  return Balau::Boost::Locale::Conv::utf_to_utf<char16_t, char, AllocatorT>(value);
496 }
497 
501 template <typename AllocatorT>
502 inline Balau::U16String<AllocatorT> toString16(const std::string & value) {
503  return Balau::Boost::Locale::Conv::utf_to_utf<char16_t, char, AllocatorT>(Balau::U8String<AllocatorT>(value));
504 }
505 
509 template <typename AllocatorT>
510 inline Balau::U16String<AllocatorT> toString16(const std::string_view & value) {
511  return toString16<AllocatorT>(Balau::U8String<AllocatorT>(value));
512 }
513 
514 
515 #ifndef BALAU_USE_BOOST_STRING_VIEW
516 
520 template <typename AllocatorT>
521 inline Balau::U16String<AllocatorT> toString16(const boost::string_view & value) {
522  return toString16<AllocatorT>(Balau::U8String<AllocatorT>(value.to_string()));
523 }
524 
525 #endif
526 
530 template <typename AllocatorT>
532  return value;
533 }
534 
538 template <typename AllocatorT>
539 inline Balau::U16String<AllocatorT> toString16(const std::u16string & value) {
540  return Balau::U16String<AllocatorT>(value.data(), value.length());
541 }
542 
546 template <typename AllocatorT>
547 inline Balau::U16String<AllocatorT> toString16(const std::u16string_view & value) {
548  return Balau::U16String<AllocatorT>(value);
549 }
550 
554 template <typename AllocatorT>
555 inline Balau::U16String<AllocatorT> toString16(const std::u32string & value) {
556  return Balau::Boost::Locale::Conv::utf_to_utf<char16_t, char32_t, AllocatorT>(value);
557 }
558 
562 template <typename AllocatorT>
565  str += value;
566  return toString16<AllocatorT>(str);
567 }
568 
572 template <typename AllocatorT>
573 inline Balau::U16String<AllocatorT> toString16(char16_t & value) {
575  str += value;
576  return str;
577 }
578 
582 template <typename AllocatorT>
583 inline Balau::U16String<AllocatorT> toString16(char32_t & value) {
585  str += value;
586  return toString16<AllocatorT>(str);
587 }
588 
592 template <typename AllocatorT>
593 inline Balau::U16String<AllocatorT> toString16(signed char value) {
594  return toString16<AllocatorT>(toString<AllocatorT>(value));
595 }
596 
600 template <typename AllocatorT>
602  return toString16<AllocatorT>(toString<AllocatorT>(value));
603 }
604 
608 template <typename AllocatorT>
610  return toString16<AllocatorT>(toString<AllocatorT>(value));
611 }
612 
616 template <typename AllocatorT>
618  return toString16<AllocatorT>(toString<AllocatorT>(value));
619 }
620 
624 template <typename AllocatorT>
625 inline Balau::U16String<AllocatorT> toString16(long long value) {
626  return toString16<AllocatorT>(toString<AllocatorT>(value));
627 }
628 
632 template <typename AllocatorT>
633 inline Balau::U16String<AllocatorT> toString16(unsigned char value) {
634  return toString16<AllocatorT>(toString<AllocatorT>(value));
635 }
636 
640 template <typename AllocatorT>
641 inline Balau::U16String<AllocatorT> toString16(unsigned short value) {
642  return toString16<AllocatorT>(toString<AllocatorT>(value));
643 }
644 
648 template <typename AllocatorT>
649 inline Balau::U16String<AllocatorT> toString16(unsigned int value) {
650  return toString16<AllocatorT>(toString<AllocatorT>(value));
651 }
652 
656 template <typename AllocatorT>
657 inline Balau::U16String<AllocatorT> toString16(unsigned long value) {
658  return toString16<AllocatorT>(toString<AllocatorT>(value));
659 }
660 
664 template <typename AllocatorT>
665 inline Balau::U16String<AllocatorT> toString16(unsigned long long value) {
666  return toString16<AllocatorT>(toString<AllocatorT>(value));
667 }
668 
672 template <typename AllocatorT>
674  return toString16<AllocatorT>(toString<AllocatorT>(value));
675 }
676 
680 template <typename AllocatorT>
682  return toString16<AllocatorT>(toString<AllocatorT>(value));
683 }
684 
688 template <typename AllocatorT>
689 inline Balau::U16String<AllocatorT> toString16(long double value) {
690  return toString16<AllocatorT>(toString<AllocatorT>(value));
691 }
692 
696 template <typename T, typename AllocatorT>
697 inline Balau::U16String<AllocatorT> toString16(const std::complex<T> & value) {
698  return toString16<AllocatorT>(value.real(), " + j", value.imag());
699 }
700 
704 template <typename AllocatorT>
706  return value ? u"true" : u"false";
707 }
708 
712 template <typename AllocatorT>
713 inline Balau::U16String<AllocatorT> toString16(const char * value) {
714  return toString16<AllocatorT>(toString<AllocatorT>((value)));
715 }
716 
720 template <typename AllocatorT>
721 inline Balau::U16String<AllocatorT> toString16(const char16_t * value) {
722  return std::u16string(value);
723 }
724 
728 template <typename AllocatorT>
729 inline Balau::U16String<AllocatorT> toString16(const char32_t * value) {
730  return toString16<AllocatorT>(toString32<AllocatorT>(value));
731 }
732 
739 template <typename AllocatorT>
740 inline Balau::U16String<AllocatorT> toString16(const void * ptr) {
741  return toString16<AllocatorT>((size_t) ptr);
742 }
743 
750 template <typename AllocatorT>
751 inline Balau::U16String<AllocatorT> toString16(std::nullptr_t) {
752  return u"0";
753 }
754 
758 template <typename AllocatorT>
759 inline Balau::U16String<AllocatorT> toString16(std::type_index value) {
760  return toString16<AllocatorT>(value.name());
761 }
762 
766 template <typename AllocatorT>
767 inline Balau::U16String<AllocatorT> toString16(const std::function<std::u16string ()> & f) {
768  return f();
769 }
770 
774 template <typename AllocatorT, typename F, typename S>
775 inline Balau::U16String<AllocatorT> toString16(const std::pair<F, S> & p) {
776  return std::u16string(u"{ ") + toString16<AllocatorT>(p.first) + u", " + toString16<AllocatorT>(p.second) + u" }";
777 }
778 
784 template <typename AllocatorT, typename ... T, template <typename ...> class C>
785 inline std::u16string toString16Helper(const C<T ...> & c) {
786  std::u16string builder = u"{";
787  std::u16string prefix = u" ";
788  bool empty = true;
789 
790  for (const auto & e : c) {
791  builder += prefix + toString16<AllocatorT>(e);
792  prefix = u", ";
793  empty = false;
794  }
795 
796  if (!empty) {
797  builder += u" ";
798  }
799 
800  builder += u"}";
801 
802  return builder;
803 }
804 
808 #define BALAU_CONTAINER1_TO_STRING16_A(CONTAINER_TYPE) \
809  template <typename AllocatorT, typename T> \
810  inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T> & c) { \
811  return toString16Helper<AllocatorT>(c); \
812  }
813 
817 #define BALAU_CONTAINER2_TO_STRING16_A(CONTAINER_TYPE) \
818  template <typename AllocatorT, typename T, typename U> \
819  inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U> & c) { \
820  return toString16Helper<AllocatorT>(c); \
821  }
822 
826 #define BALAU_CONTAINER3_TO_STRING16_A(CONTAINER_TYPE) \
827  template <typename AllocatorT, typename T, typename U, typename V> \
828  inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U, V> & c) { \
829  return toString16Helper<AllocatorT>(c); \
830  }
831 
835 #define BALAU_CONTAINER4_TO_STRING16_A(CONTAINER_TYPE) \
836  template <typename AllocatorT, typename T, typename U, typename V, typename W> \
837  inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U, V, W> & c) { \
838  return toString16Helper<AllocatorT>(c); \
839  }
840 
844 #define BALAU_CONTAINER5_TO_STRING16_A(CONTAINER_TYPE) \
845  template <typename AllocatorT, typename T, typename U, typename V, typename W, typename X> \
846  inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U, V, W, X> & c) { \
847  return toString16Helper<AllocatorT>(c); \
848  }
849 
851 BALAU_CONTAINER2_TO_STRING16_A(std::forward_list)
854 BALAU_CONTAINER3_TO_STRING16_A(std::multiset)
855 BALAU_CONTAINER4_TO_STRING16_A(std::multimap)
856 BALAU_CONTAINER3_TO_STRING16_A(std::priority_queue)
860 BALAU_CONTAINER5_TO_STRING16_A(std::unordered_map)
861 BALAU_CONTAINER5_TO_STRING16_A(std::unordered_multimap)
862 BALAU_CONTAINER4_TO_STRING16_A(std::unordered_multiset)
863 BALAU_CONTAINER3_TO_STRING16_A(std::unordered_set)
865 
866 template <typename AllocatorT, typename P1, typename P2, typename ... P>
873 inline Balau::U16String<AllocatorT> toString16(const P1 & p1, const P2 & p2, const P & ... p) {
874  return toString16<AllocatorT>(p1)
875  + toString16<AllocatorT>(p2)
876  + (Balau::U16String<AllocatorT>() + ... + toString16<AllocatorT>(p));
877 }
878 
880 
884 template <typename AllocatorT>
885 inline Balau::U32String<AllocatorT> toString32(const std::string & value) {
886  return Balau::Boost::Locale::Conv::utf_to_utf<char32_t, char, AllocatorT>(Balau::U8String<AllocatorT>(value));
887 }
888 
892 template <typename AllocatorT>
894  return Balau::Boost::Locale::Conv::utf_to_utf<char32_t, char, AllocatorT>(value);
895 }
896 
900 template <typename AllocatorT>
901 inline Balau::U32String<AllocatorT> toString32(const std::string_view & value) {
902  return toString32<AllocatorT>(Balau::U8String<AllocatorT>(value));
903 }
904 
905 #ifndef BALAU_USE_BOOST_STRING_VIEW
906 
910 template <typename AllocatorT>
911 inline Balau::U32String<AllocatorT> toString32(const boost::string_view & value) {
912  return toString32<AllocatorT>(Balau::U8String<AllocatorT>(value.to_string()));
913 }
914 
915 #endif
916 
920 template <typename AllocatorT>
921 inline Balau::U32String<AllocatorT> toString32(const std::u16string & value) {
922  return Balau::Boost::Locale::Conv::utf_to_utf<char32_t, char16_t, AllocatorT>(value);
923 }
924 
928 template <typename AllocatorT>
930  return value;
931 }
932 
936 template <typename AllocatorT>
937 inline Balau::U32String<AllocatorT> toString32(const std::u32string & value) {
938  return Balau::U8String<AllocatorT>(value.data(), value.length());
939 }
940 
944 template <typename AllocatorT>
945 inline Balau::U32String<AllocatorT> toString32(const std::u32string_view & value) {
946  return Balau::U32String<AllocatorT>(value);
947 }
948 
952 template <typename AllocatorT>
955  str += value;
956  return toString32<AllocatorT>(str);
957 }
958 
962 template <typename AllocatorT>
963 inline Balau::U32String<AllocatorT> toString32(char16_t & value) {
965  str += value;
966  return toString32<AllocatorT>(str);
967 }
968 
972 template <typename AllocatorT>
973 inline Balau::U32String<AllocatorT> toString32(char32_t & value) {
975  str += value;
976  return str;
977 }
978 
982 template <typename AllocatorT>
983 inline Balau::U32String<AllocatorT> toString32(signed char value) {
984  return toString32<AllocatorT>(toString<AllocatorT>(value));
985 }
986 
990 template <typename AllocatorT>
992  return toString32<AllocatorT>(toString<AllocatorT>(value));
993 }
994 
998 template <typename AllocatorT>
1000  return toString32<AllocatorT>(toString<AllocatorT>(value));
1001 }
1002 
1006 template <typename AllocatorT>
1008  return toString32<AllocatorT>(toString<AllocatorT>(value));
1009 }
1010 
1014 template <typename AllocatorT>
1015 inline Balau::U32String<AllocatorT> toString32(long long value) {
1016  return toString32<AllocatorT>(toString<AllocatorT>(value));
1017 }
1018 
1022 template <typename AllocatorT>
1023 inline Balau::U32String<AllocatorT> toString32(unsigned char value) {
1024  return toString32<AllocatorT>(toString<AllocatorT>(value));
1025 }
1026 
1030 template <typename AllocatorT>
1031 inline Balau::U32String<AllocatorT> toString32(unsigned short value) {
1032  return toString32<AllocatorT>(toString<AllocatorT>(value));
1033 }
1034 
1038 template <typename AllocatorT>
1039 inline Balau::U32String<AllocatorT> toString32(unsigned int value) {
1040  return toString32<AllocatorT>(toString<AllocatorT>(value));
1041 }
1042 
1046 template <typename AllocatorT>
1047 inline Balau::U32String<AllocatorT> toString32(unsigned long value) {
1048  return toString32<AllocatorT>(toString<AllocatorT>(value));
1049 }
1050 
1054 template <typename AllocatorT>
1055 inline Balau::U32String<AllocatorT> toString32(unsigned long long value) {
1056  return toString32<AllocatorT>(toString<AllocatorT>(value));
1057 }
1058 
1062 template <typename AllocatorT>
1064  return toString32<AllocatorT>(toString<AllocatorT>(value));
1065 }
1066 
1070 template <typename AllocatorT>
1072  return toString32<AllocatorT>(toString<AllocatorT>(value));
1073 }
1074 
1078 template <typename AllocatorT>
1079 inline Balau::U32String<AllocatorT> toString32(long double value) {
1080  return toString32<AllocatorT>(toString<AllocatorT>(value));
1081 }
1082 
1086 template <typename T, typename AllocatorT>
1087 inline Balau::U32String<AllocatorT> toString32(const std::complex<T> & value) {
1088  return toString32<AllocatorT>(value.real(), " + j", value.imag());
1089 }
1090 
1094 template <typename AllocatorT>
1096  return value ? U"true" : U"false";
1097 }
1098 
1102 template <typename AllocatorT>
1103 inline Balau::U32String<AllocatorT> toString32(const char * value) {
1104  return toString32<AllocatorT>(toString<AllocatorT>((value)));
1105 }
1106 
1110 template <typename AllocatorT>
1111 inline Balau::U32String<AllocatorT> toString32(const char16_t * value) {
1112  return toString32<AllocatorT>(toString16<AllocatorT>((value)));
1113 }
1114 
1118 template <typename AllocatorT>
1119 inline Balau::U32String<AllocatorT> toString32(const char32_t * value) {
1120  return Balau::U32String<AllocatorT>(value);
1121 }
1122 
1129 template <typename AllocatorT>
1130 inline Balau::U32String<AllocatorT> toString32(const void * ptr) {
1131  return toString32<AllocatorT>((size_t) ptr);
1132 }
1133 
1140 template <typename AllocatorT>
1142  return U"0";
1143 }
1144 
1148 template <typename AllocatorT>
1149 inline Balau::U32String<AllocatorT> toString32(std::type_index value) {
1150  return toString32<AllocatorT>(value.name());
1151 }
1152 
1156 template <typename AllocatorT>
1158  return f();
1159 }
1160 
1164 template <typename AllocatorT, typename F, typename S>
1165 inline Balau::U32String<AllocatorT> toString32(const std::pair<F, S> & p) {
1166  return Balau::U32String<AllocatorT>(U"{ ")
1167  + toString32<AllocatorT>(p.first)
1168  + U", "
1169  + toString32<AllocatorT>(p.second)
1170  + U" }";
1171 }
1172 
1178 template <typename AllocatorT, typename ... T, template <typename ...> class C>
1180  Balau::U32String<AllocatorT> builder = U"{";
1181  Balau::U32String<AllocatorT> prefix = U" ";
1182  bool empty = true;
1183 
1184  for (const auto & e : c) {
1185  builder += prefix + toString32<AllocatorT>(e);
1186  prefix = U", ";
1187  empty = false;
1188  }
1189 
1190  if (!empty) {
1191  builder += U" ";
1192  }
1193 
1194  builder += U"}";
1195 
1196  return builder;
1197 }
1198 
1202 #define BALAU_CONTAINER1_TO_STRING32_A(CONTAINER_TYPE) \
1203  template <typename AllocatorT, typename T> \
1204  inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T> & c) { \
1205  return toString32Helper<AllocatorT>(c); \
1206  }
1207 
1211 #define BALAU_CONTAINER2_TO_STRING32_A(CONTAINER_TYPE) \
1212  template <typename AllocatorT, typename T, typename U> \
1213  inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U> & c) { \
1214  return toString32Helper<AllocatorT>(c); \
1215  }
1216 
1220 #define BALAU_CONTAINER3_TO_STRING32_A(CONTAINER_TYPE) \
1221  template <typename AllocatorT, typename T, typename U, typename V> \
1222  inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U, V> & c) { \
1223  return toString32Helper<AllocatorT>(c); \
1224  }
1225 
1229 #define BALAU_CONTAINER4_TO_STRING32_A(CONTAINER_TYPE) \
1230  template <typename AllocatorT, typename T, typename U, typename V, typename W> \
1231  inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U, V, W> & c) { \
1232  return toString32Helper<AllocatorT>(c); \
1233  }
1234 
1238 #define BALAU_CONTAINER5_TO_STRING32_A(CONTAINER_TYPE) \
1239  template <typename AllocatorT, typename T, typename U, typename V, typename W, typename X> \
1240  inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U, V, W, X> & c) { \
1241  return toString32Helper<AllocatorT>(c); \
1242  }
1243 
1245 BALAU_CONTAINER2_TO_STRING32_A(std::forward_list)
1248 BALAU_CONTAINER3_TO_STRING32_A(std::multiset)
1249 BALAU_CONTAINER4_TO_STRING32_A(std::multimap)
1250 BALAU_CONTAINER3_TO_STRING32_A(std::priority_queue)
1254 BALAU_CONTAINER5_TO_STRING32_A(std::unordered_map)
1255 BALAU_CONTAINER5_TO_STRING32_A(std::unordered_multimap)
1256 BALAU_CONTAINER4_TO_STRING32_A(std::unordered_multiset)
1257 BALAU_CONTAINER3_TO_STRING32_A(std::unordered_set)
1258 BALAU_CONTAINER2_TO_STRING32_A(std::vector)
1259 
1260 template <typename AllocatorT, typename P1, typename P2, typename ... P>
1267 inline Balau::U32String<AllocatorT> toString32(const P1 & p1, const P2 & p2, const P & ... p) {
1268  return toString32<AllocatorT>(p1)
1269  + toString32<AllocatorT>(p2)
1270  + (Balau::U32String<AllocatorT>() + ... + toString32<AllocatorT>(p));
1271 }
1272 
1274 
1278 template <typename CharT, typename AllocatorT = std::allocator<CharT>> struct ToString;
1279 
1285 template <typename AllocatorT> struct ToString<char, AllocatorT> {
1286  template <typename T> Balau::U8String<AllocatorT> operator () (const T & object) const {
1287  return toString<AllocatorT>(object);
1288  }
1289 };
1290 
1296 template <typename AllocatorT> struct ToString<char16_t, AllocatorT> {
1297  template <typename T> Balau::U16String<AllocatorT> operator () (const T & object) const {
1298  return toString16<AllocatorT>(object);
1299  }
1300 };
1301 
1307 template <typename AllocatorT> struct ToString<char32_t, AllocatorT> {
1308  template <typename T> Balau::U32String<AllocatorT> operator () (const T & object) const {
1309  return toString32<AllocatorT>(object);
1310  }
1311 };
1312 
1313 #endif // COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_A
std::basic_ostringstream< char16_t, std::char_traits< char16_t >, AllocatorT > U16OStringStream
UTF-16 output string stream type with selectable allocator.
Definition: ToStringA.hpp:65
#define BALAU_CONTAINER3_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has three template parameters.
Definition: ToStringA.hpp:826
Balau::U8String< AllocatorT > toStringHelper(const C< T ... > &c)
Helper for container to UTF-8 string functions.
Definition: ToStringA.hpp:386
std::u16string toString16Helper(const C< T ... > &c)
Helper for container to UTF-16 string functions.
Definition: ToStringA.hpp:785
std::basic_string< char16_t, std::char_traits< char16_t >, AllocatorT > U16String
UTF-16 string type with selectable allocator.
Definition: ToStringA.hpp:47
#define BALAU_CONTAINER5_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has five template parameters.
Definition: ToStringA.hpp:844
#define BALAU_CONTAINER3_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has three template parameters.
Definition: ToStringA.hpp:427
std::basic_ostringstream< char32_t, std::char_traits< char32_t >, AllocatorT > U32OStringStream
UTF-32 output string stream type with selectable allocator.
Definition: ToStringA.hpp:71
#define BALAU_CONTAINER4_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has four template parameters.
Definition: ToStringA.hpp:1229
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
Balau::U16String< AllocatorT > toString16(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringA.hpp:873
#define BALAU_CONTAINER5_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has five template parameters.
Definition: ToStringA.hpp:445
Core includes, typedefs and functions.
std::basic_ostringstream< char, std::char_traits< char >, AllocatorT > U8OStringStream
UTF-8 output string stream type with selectable allocator.
Definition: ToStringA.hpp:59
std::basic_string< char32_t, std::char_traits< char32_t >, AllocatorT > U32String
UTF-32 string type with selectable allocator.
Definition: ToStringA.hpp:53
#define BALAU_CONTAINER4_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has four template parameters.
Definition: ToStringA.hpp:835
#define BALAU_CONTAINER5_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has five template parameters.
Definition: ToStringA.hpp:1238
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
Balau::U32String< AllocatorT > toString32Helper(const C< T ... > &c)
Helper for container to UTF-8 string functions.
Definition: ToStringA.hpp:1179
#define BALAU_CONTAINER2_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has two template parameters.
Definition: ToStringA.hpp:1211
#define BALAU_CONTAINER3_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has three template parameters.
Definition: ToStringA.hpp:1220
#define BALAU_CONTAINER2_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has two template parameters.
Definition: ToStringA.hpp:817
Balau::U32String< AllocatorT > toString32(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringA.hpp:1267
#define BALAU_CONTAINER2_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has two template parameters.
Definition: ToStringA.hpp:418
Template class based to-string function for use in template classes.
Definition: ToStringA.hpp:1278
Balau::U8String< AllocatorT > toString(LoggingLevel level)
Print the logging level as a UTF-8 string.
Definition: LoggingLevel.hpp:73
#define BALAU_CONTAINER4_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has four template parameters.
Definition: ToStringA.hpp:436