Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/pointer 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_pointer
0005 #define tools_pointer
0006 
0007 //WARNING : touchy.
0008 //WARNING : _MSC_VER && _WIN64 : sizeof(void*) is NOT sizeof(unsigned long).
0009 
0010 #include "typedefs"
0011 
0012 #include "snpf"
0013 
0014 #include <string>
0015 
0016 namespace tools {
0017 
0018 inline bool to_pointer(const std::string& a_string,void*& a_value){
0019   upointer v = 0;
0020   if(::sscanf(a_string.c_str(),upointer_format_x(),&v)!=1) {
0021     if(::sscanf(a_string.c_str(),upointer_format(),&v)!=1) {
0022       a_value = 0;
0023       return false;
0024     }
0025   }
0026   a_value = (void*)v;
0027   return true;
0028 }
0029 
0030 inline bool to_pointer(const char* a_string,void*& a_value){
0031   upointer v = 0;
0032   if(::sscanf(a_string,upointer_format_x(),&v)!=1) {
0033     if(::sscanf(a_string,upointer_format(),&v)!=1) {
0034       a_value = 0;
0035       return false;
0036     }
0037   }
0038   a_value = (void*)v;
0039   return true;
0040 }
0041 
0042 inline bool p2s(const void* a_value,std::string& a_s){
0043   char _s[512];
0044   snpf(_s,sizeof(_s),upointer_format(),(upointer)a_value);
0045   a_s = _s;
0046   return true;
0047 }
0048 
0049 inline bool p2sx(const void* a_value,std::string& a_s){
0050   char _s[512];
0051   snpf(_s,sizeof(_s),upointer_format_x(),(upointer)a_value);
0052   a_s = _s;
0053   return true;
0054 }
0055 
0056 /*
0057 inline std::string p2s(const void* a_value){
0058   char _s[512];
0059   snpf(_s,sizeof(_s),"%lu",(unsigned long)a_value);
0060   return _s;
0061 }
0062 
0063 inline std::string p2sx(const void* a_value){
0064   char _s[512];
0065   snpf(_s,sizeof(_s),"0x%lx",(unsigned long)a_value);
0066   return _s;
0067 }
0068 
0069 inline std::string char_p2s(const char* a_value) {
0070   char _s[512];
0071   snpf(_s,sizeof(_s),"%lu",(unsigned long)a_value);
0072   return std::string(_s);
0073 }
0074 
0075 inline std::string long2s(const long a_value) {
0076   char _s[512];
0077   snpf(_s,sizeof(_s),"%ld",a_value);
0078   return std::string(_s);
0079 }
0080 */
0081 
0082 }
0083 
0084 #endif