Warning, /include/Geant4/tools/tosu 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_tosu
0005 #define tools_tosu
0006
0007 // have a "sprintf(%u)" without #include.
0008 // It is used in platform.
0009
0010 namespace tools {
0011
0012 inline void toss(const char* a_from,char a_s[],unsigned int& a_l) {
0013 char* _s = (char*)a_from;
0014 a_l = 0;
0015 char* pos = a_s;
0016 while(*_s) {
0017 *pos = *_s;pos++;
0018 a_l++;
0019 _s++;
0020 }
0021 *pos = 0;
0022 }
0023
0024 template <class T> //T must be an unsigned number type.
0025 inline void tosu(T a_i,char a_s[],unsigned int& a_l) {
0026 //assume a_s is sufficently allocated (32 is ok).
0027 a_l = 0;
0028 {char* pos = a_s;
0029 T i = a_i;
0030 while(true) {
0031 if(i<=9) {*pos = '0'+char(i);pos++;a_l++;*pos=0;pos++;break;}
0032 T r = i % 10;
0033 *pos = '0'+char(r);pos++;
0034 a_l++;
0035 i = i/10;
0036 }}
0037 //strrev(s);
0038 {unsigned int hl = a_l/2;
0039 char* beg = a_s;
0040 char* end = a_s+a_l-1;
0041 for(unsigned int i=0;i<hl;i++) {
0042 char c = *end;
0043 *end = *beg;
0044 *beg = c;
0045 beg++;end--;
0046 }}
0047 }
0048
0049 }
0050
0051 #endif