Import Geant4 1.0.0 source tree
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: cstring.h,v 1.6 1999/11/29 10:17:39 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4String
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Definition of a Geant4 string.
|
||||
// It's currently implemented as an STL wrapper class for Strings.
|
||||
// It implements Rogue Wave RWCString signature but intrinsically
|
||||
// using STL string.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __cstring
|
||||
#define __cstring
|
||||
|
||||
#include <string>
|
||||
#include "G4Types.hh"
|
||||
#include "g4rw/defs.h"
|
||||
|
||||
#ifdef __KCC
|
||||
#include <istream>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define strcasecmp _stricmp
|
||||
#endif
|
||||
|
||||
class G4String;
|
||||
|
||||
class G4SubString
|
||||
{
|
||||
public:
|
||||
|
||||
inline G4SubString(const G4SubString&);
|
||||
|
||||
inline G4SubString& operator=(const char*);
|
||||
|
||||
inline G4SubString& operator=(const G4String&);
|
||||
inline G4SubString& operator=(const G4SubString&);
|
||||
|
||||
inline char& operator()(size_t);
|
||||
inline char operator()(size_t) const;
|
||||
inline char& operator[](size_t);
|
||||
inline char operator[](size_t) const;
|
||||
|
||||
inline int operator!() const;
|
||||
|
||||
inline G4bool operator==(G4String) const;
|
||||
inline G4bool operator==(const char*) const;
|
||||
inline G4bool operator!=(G4String) const;
|
||||
inline G4bool operator!=(const char*) const;
|
||||
|
||||
inline size_t length() const;
|
||||
inline size_t start() const;
|
||||
|
||||
// For detecting null substrings
|
||||
//
|
||||
inline G4bool isNull() const;
|
||||
|
||||
private:
|
||||
|
||||
inline G4SubString(G4String&, size_t, size_t);
|
||||
|
||||
G4String* mystring;
|
||||
size_t mystart;
|
||||
size_t extent;
|
||||
|
||||
friend class G4String;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class G4String : public G4std::string
|
||||
{
|
||||
|
||||
typedef G4std::string std_string;
|
||||
|
||||
public:
|
||||
|
||||
enum caseCompare { exact, ignoreCase };
|
||||
enum stripType { leading, trailing, both };
|
||||
|
||||
inline G4String ();
|
||||
inline G4String ( char );
|
||||
inline G4String ( const char * );
|
||||
inline G4String ( const G4String& );
|
||||
inline G4String ( const G4SubString& );
|
||||
inline G4String ( const std_string& );
|
||||
virtual ~G4String () {}
|
||||
|
||||
inline G4String& operator=(const G4String&);
|
||||
inline G4String& operator=(const std_string&);
|
||||
inline G4String& operator=(const char*);
|
||||
|
||||
inline char operator () (size_t) const;
|
||||
inline char& operator () (size_t);
|
||||
|
||||
inline G4String& operator+=(const G4SubString&);
|
||||
inline G4String& operator+=(const char*);
|
||||
inline G4String& operator+=(const std_string&);
|
||||
inline G4String& operator+=(const char&);
|
||||
inline G4bool operator==(const G4String&) const;
|
||||
inline G4bool operator==(const char*) const;
|
||||
inline G4bool operator!=(const G4String&) const;
|
||||
inline G4bool operator!=(const char*) const;
|
||||
|
||||
//inline G4String operator () (unsigned int, unsigned int);
|
||||
inline operator const char*() const;
|
||||
inline G4SubString operator()(size_t, size_t);
|
||||
|
||||
inline int compareTo(const char*, caseCompare mode=exact);
|
||||
inline int compareTo(const G4String&, caseCompare mode=exact);
|
||||
|
||||
inline G4String& prepend (const char*);
|
||||
inline G4String& append (const G4String&);
|
||||
|
||||
inline G4std::istream& readLine (G4std::istream&, G4bool skipWhite=true);
|
||||
|
||||
inline G4String& replace (unsigned int, unsigned int,
|
||||
const char*, unsigned int );
|
||||
inline G4String& replace(size_t, size_t, const char*);
|
||||
|
||||
inline G4String& remove(size_t);
|
||||
inline G4String& remove(size_t, size_t);
|
||||
|
||||
inline int first(char) const;
|
||||
inline int last(char) const;
|
||||
|
||||
inline G4bool contains(std_string) const;
|
||||
inline G4bool contains(char) const;
|
||||
|
||||
// stripType = 0 beginning
|
||||
// stripType = 1 end
|
||||
// stripType = 2 both
|
||||
//
|
||||
inline G4String strip (int stripType=trailing, char c=' ');
|
||||
|
||||
inline void toLower ( void );
|
||||
inline void toUpper ( void );
|
||||
|
||||
inline G4bool isNull() const;
|
||||
|
||||
inline size_t index (const char*, int pos=0) const;
|
||||
inline size_t index (char, int pos=0) const;
|
||||
inline size_t index (const G4String&, size_t, size_t, caseCompare) const;
|
||||
|
||||
inline const char* data() const;
|
||||
|
||||
inline unsigned int hash( caseCompare cmp = exact ) const;
|
||||
inline unsigned int stlhash() const;
|
||||
|
||||
// useful for supplying hash functions to template hash collection ctors
|
||||
//
|
||||
static inline unsigned hash(const G4String&);
|
||||
|
||||
};
|
||||
|
||||
#include "g4rw/cstring.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,440 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: cstring.icc,v 1.2 1999/11/26 17:17:57 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4String
|
||||
//---------------------------------------------------------------
|
||||
|
||||
// **************************************************************
|
||||
// G4SubString
|
||||
// **************************************************************
|
||||
|
||||
G4SubString::G4SubString(const G4SubString&s)
|
||||
{
|
||||
mystring=s.mystring;
|
||||
mystart=s.mystart;
|
||||
extent=s.extent;
|
||||
}
|
||||
|
||||
G4SubString::G4SubString(G4String& str, size_t s, size_t e)
|
||||
: mystring(&str),mystart(s),extent(e)
|
||||
{
|
||||
}
|
||||
|
||||
G4SubString& G4SubString::operator=(const G4String&s)
|
||||
{
|
||||
G4String str(s);
|
||||
return operator=(str);
|
||||
}
|
||||
|
||||
G4SubString& G4SubString::operator=(const G4SubString&s)
|
||||
{
|
||||
mystring->replace(mystart,extent,s.mystring->data(),s.length());
|
||||
extent=s.length();
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4SubString& G4SubString::operator=(const char*s)
|
||||
{
|
||||
mystring->replace(mystart,extent,s,strlen(s));
|
||||
extent=strlen(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
char& G4SubString::operator()(size_t i)
|
||||
{
|
||||
return mystring->operator[](mystart+i);
|
||||
}
|
||||
|
||||
char G4SubString::operator()(size_t i) const
|
||||
{
|
||||
return mystring->operator[](mystart+i);
|
||||
}
|
||||
|
||||
char& G4SubString::operator[](size_t i)
|
||||
{
|
||||
return mystring->operator[](mystart+i);
|
||||
}
|
||||
|
||||
char G4SubString::operator[](size_t i) const
|
||||
{
|
||||
return mystring->operator[](mystart+i);
|
||||
}
|
||||
|
||||
int G4SubString::operator!() const
|
||||
{
|
||||
return extent==0 ? 1 : 0;
|
||||
}
|
||||
|
||||
G4bool G4SubString::operator==(G4String s) const
|
||||
{
|
||||
return mystring->substr(mystart,extent) == s ? true:false;
|
||||
}
|
||||
|
||||
G4bool G4SubString::operator==(const char* s) const
|
||||
{
|
||||
return mystring->substr(mystart,extent) == G4std::string(s) ? true:false;
|
||||
}
|
||||
|
||||
G4bool G4SubString::operator!=(G4String s) const
|
||||
{
|
||||
return mystring->substr(mystart,extent) != G4std::string(s) ? true:false;
|
||||
}
|
||||
|
||||
G4bool G4SubString::operator!=(const char* s) const
|
||||
{
|
||||
return mystring->substr(mystart,extent) != G4std::string(s) ? true:false;
|
||||
}
|
||||
|
||||
size_t G4SubString::length() const
|
||||
{
|
||||
return extent;
|
||||
}
|
||||
|
||||
size_t G4SubString::start() const
|
||||
{
|
||||
return mystart;
|
||||
}
|
||||
|
||||
G4bool G4SubString::isNull() const
|
||||
{
|
||||
return extent==0 ? true : false;
|
||||
}
|
||||
|
||||
// **************************************************************
|
||||
// G4String
|
||||
// **************************************************************
|
||||
|
||||
G4String::G4String () {}
|
||||
|
||||
G4String::G4String ( const char * astring )
|
||||
: std_string ( astring ) {}
|
||||
|
||||
G4String::G4String ( char c )
|
||||
{
|
||||
char str[2];
|
||||
str[0]=c;
|
||||
str[1]='\0';
|
||||
std_string::operator=(str);
|
||||
}
|
||||
|
||||
G4String::G4String ( const G4String& s )
|
||||
: std_string(s) {}
|
||||
|
||||
G4String::G4String ( const G4SubString& s )
|
||||
: std_string(*(s.mystring),s.mystart,s.extent) {}
|
||||
|
||||
G4String::G4String ( const std_string& s )
|
||||
: std_string(s) {}
|
||||
|
||||
G4String& G4String::operator=(const G4String& s)
|
||||
{
|
||||
std_string::operator=(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::operator=(const std_string& s)
|
||||
{
|
||||
std_string::operator=(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::operator=(const char* s)
|
||||
{
|
||||
std_string::operator=(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// "cmp" optional parameter is NOT implemented !
|
||||
// N.B.: The hash value returned is generally DIFFERENT from the
|
||||
// one returned by the original RW function.
|
||||
// Users should not rely on the specific return value.
|
||||
//
|
||||
char G4String::operator () (size_t i) const
|
||||
{
|
||||
return operator[](i);
|
||||
}
|
||||
|
||||
char& G4String::operator () (size_t i)
|
||||
{
|
||||
return std_string::operator[](i);
|
||||
}
|
||||
|
||||
G4String& G4String::operator+=(const G4SubString&s)
|
||||
{
|
||||
G4String tmp(s);
|
||||
std_string::operator+=(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::operator+=(const char*s)
|
||||
{
|
||||
std_string::operator+=(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::operator+=(const std_string &s)
|
||||
{
|
||||
std_string::operator+=(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::operator+=(const char &c)
|
||||
{
|
||||
std_string::operator+=(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4bool G4String::operator==(const G4String &s) const
|
||||
{
|
||||
const std_string *a=this;
|
||||
const std_string *b=&s;
|
||||
return *a==*b;
|
||||
}
|
||||
|
||||
G4bool G4String::operator==(const char* s) const
|
||||
{
|
||||
const std_string *a=this;
|
||||
const std_string b=s;
|
||||
return *a==b;
|
||||
}
|
||||
|
||||
G4bool G4String::operator!=(const G4String &s) const
|
||||
{
|
||||
const std_string *a=this;
|
||||
const std_string *b=&s;
|
||||
return *a!=*b;
|
||||
}
|
||||
|
||||
G4bool G4String::operator!=(const char* s) const
|
||||
{
|
||||
const std_string *a=this;
|
||||
const std_string b=s;
|
||||
return *a!=b;
|
||||
}
|
||||
|
||||
G4String::operator const char*() const
|
||||
{
|
||||
return c_str();
|
||||
}
|
||||
|
||||
int G4String::compareTo(const char* s, caseCompare mode)
|
||||
{
|
||||
//GB:OSF1-cxx if(mode=exact)
|
||||
if(mode==exact)
|
||||
return strcmp(c_str(),s);
|
||||
else
|
||||
return strcasecmp(c_str(),s);
|
||||
}
|
||||
|
||||
int G4String::compareTo(const G4String& s, caseCompare mode)
|
||||
{
|
||||
//GB:OSF1-cxx if(mode=exact)
|
||||
if(mode==exact)
|
||||
return strcmp(data(),s.data());
|
||||
else
|
||||
return strcasecmp(data(),s.data());
|
||||
}
|
||||
|
||||
G4String& G4String::prepend (const char* str)
|
||||
{
|
||||
insert(0,str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::append(const G4String& s)
|
||||
{
|
||||
std_string::operator+=(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4std::istream&
|
||||
G4String::readLine (G4std::istream& s, G4bool skipWhite)
|
||||
{
|
||||
char tmp[256];
|
||||
if ( skipWhite ) {
|
||||
s >> G4std::ws;
|
||||
s.getline(tmp,256);
|
||||
*this=tmp;
|
||||
}
|
||||
else {
|
||||
s.getline(tmp,256);
|
||||
*this=tmp;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
G4String& G4String::replace (unsigned int start, unsigned int nbytes,
|
||||
const char* buff, unsigned int n2 )
|
||||
{
|
||||
std_string::replace ( start, nbytes, buff, n2 );
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::replace(size_t pos, size_t n, const char* s)
|
||||
{
|
||||
std_string::replace(pos,n,s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::remove(size_t n)
|
||||
{
|
||||
if(n<size())
|
||||
erase(n,size()-n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4String& G4String::remove(size_t pos, size_t N)
|
||||
{
|
||||
erase(pos,N+pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
int G4String::first(char c) const
|
||||
{
|
||||
return find(c);
|
||||
}
|
||||
|
||||
int G4String::last(char c) const
|
||||
{
|
||||
return rfind(c);
|
||||
}
|
||||
|
||||
G4bool G4String::contains(std_string s) const
|
||||
{
|
||||
int i=find(s);
|
||||
if(i != std_string::npos)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
G4bool G4String::contains(char c) const
|
||||
{
|
||||
int i=find(c);
|
||||
if(i != std_string::npos)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
G4String G4String::strip (int stripType, char c)
|
||||
{
|
||||
G4String retVal = *this;
|
||||
if(length()==0) return retVal;
|
||||
int i;
|
||||
switch ( stripType ) {
|
||||
case leading:
|
||||
{
|
||||
for(i=0;i<length();i++)
|
||||
if (std_string::operator[](i) != c) break;
|
||||
retVal = substr(i,length()-i);
|
||||
}
|
||||
break;
|
||||
case trailing:
|
||||
{
|
||||
for(i=length()-1;i>=0;i--)
|
||||
if (std_string::operator[](i) != c) break;
|
||||
retVal = substr(0,i+1);
|
||||
}
|
||||
break;
|
||||
case both:
|
||||
{
|
||||
for(i=0;i<length();i++)
|
||||
if (std_string::operator[](i) != c) break;
|
||||
G4String tmp(substr(i,length()-i));
|
||||
for(i=tmp.length()-1;i>=0;i--)
|
||||
if (tmp.std_string::operator[](i) != c) break;
|
||||
retVal = tmp.substr(0,i+1);
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void G4String::toLower ( void )
|
||||
{
|
||||
for (int i=0; i<=size();i++)
|
||||
{
|
||||
//GB:HP-UX-aCC,Linux-KCC
|
||||
std_string::operator[](i) = tolower(std_string::operator[](i));
|
||||
//at(i) = tolower(at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void G4String::toUpper ( void )
|
||||
{
|
||||
for (int i=0; i<=size();i++)
|
||||
{
|
||||
//GB:HP-UX-aCC,Linux-KCC
|
||||
std_string::operator[](i) = tolower(std_string::operator[](i));
|
||||
//at(i) = toupper(at(i));
|
||||
}
|
||||
}
|
||||
|
||||
G4bool G4String::isNull() const
|
||||
{
|
||||
return empty ();
|
||||
}
|
||||
|
||||
// "cs" optional parameter is NOT implemented !
|
||||
//
|
||||
size_t G4String::index( const G4String& s, size_t ln,
|
||||
size_t st, G4String::caseCompare cs ) const
|
||||
{
|
||||
return std_string::find( s.c_str(), st, ln );
|
||||
}
|
||||
|
||||
size_t G4String::index (const char* str, int pos) const
|
||||
{
|
||||
return std_string::find(str,pos);
|
||||
}
|
||||
|
||||
size_t G4String::index (char c, int pos) const
|
||||
{
|
||||
return std_string::find(c,pos);
|
||||
}
|
||||
|
||||
G4SubString G4String::operator()(size_t start, size_t extent)
|
||||
{
|
||||
return G4SubString(*this,start,extent);
|
||||
}
|
||||
|
||||
const char* G4String::data() const
|
||||
{
|
||||
return c_str();
|
||||
}
|
||||
|
||||
unsigned int G4String::hash( caseCompare cmp ) const
|
||||
{
|
||||
const char*s=c_str();
|
||||
unsigned long h = 0;
|
||||
for ( ; *s; ++s)
|
||||
h = 5*h + *s;
|
||||
|
||||
return size_t(h);
|
||||
}
|
||||
|
||||
unsigned int G4String::stlhash() const
|
||||
{
|
||||
const char*s=c_str();
|
||||
unsigned long h = 0;
|
||||
for ( ; *s; ++s)
|
||||
h = 5*h + *s;
|
||||
|
||||
return size_t(h);
|
||||
}
|
||||
|
||||
unsigned G4String::hash(const G4String& s)
|
||||
{
|
||||
return s.hash();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: ctoken.h,v 1.5 1999/11/29 10:17:41 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4Tokenizer
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper class for String tokenizer.
|
||||
// It implements Rogue Wave RWTokenizer signature but
|
||||
// intrinsically using STL string.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __ctoken
|
||||
#define __ctoken
|
||||
|
||||
#include "g4rw/defs.h"
|
||||
#include "g4rw/cstring.h"
|
||||
|
||||
class G4Tokenizer
|
||||
{
|
||||
public:
|
||||
G4Tokenizer(const G4String& s):string2tokenize(s),actual(0){}
|
||||
|
||||
G4SubString operator()(const char* str=" \t\n",size_t l=0)
|
||||
{
|
||||
size_t i,j,tmp;
|
||||
G4bool hasws=false;
|
||||
if(l==0) l=strlen(str);
|
||||
//Skip leading delimeters
|
||||
while(actual<string2tokenize.size())
|
||||
{
|
||||
|
||||
for(i=0;i<l;i++)
|
||||
if(string2tokenize[actual]==str[i]) hasws=true;
|
||||
if(hasws)
|
||||
{
|
||||
actual++;
|
||||
hasws=false;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
for(j=actual;j<string2tokenize.size();j++)
|
||||
{
|
||||
for(i=0;i<l;i++)
|
||||
if(string2tokenize[j]==str[i]) break;
|
||||
if(i<l) break;
|
||||
}
|
||||
if(j!=string2tokenize.size())
|
||||
{
|
||||
tmp=actual;
|
||||
actual=j+1;
|
||||
return string2tokenize(tmp,j-tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp=actual;
|
||||
actual=j;
|
||||
return string2tokenize(tmp,j-tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
G4String string2tokenize;
|
||||
size_t actual;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: defs.h,v 1.7 1999/11/29 16:52:36 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWBoundsErr, G4RWGeneralException
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper classes for Errors and Exceptions utilities.
|
||||
// It implements Rogue Wave RWBoundsErr and RWGeneralException
|
||||
// signatures but intrinsically decoupled from Rogue Wave.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __defs
|
||||
#define __defs
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "G4Types.hh"
|
||||
|
||||
#define G4RWDEFAULT_CAPACITY (64)
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#define CLHEP_MAX_MIN_DEFINED
|
||||
#include <CLHEP/config/TemplateFunctions.h>
|
||||
|
||||
class G4RWBoundsErr
|
||||
{
|
||||
public:
|
||||
|
||||
G4RWBoundsErr(const char* s,int b=0,int v=0)
|
||||
{
|
||||
char btmp[80],vtmp[80];
|
||||
sprintf(btmp,"%d",b);
|
||||
sprintf(vtmp,"%d",v);
|
||||
str=new char[strlen(s)+8+strlen(btmp)+7+strlen(vtmp)+1];
|
||||
strcpy(str,s);
|
||||
strcat(str,": bound:");
|
||||
strcat(str,btmp);
|
||||
strcat(str," value:");
|
||||
strcat(str,vtmp);
|
||||
}
|
||||
|
||||
G4RWBoundsErr(const G4RWBoundsErr&e)
|
||||
{
|
||||
str=new char[strlen(e.str)+1];
|
||||
strcpy(str,e.str);
|
||||
}
|
||||
|
||||
~G4RWBoundsErr()
|
||||
{
|
||||
delete str;
|
||||
}
|
||||
|
||||
const char * why() const
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char* str;
|
||||
|
||||
};
|
||||
|
||||
class G4RWGeneralException
|
||||
{
|
||||
public:
|
||||
|
||||
G4RWGeneralException(const char* s)
|
||||
{
|
||||
str=new char[strlen(s)+1];
|
||||
strcpy(str,s);
|
||||
}
|
||||
|
||||
G4RWGeneralException(const G4RWGeneralException&e)
|
||||
{
|
||||
str=new char[strlen(e.str)+1];
|
||||
strcpy(str,e.str);
|
||||
}
|
||||
|
||||
~G4RWGeneralException()
|
||||
{
|
||||
delete str;
|
||||
}
|
||||
|
||||
const char * why() const
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char* str;
|
||||
|
||||
};
|
||||
|
||||
#define G4RWTHROW(a) throw a
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: rstream.h,v 1.4 1999/11/25 10:14:45 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 utility file
|
||||
//
|
||||
// Definition of utility function rwEatwhite.
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __rstream
|
||||
#define __rstream
|
||||
|
||||
#include "g4rw/defs.h"
|
||||
#include "G4Types.hh"
|
||||
#include "g4std/iostream"
|
||||
|
||||
inline G4std::istream& rwEatwhite(G4std::istream& stream)
|
||||
{
|
||||
return stream >> G4std::ws;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: rw2stl_algo.h,v 1.4 1999/11/25 10:14:45 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RW2STL_LessPtr
|
||||
//
|
||||
// STL wrapper utility class G4RW2STL_LessPtr.
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef rw2stl_algo_h
|
||||
#define rw2stl_algo_h
|
||||
|
||||
#include "g4rw/defs.h"
|
||||
|
||||
template <class T>
|
||||
class G4RW2STL_LessPtr
|
||||
{
|
||||
public:
|
||||
|
||||
G4bool operator()(const T* a, const T* b) const
|
||||
{
|
||||
if(a==0) return false;
|
||||
if(b==0) return true;
|
||||
return *a<*b;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tpordvec.h,v 1.7 1999/11/26 17:17:57 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTPtrOrderedVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper class for Pointer Ordered arrays. It implements
|
||||
// Rogue Wave RWTPtrOrderedVector signature but intrinsically
|
||||
// using STL vector.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __tpordvec
|
||||
#define __tpordvec
|
||||
|
||||
#include "g4std/vector"
|
||||
#include "g4std/set"
|
||||
#include "g4std/functional"
|
||||
#include "g4rw/defs.h"
|
||||
|
||||
template<class T>
|
||||
class G4RWTPtrOrderedVector : public G4std::vector<T*>
|
||||
{
|
||||
typedef G4std::vector<T*> std_pvector;
|
||||
typedef typename std_pvector::iterator iterator;
|
||||
typedef typename std_pvector::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
|
||||
G4RWTPtrOrderedVector(size_t capacity=G4RWDEFAULT_CAPACITY);
|
||||
G4RWTPtrOrderedVector(const G4RWTPtrOrderedVector<T>&);
|
||||
virtual ~G4RWTPtrOrderedVector();
|
||||
|
||||
inline G4RWTPtrOrderedVector<T>& operator=(const G4RWTPtrOrderedVector<T>&);
|
||||
|
||||
inline T*& operator()(size_t);
|
||||
inline T* const& operator()(size_t) const;
|
||||
inline T*& operator[](size_t);
|
||||
inline T* const& operator[](size_t) const;
|
||||
|
||||
void clearAndDestroy();
|
||||
void clear();
|
||||
|
||||
size_t index (const T*) const;
|
||||
void resize (size_t);
|
||||
inline void insert (T*);
|
||||
void insertAt (size_t, T*);
|
||||
size_t occurrencesOf (const T*) const;
|
||||
|
||||
T* remove (const T*);
|
||||
size_t removeAll (const T*);
|
||||
T* removeAt (size_t);
|
||||
T* removeFirst ();
|
||||
T* removeLast ();
|
||||
|
||||
T* find (const T*) const;
|
||||
inline size_t entries() const;
|
||||
inline void append (T*);
|
||||
inline size_t length() const;
|
||||
inline T*& at (size_t);
|
||||
inline T*const& at (size_t) const;
|
||||
G4bool contains (const T*) const;
|
||||
inline G4bool isEmpty() const;
|
||||
|
||||
inline T* first() const;
|
||||
inline T* last() const;
|
||||
inline void prepend(T* const);
|
||||
|
||||
private:
|
||||
|
||||
size_t rwsize;
|
||||
|
||||
};
|
||||
|
||||
// Include actual implementations of templated class methods.
|
||||
|
||||
#include "g4rw/tpordvec.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,355 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tpordvec.icc,v 1.1 1999/11/25 10:14:45 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4RWTPtrOrderedVector
|
||||
//---------------------------------------------------------------
|
||||
|
||||
template<class T >
|
||||
G4RWTPtrOrderedVector<T>::G4RWTPtrOrderedVector(size_t capacity)
|
||||
: std_pvector(capacity,(T*)0),rwsize(0){}
|
||||
|
||||
template<class T >
|
||||
G4RWTPtrOrderedVector<T>::G4RWTPtrOrderedVector(const G4RWTPtrOrderedVector<T>& v)
|
||||
: std_pvector(v),rwsize(v.rwsize){}
|
||||
|
||||
template<class T >
|
||||
G4RWTPtrOrderedVector<T>::~G4RWTPtrOrderedVector(){}
|
||||
|
||||
template<class T >
|
||||
G4RWTPtrOrderedVector<T>&
|
||||
G4RWTPtrOrderedVector<T>::operator=(const G4RWTPtrOrderedVector<T>& v)
|
||||
{
|
||||
std_pvector::operator=(v),
|
||||
rwsize=v.rwsize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T >
|
||||
T*& G4RWTPtrOrderedVector<T>::operator()(size_t i)
|
||||
{
|
||||
//if(i>=rwsize)
|
||||
// G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector ()",rwsize,i));
|
||||
if(i<std_pvector::size() && rwsize<=i) rwsize=i+1;
|
||||
return std_pvector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T >
|
||||
T* const& G4RWTPtrOrderedVector<T>::operator()(size_t i) const
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector const ()",rwsize,i));
|
||||
return std_pvector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T >
|
||||
T*& G4RWTPtrOrderedVector<T>::operator[](size_t i)
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector []",rwsize,i));
|
||||
//if(i<std_pvector::size() && rwsize<=i) rwsize=i+1;
|
||||
return std_pvector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T >
|
||||
T* const& G4RWTPtrOrderedVector<T>::operator[](size_t i) const
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector const []",rwsize,i));
|
||||
return std_pvector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T >
|
||||
void G4RWTPtrOrderedVector<T>::clear()
|
||||
{
|
||||
// std_pvector::erase(std_pvector::begin(), std_pvector::end());
|
||||
rwsize=0;
|
||||
}
|
||||
|
||||
template<class T >
|
||||
void G4RWTPtrOrderedVector<T>::clearAndDestroy()
|
||||
{
|
||||
int sz;
|
||||
G4std::set<T*,G4std::greater<T*> > tmp;
|
||||
for (sz=0;sz<rwsize;sz++)
|
||||
{
|
||||
T* current;
|
||||
current=std_pvector::operator[](sz);
|
||||
if ( current )
|
||||
tmp.insert(current);
|
||||
}
|
||||
typename G4std::set<T*,G4std::greater<T*> >::iterator it;
|
||||
for(it=tmp.begin();it!=tmp.end();it++)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
// std_pvector::erase(std_pvector::begin(), std_pvector::end());
|
||||
rwsize=0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrOrderedVector<T>::index( const T* a ) const
|
||||
{
|
||||
const_iterator i;
|
||||
size_t ptn = 0;
|
||||
for (i = std_pvector::begin();ptn<rwsize; i++,ptn++)
|
||||
{
|
||||
if (**i==*a) return ptn;
|
||||
}
|
||||
return (ptn=~(size_t)0);
|
||||
}
|
||||
|
||||
template<class T >
|
||||
void G4RWTPtrOrderedVector<T>::insert ( T* a )
|
||||
{
|
||||
if(rwsize<std_pvector::size())
|
||||
{
|
||||
std_pvector::operator[](rwsize)=a;
|
||||
rwsize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
std_pvector::push_back(a);
|
||||
rwsize=std_pvector::size();
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrOrderedVector<T>::occurrencesOf( const T* a ) const
|
||||
{
|
||||
const_iterator i;
|
||||
size_t ptn = 0;
|
||||
size_t sz=0;
|
||||
for (i = std_pvector::begin();sz<rwsize; i++,sz++)
|
||||
{
|
||||
if (**i==*a) ptn++;
|
||||
}
|
||||
return ptn;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4bool G4RWTPtrOrderedVector<T>::contains( const T* a ) const
|
||||
{
|
||||
const_iterator i;
|
||||
size_t ptn=0;
|
||||
for (i = std_pvector::begin(); ptn<rwsize; i++,ptn++)
|
||||
{
|
||||
if (**i==*a) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::remove( const T* a )
|
||||
{
|
||||
iterator i;
|
||||
size_t ptn=0;
|
||||
size_t rwsz=rwsize;
|
||||
for (i = std_pvector::begin();ptn<rwsz; i++,ptn++)
|
||||
{
|
||||
if (**i==*a)
|
||||
{
|
||||
T* tmp=*i;
|
||||
std_pvector::erase(i);
|
||||
rwsize--;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrOrderedVector<T>::removeAll( const T* a )
|
||||
{
|
||||
iterator i;
|
||||
size_t ptn = 0;
|
||||
size_t sz=0;
|
||||
size_t rwsz=rwsize;
|
||||
for (i = std_pvector::begin();sz<rwsz; i++,sz++)
|
||||
{
|
||||
if (**i==*a)
|
||||
{
|
||||
std_pvector::erase(i);
|
||||
rwsize--;
|
||||
i--;
|
||||
ptn++;
|
||||
}
|
||||
}
|
||||
return ptn;
|
||||
}
|
||||
|
||||
// should throw exception if ...
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::removeAt( size_t i )
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector removeAt",rwsize,i));
|
||||
iterator it=std_pvector::begin();
|
||||
int j;
|
||||
for(j=0;j<rwsize && j<i;j++) it++;
|
||||
if(it!=std_pvector::end())
|
||||
{
|
||||
T* tmp = operator[](i);
|
||||
std_pvector::erase(it);
|
||||
rwsize--;
|
||||
return tmp;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::find(const T* a) const
|
||||
{
|
||||
const_iterator i;
|
||||
size_t ptn=0;
|
||||
for (i = std_pvector::begin(); ptn<rwsize; i++,ptn++)
|
||||
{
|
||||
if (**i==*a)
|
||||
{
|
||||
return *i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrOrderedVector<T>::resize(size_t N)
|
||||
{
|
||||
if(N>std_pvector::size())
|
||||
{
|
||||
int e=N-std_pvector::size();
|
||||
for(int i=0;i<e;i++)
|
||||
std_pvector::push_back(0);
|
||||
}
|
||||
else if(N>rwsize)
|
||||
{
|
||||
iterator it=std_pvector::begin();
|
||||
for(int i=0;i<N;i++,it++);
|
||||
std_pvector::erase(it,std_pvector::end());
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrOrderedVector<T>::insertAt ( size_t i, T* a )
|
||||
{
|
||||
// insertAt throws an exception of type G4RWBoundsErr
|
||||
// if you try to insert out of range
|
||||
//
|
||||
if(i>rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector insertAt",rwsize,i));
|
||||
if(rwsize<std_pvector::size())
|
||||
{
|
||||
for(int j=rwsize;j>i;j--)
|
||||
std_pvector::operator[](j)=std_pvector::operator[](j-1);
|
||||
std_pvector::operator[](i)=a;
|
||||
rwsize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator it=std_pvector::begin();
|
||||
for(int j=0;j<i;j++,it++);
|
||||
std_pvector::insert(it,a);
|
||||
rwsize++;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::removeFirst ()
|
||||
{
|
||||
if(rwsize!=0)
|
||||
{
|
||||
T* tmp=std_pvector::front();
|
||||
std_pvector::erase(std_pvector::begin());
|
||||
rwsize--;
|
||||
return tmp;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::removeLast ()
|
||||
{
|
||||
if(rwsize==0) return (T*) 0;
|
||||
|
||||
rwsize--;
|
||||
T* tmp=std_pvector::operator[](rwsize);
|
||||
std_pvector::operator[](rwsize)=0;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrOrderedVector<T>::entries() const
|
||||
{
|
||||
return rwsize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrOrderedVector<T>::append ( T* a )
|
||||
{
|
||||
insert( a );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrOrderedVector<T>::length() const
|
||||
{
|
||||
return rwsize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T*& G4RWTPtrOrderedVector<T>::at ( size_t i )
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector at",rwsize,i));
|
||||
return operator()(i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T*const& G4RWTPtrOrderedVector<T>::at ( size_t i ) const
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector const at",rwsize,i));
|
||||
return operator()(i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4bool G4RWTPtrOrderedVector<T>::isEmpty() const
|
||||
{
|
||||
return rwsize==0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::first() const
|
||||
{
|
||||
if(!rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrOrderedVector front",rwsize,0));
|
||||
return std_pvector::front();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrOrderedVector<T>::last() const
|
||||
{
|
||||
if(rwsize)
|
||||
return std_pvector::operator[](rwsize-1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrOrderedVector<T>::prepend(T* const ptr)
|
||||
{
|
||||
std_pvector::insert(std_pvector::begin(),ptr);
|
||||
rwsize++;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tpsrtvec.h,v 1.8 1999/11/26 17:17:57 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTPtrSortedVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper class for Pointer Sorted arrays. It implements
|
||||
// Rogue Wave RWTPtrSortedVector signature but intrinsically
|
||||
// using STL vector.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __tpsrtvec
|
||||
#define __tpsrtvec
|
||||
|
||||
#include "g4rw/rw2stl_algo.h"
|
||||
#include "g4std/vector"
|
||||
#include "g4std/algorithm"
|
||||
#include "g4rw/defs.h"
|
||||
|
||||
|
||||
template <class T>
|
||||
class G4RWTPtrSortedVector : public G4std::vector<T*>
|
||||
{
|
||||
|
||||
typedef G4std::vector<T*> std_pvector;
|
||||
typedef typename std_pvector::iterator iterator;
|
||||
typedef typename std_pvector::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
|
||||
G4RWTPtrSortedVector(size_t n=G4RWDEFAULT_CAPACITY);
|
||||
G4RWTPtrSortedVector(const G4RWTPtrSortedVector<T>&);
|
||||
virtual ~G4RWTPtrSortedVector();
|
||||
|
||||
inline G4RWTPtrSortedVector<T>& operator=(const G4RWTPtrSortedVector<T>&);
|
||||
|
||||
inline T* const& operator [] (size_t) const;
|
||||
inline T* const& operator () (size_t) const;
|
||||
|
||||
inline T*& at (size_t);
|
||||
inline T* at (size_t) const;
|
||||
|
||||
void clear();
|
||||
void clearAndDestroy ();
|
||||
|
||||
T* find (const T*) const;
|
||||
inline size_t entries () const;
|
||||
inline void insert (T*);
|
||||
size_t index (const T* a);
|
||||
inline G4bool isEmpty () const;
|
||||
|
||||
inline T* const & first () const;
|
||||
inline T* const & last () const;
|
||||
|
||||
size_t occurrencesOf(const T*) const;
|
||||
|
||||
T* remove (const T*);
|
||||
size_t removeAll (const T*);
|
||||
|
||||
private:
|
||||
|
||||
size_t rwsize;
|
||||
G4RW2STL_LessPtr<T> sorter;
|
||||
|
||||
};
|
||||
|
||||
// Include actual implementations of templated class methods.
|
||||
|
||||
#include "g4rw/tpsrtvec.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tpsrtvec.icc,v 1.2 1999/11/25 13:41:26 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4RWTPtrSortedVector
|
||||
//---------------------------------------------------------------
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrSortedVector<T>::G4RWTPtrSortedVector(size_t n)
|
||||
: std_pvector(n),rwsize(0)
|
||||
{
|
||||
for(int i=0;i<n;i++)
|
||||
std_pvector::operator[](i)=0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrSortedVector<T>::G4RWTPtrSortedVector(const G4RWTPtrSortedVector<T>& v)
|
||||
: std_pvector(v), rwsize(v.rwsize){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrSortedVector<T>::~G4RWTPtrSortedVector(){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrSortedVector<T>&
|
||||
G4RWTPtrSortedVector<T>::operator=(const G4RWTPtrSortedVector<T>& v)
|
||||
{
|
||||
std_pvector::operator=(v);
|
||||
rwsize=v.rwsize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* const& G4RWTPtrSortedVector<T>::operator [] (size_t n) const
|
||||
{
|
||||
if(n>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrSortedVector",rwsize,n));
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* const& G4RWTPtrSortedVector<T>::operator () (size_t n) const
|
||||
{
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T*& G4RWTPtrSortedVector<T>::at(size_t n )
|
||||
{
|
||||
if(n>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrSortedVector",rwsize,n));
|
||||
if(n<std_pvector::size() && rwsize<=n)
|
||||
rwsize=n+1;
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrSortedVector<T>::at(size_t n ) const
|
||||
{
|
||||
if(n>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrSortedVector",rwsize,n));
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrSortedVector<T>::clear()
|
||||
{
|
||||
std_pvector::erase(std_pvector::begin(),std_pvector::end());
|
||||
rwsize=0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrSortedVector<T>::clearAndDestroy ()
|
||||
{
|
||||
size_t sz=0;
|
||||
for(iterator it=std_pvector::begin();sz<rwsize;it++,sz++)
|
||||
delete *it;
|
||||
std_pvector::erase(std_pvector::begin(),std_pvector::end());
|
||||
rwsize=0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrSortedVector<T>::find (const T* a) const
|
||||
{
|
||||
if(!a || std_pvector::empty()) return 0;
|
||||
//We are sorted, so try a n log n search
|
||||
int t,d;
|
||||
int u=rwsize,l=0;
|
||||
do
|
||||
{
|
||||
d=(u-l)/2;
|
||||
t=d+l;
|
||||
//this asks *a <= (*(*this)[t] whithout requiring operator<=
|
||||
if(sorter(a,(*this)[t]) || *a==*(*this)[t])
|
||||
u=t;
|
||||
else
|
||||
l=t;
|
||||
}
|
||||
while(d>0);
|
||||
|
||||
if(*(*this)[u]==*a)
|
||||
return (*this)[u];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrSortedVector<T>::entries () const
|
||||
{
|
||||
return rwsize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrSortedVector<T>::insert ( T* a )
|
||||
{
|
||||
if(rwsize<std_pvector::size())
|
||||
{
|
||||
//We have empty entries
|
||||
iterator it=std_pvector::begin();
|
||||
for(int i=0;i<rwsize;i++,it++);
|
||||
*it=a;
|
||||
it++;
|
||||
G4std::sort(std_pvector::begin(),it,sorter);
|
||||
}
|
||||
else
|
||||
{
|
||||
std_pvector::push_back(a);
|
||||
//This makes it a sorted thing;
|
||||
G4std::sort(std_pvector::begin(),std_pvector::end(),sorter);
|
||||
}
|
||||
rwsize++;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrSortedVector<T>::index ( const T* a )
|
||||
{
|
||||
T*const* ii = std_pvector::begin();
|
||||
size_t cnt = 0;
|
||||
for (T*const* it = ii;cnt<rwsize; ++it,cnt++)
|
||||
{
|
||||
if ( **it == *a ) return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4bool G4RWTPtrSortedVector<T>::isEmpty () const
|
||||
{
|
||||
return rwsize==0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* const & G4RWTPtrSortedVector<T>::first () const
|
||||
{
|
||||
if(!rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrSortedVector first()",rwsize,0));
|
||||
return std_pvector::front();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* const & G4RWTPtrSortedVector<T>::last () const
|
||||
{
|
||||
if(rwsize)
|
||||
return std_pvector::operator[](rwsize-1);
|
||||
else
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTPtrSortedVector last()",rwsize,0));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrSortedVector<T>::occurrencesOf(const T* a) const
|
||||
{
|
||||
size_t cnt = 0;
|
||||
size_t sz = 0;
|
||||
for (const_iterator it = std_pvector::begin();sz<rwsize; ++it,sz++)
|
||||
{
|
||||
if ( **it == *a ) cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrSortedVector<T>::remove ( const T* a )
|
||||
{
|
||||
iterator retval;
|
||||
size_t sz=0;
|
||||
for(retval=std_pvector::begin();sz<rwsize;retval++,sz++)
|
||||
if(**retval==*a) break;
|
||||
if(sz<rwsize && retval!=std_pvector::end())
|
||||
{
|
||||
T* tmp=*retval;
|
||||
std_pvector::erase(retval);
|
||||
rwsize--;
|
||||
return tmp;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrSortedVector<T>::removeAll ( const T* a)
|
||||
{
|
||||
iterator s=std_pvector::end();
|
||||
iterator e=std_pvector::end();
|
||||
iterator r;
|
||||
size_t sz=0;
|
||||
int i=0;
|
||||
for(r=std_pvector::begin();sz<rwsize;r++,sz++)
|
||||
{
|
||||
if(i==0)
|
||||
{
|
||||
if(**r==*a)
|
||||
{
|
||||
s=r;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(**r!=*a)
|
||||
{
|
||||
e=r;
|
||||
break;
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
}
|
||||
std_pvector::erase(s,e);
|
||||
rwsize-=i;
|
||||
return i;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tpvector.h,v 1.7 1999/11/26 17:17:58 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTPtrVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper class for Pointer arrays. It implements
|
||||
// Rogue Wave RWTPtrVector signature but intrinsically
|
||||
// using STL vector.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __tpvector
|
||||
#define __tpvector
|
||||
|
||||
#include "g4std/vector"
|
||||
#include "g4rw/defs.h"
|
||||
|
||||
template<class T>
|
||||
class G4RWTPtrVector : public G4std::vector<T*>
|
||||
{
|
||||
|
||||
typedef G4std::vector<T*> std_pvector;
|
||||
typedef typename std_pvector::iterator iterator;
|
||||
typedef typename std_pvector::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
|
||||
G4RWTPtrVector ();
|
||||
G4RWTPtrVector (unsigned int);
|
||||
G4RWTPtrVector (unsigned int, T* const &);
|
||||
G4RWTPtrVector (const G4RWTPtrVector<T>&);
|
||||
virtual ~G4RWTPtrVector();
|
||||
|
||||
G4RWTPtrVector<T>& operator = (T*);
|
||||
|
||||
inline T* operator () (size_t) const;
|
||||
inline T*& operator () (size_t);
|
||||
|
||||
inline T* operator [] (size_t) const;
|
||||
inline T*& operator [] (size_t);
|
||||
inline T* const * data() const;
|
||||
inline size_t length();
|
||||
inline void reshape(size_t);
|
||||
|
||||
};
|
||||
|
||||
// Include actual implementations of templated class methods.
|
||||
|
||||
#include "g4rw/tpvector.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tpvector.icc,v 1.4 1999/11/25 10:14:46 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTPtrVector
|
||||
//---------------------------------------------------------------
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrVector<T>::G4RWTPtrVector ()
|
||||
: std_pvector(){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrVector<T>::G4RWTPtrVector (unsigned int n)
|
||||
: std_pvector(n){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrVector<T>::G4RWTPtrVector (unsigned int n, T* const & iPtr)
|
||||
: std_pvector(n, iPtr){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrVector<T>::G4RWTPtrVector (const G4RWTPtrVector<T>& iPtr)
|
||||
: std_pvector(iPtr){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrVector<T>::~G4RWTPtrVector(){}
|
||||
|
||||
template<class T>
|
||||
G4RWTPtrVector<T>& G4RWTPtrVector<T>::operator = (T* p)
|
||||
{
|
||||
for(iterator i = std_pvector::begin(); i != std_pvector::end(); ++i)
|
||||
{
|
||||
*i = p;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4RWTPtrVector<T>::operator () ( size_t n ) const
|
||||
{
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T*& G4RWTPtrVector<T>::operator () ( size_t n )
|
||||
{
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
// The [] operator should perform bound checking
|
||||
//
|
||||
template<class T>
|
||||
T* G4RWTPtrVector<T>::operator [] ( size_t n ) const
|
||||
{
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T*& G4RWTPtrVector<T>::operator [] ( size_t n )
|
||||
{
|
||||
return std_pvector::operator[](n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* const * G4RWTPtrVector<T>::data() const
|
||||
{
|
||||
return &(std_pvector::front());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTPtrVector<T>::length()
|
||||
{
|
||||
return std_pvector::size();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTPtrVector<T>::reshape( size_t n )
|
||||
{
|
||||
std_pvector::resize(n);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tvordvec.h,v 1.7 1999/11/26 17:17:58 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTValOrderedVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper class for Value Ordered arrays. It implements
|
||||
// Rogue Wave RWTValOrderedVector signature but intrinsically
|
||||
// using STL vector.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __tvordvec
|
||||
#define __tvordvec
|
||||
|
||||
#include "g4std/vector"
|
||||
#include "g4std/algorithm"
|
||||
|
||||
#include "g4rw/defs.h"
|
||||
#include "g4rw/tvvector.h"
|
||||
|
||||
template<class T>
|
||||
class G4RWTValOrderedVector : public G4std::vector<T>
|
||||
{
|
||||
|
||||
typedef G4std::vector<T> std_vector;
|
||||
typedef typename std_vector::iterator iterator;
|
||||
typedef typename std_vector::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
|
||||
G4RWTValOrderedVector(size_t capacity=G4RWDEFAULT_CAPACITY);
|
||||
G4RWTValOrderedVector(const G4RWTValOrderedVector<T>&);
|
||||
virtual ~G4RWTValOrderedVector();
|
||||
|
||||
inline G4RWTValOrderedVector<T>& operator=(const G4RWTValOrderedVector<T>&);
|
||||
|
||||
inline T& operator()(size_t);
|
||||
inline const T& operator()(size_t) const;
|
||||
inline T& operator[](size_t);
|
||||
inline const T& operator[](size_t) const;
|
||||
|
||||
inline T& at (size_t);
|
||||
inline T at (size_t) const;
|
||||
|
||||
void resize (size_t);
|
||||
void clear( void );
|
||||
G4bool contains(const T) const;
|
||||
inline size_t length() const;
|
||||
size_t index (const T&);
|
||||
|
||||
inline G4bool insert (const T&);
|
||||
void insertAt (size_t, const T&);
|
||||
|
||||
size_t occurrencesOf (const T&) const;
|
||||
|
||||
G4bool remove (const T&);
|
||||
size_t removeAll (const T&);
|
||||
T removeAt (size_t);
|
||||
|
||||
size_t entries () const;
|
||||
inline void append (const T&);
|
||||
|
||||
inline T first() const;
|
||||
inline T last() const;
|
||||
|
||||
private:
|
||||
|
||||
size_t rwsize;
|
||||
|
||||
};
|
||||
|
||||
// Include actual implementations of templated class methods.
|
||||
|
||||
#include "g4rw/tvordvec.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tvordvec.icc,v 1.1 1999/11/25 10:14:46 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTValOrderedVector
|
||||
//---------------------------------------------------------------
|
||||
|
||||
template<class T>
|
||||
G4RWTValOrderedVector<T>::G4RWTValOrderedVector(size_t capacity)
|
||||
: std_vector(capacity),rwsize(0){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValOrderedVector<T>::G4RWTValOrderedVector(const G4RWTValOrderedVector<T>& v)
|
||||
: std_vector(v),rwsize(v.rwsize){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValOrderedVector<T>::~G4RWTValOrderedVector(){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValOrderedVector<T>&
|
||||
G4RWTValOrderedVector<T>::operator=(const G4RWTValOrderedVector<T>& v)
|
||||
{
|
||||
std_vector::operator=(v);
|
||||
rwsize=v.rwsize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& G4RWTValOrderedVector<T>::operator()(size_t i)
|
||||
{
|
||||
//if(i>=rwsize)
|
||||
// G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector ()",rwsize,i));
|
||||
if(i<std_vector::size() && rwsize<=i)
|
||||
rwsize=i+1;
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T& G4RWTValOrderedVector<T>::operator()(size_t i) const
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector const()",rwsize,i));
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& G4RWTValOrderedVector<T>::operator[](size_t i)
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector []",rwsize,i));
|
||||
//if(i<std_vector::size() && rwsize<=i)
|
||||
// rwsize=i+1;
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T& G4RWTValOrderedVector<T>::operator[](size_t i) const
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector const []",rwsize,i));
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& G4RWTValOrderedVector<T>::at(size_t n)
|
||||
{
|
||||
if(n>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector at",rwsize,n));
|
||||
return operator()(n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T G4RWTValOrderedVector<T>::at(size_t n ) const
|
||||
{
|
||||
if(n>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector const at",rwsize,n));
|
||||
return operator()(n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTValOrderedVector<T>::clear( void )
|
||||
{
|
||||
//std_vector::erase(std_vector::begin(), std_vector::end());
|
||||
for(size_t i=0;i<rwsize;i++)
|
||||
std_vector::operator[](i)=T();
|
||||
rwsize=0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTValOrderedVector<T>::length() const
|
||||
{
|
||||
return rwsize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTValOrderedVector<T>::entries () const
|
||||
{
|
||||
return rwsize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTValOrderedVector<T>::append ( const T& a )
|
||||
{
|
||||
insert ( a );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T G4RWTValOrderedVector<T>::first() const
|
||||
{
|
||||
if(!rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector first",rwsize,0));
|
||||
return std_vector::front();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T G4RWTValOrderedVector<T>::last() const
|
||||
{
|
||||
if(rwsize)
|
||||
return std_vector::operator[](rwsize-1);
|
||||
else
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector last",rwsize,0));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTValOrderedVector<T>::index( const T& a )
|
||||
{
|
||||
iterator i;
|
||||
size_t ptn = 0;
|
||||
for (i = std_vector::begin();ptn<rwsize; i++,ptn++)
|
||||
{
|
||||
if (*i==a) return ptn;
|
||||
}
|
||||
return (ptn=~(size_t)0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTValOrderedVector<T>::occurrencesOf( const T& a ) const
|
||||
{
|
||||
const_iterator i;
|
||||
size_t ptn = 0;
|
||||
size_t sz=0;
|
||||
for (i = std_vector::begin(); sz<rwsize; i++,sz++)
|
||||
{
|
||||
if (*i==a) ptn++;
|
||||
}
|
||||
return ptn;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4bool G4RWTValOrderedVector<T>::remove( const T& a )
|
||||
{
|
||||
iterator i;
|
||||
size_t sz=0;
|
||||
size_t rwsz=rwsize;
|
||||
for (i = std_vector::begin(); sz<rwsz; i++,sz++)
|
||||
{
|
||||
if (*i==a)
|
||||
{
|
||||
std_vector::erase(i);
|
||||
rwsize--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTValOrderedVector<T>::removeAll( const T& a )
|
||||
{
|
||||
iterator i;
|
||||
size_t ptn = 0;
|
||||
size_t sz=0;
|
||||
size_t rwsz=rwsize;
|
||||
for (i = std_vector::begin();sz<rwsz; i++,sz++)
|
||||
{
|
||||
if (*i==a)
|
||||
{
|
||||
std_vector::erase(i);
|
||||
ptn++;
|
||||
i--;
|
||||
rwsize--;
|
||||
}
|
||||
}
|
||||
return ptn;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T G4RWTValOrderedVector<T>::removeAt( size_t i )
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector removeAt",rwsize,i));
|
||||
T tmp = operator[](i);
|
||||
iterator it=std_vector::begin();
|
||||
int j;
|
||||
for(j=0;j<rwsize && j<i;j++) it++;
|
||||
if(it!=std_vector::end())
|
||||
{
|
||||
std_vector::erase(it);
|
||||
rwsize--;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTValOrderedVector<T>::resize(size_t N)
|
||||
{
|
||||
if(N>std_vector::size())
|
||||
{
|
||||
int e=N-std_vector::size();
|
||||
for(int i=0;i<e;i++)
|
||||
std_vector::push_back(T());
|
||||
}
|
||||
else if(N>rwsize )
|
||||
{
|
||||
iterator it=std_vector::begin();
|
||||
for(int i=0;i<N;i++,it++);
|
||||
std_vector::erase(it,std_vector::end());
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4bool G4RWTValOrderedVector<T>::contains( const T a ) const
|
||||
{
|
||||
const_iterator i;
|
||||
size_t sz=0;
|
||||
for (i = std_vector::begin();sz<rwsize; i++,sz++)
|
||||
{
|
||||
if (*i==a) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4bool G4RWTValOrderedVector<T>::insert ( const T& a )
|
||||
{
|
||||
if(rwsize<std_vector::size())
|
||||
{
|
||||
this->std_vector::operator[](rwsize)=a;
|
||||
rwsize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
std_vector::push_back(a);
|
||||
rwsize=std_vector::size();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// insertAt throws an exception of type G4RWBoundsErr if you try
|
||||
// to insert out of range
|
||||
//
|
||||
template<class T>
|
||||
void G4RWTValOrderedVector<T>::insertAt ( size_t i, const T& a )
|
||||
{
|
||||
if(i>rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValOrderedVector insertAt",rwsize,i));
|
||||
if(rwsize<std_vector::size())
|
||||
{
|
||||
for(int j=rwsize;j>i;j--)
|
||||
std_vector::operator[](j)=this->std_vector::operator[](j-1);
|
||||
std_vector::operator[](i)=a;
|
||||
rwsize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator it=std_vector::begin();
|
||||
for(int j=0;j<i;j++,it++);
|
||||
std_vector::insert(it,a);
|
||||
rwsize++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tvvector.h,v 1.7 1999/11/26 17:17:58 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTValVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// STL wrapper class for Value arrays. It implements
|
||||
// Rogue Wave RWTValVector signature but intrinsically
|
||||
// using STL vector.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __tvvector
|
||||
#define __tvvector
|
||||
|
||||
#include "g4std/vector"
|
||||
#include "g4rw/defs.h"
|
||||
|
||||
template<class T>
|
||||
class G4RWTValVector : public G4std::vector<T>
|
||||
{
|
||||
|
||||
typedef G4std::vector<T> std_vector;
|
||||
typedef typename std_vector::iterator iterator;
|
||||
typedef typename std_vector::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
|
||||
G4RWTValVector ();
|
||||
G4RWTValVector (size_t);
|
||||
G4RWTValVector (size_t, const T&);
|
||||
G4RWTValVector (const G4RWTValVector<T>&);
|
||||
virtual ~G4RWTValVector();
|
||||
|
||||
inline G4RWTValVector<T>& operator= (const G4RWTValVector<T>&);
|
||||
|
||||
inline T& operator()(size_t);
|
||||
inline const T& operator()(size_t) const;
|
||||
inline T& operator[](size_t);
|
||||
inline const T& operator[](size_t) const;
|
||||
|
||||
inline size_t length() const;
|
||||
|
||||
inline const T* data() const;
|
||||
void resize(size_t);
|
||||
inline void reshape(size_t);
|
||||
inline const T& ref(size_t) const;
|
||||
|
||||
private:
|
||||
|
||||
size_t rwsize;
|
||||
|
||||
};
|
||||
|
||||
// Include actual implementations of templated class methods.
|
||||
|
||||
#include "g4rw/tvvector.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,120 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: tvvector.icc,v 1.1 1999/11/25 10:14:47 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4RWTValVector
|
||||
//---------------------------------------------------------------
|
||||
|
||||
template<class T>
|
||||
G4RWTValVector<T>::G4RWTValVector ()
|
||||
: rwsize(0){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValVector<T>::G4RWTValVector (size_t n)
|
||||
: std_vector(n), rwsize(n){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValVector<T>::G4RWTValVector (size_t n, const T& ival)
|
||||
: std_vector(n,ival), rwsize(n){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValVector<T>::G4RWTValVector (const G4RWTValVector<T>& ival)
|
||||
: std_vector(ival), rwsize(ival.rwsize){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValVector<T>::~G4RWTValVector(){}
|
||||
|
||||
template<class T>
|
||||
G4RWTValVector<T>&
|
||||
G4RWTValVector<T>::operator= (const G4RWTValVector<T>& v)
|
||||
{
|
||||
std_vector::operator=(v);
|
||||
rwsize=v.rwsize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t G4RWTValVector<T>::length() const
|
||||
{
|
||||
return std_vector::size();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& G4RWTValVector<T>::operator()(size_t i)
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValVector operator()",rwsize,i));
|
||||
if(i<std_vector::size() && rwsize<i)
|
||||
rwsize=i+1;
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T& G4RWTValVector<T>::operator()(size_t i) const
|
||||
{
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& G4RWTValVector<T>::operator[](size_t i)
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValVector operator[]",rwsize,i));
|
||||
if(i<std_vector::size() && rwsize<i)
|
||||
rwsize=i+1;
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T& G4RWTValVector<T>::operator[](size_t i) const
|
||||
{
|
||||
if(i>=rwsize)
|
||||
G4RWTHROW(G4RWBoundsErr("G4RWTValVector const operator[]",rwsize,i));
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T* G4RWTValVector<T>::data() const
|
||||
{
|
||||
return &(std_vector::front());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTValVector<T>::resize(size_t N)
|
||||
{
|
||||
if(N>std_vector::size())
|
||||
{
|
||||
int e=N-std_vector::size();
|
||||
for(int i=0;i<e;i++)
|
||||
std_vector::push_back(T());
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator it=std_vector::begin();
|
||||
for(int i=1;i<=N;i++,it++);
|
||||
std_vector::erase(it,std_vector::end());
|
||||
}
|
||||
rwsize=N;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4RWTValVector<T>::reshape(size_t n)
|
||||
{
|
||||
resize(n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T& G4RWTValVector<T>::ref(size_t i) const
|
||||
{
|
||||
return std_vector::operator[](i);
|
||||
}
|
||||
Reference in New Issue
Block a user