Geant4 Cross Reference |
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_charp_out 4 #ifndef tools_charp_out 5 #define tools_charp_out 5 #define tools_charp_out 6 6 7 #include "snpf" 7 #include "snpf" 8 #include <string> 8 #include <string> 9 9 10 namespace tools { 10 namespace tools { 11 11 12 class charp_out : public std::string { 12 class charp_out : public std::string { 13 typedef std::string parent; 13 typedef std::string parent; 14 public: 14 public: 15 charp_out(const char* a_value) { 15 charp_out(const char* a_value) { 16 char _s[512]; << 16 char s[512]; 17 if(sizeof(unsigned long)==sizeof(char*)) { 17 if(sizeof(unsigned long)==sizeof(char*)) { //majority of cases. 18 snpf(_s,sizeof(_s),"%lu",a_value); << 18 snpf(s,sizeof(s),"%lu",a_value); 19 parent::operator+=(_s); << 19 parent::operator+=(s); 20 } else if(sizeof(unsigned long long)==size 20 } else if(sizeof(unsigned long long)==sizeof(char*)) { //majority of cases. 21 snpf(_s,sizeof(_s),"%llu",a_value); << 21 snpf(s,sizeof(s),"%llu",a_value); 22 parent::operator+=(_s); << 22 parent::operator+=(s); 23 } else { 23 } else { 24 parent::operator+=("charp_out_failed"); 24 parent::operator+=("charp_out_failed"); 25 } 25 } 26 } 26 } 27 public: 27 public: 28 charp_out(const charp_out& a_from):parent(a_ 28 charp_out(const charp_out& a_from):parent(a_from){} 29 charp_out& operator=(const charp_out& a_from 29 charp_out& operator=(const charp_out& a_from){parent::operator=(a_from);return *this;} 30 }; 30 }; 31 31 32 } 32 } 33 33 34 #endif 34 #endif