00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanOperators.h"
00028
00029 #include "CeylanStringUtils.h"
00030
00031
00032 #ifdef CEYLAN_USES_CONFIG_H
00033 #include "CeylanConfig.h"
00034 #endif // CEYLAN_USES_CONFIG_H
00035
00036
00037 #include <sstream>
00038 using std::ostringstream ;
00039 using std::istringstream ;
00040
00041
00042
00043
00044 using std::string ;
00045 using std::list ;
00046
00047
00048 const Ceylan::Uint16 Ceylan::DigitOutputPrecision = 40 ;
00049
00050 const std::string Ceylan::HexDigits = "0123456789ABCDEF" ;
00051
00052
00053
00064 string operator + ( const string & s, Ceylan::Sint8 i )
00065 {
00066
00067 ostringstream oss ;
00068 string res ;
00069
00070 oss.precision( Ceylan::DigitOutputPrecision ) ;
00071
00072
00073
00074
00075
00076
00077 oss << static_cast<Ceylan::Sint16>( i ) ;
00078 res = s + oss.str() ;
00079
00080 #if CEYLAN_DEBUG
00081
00082 if ( oss.fail() )
00083 {
00084 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00085 "const string & + Ceylan::Sint8 -> string." ) ;
00086 }
00087
00088 #endif // CEYLAN_DEBUG
00089
00090 return ( res ) ;
00091
00092 }
00093
00094
00095
00096 string operator + ( Ceylan::Sint8 i, const string & s )
00097 {
00098
00099 ostringstream oss ;
00100 string res ;
00101
00102 oss.precision( Ceylan::DigitOutputPrecision ) ;
00103
00104
00105
00106
00107
00108
00109 oss << static_cast<Ceylan::Sint16>( i ) ;
00110 res = oss.str() + s ;
00111
00112 #if CEYLAN_DEBUG
00113
00114 if ( oss.fail() )
00115 {
00116 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00117 "Ceylan::Sint8 + const string & -> string." ) ;
00118 }
00119
00120 #endif // CEYLAN_DEBUG
00121
00122 return ( res ) ;
00123
00124 }
00125
00126
00127
00128 string operator + ( const string & s, Ceylan::Uint8 i )
00129 {
00130
00131 ostringstream oss ;
00132 string res ;
00133
00134 oss.precision( Ceylan::DigitOutputPrecision ) ;
00135
00136
00137
00138
00139
00140
00141 oss << static_cast<Ceylan::Uint16>( i ) ;
00142 res = s + oss.str() ;
00143
00144 #if CEYLAN_DEBUG
00145
00146 if ( oss.fail() )
00147 {
00148 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00149 "const string & + Ceylan::Uint8 -> string." ) ;
00150 }
00151
00152 #endif // CEYLAN_DEBUG
00153
00154 return ( res ) ;
00155
00156 }
00157
00158
00159
00160 string operator + ( Ceylan::Uint8 i, const string & s )
00161 {
00162
00163 ostringstream oss ;
00164 string res ;
00165
00166
00167
00168
00169
00170
00171 oss.precision( Ceylan::DigitOutputPrecision ) ;
00172
00173 oss << static_cast<Ceylan::Uint16>( i ) ;
00174 res = oss.str() + s ;
00175
00176 #if CEYLAN_DEBUG
00177
00178 if ( oss.fail() )
00179 {
00180 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00181 "Ceylan::Uint8 + const string & +-> string." ) ;
00182 }
00183
00184 #endif // CEYLAN_DEBUG
00185
00186 return ( res ) ;
00187
00188 }
00189
00190
00191
00192 string operator + ( const string & s, Ceylan::Sint16 i )
00193 {
00194
00195 ostringstream oss ;
00196 string res ;
00197
00198 oss.precision( Ceylan::DigitOutputPrecision ) ;
00199
00200 oss << i ;
00201 res = s + oss.str() ;
00202
00203 #if CEYLAN_DEBUG
00204
00205 if ( oss.fail() )
00206 {
00207 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00208 "const string & + Ceylan::Sint16 -> string." ) ;
00209 }
00210
00211 #endif // CEYLAN_DEBUG
00212
00213 return ( res ) ;
00214
00215 }
00216
00217
00218
00219 string operator + ( Ceylan::Sint16 i, const string & s )
00220 {
00221
00222 ostringstream oss ;
00223 string res ;
00224
00225 oss.precision( Ceylan::DigitOutputPrecision ) ;
00226
00227 oss << i ;
00228 res = oss.str() + s ;
00229
00230 #if CEYLAN_DEBUG
00231
00232 if ( oss.fail() )
00233 {
00234 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00235 "Ceylan::Sint16 + const string & -> string." ) ;
00236 }
00237
00238 #endif // CEYLAN_DEBUG
00239
00240 return ( res ) ;
00241
00242 }
00243
00244
00245
00246 string operator + ( const string & s, Ceylan::Uint16 i )
00247 {
00248
00249 ostringstream oss ;
00250 string res ;
00251
00252 oss.precision( Ceylan::DigitOutputPrecision ) ;
00253
00254 oss << i ;
00255 res = s + oss.str() ;
00256
00257 #if CEYLAN_DEBUG
00258
00259 if ( oss.fail() )
00260 {
00261 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00262 "const string & + Ceylan::Uint16 -> string." ) ;
00263 }
00264
00265 #endif // CEYLAN_DEBUG
00266
00267 return ( res ) ;
00268
00269 }
00270
00271
00272
00273 string operator + ( Ceylan::Uint16 i, const string & s )
00274 {
00275
00276 ostringstream oss ;
00277 string res ;
00278
00279 oss.precision( Ceylan::DigitOutputPrecision ) ;
00280
00281 oss << i ;
00282 res = oss.str() + s ;
00283
00284 #if CEYLAN_DEBUG
00285
00286 if ( oss.fail() )
00287 {
00288 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00289 "Ceylan::Uint16 + const string & -> string." ) ;
00290 }
00291
00292 #endif // CEYLAN_DEBUG
00293
00294 return ( res ) ;
00295
00296 }
00297
00298
00299
00300 string operator + ( const string & s, Ceylan::Sint32 i )
00301 {
00302
00303 ostringstream oss ;
00304 string res ;
00305
00306 oss.precision( Ceylan::DigitOutputPrecision ) ;
00307
00308 oss << i ;
00309 res = s + oss.str() ;
00310
00311 #if CEYLAN_DEBUG
00312
00313 if ( oss.fail() )
00314 {
00315 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00316 "const string & + Ceylan::Sint32 -> string." ) ;
00317 }
00318
00319 #endif // CEYLAN_DEBUG
00320
00321 return ( res ) ;
00322
00323 }
00324
00325
00326
00327 string operator + ( Ceylan::Sint32 i, const string & s )
00328 {
00329
00330 ostringstream oss ;
00331 string res ;
00332
00333 oss.precision( Ceylan::DigitOutputPrecision ) ;
00334
00335 oss << i ;
00336 res = oss.str() + s ;
00337
00338 #if CEYLAN_DEBUG
00339
00340 if ( oss.fail() )
00341 {
00342 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00343 "Ceylan::Sint32 + const string & -> string." ) ;
00344 }
00345
00346 #endif // CEYLAN_DEBUG
00347
00348 return ( res ) ;
00349
00350 }
00351
00352
00353
00354 string operator + ( const string & s, Ceylan::Uint32 i )
00355 {
00356
00357 ostringstream oss ;
00358 string res ;
00359
00360 oss.precision( Ceylan::DigitOutputPrecision ) ;
00361
00362 oss << i ;
00363 res = s + oss.str() ;
00364
00365 #if CEYLAN_DEBUG
00366
00367 if ( oss.fail() )
00368 {
00369 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00370 "const string & + Ceylan::Uint32 -> string." ) ;
00371 }
00372
00373 #endif // CEYLAN_DEBUG
00374
00375 return ( res ) ;
00376
00377 }
00378
00379
00380
00381 string operator + ( Ceylan::Uint32 i, const string & s )
00382 {
00383
00384 ostringstream oss ;
00385 string res ;
00386
00387 oss.precision( Ceylan::DigitOutputPrecision ) ;
00388
00389 oss << i ;
00390 res = oss.str() + s ;
00391
00392 #if CEYLAN_DEBUG
00393
00394 if ( oss.fail() )
00395 {
00396 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00397 "Ceylan::Uint32 + const string & -> string." ) ;
00398 }
00399
00400 #endif // CEYLAN_DEBUG
00401
00402 return ( res ) ;
00403
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 string operator + ( const string & s, Ceylan::SignedLongInteger i )
00446 {
00447
00448 ostringstream oss ;
00449 string res ;
00450
00451 oss.precision( Ceylan::DigitOutputPrecision ) ;
00452
00453 oss << i ;
00454 res = s + oss.str() ;
00455
00456 #if CEYLAN_DEBUG
00457
00458 if ( oss.fail() )
00459 {
00460 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00461 "const string & + Ceylan::SignedLongInteger -> string." ) ;
00462 }
00463
00464 #endif // CEYLAN_DEBUG
00465
00466 return ( res ) ;
00467
00468 }
00469
00470
00471
00472 string operator + ( Ceylan::SignedLongInteger i, const string & s )
00473 {
00474
00475 ostringstream oss ;
00476 string res ;
00477
00478 oss.precision( Ceylan::DigitOutputPrecision ) ;
00479
00480 oss << i ;
00481 res = oss.str() + s ;
00482
00483 #if CEYLAN_DEBUG
00484
00485 if ( oss.fail() )
00486 {
00487 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00488 "Ceylan::SignedLongInteger + const string & -> string." ) ;
00489 }
00490
00491 #endif // CEYLAN_DEBUG
00492
00493 return ( res ) ;
00494
00495 }
00496
00497
00498
00499 string operator + ( const string & s, Ceylan::UnsignedLongInteger i )
00500 {
00501
00502 ostringstream oss ;
00503 string res ;
00504
00505 oss.precision( Ceylan::DigitOutputPrecision ) ;
00506
00507 oss << i ;
00508 res = s + oss.str() ;
00509
00510 #if CEYLAN_DEBUG
00511
00512 if ( oss.fail() )
00513 {
00514 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00515 "const string & + Ceylan::UnsignedLongInteger -> string." ) ;
00516 }
00517
00518 #endif // CEYLAN_DEBUG
00519
00520 return ( res ) ;
00521
00522 }
00523
00524
00525
00526 string operator + ( Ceylan::UnsignedLongInteger i, const string & s )
00527 {
00528
00529 ostringstream oss ;
00530 string res ;
00531
00532 oss.precision( Ceylan::DigitOutputPrecision ) ;
00533
00534 oss << i ;
00535 res = oss.str() + s ;
00536
00537 #if CEYLAN_DEBUG
00538
00539 if ( oss.fail() )
00540 {
00541 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00542 "Ceylan::UnsignedLongInteger + const string & -> string." ) ;
00543 }
00544
00545 #endif // CEYLAN_DEBUG
00546
00547 return ( res ) ;
00548
00549 }
00550
00551
00552
00553
00554 string operator + ( const string & s, Ceylan::Float32 i )
00555 {
00556
00557 ostringstream oss ;
00558 string res ;
00559
00560 oss.precision( Ceylan::DigitOutputPrecision ) ;
00561
00562 oss << i ;
00563 res = s + oss.str() ;
00564
00565 #if CEYLAN_DEBUG
00566
00567 if ( oss.fail() )
00568 {
00569 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00570 "const string & + Ceylan::Float32 -> string." ) ;
00571 }
00572
00573 #endif // CEYLAN_DEBUG
00574
00575 return ( res ) ;
00576
00577 }
00578
00579
00580
00581 string operator + ( Ceylan::Float32 i, const string & s )
00582 {
00583
00584 ostringstream oss ;
00585 string res ;
00586
00587 oss.precision( Ceylan::DigitOutputPrecision ) ;
00588
00589 oss << i ;
00590 res = oss.str() + s ;
00591
00592 #if CEYLAN_DEBUG
00593
00594 if ( oss.fail() )
00595 {
00596 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00597 "Ceylan::Float32 + const string & -> string." ) ;
00598 }
00599
00600 #endif // CEYLAN_DEBUG
00601
00602 return ( res ) ;
00603
00604 }
00605
00606
00607
00608 string operator + ( const string & s, Ceylan::Float64 i )
00609 {
00610
00611 ostringstream oss ;
00612 string res ;
00613
00614 oss.precision( Ceylan::DigitOutputPrecision ) ;
00615
00616 oss << i ;
00617 res = s + oss.str() ;
00618
00619 #if CEYLAN_DEBUG
00620
00621 if ( oss.fail() )
00622 {
00623 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00624 "const string & + Ceylan::Float64 -> string." ) ;
00625 }
00626
00627 #endif // CEYLAN_DEBUG
00628
00629 return ( res ) ;
00630
00631 }
00632
00633
00634
00635 string operator + ( Ceylan::Float64 i, const string & s )
00636 {
00637
00638 ostringstream oss ;
00639 string res ;
00640
00641 oss.precision( Ceylan::DigitOutputPrecision ) ;
00642
00643 oss << i ;
00644 res = oss.str() + s ;
00645
00646 #if CEYLAN_DEBUG
00647
00648 if ( oss.fail() )
00649 {
00650 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00651 "Ceylan::Float64 + const string & -> string." ) ;
00652 }
00653
00654 #endif // CEYLAN_DEBUG
00655
00656 return ( res ) ;
00657
00658 }
00659
00660
00661
00662
00663
00664
00665
00666
00667 string operator + ( const string & s, Ceylan::LongFloat i )
00668 {
00669
00670 ostringstream oss ;
00671 string res ;
00672
00673 oss.precision( Ceylan::DigitOutputPrecision ) ;
00674
00675 oss << i ;
00676 res = s + oss.str() ;
00677
00678 #if CEYLAN_DEBUG
00679
00680 if ( oss.fail() )
00681 {
00682 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00683 "const string & + Ceylan::LongFloat -> string." ) ;
00684 }
00685
00686 #endif // CEYLAN_DEBUG
00687
00688 return ( res ) ;
00689
00690 }
00691
00692
00693
00694 string operator + ( Ceylan::LongFloat i, const string & s )
00695 {
00696
00697 ostringstream oss ;
00698 string res ;
00699
00700 oss.precision( Ceylan::DigitOutputPrecision ) ;
00701
00702 oss << i ;
00703 res = oss.str() + s ;
00704
00705 #if CEYLAN_DEBUG
00706
00707 if ( oss.fail() )
00708 {
00709 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00710 "Ceylan::LongFloat + const string & -> string." ) ;
00711 }
00712
00713 #endif // CEYLAN_DEBUG
00714
00715 return ( res ) ;
00716
00717 }
00718
00719
00720
00721 string operator + ( const string & s, const void * p )
00722 {
00723
00724 ostringstream oss ;
00725 string res ;
00726
00727 oss.precision( Ceylan::DigitOutputPrecision ) ;
00728
00729 oss << p ;
00730 res = s + oss.str() ;
00731
00732 #if CEYLAN_DEBUG
00733
00734 if ( oss.fail() )
00735 {
00736 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00737 "const string & + const void * -> string." ) ;
00738 }
00739
00740 #endif // CEYLAN_DEBUG
00741
00742 return ( res ) ;
00743
00744 }
00745
00746
00747
00748 string operator + ( const void * p, const string & s )
00749 {
00750
00751 ostringstream oss ;
00752 string res ;
00753
00754 oss.precision( Ceylan::DigitOutputPrecision ) ;
00755
00756 oss << p ;
00757 res = oss.str() + s ;
00758
00759 #if CEYLAN_DEBUG
00760
00761 if ( oss.fail() )
00762 {
00763 throw Ceylan::Exception( "Conversion error in Ceylan operator "
00764 "const void * + const string & + -> string." ) ;
00765 }
00766
00767 #endif // CEYLAN_DEBUG
00768
00769 return ( res ) ;
00770
00771 }
00772
00773
00774
00775 string operator + ( const string & a, const char * b )
00776 {
00777
00778 return a + string( b ) ;
00779
00780 }
00781
00782
00783
00784 string operator + ( const char * a, const string & b )
00785 {
00786
00787 return string( a ) + b ;
00788
00789 }
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 string Ceylan::toString( const void * pointer )
00801 {
00802
00803 ostringstream oss ;
00804 string res ;
00805
00806 oss.precision( Ceylan::DigitOutputPrecision ) ;
00807
00808 oss << pointer ;
00809 res = oss.str() ;
00810
00811 #if CEYLAN_DEBUG
00812
00813 if ( oss.fail() )
00814 {
00815 throw Ceylan::Exception( "Conversion error in method "
00816 "Ceylan::toString: const void * -> string." ) ;
00817 }
00818
00819 #endif // CEYLAN_DEBUG
00820
00821 return ( res ) ;
00822
00823 }
00824
00825
00826
00827 string Ceylan::toString( bool value )
00828 {
00829
00830 if ( value )
00831 {
00832 return "true" ;
00833 }
00834 else
00835 {
00836 return "false" ;
00837 }
00838
00839 }
00840
00841
00842
00843 string Ceylan::toString( Ceylan::Sint8 value, bool bitField )
00844 {
00845
00846 if ( bitField )
00847 return Ceylan::toString(
00848 static_cast<UnsignedLongInteger>( value ), true ) ;
00849
00850 ostringstream oss ;
00851 string res ;
00852
00853 oss.precision( Ceylan::DigitOutputPrecision ) ;
00854
00855 if ( bitField )
00856 oss <<
00857 oss << value ;
00858 res = oss.str() ;
00859
00860 #if CEYLAN_DEBUG
00861
00862 if ( oss.fail() )
00863 {
00864 throw Ceylan::Exception( "Conversion error in method "
00865 "Ceylan::toString: Ceylan::Sint8 -> string." ) ;
00866 }
00867
00868 #endif // CEYLAN_DEBUG
00869
00870 return ( res ) ;
00871
00872 }
00873
00874
00875
00876 string Ceylan::toString( Ceylan::Uint8 value, bool bitField )
00877 {
00878
00879 if ( bitField )
00880 return Ceylan::toString(
00881 static_cast<UnsignedLongInteger>( value ), true ) ;
00882
00883 string res ;
00884
00885 ostringstream oss ;
00886
00887 oss.precision( Ceylan::DigitOutputPrecision ) ;
00888
00889 oss << value ;
00890 res = oss.str() ;
00891
00892 #if CEYLAN_DEBUG
00893
00894 if ( oss.fail() )
00895 {
00896 throw Ceylan::Exception( "Conversion error in method "
00897 "Ceylan::toString: Ceylan::Uint8 -> string." ) ;
00898 }
00899
00900 #endif // CEYLAN_DEBUG
00901
00902 return ( res ) ;
00903
00904 }
00905
00906
00907
00908 string Ceylan::toString( Ceylan::Sint16 value, bool bitField )
00909 {
00910
00911 if ( bitField )
00912 return Ceylan::toString(
00913 static_cast<UnsignedLongInteger>( value ), true ) ;
00914
00915 ostringstream oss ;
00916
00917 oss.precision( Ceylan::DigitOutputPrecision ) ;
00918
00919 string res ;
00920
00921 oss << value ;
00922 res = oss.str() ;
00923
00924 #if CEYLAN_DEBUG
00925
00926 if ( oss.fail() )
00927 {
00928 throw Ceylan::Exception( "Conversion error in method "
00929 "Ceylan::toString: Ceylan::Sint16 -> string." ) ;
00930 }
00931
00932 #endif // CEYLAN_DEBUG
00933
00934 return ( res ) ;
00935
00936 }
00937
00938
00939
00940 string Ceylan::toString( Ceylan::Uint16 value, bool bitField )
00941 {
00942
00943 if ( bitField )
00944 return Ceylan::toString(
00945 static_cast<UnsignedLongInteger>( value ), true ) ;
00946
00947 ostringstream oss ;
00948
00949 oss.precision( Ceylan::DigitOutputPrecision ) ;
00950
00951 string res ;
00952
00953 oss << value ;
00954 res = oss.str() ;
00955
00956 #if CEYLAN_DEBUG
00957
00958 if ( oss.fail() )
00959 {
00960 throw Ceylan::Exception( "Conversion error in method "
00961 "Ceylan::toString: Ceylan::Uint16 -> string." ) ;
00962 }
00963
00964 #endif // CEYLAN_DEBUG
00965
00966 return ( res ) ;
00967
00968 }
00969
00970
00971
00972 string Ceylan::toString( Ceylan::Sint32 value, bool bitField )
00973 {
00974
00975 if ( bitField )
00976 return Ceylan::toString(
00977 static_cast<UnsignedLongInteger>( value ), true ) ;
00978
00979 ostringstream oss ;
00980
00981 oss.precision( Ceylan::DigitOutputPrecision ) ;
00982
00983 string res ;
00984
00985 oss << value ;
00986 res = oss.str() ;
00987
00988 #if CEYLAN_DEBUG
00989
00990 if ( oss.fail() )
00991 {
00992 throw Ceylan::Exception( "Conversion error in method "
00993 "Ceylan::toString: Ceylan::Sint32 -> string." ) ;
00994 }
00995
00996 #endif // CEYLAN_DEBUG
00997
00998 return ( res ) ;
00999
01000 }
01001
01002
01003
01004 string Ceylan::toString( Ceylan::Uint32 value, bool bitField )
01005 {
01006
01007 if ( bitField )
01008 return Ceylan::toString(
01009 static_cast<UnsignedLongInteger>( value ), true ) ;
01010
01011 ostringstream oss ;
01012
01013 oss.precision( Ceylan::DigitOutputPrecision ) ;
01014
01015 string res ;
01016
01017 oss << value ;
01018 res = oss.str() ;
01019
01020 #if CEYLAN_DEBUG
01021
01022 if ( oss.fail() )
01023 {
01024 throw Ceylan::Exception( "Conversion error in method "
01025 "Ceylan::toString: Ceylan::Uint32 -> string." ) ;
01026 }
01027
01028 #endif // CEYLAN_DEBUG
01029
01030 return ( res ) ;
01031
01032 }
01033
01034
01035
01036 string Ceylan::toString( UnsignedLongInteger value, bool bitField )
01037 {
01038
01039 string res ;
01040
01041 if ( bitField )
01042 {
01043
01044 while ( value )
01045 {
01046 res += Ceylan::toString( value % 2 ) ;
01047 value /= 2 ;
01048 }
01049
01050
01051 if ( res.empty() )
01052 return "0b0" ;
01053
01054 return "0b" + Ceylan::reverse( res ) ;
01055
01056 }
01057
01058 ostringstream oss ;
01059
01060 oss.precision( Ceylan::DigitOutputPrecision ) ;
01061
01062 oss << value ;
01063 res = oss.str() ;
01064
01065 #if CEYLAN_DEBUG
01066
01067 if ( oss.fail() )
01068 {
01069 throw Ceylan::Exception( "Conversion error in method "
01070 "Ceylan::toString: UnsignedLongInteger -> string." ) ;
01071 }
01072
01073 #endif // CEYLAN_DEBUG
01074
01075 return ( res ) ;
01076
01077 }
01078
01079
01080
01081 string Ceylan::toString( SignedLongInteger value, bool bitField )
01082 {
01083
01084 string res ;
01085
01086 if ( bitField )
01087 {
01088
01089 string begin ;
01090
01091 if ( value < 0 )
01092 {
01093 value = -value ;
01094 begin = "-" ;
01095 }
01096
01097 while ( value )
01098 {
01099 res += Ceylan::toString( value % 2 ) ;
01100 value /= 2 ;
01101 }
01102
01103
01104 if ( res.empty() )
01105 return "0b0" ;
01106
01107 return begin + "0b" + Ceylan::reverse( res ) ;
01108
01109 }
01110
01111 ostringstream oss ;
01112
01113 oss.precision( Ceylan::DigitOutputPrecision ) ;
01114
01115 oss << value ;
01116 res = oss.str() ;
01117
01118 #if CEYLAN_DEBUG
01119
01120 if ( oss.fail() )
01121 {
01122 throw Ceylan::Exception( "Conversion error in method "
01123 "Ceylan::toString: SignedLongInteger -> string." ) ;
01124 }
01125
01126 #endif // CEYLAN_DEBUG
01127
01128 return ( res ) ;
01129
01130 }
01131
01132
01133
01134 string Ceylan::toHexString( Ceylan::UnsignedLongInteger value, bool prefix,
01135 Ceylan::Uint8 minDigits )
01136 {
01137
01138 string res ;
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152 while ( value )
01153 {
01154 res += HexDigits[ value % 16 ] ;
01155 value /= 16 ;
01156 }
01157
01158 while ( res.size() < minDigits )
01159 res += "0" ;
01160
01161 return
01162 ( prefix ? "0x" : "" ) + Ceylan::reverse( res ) ;
01163
01164 }
01165
01166
01167
01168 string Ceylan::toString( Ceylan::Float32 value, Ceylan::Uint8 precision )
01169 {
01170
01171 ostringstream oss ;
01172
01173 oss << std::fixed ;
01174 oss.precision( precision ) ;
01175
01176 string res ;
01177
01178 oss << value ;
01179 res = oss.str() ;
01180
01181 #if CEYLAN_DEBUG
01182
01183 if ( oss.fail() )
01184 {
01185 throw Ceylan::Exception( "Conversion error in method "
01186 "Ceylan::toString: Ceylan::Float32 -> string." ) ;
01187 }
01188
01189 #endif // CEYLAN_DEBUG
01190
01191 return ( res ) ;
01192
01193 }
01194
01195
01196
01197 string Ceylan::toString( Ceylan::Float64 value, Ceylan::Uint8 precision )
01198 {
01199 ostringstream oss ;
01200
01201 oss << std::fixed ;
01202 oss.precision( precision ) ;
01203 string res ;
01204
01205 oss << value ;
01206 res = oss.str() ;
01207
01208 #if CEYLAN_DEBUG
01209
01210 if ( oss.fail() )
01211 {
01212 throw Ceylan::Exception( "Conversion error in method "
01213 "Ceylan::toString: Ceylan::Float64 -> string." ) ;
01214 }
01215
01216 #endif // CEYLAN_DEBUG
01217
01218 return ( res ) ;
01219
01220 }
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230 string Ceylan::toString( Ceylan::LongFloat value, Ceylan::Uint8 precision )
01231 {
01232 ostringstream oss ;
01233
01234 oss << std::fixed ;
01235 oss.precision( precision ) ;
01236
01237 string res ;
01238
01239 oss << std::fixed << value ;
01240 res = oss.str() ;
01241
01242 #if CEYLAN_DEBUG
01243
01244 if ( oss.fail() )
01245 {
01246 throw Ceylan::Exception( "Conversion error in method "
01247 "Ceylan::toString: Ceylan::LongFloat -> string." ) ;
01248 }
01249
01250 #endif // CEYLAN_DEBUG
01251
01252 return ( res ) ;
01253
01254 }
01255
01256
01257
01258 string Ceylan::toString( Ceylan::VerbosityLevels level )
01259 {
01260
01261 switch( level )
01262 {
01263
01264 case low:
01265 return "low" ;
01266 break ;
01267
01268 case medium:
01269 return "medium" ;
01270 break ;
01271
01272 case high:
01273 return "high" ;
01274 break ;
01275
01276 default:
01277 throw Ceylan::Exception( "Conversion error in method "
01278 "Ceylan::toString: Ceylan::VerbosityLevels -> string: "
01279 "unknown verbosity level." ) ;
01280 break ;
01281
01282 }
01283
01284 }
01285
01286
01287
01288 std::string Ceylan::toString( const std::list<Ceylan::Uint32> & intList )
01289 {
01290
01291 list<string> res ;
01292
01293 for ( list<Ceylan::Uint32>::const_iterator it = intList.begin();
01294 it != intList.end(); it++ )
01295 res.push_back( toString( *it ) ) ;
01296
01297 return join( res, " - " ) ;
01298
01299 }
01300
01301
01302
01303 std::string Ceylan::toString( const std::list<const void *> & pointerList )
01304 {
01305
01306 list<string> res ;
01307
01308 for ( list<const void *>::const_iterator it = pointerList.begin();
01309 it != pointerList.end(); it++ )
01310 res.push_back( toString( *it ) ) ;
01311
01312 return join( res, " - " ) ;
01313
01314 }
01315
01316
01317
01318 string Ceylan::toNumericalString( Uint8 number )
01319 {
01320
01321 ostringstream oss ;
01322
01323 oss.precision( Ceylan::DigitOutputPrecision ) ;
01324
01325 string res ;
01326
01327 oss << static_cast<Ceylan::Uint16>( number ) ;
01328 res = oss.str() ;
01329
01330 #if CEYLAN_DEBUG
01331
01332 if ( oss.fail() )
01333 {
01334 throw Ceylan::Exception( "Conversion error in method "
01335 "Ceylan::toNumericalString: Uint8 -> string." ) ;
01336 }
01337
01338 #endif // CEYLAN_DEBUG
01339
01340 return ( res ) ;
01341
01342 }
01343
01344
01345
01346 string Ceylan::toString( char character )
01347 {
01348
01349 string res ;
01350
01351 res += character ;
01352
01353 return res ;
01354
01355 }
01356
01357
01358
01359 int Ceylan::stringToUnsignedLong( const string & numericalString )
01360 {
01361
01362 int result ;
01363
01364 istringstream iss( numericalString ) ;
01365 iss >> result ;
01366
01367
01368 if ( iss.fail() )
01369 {
01370 throw Ceylan::Exception( "Conversion error in method "
01371 "Ceylan::stringToUnsignedLong, while operating on "
01372 + numericalString + "." ) ;
01373 }
01374
01375 return result ;
01376
01377 }
01378
01379
01380
01381 void * Ceylan::stringToAddress( const string & addressString )
01382 {
01383
01384 void * result ;
01385
01386 istringstream iss( addressString ) ;
01387 iss >> result ;
01388
01389
01390 if ( iss.fail() )
01391 {
01392 throw Ceylan::Exception(
01393 "Ceylan::stringToAddress: conversion error while operating on '"
01394 + addressString + "'." ) ;
01395 }
01396
01397 return result ;
01398
01399 }
01400