Import Geant4 2.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 15:42:07 +02:00
parent 103bda00c8
commit e7d7193284
3106 changed files with 171117 additions and 90550 deletions
+114 -38
View File
@@ -1,18 +1,8 @@
//
//
// $Id: scl_string.cc,v 1.2 1999/05/21 20:21:13 japost Exp $
// GEANT4 tag $Name: geant4-01-01 $
//
/*
* NIST Utils Class Library
* clutils/scl_string.cc
* May 1995
* April 1997
* K. C. Morris
* David Sauder
@@ -20,15 +10,28 @@
* and is not subject to copyright.
*/
/* */
/* $Id: scl_string.cc,v 1.3 2000/01/21 13:43:15 gcosmo Exp $ */
#include <scl_string.h>
#include <stdio.h>
/*******************************************************************/
int SCLstring::newBufSize (int len) const
void
SCLstring::PrintContents(G4std::ostream &out) const
{
int rval = (((len + 1)/32) +1) * 32;
if(_strBuf)
{
out << "_strBuf in parens" << G4endl << "(";
out << _strBuf << ")" << G4endl;
}
else
out << "_strBuf is a null pointer" << G4endl;
out << "_strBufSize: " << _strBufSize << G4endl;
out << "_max_len: " << _max_len << G4endl;
}
int SCLstring::newBufSize (int l) const
{
int rval = (((l + 1)/32) +1) * 32;
// if there\'s a max and rval > max return max +1
return (MaxLength () && (rval > MaxLength ())) ? MaxLength ()+1 : rval;
@@ -42,29 +45,40 @@ SCLstring::SCLstring (const char * str, int lim)
if (!str) { _strBufSize = 0; _strBuf = 0; return; }
// check the length
int len;
if (lim && (strlen (str) > lim)) len = lim;
else len = strlen (str);
int l;
if (lim && (strlen (str) > lim)) l = lim;
else l = strlen (str);
_strBufSize = newBufSize (len);
_strBufSize = newBufSize (l);
#ifdef __OSTORE__
_strBuf = new (os_database::of(this), os_typespec::get_char(), _strBufSize)
char[_strBufSize];
#else
_strBuf = new char[_strBufSize];
strncpy (_strBuf, str, len);
_strBuf [len] = '\0';
#endif
strncpy (_strBuf, str, l);
_strBuf [l] = '\0';
}
SCLstring::SCLstring (const SCLstring& s)
: _max_len (s.MaxLength ())
{
if (s.is_null ()) { _strBufSize = 0; _strBuf = 0; return; }
if (s.is_undefined ()) { _strBufSize = 0; _strBuf = 0; return; }
// int len = newBufSize (s.Length ());
// _strBuf = new char [len];
// strncpy (_strBuf, s, len);
// _strBuf [len] = '\0';
_strBufSize = newBufSize (s.Length ());
_strBuf = new char [_strBufSize];
#ifdef __OSTORE__
_strBuf = new (os_database::of(this), os_typespec::get_char(), _strBufSize)
char[_strBufSize];
#else
_strBuf = new char[_strBufSize];
#endif
strncpy (_strBuf, s, _strBufSize);
_strBuf [_strBufSize] = '\0';
_strBuf [_strBufSize-1] = '\0';
}
//destructor
@@ -91,7 +105,12 @@ SCLstring& SCLstring::operator= (const char* str)
// first clean up the space
if (_strBuf) delete [] _strBuf;
_strBufSize = newBufSize (slen+1);
#ifdef __OSTORE__
_strBuf = new (os_database::of(this), os_typespec::get_char(),
_strBufSize) char[_strBufSize];
#else
_strBuf = new char[_strBufSize];
#endif
}
strncpy (_strBuf, str, _strBufSize -1);
_strBuf [_strBufSize -1] = '\0';
@@ -103,9 +122,9 @@ SCLstring& SCLstring::operator= (const char* str)
SCLstring& SCLstring::operator= (const SCLstring& s)
{
// changed from sending s.chars() so undefined will be set correctly - DAS
// _max_len = s.MaxLength(); // Do we want this to happen? - DAS
operator=(s.rep());
_strBufSize = s.StrBufSize();
_max_len = s.MaxLength();
// _strBufSize = s.StrBufSize(); // this seems wrong - DAS
return *this;
}
@@ -119,17 +138,26 @@ SCLstring&
SCLstring::Append (const char * s)
{
if (!s) return *this;
int olen = Length (), slen = strlen (s);
int len = olen + slen +1;
if (_strBuf && (len < _strBufSize)) strncat (_strBuf, s, slen+1);
int oldlen = Length ();
int slen = strlen (s);
int l = oldlen + slen +1;
if (_strBuf && (l < _strBufSize)) strncat (_strBuf, s, slen+1);
else { // make more space
int sz = newBufSize (len);
char * tmp = new char [sz]; tmp [0] ='\0';
int sz = newBufSize (l);
#ifdef __OSTORE__
char * tmp = new (os_database::of(this), os_typespec::get_char(), sz)
char[sz];
#else
char * tmp = new char [sz];
#endif
tmp [0] ='\0';
_strBufSize = sz;
if (_strBuf) strcpy (tmp, _strBuf );
len = ((slen > sz-olen) ? sz-olen : slen);
strncat (tmp, s, len);
*(tmp+olen+len) = '\0';
l = (( slen > (sz-oldlen) ) ? sz-oldlen : slen);
strncat (tmp, s, l);
*(tmp+oldlen+l) = '\0';
delete [] _strBuf;
_strBuf = tmp;
}
@@ -164,9 +192,44 @@ SCLstring::Append (const int i)
SCLstring&
SCLstring::Append (const double i, const int prec)
{
char tmp [BUFSIZ];
sprintf (tmp, "%.*g", prec, i);
return Append (tmp);
char tmp [BUFSIZ];
// sprintf (tmp, "%.*g", prec, i);
// replace the above line with this code so that writing the '.' is
// guaranteed for reals. If you use e or E then you get many
// unnecessary trailing zeros. g and G truncates all trailing zeros
// to save space but when no non-zero precision exists it also
// truncates the decimal. The decimal is required by Part 21.
// Also use G instead of g since G writes uppercase E (E instead of e
// is also required by Part 21) when scientific notation is used - DAS
sprintf(tmp, "%.*G", prec, i);
if(!strchr(tmp, '.'))
{
if(strchr(tmp, 'E') || strchr(tmp, 'e'))
{
char *expon = strchr(tmp, 'E');
if( !expon)
{
expon = strchr(tmp, 'e');
}
*expon = '\0';
Append(tmp);
Append('.');
Append('E');
expon++;
Append(expon);
}
else
{
int rindex = strlen(tmp);
tmp[rindex] = '.';
tmp[rindex+1] = '\0';
Append(tmp);
}
return *this;
}
return Append (tmp);
}
SCLstring&
@@ -174,16 +237,29 @@ SCLstring::Prepend (const char * s)
{
if (!_strBuf) { // no string
int sz = newBufSize (strlen (s));
#ifdef __OSTORE__
_strBuf = new (os_database::of(this), os_typespec::get_char(), sz)
char[sz];
#else
_strBuf = new char [sz];
#endif
sz = sz-1;
strncpy (_strBuf, s, sz);
_strBuf [sz] = '\0';
_strBuf [sz-1] = '\0';
return *this;
}
// otherwise make some space
int slen = strlen (s);
int sz = newBufSize (slen + Length () );
#ifdef __OSTORE__
char * nstr = new (os_database::of(this), os_typespec::get_char(), sz)
char[sz];
#else
char * nstr = new char [sz];
#endif
strncpy (nstr, s, sz-1);
if (slen < sz) // copy the rest
strncat (nstr, _strBuf, sz-slen);