cfgfile 0.2.11
Loading...
Searching...
No Matches
format.hpp
Go to the documentation of this file.
1
31#ifndef CFGFILE__FORMAT_HPP__INCLUDED
32#define CFGFILE__FORMAT_HPP__INCLUDED
33
34// cfgfile include.
35#include "parser_info.hpp"
36#include "exceptions.hpp"
37#include "const.hpp"
38#include "types.hpp"
39
40// C++ include.
41#include <limits>
42
43#ifdef CFGFILE_QT_SUPPORT
44// Qt include.
45#include <QString>
46#endif
47
48
49namespace cfgfile {
50
51//
52// format_t
53//
54
56template< class T, class Trait >
57class format_t {
58public:
60 static typename Trait::string_t to_string( const T & );
61
64 const typename Trait::string_t & );
65}; // class format_t
66
67
68#ifndef CFGFILE_DISABLE_STL
69
70template<>
71class format_t< int, string_trait_t > {
72public:
74 static string_trait_t::string_t to_string( const int & value )
75 {
76 return std::to_string( value );
77 }
78
81 const string_trait_t::string_t & value )
82 {
83 try {
84 std::size_t pos = 0;
85
86 int result = std::stoi( value, &pos );
87
88 if( pos != value.length() )
90 string_trait_t::from_ascii( "Invalid value: \"" ) +
91 value + string_trait_t::from_ascii( "\". In file \"" ) +
92 info.file_name() +
93 string_trait_t::from_ascii( "\" on line " ) +
96
97 return result;
98 }
99 catch( const std::exception & )
100 {
102 string_trait_t::from_ascii( "Invalid value: \"" ) +
103 value + string_trait_t::from_ascii( "\". In file \"" ) +
104 info.file_name() + string_trait_t::from_ascii( "\" on line " ) +
107 }
108 }
109}; // class format_t< int >
110
111
112template<>
114public:
116 static wstring_trait_t::string_t to_string( const int & value )
117 {
118 return std::to_wstring( value );
119 }
120
123 const wstring_trait_t::string_t & value )
124 {
125 try {
126 std::size_t pos = 0;
127
128 int result = std::stoi( value, &pos );
129
130 if( pos != value.length() )
132 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
133 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
134 info.file_name() +
135 wstring_trait_t::from_ascii( "\" on line " ) +
136 wstring_trait_t::to_string( info.line_number() ) +
138
139 return result;
140 }
141 catch( const std::exception & )
142 {
144 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
145 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
146 info.file_name() +
147 wstring_trait_t::from_ascii( "\" on line " ) +
148 wstring_trait_t::to_string( info.line_number() ) +
150 }
151 }
152}; // class format_t< int >
153
154#endif // CFGFILE_DISABLE_STL
155
156
157#ifdef CFGFILE_QT_SUPPORT
158template<>
160public:
162 static qstring_trait_t::string_t to_string( const int & value )
163 {
164 return QString::number( value );
165 }
166
169 const qstring_trait_t::string_t & value )
170 {
171 bool ok = false;
172 int result = ((QString)value).toInt( &ok );
173
174 if( !ok )
176 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
177 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
178 info.file_name() +
179 qstring_trait_t::from_ascii( "\" on line " ) +
180 qstring_trait_t::to_string( info.line_number() ) +
182 else
183 return result;
184 }
185}; // class format_t< int >
186#endif // CFGFILE_QT_SUPPORT
187
188
189#ifndef CFGFILE_DISABLE_STL
190
191template<>
193public:
195 static string_trait_t::string_t to_string( const unsigned int & value )
196 {
197 return std::to_string( value );
198 }
199
202 const string_trait_t::string_t & value )
203 {
204 try {
205 std::size_t pos = 0;
206
207 unsigned long result = std::stoul( value, &pos );
208
209 if( pos != value.length() ||
210 result > std::numeric_limits< unsigned int >::max() )
212 string_trait_t::from_ascii( "Invalid value: \"" ) +
213 value + string_trait_t::from_ascii( "\". In file \"" ) +
214 info.file_name() +
215 string_trait_t::from_ascii( "\" on line " ) +
216 string_trait_t::to_string( info.line_number() ) +
218
219 return (unsigned int) result;
220 }
221 catch( const std::exception & )
222 {
224 string_trait_t::from_ascii( "Invalid value: \"" ) +
225 value + string_trait_t::from_ascii( "\". In file \"" ) +
226 info.file_name() +
227 string_trait_t::from_ascii( "\" on line " ) +
228 string_trait_t::to_string( info.line_number() ) +
230 }
231 }
232}; // class format_t< unsigned int >
233
234
235template<>
237public:
239 static wstring_trait_t::string_t to_string( const unsigned int & value )
240 {
241 return std::to_wstring( value );
242 }
243
246 const wstring_trait_t::string_t & value )
247 {
248 try {
249 std::size_t pos = 0;
250
251 unsigned long result = std::stoul( value, &pos );
252
253 if( pos != value.length() ||
254 result > std::numeric_limits< unsigned int >::max() )
256 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
257 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
258 info.file_name() +
259 wstring_trait_t::from_ascii( "\" on line " ) +
260 wstring_trait_t::to_string( info.line_number() ) +
262
263 return (unsigned int) result;
264 }
265 catch( const std::exception & )
266 {
268 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
269 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
270 info.file_name() +
271 wstring_trait_t::from_ascii( "\" on line " ) +
272 wstring_trait_t::to_string( info.line_number() ) +
274 }
275 }
276}; // class format_t< unsigned int >
277
278#endif // CFGFILE_DISABLE_STL
279
280
281#ifdef CFGFILE_QT_SUPPORT
282template<>
284public:
286 static qstring_trait_t::string_t to_string( const unsigned int & value )
287 {
288 return QString::number( value );
289 }
290
293 const qstring_trait_t::string_t & value )
294 {
295 bool ok = false;
296 unsigned int result = ((QString)value).toUInt( &ok );
297
298 if( !ok )
300 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
301 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
302 info.file_name() +
303 qstring_trait_t::from_ascii( "\" on line " ) +
304 qstring_trait_t::to_string( info.line_number() ) +
306 else
307 return result;
308 }
309}; // class format_t< unsigned int >
310#endif // CFGFILE_QT_SUPPORT
311
312
313#ifndef CFGFILE_DISABLE_STL
314
315template<>
317public:
319 static string_trait_t::string_t to_string( const long & value )
320 {
321 return std::to_string( value );
322 }
323
326 const string_trait_t::string_t & value )
327 {
328 try {
329 std::size_t pos = 0;
330
331 long result = std::stol( value, &pos );
332
333 if( pos != value.length() )
335 string_trait_t::from_ascii( "Invalid value: \"" ) +
336 value + string_trait_t::from_ascii( "\". In file \"" ) +
337 info.file_name() +
338 string_trait_t::from_ascii( "\" on line " ) +
339 string_trait_t::to_string( info.line_number() ) +
341
342 return result;
343 }
344 catch( const std::exception & )
345 {
347 string_trait_t::from_ascii( "Invalid value: \"" ) +
348 value + string_trait_t::from_ascii( "\". In file \"" ) +
349 info.file_name() +
350 string_trait_t::from_ascii( "\" on line " ) +
351 string_trait_t::to_string( info.line_number() ) +
353 }
354 }
355}; // class format_t< long >
356
357
358template<>
360public:
362 static wstring_trait_t::string_t to_string( const long & value )
363 {
364 return std::to_wstring( value );
365 }
366
369 const wstring_trait_t::string_t & value )
370 {
371 try {
372 std::size_t pos = 0;
373
374 long result = std::stol( value, &pos );
375
376 if( pos != value.length() )
378 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
379 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
380 info.file_name() +
381 wstring_trait_t::from_ascii( "\" on line " ) +
382 wstring_trait_t::to_string( info.line_number() ) +
384
385 return result;
386 }
387 catch( const std::exception & )
388 {
390 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
391 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
392 info.file_name() +
393 wstring_trait_t::from_ascii( "\" on line " ) +
394 wstring_trait_t::to_string( info.line_number() ) +
396 }
397 }
398}; // class format_t< long >
399
400#endif // CFGFILE_DISABLE_STL
401
402
403#ifdef CFGFILE_QT_SUPPORT
404template<>
406public:
408 static qstring_trait_t::string_t to_string( const long & value )
409 {
410 return QString::number( value );
411 }
412
415 const qstring_trait_t::string_t & value )
416 {
417 bool ok = false;
418 long result = ((QString)value).toLong( &ok );
419
420 if( !ok )
422 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
423 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
424 info.file_name() +
425 qstring_trait_t::from_ascii( "\" on line " ) +
426 qstring_trait_t::to_string( info.line_number() ) +
428 else
429 return result;
430 }
431}; // class format_t< long >
432#endif // CFGFILE_QT_SUPPORT
433
434
435#ifndef CFGFILE_DISABLE_STL
436
437template<>
439public:
441 static string_trait_t::string_t to_string( const unsigned long & value )
442 {
443 return std::to_string( value );
444 }
445
447 static unsigned long from_string( const parser_info_t< string_trait_t > & info,
448 const string_trait_t::string_t & value )
449 {
450 try {
451 std::size_t pos = 0;
452
453 unsigned long result = std::stoul( value, &pos );
454
455 if( pos != value.length() )
457 string_trait_t::from_ascii( "Invalid value: \"" ) +
458 value + string_trait_t::from_ascii( "\". In file \"" ) +
459 info.file_name() +
460 string_trait_t::from_ascii( "\" on line " ) +
461 string_trait_t::to_string( info.line_number() ) +
463
464 return result;
465 }
466 catch( const std::exception & )
467 {
469 string_trait_t::from_ascii( "Invalid value: \"" ) +
470 value + string_trait_t::from_ascii( "\". In file \"" ) +
471 info.file_name() +
472 string_trait_t::from_ascii( "\" on line " ) +
473 string_trait_t::to_string( info.line_number() ) +
475 }
476 }
477}; // class format_t< unsigned long >
478
479
480template<>
482public:
484 static wstring_trait_t::string_t to_string( const unsigned long & value )
485 {
486 return std::to_wstring( value );
487 }
488
490 static unsigned long from_string( const parser_info_t< wstring_trait_t > & info,
491 const wstring_trait_t::string_t & value )
492 {
493 try {
494 std::size_t pos = 0;
495
496 unsigned long result = std::stoul( value, &pos );
497
498 if( pos != value.length() )
500 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
501 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
502 info.file_name() +
503 wstring_trait_t::from_ascii( "\" on line " ) +
504 wstring_trait_t::to_string( info.line_number() ) +
506
507 return result;
508 }
509 catch( const std::exception & )
510 {
512 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
513 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
514 info.file_name() +
515 wstring_trait_t::from_ascii( "\" on line " ) +
516 wstring_trait_t::to_string( info.line_number() ) +
518 }
519 }
520}; // class format_t< unsigned long >
521
522#endif // CFGFILE_DISABLE_STL
523
524
525#ifdef CFGFILE_QT_SUPPORT
526template<>
528public:
530 static qstring_trait_t::string_t to_string( const unsigned long & value )
531 {
532 return QString::number( value );
533 }
534
536 static unsigned long from_string( const parser_info_t< qstring_trait_t > & info,
537 const qstring_trait_t::string_t & value )
538 {
539 bool ok = false;
540 unsigned long result = ((QString)value).toULong( &ok );
541
542 if( !ok )
544 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
545 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
546 info.file_name() +
547 qstring_trait_t::from_ascii( "\" on line " ) +
548 qstring_trait_t::to_string( info.line_number() ) +
550 else
551 return result;
552 }
553}; // class format_t< unsigned long >
554#endif // CFGFILE_QT_SUPPORT
555
556
557#ifndef CFGFILE_DISABLE_STL
558
559template<>
561public:
563 static string_trait_t::string_t to_string( const long long & value )
564 {
565 return std::to_string( value );
566 }
567
570 const string_trait_t::string_t & value )
571 {
572 try {
573 std::size_t pos = 0;
574
575 long long result = std::stoll( value, &pos );
576
577 if( pos != value.length() )
579 string_trait_t::from_ascii( "Invalid value: \"" ) +
580 value + string_trait_t::from_ascii( "\". In file \"" ) +
581 info.file_name() +
582 string_trait_t::from_ascii( "\" on line " ) +
583 string_trait_t::to_string( info.line_number() ) +
585
586 return result;
587 }
588 catch( const std::exception & )
589 {
591 string_trait_t::from_ascii( "Invalid value: \"" ) +
592 value + string_trait_t::from_ascii( "\". In file \"" ) +
593 info.file_name() +
594 string_trait_t::from_ascii( "\" on line " ) +
595 string_trait_t::to_string( info.line_number() ) +
597 }
598 }
599}; // class format_t< long long >
600
601
602template<>
604public:
606 static wstring_trait_t::string_t to_string( const long long & value )
607 {
608 return std::to_wstring( value );
609 }
610
613 const wstring_trait_t::string_t & value )
614 {
615 try {
616 std::size_t pos = 0;
617
618 long long result = std::stoll( value, &pos );
619
620 if( pos != value.length() )
622 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
623 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
624 info.file_name() +
625 wstring_trait_t::from_ascii( "\" on line " ) +
626 wstring_trait_t::to_string( info.line_number() ) +
628
629 return result;
630 }
631 catch( const std::exception & )
632 {
634 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
635 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
636 info.file_name() +
637 wstring_trait_t::from_ascii( "\" on line " ) +
638 wstring_trait_t::to_string( info.line_number() ) +
640 }
641 }
642}; // class format_t< long long >
643
644#endif // CFGFILE_DISABLE_STL
645
646
647#ifdef CFGFILE_QT_SUPPORT
648template<>
650public:
652 static qstring_trait_t::string_t to_string( const long long & value )
653 {
654 return QString::number( value );
655 }
656
659 const qstring_trait_t::string_t & value )
660 {
661 bool ok = false;
662 long long result = ((QString)value).toLongLong( &ok );
663
664 if( !ok )
666 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
667 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
668 info.file_name() +
669 qstring_trait_t::from_ascii( "\" on line " ) +
670 qstring_trait_t::to_string( info.line_number() ) +
672 else
673 return result;
674 }
675}; // class format_t< long long >
676#endif // CFGFILE_QT_SUPPORT
677
678
679#ifndef CFGFILE_DISABLE_STL
680
681template<>
683public:
685 static string_trait_t::string_t to_string( const unsigned long long & value )
686 {
687 return std::to_string( value );
688 }
689
691 static unsigned long long from_string( const parser_info_t< string_trait_t > & info,
692 const string_trait_t::string_t & value )
693 {
694 try {
695 std::size_t pos = 0;
696
697 unsigned long long result = std::stoull( value, &pos );
698
699 if( pos != value.length() )
701 string_trait_t::from_ascii( "Invalid value: \"" ) +
702 value + string_trait_t::from_ascii( "\". In file \"" ) +
703 info.file_name() +
704 string_trait_t::from_ascii( "\" on line " ) +
705 string_trait_t::to_string( info.line_number() ) +
707
708 return result;
709 }
710 catch( const std::exception & )
711 {
713 string_trait_t::from_ascii( "Invalid value: \"" ) +
714 value + string_trait_t::from_ascii( "\". In file \"" ) +
715 info.file_name() +
716 string_trait_t::from_ascii( "\" on line " ) +
717 string_trait_t::to_string( info.line_number() ) +
719 }
720 }
721}; // class format_t< unsigned long long >
722
723
724template<>
726public:
728 static wstring_trait_t::string_t to_string( const unsigned long long & value )
729 {
730 return std::to_wstring( value );
731 }
732
734 static unsigned long long from_string( const parser_info_t< wstring_trait_t > & info,
735 const wstring_trait_t::string_t & value )
736 {
737 try {
738 std::size_t pos = 0;
739
740 unsigned long long result = std::stoull( value, &pos );
741
742 if( pos != value.length() )
744 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
745 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
746 info.file_name() +
747 wstring_trait_t::from_ascii( "\" on line " ) +
748 wstring_trait_t::to_string( info.line_number() ) +
750
751 return result;
752 }
753 catch( const std::exception & )
754 {
756 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
757 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
758 info.file_name() +
759 wstring_trait_t::from_ascii( "\" on line " ) +
760 wstring_trait_t::to_string( info.line_number() ) +
762 }
763 }
764}; // class format_t< unsigned long long >
765
766#endif // CFGFILE_DISABLE_STL
767
768
769#ifdef CFGFILE_QT_SUPPORT
770template<>
772public:
774 static qstring_trait_t::string_t to_string( const unsigned long long & value )
775 {
776 return QString::number( value );
777 }
778
780 static unsigned long long from_string( const parser_info_t< qstring_trait_t > & info,
781 const qstring_trait_t::string_t & value )
782 {
783 bool ok = false;
784 unsigned long long result = ((QString)value).toULongLong( &ok );
785
786 if( !ok )
788 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
789 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
790 info.file_name() +
791 qstring_trait_t::from_ascii( "\" on line " ) +
792 qstring_trait_t::to_string( info.line_number() ) +
794 else
795 return result;
796 }
797}; // class format_t< unsigned long long >
798#endif // CFGFILE_QT_SUPPORT
799
800
801#ifndef CFGFILE_DISABLE_STL
802
803template<>
805public:
807 static string_trait_t::string_t to_string( const double & value )
808 {
809 return std::to_string( value );
810 }
811
814 const string_trait_t::string_t & value )
815 {
816 try {
817 std::size_t pos = 0;
818
819 double result = std::stod( value, &pos );
820
821 if( pos != value.length() )
823 string_trait_t::from_ascii( "Invalid value: \"" ) +
824 value + string_trait_t::from_ascii( "\". In file \"" ) +
825 info.file_name() +
826 string_trait_t::from_ascii( "\" on line " ) +
827 string_trait_t::to_string( info.line_number() ) +
829
830 return result;
831 }
832 catch( const std::exception & )
833 {
835 string_trait_t::from_ascii( "Invalid value: \"" ) +
836 value + string_trait_t::from_ascii( "\". In file \"" ) +
837 info.file_name() +
838 string_trait_t::from_ascii( "\" on line " ) +
839 string_trait_t::to_string( info.line_number() ) +
841 }
842 }
843}; // class format_t< double >
844
845
846template<>
848public:
850 static wstring_trait_t::string_t to_string( const double & value )
851 {
852 return std::to_wstring( value );
853 }
854
857 const wstring_trait_t::string_t & value )
858 {
859 try {
860 std::size_t pos = 0;
861
862 double result = std::stod( value, &pos );
863
864 if( pos != value.length() )
866 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
867 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
868 info.file_name() +
869 wstring_trait_t::from_ascii( "\" on line " ) +
870 wstring_trait_t::to_string( info.line_number() ) +
872
873 return result;
874 }
875 catch( const std::exception & )
876 {
878 wstring_trait_t::from_ascii( "Invalid value: \"" ) +
879 value + wstring_trait_t::from_ascii( "\". In file \"" ) +
880 info.file_name() +
881 wstring_trait_t::from_ascii( "\" on line " ) +
882 wstring_trait_t::to_string( info.line_number() ) +
884 }
885 }
886}; // class format_t< double >
887
888#endif // CFGFILE_DISABLE_STL
889
890
891#ifdef CFGFILE_QT_SUPPORT
892template<>
894public:
896 static qstring_trait_t::string_t to_string( const double & value )
897 {
898 return QString::number( value, 'g', 999 );
899 }
900
903 const qstring_trait_t::string_t & value )
904 {
905 bool ok = false;
906 double result = ((QString)value).toDouble( &ok );
907
908 if( !ok )
910 qstring_trait_t::from_ascii( "Invalid value: \"" ) +
911 value + qstring_trait_t::from_ascii( "\". In file \"" ) +
912 info.file_name() +
913 qstring_trait_t::from_ascii( "\" on line " ) +
914 qstring_trait_t::to_string( info.line_number() ) +
916 else
917 return result;
918 }
919}; // class format_t< double >
920#endif // CFGFILE_QT_SUPPORT
921
922
923template< typename Trait >
924class format_t< typename Trait::string_t, Trait > {
925public:
927 static typename Trait::string_t to_string( const typename Trait::string_t & value )
928 {
929 return value;
930 }
931
933 static typename Trait::string_t from_string( const parser_info_t< Trait > &,
934 const typename Trait::string_t & value )
935 {
936 return value;
937 }
938}; // class format_t< Trait::string_t, Trait >
939
940
941#ifndef CFGFILE_DISABLE_STL
942
943template<>
945public:
947 static wstring_trait_t::string_t to_string( const std::string & value )
948 {
949 std::wstring res;
950 res.assign( value.cbegin(), value.cend() );
951
952 return res;
953 }
954
957 const wstring_trait_t::string_t & value )
958 {
959 std::string res;
960
961 for( const auto & ch : value )
962 res.push_back( static_cast< char > ( ch ) );
963
964 return res;
965 }
966}; // class format_t< std::string >
967
968#endif // CFGFILE_DISABLE_STL
969
970
971#if defined(CFGFILE_QT_SUPPORT) && !defined(CFGFILE_DISABLE_STL)
972template<>
974public:
976 static qstring_trait_t::string_t to_string( const std::string & value )
977 {
978 return QString::fromStdString( value );
979 }
980
983 const qstring_trait_t::string_t & value )
984 {
985 return ((QString)value).toStdString();
986 }
987}; // class format_t< std::string >
988#endif
989
990
991#ifndef CFGFILE_DISABLE_STL
992
993template<>
995public:
997 static string_trait_t::string_t to_string( const std::wstring & value )
998 {
999 std::string res;
1000
1001 for( const auto & ch : value )
1002 res.push_back( static_cast< char > ( ch ) );
1003
1004 return res;
1005 }
1006
1008 static std::wstring from_string( const parser_info_t< string_trait_t > &,
1009 const string_trait_t::string_t & value )
1010 {
1011 std::wstring res;
1012 res.assign( value.cbegin(), value.cend() );
1013
1014 return res;
1015 }
1016}; // class format_t< std::wstring >
1017
1018#endif // CFGFILE_DISABLE_STL
1019
1020
1021#if defined(CFGFILE_QT_SUPPORT) && !defined(CFGFILE_DISABLE_STL)
1022template<>
1024public:
1026 static qstring_trait_t::string_t to_string( const std::wstring & value )
1027 {
1028 return QString::fromStdWString( value );
1029 }
1030
1032 static std::wstring from_string( const parser_info_t< qstring_trait_t > &,
1033 const qstring_trait_t::string_t & value )
1034 {
1035 return ((QString)value).toStdWString();
1036 }
1037}; // class format_t< std::wstring >
1038#endif
1039
1040
1041#if defined(CFGFILE_QT_SUPPORT) && !defined(CFGFILE_DISABLE_STL)
1042template<>
1044public:
1047 {
1048 return value.toStdString();
1049 }
1050
1053 const string_trait_t::string_t & value )
1054 {
1055 return QString::fromStdString( value );
1056 }
1057}; // class format_t< QString >
1058
1059
1060template<>
1062public:
1065 {
1066 return value.toStdWString();
1067 }
1068
1071 const wstring_trait_t::string_t & value )
1072 {
1073 return QString::fromStdWString( value );
1074 }
1075}; // class format_t< QString >
1076#endif
1077
1078
1079#ifdef CFGFILE_QT_SUPPORT
1080template<>
1082public:
1085 {
1086 return value;
1087 }
1088
1091 const qstring_trait_t::string_t & value )
1092 {
1093 return value;
1094 }
1095}; // class format_t< QString >
1096#endif // CFGFILE_QT_SUPPORT
1097
1098
1099template< typename Trait >
1101public:
1103 static typename Trait::string_t to_string( const bool & value )
1104 {
1105 return ( value ? const_t< Trait >::c_true :
1107 }
1108
1111 const typename Trait::string_t & value )
1112 {
1113 if( value == const_t< Trait >::c_on ||
1114 value == const_t< Trait >::c_true ||
1115 value == const_t< Trait >::c_1 ||
1116 value == const_t< Trait >::c_yes )
1117 return true;
1118 else if( value == const_t< Trait >::c_off ||
1119 value == const_t< Trait >::c_false ||
1120 value == const_t< Trait >::c_0 ||
1121 value == const_t< Trait >::c_no )
1122 return false;
1123 else
1125 Trait::from_ascii( "Invalid value: \"" ) +
1126 value + Trait::from_ascii( "\". In file \"" ) +
1127 info.file_name() + Trait::from_ascii( "\" on line " ) +
1128 Trait::to_string( info.line_number() ) +
1129 Trait::from_ascii( "." ) );
1130 }
1131}; // class format_t< bool >
1132
1133} /* namespace cfgfile */
1134
1135#endif // CFGFILE__FORMAT_HPP__INCLUDED
Definition exceptions.hpp:85
Exception in the library.
Definition exceptions.hpp:51
static QString from_string(const parser_info_t< qstring_trait_t > &, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:1090
static qstring_trait_t::string_t to_string(const QString &value)
Format value to string.
Definition format.hpp:1084
static string_trait_t::string_t to_string(const QString &value)
Format value to string.
Definition format.hpp:1046
static QString from_string(const parser_info_t< string_trait_t > &, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:1052
static wstring_trait_t::string_t to_string(const QString &value)
Format value to string.
Definition format.hpp:1064
static QString from_string(const parser_info_t< wstring_trait_t > &, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:1070
static Trait::string_t to_string(const bool &value)
Format value to string.
Definition format.hpp:1103
static bool from_string(const parser_info_t< Trait > &info, const typename Trait::string_t &value)
Format value from string.
Definition format.hpp:1110
static double from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:902
static qstring_trait_t::string_t to_string(const double &value)
Format value to string.
Definition format.hpp:896
static double from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:813
static string_trait_t::string_t to_string(const double &value)
Format value to string.
Definition format.hpp:807
static double from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:856
static wstring_trait_t::string_t to_string(const double &value)
Format value to string.
Definition format.hpp:850
static int from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:168
static qstring_trait_t::string_t to_string(const int &value)
Format value to string.
Definition format.hpp:162
static int from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:80
static string_trait_t::string_t to_string(const int &value)
Format value to string.
Definition format.hpp:74
static wstring_trait_t::string_t to_string(const int &value)
Format value to string.
Definition format.hpp:116
static int from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:122
static long from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:414
static qstring_trait_t::string_t to_string(const long &value)
Format value to string.
Definition format.hpp:408
static string_trait_t::string_t to_string(const long &value)
Format value to string.
Definition format.hpp:319
static long from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:325
static wstring_trait_t::string_t to_string(const long &value)
Format value to string.
Definition format.hpp:362
static long from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:368
static long long from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:658
static qstring_trait_t::string_t to_string(const long long &value)
Format value to string.
Definition format.hpp:652
static long long from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:569
static string_trait_t::string_t to_string(const long long &value)
Format value to string.
Definition format.hpp:563
static long long from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:612
static wstring_trait_t::string_t to_string(const long long &value)
Format value to string.
Definition format.hpp:606
static std::string from_string(const parser_info_t< qstring_trait_t > &, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:982
static qstring_trait_t::string_t to_string(const std::string &value)
Format value to string.
Definition format.hpp:976
static wstring_trait_t::string_t to_string(const std::string &value)
Format value to string.
Definition format.hpp:947
static std::string from_string(const parser_info_t< wstring_trait_t > &, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:956
static qstring_trait_t::string_t to_string(const std::wstring &value)
Format value to string.
Definition format.hpp:1026
static std::wstring from_string(const parser_info_t< qstring_trait_t > &, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:1032
static string_trait_t::string_t to_string(const std::wstring &value)
Format value to string.
Definition format.hpp:997
static std::wstring from_string(const parser_info_t< string_trait_t > &, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:1008
static Trait::string_t to_string(const typename Trait::string_t &value)
Format value to string.
Definition format.hpp:927
static Trait::string_t from_string(const parser_info_t< Trait > &, const typename Trait::string_t &value)
Format value from string.
Definition format.hpp:933
static unsigned int from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:292
static qstring_trait_t::string_t to_string(const unsigned int &value)
Format value to string.
Definition format.hpp:286
static string_trait_t::string_t to_string(const unsigned int &value)
Format value to string.
Definition format.hpp:195
static unsigned int from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:201
static unsigned int from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:245
static wstring_trait_t::string_t to_string(const unsigned int &value)
Format value to string.
Definition format.hpp:239
static qstring_trait_t::string_t to_string(const unsigned long &value)
Format value to string.
Definition format.hpp:530
static unsigned long from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:536
static string_trait_t::string_t to_string(const unsigned long &value)
Format value to string.
Definition format.hpp:441
static unsigned long from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:447
static unsigned long from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:490
static wstring_trait_t::string_t to_string(const unsigned long &value)
Format value to string.
Definition format.hpp:484
static qstring_trait_t::string_t to_string(const unsigned long long &value)
Format value to string.
Definition format.hpp:774
static unsigned long long from_string(const parser_info_t< qstring_trait_t > &info, const qstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:780
static unsigned long long from_string(const parser_info_t< string_trait_t > &info, const string_trait_t::string_t &value)
Format value from string.
Definition format.hpp:691
static string_trait_t::string_t to_string(const unsigned long long &value)
Format value to string.
Definition format.hpp:685
static unsigned long long from_string(const parser_info_t< wstring_trait_t > &info, const wstring_trait_t::string_t &value)
Format value from string.
Definition format.hpp:734
static wstring_trait_t::string_t to_string(const unsigned long long &value)
Format value to string.
Definition format.hpp:728
Format template value to the string and back.
Definition format.hpp:57
static T from_string(const parser_info_t< Trait > &, const typename Trait::string_t &)
Format value from string.
static Trait::string_t to_string(const T &)
Format value to string.
Information about parsed file and current state of parsing.
Definition parser_info.hpp:46
const Trait::string_t & file_name() const
Definition parser_info.hpp:58
Trait::pos_t line_number() const
Definition parser_info.hpp:64
QString wrapper.
Definition types.hpp:282
Definition const.hpp:38
@ string
String lexeme.
Definition const.hpp:45
Trait for QString support.
Definition types.hpp:502
static string_t from_ascii(const std::string &str)
Definition types.hpp:526
static string_t to_string(pos_t pos)
Definition types.hpp:521
Trait for std::string support.
Definition types.hpp:170
std::string string_t
String type.
Definition types.hpp:172
static string_t from_ascii(const std::string &str)
Definition types.hpp:194
static string_t to_string(pos_t pos)
Definition types.hpp:189
Trait for std::wstring support.
Definition types.hpp:59
static string_t to_string(pos_t pos)
Definition types.hpp:78
std::wstring string_t
String type.
Definition types.hpp:61
static string_t from_ascii(const std::string &str)
Definition types.hpp:83