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