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 tosx(unsigned int a_value) {
0056 std::string _s;
0057 sprintf(_s,32,"%x",a_value);
0058 return _s;
0059 }
0060
0061 inline std::string tos(int a_value){
0062 std::string _s;
0063 sprintf(_s,32,"%d",a_value);
0064 return _s;
0065 }
0066
0067 inline std::string tos(uint64 a_value) {
0068 std::string _s;
0069 sprintf(_s,32,uint64_format(),a_value);
0070 return _s;
0071 }
0072
0073 inline std::string tos(int64 a_value){
0074 std::string _s;
0075 sprintf(_s,32,int64_format(),a_value);
0076 return _s;
0077 }
0078
0079 inline std::string tos(float a_value){
0080 std::string _s;
0081 sprintf(_s,32,"%g",a_value);
0082 return _s;
0083 }
0084
0085 inline std::string tos(double a_value){
0086 std::string _s;
0087 sprintf(_s,32,"%g",a_value);
0088 return _s;
0089 }
0090
0091 inline std::string tos(bool a_value){
0092 return std::string(a_value?"true":"false");
0093 }
0094
0095 inline std::string tos(const std::string& a_value){return a_value;}
0096
0097 template <class T>
0098 inline std::string tos(const std::vector<T>& a_vals,
0099 const std::string& a_sep = "\n",
0100 bool a_sep_at_end = false) {
0101 size_t number = a_vals.size();
0102 if(number<=0) return "";
0103 std::string result;
0104 number--;
0105 for(size_t index=0;index<number;index++) {
0106 result += tos(a_vals[index]);
0107 result += a_sep;
0108 }
0109 result += tos(a_vals[number]);
0110 if(a_sep_at_end) result += a_sep;
0111 return result;
0112 }
0113
0114 inline std::string tos(unsigned int a_linen,const char* a_lines[]) {
0115 std::string _s;
0116 for(unsigned int index=0;index<a_linen;index++) {
0117 _s += std::string(a_lines[index]);
0118 _s += "\n";
0119 }
0120 return _s;
0121 }
0122
0123 }
0124
0125 #endif