Files
geant4/source/analysis/g4tools/include/tools/pointer
T
2016-06-30 14:12:05 +02:00

73 lines
1.4 KiB
Plaintext

// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_pointer
#define tools_pointer
//WARNING : touchy.
//WARNING : _MSC_VER && _WIN64 : sizeof(void*) is NOT sizeof(unsigned long).
#include "typedefs"
#include "snpf"
#include <string>
namespace tools {
inline bool to_pointer(const std::string& a_string,void*& a_value){
upointer v = 0;
if(::sscanf(a_string.c_str(),upointer_format_x(),&v)!=1) {
if(::sscanf(a_string.c_str(),upointer_format(),&v)!=1) {
a_value = 0;
return false;
}
}
a_value = (void*)v;
return true;
}
inline bool p2s(const void* a_value,std::string& a_s){
char s[512];
snpf(s,sizeof(s),upointer_format(),(upointer)a_value);
a_s = s;
return true;
}
inline bool p2sx(const void* a_value,std::string& a_s){
char s[512];
snpf(s,sizeof(s),upointer_format_x(),(upointer)a_value);
a_s = s;
return true;
}
/*
inline std::string p2s(const void* a_value){
char s[512];
snpf(s,sizeof(s),"%lu",(unsigned long)a_value);
return s;
}
inline std::string p2sx(const void* a_value){
char s[512];
snpf(s,sizeof(s),"0x%lx",(unsigned long)a_value);
return s;
}
inline std::string char_p2s(const char* a_value) {
char s[512];
snpf(s,sizeof(s),"%lu",(unsigned long)a_value);
return std::string(s);
}
inline std::string long2s(const long a_value) {
char s[512];
snpf(s,sizeof(s),"%ld",a_value);
return std::string(s);
}
*/
}
#endif