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5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/tos (Version 11.3.0) and /externals/g4tools/include/tools/tos (Version 11.0)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_tos                                   4 #ifndef tools_tos
  5 #define tools_tos                                   5 #define tools_tos
  6                                                     6 
  7 // Used in BatchLab/MemoryTuple and Rio_Tuple.      7 // Used in BatchLab/MemoryTuple and Rio_Tuple.
  8 // We need something different than the to<T>       8 // We need something different than the to<T>
  9 // to handle std::vector<> and bool.                9 // to handle std::vector<> and bool.
 10                                                    10 
 11 #include "sprintf"                                 11 #include "sprintf"
 12 #include "charmanip"                               12 #include "charmanip"
 13 #include "typedefs"                                13 #include "typedefs"
 14                                                    14 
 15 #include <vector>                                  15 #include <vector>
 16                                                    16 
 17 namespace tools {                                  17 namespace tools {
 18                                                    18 
 19 inline std::string tos(unsigned char a_value){     19 inline std::string tos(unsigned char a_value){
 20   std::string _s;                              <<  20   std::string s;
 21   if(is_printable(a_value))                        21   if(is_printable(a_value))
 22     sprintf(_s,32,"%c",a_value);               <<  22     sprintf(s,32,"%c",a_value);
 23   else                                             23   else
 24     sprintf(_s,32,"%d",a_value);               <<  24     sprintf(s,32,"%d",a_value);
 25   return _s;                                   <<  25   return s;
 26 }                                                  26 }
 27                                                    27 
 28 inline std::string tos(char a_value){              28 inline std::string tos(char a_value){
 29   std::string _s;                              <<  29   std::string s;
 30   if(is_printable(a_value))                        30   if(is_printable(a_value))
 31     sprintf(_s,32,"%c",a_value);               <<  31     sprintf(s,32,"%c",a_value);
 32   else                                             32   else
 33     sprintf(_s,32,"%d",a_value);               <<  33     sprintf(s,32,"%d",a_value);
 34   return _s;                                   <<  34   return s;
 35 }                                                  35 }
 36                                                    36 
 37 inline std::string tos(unsigned short a_value)     37 inline std::string tos(unsigned short a_value) {
 38   std::string _s;                              <<  38   std::string s;
 39   sprintf(_s,32,"%d",a_value);                 <<  39   sprintf(s,32,"%d",a_value);
 40   return _s;                                   <<  40   return s;
 41 }                                                  41 }
 42                                                    42 
 43 inline std::string tos(short a_value){             43 inline std::string tos(short a_value){
 44   std::string _s;                              <<  44   std::string s;
 45   sprintf(_s,32,"%d",a_value);                 <<  45   sprintf(s,32,"%d",a_value);
 46   return _s;                                   <<  46   return s;
 47 }                                                  47 }
 48                                                    48 
 49 inline std::string tos(unsigned int a_value) {     49 inline std::string tos(unsigned int a_value) {
 50   std::string _s;                              <<  50   std::string s;
 51   sprintf(_s,32,"%u",a_value);                 <<  51   sprintf(s,32,"%u",a_value);
 52   return _s;                                   <<  52   return s;
 53 }                                                  53 }
 54                                                    54 
 55 inline std::string tosx(unsigned int a_value)      55 inline std::string tosx(unsigned int a_value) {
 56   std::string _s;                              <<  56   std::string s;
 57   sprintf(_s,32,"%x",a_value);                 <<  57   sprintf(s,32,"%x",a_value);
 58   return _s;                                   <<  58   return s;
 59 }                                                  59 }
 60                                                    60 
 61 inline std::string tos(int a_value){               61 inline std::string tos(int a_value){
 62   std::string _s;                              <<  62   std::string s;
 63   sprintf(_s,32,"%d",a_value);                 <<  63   sprintf(s,32,"%d",a_value);
 64   return _s;                                   <<  64   return s;
 65 }                                                  65 }
 66                                                    66 
 67 inline std::string tos(uint64 a_value) {           67 inline std::string tos(uint64 a_value) {
 68   std::string _s;                              <<  68   std::string s;
 69   sprintf(_s,32,uint64_format(),a_value);      <<  69   sprintf(s,32,uint64_format(),a_value);
 70   return _s;                                   <<  70   return s;
 71 }                                                  71 }
 72                                                    72 
 73 inline std::string tos(int64 a_value){             73 inline std::string tos(int64 a_value){
 74   std::string _s;                              <<  74   std::string s;
 75   sprintf(_s,32,int64_format(),a_value);       <<  75   sprintf(s,32,int64_format(),a_value);
 76   return _s;                                   <<  76   return s;
 77 }                                                  77 }
 78                                                    78 
 79 inline std::string tos(float a_value){             79 inline std::string tos(float a_value){
 80   std::string _s;                              <<  80   std::string s;
 81   sprintf(_s,32,"%g",a_value);                 <<  81   sprintf(s,32,"%g",a_value);
 82   return _s;                                   <<  82   return s;
 83 }                                                  83 }
 84                                                    84 
 85 inline std::string tos(double a_value){            85 inline std::string tos(double a_value){
 86   std::string _s;                              <<  86   std::string s;
 87   sprintf(_s,32,"%g",a_value);                 <<  87   sprintf(s,32,"%g",a_value);
 88   return _s;                                   <<  88   return s;
 89 }                                                  89 }
 90                                                    90 
 91 inline std::string tos(bool a_value){              91 inline std::string tos(bool a_value){
 92   return std::string(a_value?"true":"false");      92   return std::string(a_value?"true":"false");
 93 }                                                  93 }
 94                                                    94 
 95 inline std::string tos(const std::string& a_va     95 inline std::string tos(const std::string& a_value){return a_value;}
 96                                                    96 
 97 template <class T>                                 97 template <class T>
 98 inline std::string tos(const std::vector<T>& a     98 inline std::string tos(const std::vector<T>& a_vals,
 99                        const std::string& a_se     99                        const std::string& a_sep = "\n",
100                        bool a_sep_at_end = fal    100                        bool a_sep_at_end = false) {
101   size_t number = a_vals.size();                  101   size_t number = a_vals.size();
102   if(number<=0) return "";                        102   if(number<=0) return "";
103   std::string result;                             103   std::string result;
104   number--;                                       104   number--;
105   for(size_t index=0;index<number;index++) {      105   for(size_t index=0;index<number;index++) {
106     result += tos(a_vals[index]);                 106     result += tos(a_vals[index]);
107     result += a_sep;                              107     result += a_sep;
108   }                                               108   }
109   result += tos(a_vals[number]);                  109   result += tos(a_vals[number]);
110   if(a_sep_at_end) result += a_sep;               110   if(a_sep_at_end) result += a_sep;
111   return result;                                  111   return result;
112 }                                                 112 }
113                                                   113 
114 inline std::string tos(unsigned int a_linen,co    114 inline std::string tos(unsigned int a_linen,const char* a_lines[]) {
115   std::string _s;                              << 115   std::string s;
116   for(unsigned int index=0;index<a_linen;index    116   for(unsigned int index=0;index<a_linen;index++) {
117     _s += std::string(a_lines[index]);         << 117     s += std::string(a_lines[index]);
118     _s += "\n";                                << 118     s += "\n";
119   }                                               119   }
120   return _s;                                   << 120   return s;
121 }                                                 121 }
122                                                   122 
123 }                                                 123 }
124                                                   124 
125 #endif                                            125 #endif