Warning, /include/Geant4/tools/tos is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_tos
0005 #define tools_tos
0006
0007 // Used in BatchLab/MemoryTuple and Rio_Tuple.
0008 // We need something different than the to<T>
0009 // to handle std::vector<> and bool.
0010
0011 #include "sprintf"
0012 #include "charmanip"
0013 #include "typedefs"
0014
0015 #include <vector>
0016
0017 namespace tools {
0018
0019 inline std::string tos(unsigned char a_value){
0020 std::string _s;
0021 if(is_printable(a_value))
0022 sprintf(_s,32,"%c",a_value);
0023 else
0024 sprintf(_s,32,"%d",a_value);
0025 return _s;
0026 }
0027
0028 inline std::string tos(char a_value){
0029 std::string _s;
0030 if(is_printable(a_value))
0031 sprintf(_s,32,"%c",a_value);
0032 else
0033 sprintf(_s,32,"%d",a_value);
0034 return _s;
0035 }
0036
0037 inline std::string tos(unsigned short a_value) {
0038 std::string _s;
0039 sprintf(_s,32,"%d",a_value);
0040 return _s;
0041 }
0042
0043 inline std::string tos(short a_value){
0044 std::string _s;
0045 sprintf(_s,32,"%d",a_value);
0046 return _s;
0047 }
0048
0049 inline std::string tos(unsigned int a_value) {
0050 std::string _s;
0051 sprintf(_s,32,"%u",a_value);
0052 return _s;
0053 }
0054
0055 inline std::string tos(int a_value){
0056 std::string _s;
0057 sprintf(_s,32,"%d",a_value);
0058 return _s;
0059 }
0060
0061 inline std::string tos(uint64 a_value) {
0062 std::string _s;
0063 sprintf(_s,32,uint64_format(),a_value);
0064 return _s;
0065 }
0066
0067 inline std::string tos(int64 a_value){
0068 std::string _s;
0069 sprintf(_s,32,int64_format(),a_value);
0070 return _s;
0071 }
0072
0073 inline std::string tos(float a_value){
0074 std::string _s;
0075 sprintf(_s,32,"%g",a_value);
0076 return _s;
0077 }
0078
0079 inline std::string tos(double a_value){
0080 std::string _s;
0081 sprintf(_s,32,"%g",a_value);
0082 return _s;
0083 }
0084
0085 inline std::string tos(bool a_value){
0086 return std::string(a_value?"true":"false");
0087 }
0088
0089 inline std::string tos(const std::string& a_value){return a_value;}
0090
0091 template <class T>
0092 inline std::string tos(const std::vector<T>& a_vals,
0093 const std::string& a_sep = "\n",
0094 bool a_sep_at_end = false) {
0095 size_t number = a_vals.size();
0096 if(number<=0) return "";
0097 std::string result;
0098 number--;
0099 for(size_t index=0;index<number;index++) {
0100 result += tos(a_vals[index]);
0101 result += a_sep;
0102 }
0103 result += tos(a_vals[number]);
0104 if(a_sep_at_end) result += a_sep;
0105 return result;
0106 }
0107
0108 }
0109
0110 #endif