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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/num2s (Version 11.3.0) and /externals/g4tools/include/tools/num2s (Version 7.1)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_num2s                               
  5 #define tools_num2s                               
  6                                                   
  7 // write numerics in a string as if done with     
  8                                                   
  9 #include "sprintf"                                
 10 #include "typedefs"                               
 11                                                   
 12 #include <cstddef> //ptrdiff_t                    
 13                                                   
 14 namespace tools {                                 
 15                                                   
 16 /*                                                
 17 inline bool num2s(unsigned char a_value,std::s    
 18   return print2s(a_s,32,"%c",a_value);            
 19 }                                                 
 20                                                   
 21 inline bool num2s(char a_value,std::string& a_    
 22   return print2s(a_s,32,"%c",a_value);            
 23 }                                                 
 24 */                                                
 25                                                   
 26 inline bool num2s(unsigned short a_value,std::    
 27   return print2s(a_s,32,"%u",a_value);            
 28 }                                                 
 29                                                   
 30 inline bool num2s(short a_value,std::string& a    
 31   return print2s(a_s,32,"%d",a_value);            
 32 }                                                 
 33                                                   
 34 inline bool num2s(unsigned int a_value,std::st    
 35   return print2s(a_s,32,"%u",a_value);            
 36 }                                                 
 37                                                   
 38 /*                                                
 39 inline bool num2sx(unsigned int a_value,std::s    
 40   return print2s(a_s,32,"%x",a_value);            
 41 }                                                 
 42 */                                                
 43                                                   
 44 inline bool num2s(int a_value,std::string& a_s    
 45   return print2s(a_s,32,"%d",a_value);            
 46 }                                                 
 47                                                   
 48 inline bool num2s(uint64 a_value,std::string&     
 49   return print2s(a_s,32,uint64_format(),a_valu    
 50 }                                                 
 51                                                   
 52 inline bool num2s(int64 a_value,std::string& a    
 53   return print2s(a_s,32,int64_format(),a_value    
 54 }                                                 
 55                                                   
 56 inline bool num2s(float a_value,std::string& a    
 57   return print2s(a_s,32,"%g",a_value);            
 58 }                                                 
 59                                                   
 60 inline bool num2s(double a_value,std::string&     
 61   return print2s(a_s,32,"%g",a_value);            
 62 }                                                 
 63                                                   
 64 inline bool size_t2s(size_t a_value,std::strin    
 65   if(sizeof(size_t)==8) {                         
 66     return num2s((uint64)a_value,a_s);            
 67   } else { //assume 4 :                           
 68     return num2s((uint32)a_value,a_s);            
 69   }                                               
 70 }                                                 
 71                                                   
 72 inline bool ptrdiff_t2s(ptrdiff_t a_value,std:    
 73   if(sizeof(ptrdiff_t)==8) {                      
 74     return num2s((int64)a_value,a_s);             
 75   } else { //assume 4 :                           
 76     return num2s((int32)a_value,a_s);             
 77   }                                               
 78 }                                                 
 79                                                   
 80 /*                                                
 81 inline bool num2s(bool a_value,std::string& a_    
 82   //a_s = a_value?"true":"false";                 
 83   a_s = a_value?"1":"0";                          
 84   return true;                                    
 85 }                                                 
 86 */                                                
 87                                                   
 88 template <class T>                                
 89 inline bool numas(const T& a_value,std::string    
 90   std::string stmp;                               
 91   if(!num2s(a_value,stmp)) return false;          
 92   a_s += stmp;                                    
 93   return true;                                    
 94 }                                                 
 95                                                   
 96 template <class T>                                
 97 inline bool size_tas(const T& a_value,std::str    
 98   std::string stmp;                               
 99   if(!size_t2s(a_value,stmp)) return false;       
100   a_s += stmp;                                    
101   return true;                                    
102 }                                                 
103                                                   
104 /*                                                
105 inline bool num2s(unsigned int a_linen,const c    
106   a_s.clear();                                    
107   for(unsigned int index=0;index<a_linen;index    
108     a_s += a_lines[index];                        
109     a_s += "\n";                                  
110   }                                               
111   return true;                                    
112 }                                                 
113 */                                                
114                                                   
115 // for the below std::vector num2s in case T=s    
116 inline bool num2s(const std::string& a_value,s    
117                                                   
118 template <class T>                                
119 class num_out : public std::string {              
120   typedef std::string parent;                     
121 private:                                          
122   //typedef typename std::enable_if<std::is_fl    
123   //typedef typename std::enable_if<std::is_in    
124   //typedef typename std::enable_if<std::is_ar    
125 public:                                           
126   num_out(const T& a_value) {                     
127     parent::operator+=("\"");                     
128     if(!numas(a_value,*this)) {} //throw          
129     parent::operator+=("\"");                     
130   }                                               
131 public:                                           
132   num_out(const num_out& a_from):parent(a_from    
133   num_out& operator=(const num_out& a_from){pa    
134 };                                                
135                                                   
136 }                                                 
137                                                   
138 #include <vector>                                 
139                                                   
140 namespace tools {                                 
141                                                   
142 template <class VEC>                              
143 inline bool nums2s(const VEC& a_vals,std::stri    
144   a_s.clear();                                    
145   typename VEC::size_type number = a_vals.size    
146   if(number<=0) return true; //it is ok.          
147   number--;                                       
148   std::string stmp;                               
149   bool status = true;                             
150   for(typename VEC::size_type index=0;index<nu    
151     if(!num2s(a_vals[index],stmp)) status = fa    
152     a_s += stmp;                                  
153     a_s += a_sep;                                 
154   }                                               
155   if(!num2s(a_vals[number],stmp)) status = fal    
156   a_s += stmp;                                    
157   if(a_sep_at_end) a_s += a_sep;                  
158   return status;                                  
159 }                                                 
160                                                   
161 template <class T>                                
162 inline bool nums2s(const std::vector<T>& a_val    
163   return nums2s< std::vector<T> >(a_vals,a_s,a    
164 }                                                 
165                                                   
166 }                                                 
167                                                   
168 #endif