Import Geant4 1.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 15:28:20 +02:00
parent aaa409b6ee
commit ca1c8cb059
2995 changed files with 106830 additions and 299600 deletions
+47 -5
View File
@@ -1,4 +1,4 @@
$Id: History,v 1.8 1999/07/06 15:02:39 gunter Exp $
$Id: History,v 1.16 1999/11/29 10:17:36 gcosmo Exp $
-------------------------------------------------------------------
=========================================================
@@ -21,6 +21,48 @@ committal in the CVS repository !
STL Interface
-------------
November 29, 99 G.Cosmo
- Removed references to g4std/string, now removed since not anymore
needed.
November 26, 99 G.Cosmo (STLInterface-V00-01-04)
- Backed up inline keyword for simple methods in vectors' classes
(test comparison with previous tag).
- Reorganised cstring[.h.icc], no functional changes.
November 25, 99 G.Cosmo (STLInterface-V00-01-03)
- STLInterface: changes for ISO/ANSI C++ support:
o Reorganised method definitions on wrapper classes; made templated
vectors' methods all not inlined (test). Created .icc files accordingly.
o Changed #define to typedef for std_string and protected in class
scope. Introduced std_vector and std_pvector for collections,
replaced G4std::vector<T> and G4std::vector<T*> accordingly.
- Added default comment header to files in STLInterface and class
descriptions for Software Reference Manual.
November 23, 99 G.Cosmo
- Introduced changes to support ISO/ANSI code:
o Modified STLInterface wrappers to invoke STL containers from G4std
namespace.
o Modified #include statements to invoke g4std wrappers.
o Introduced G4endl and G4cin in G4ios.hh. Modified code accordingly.
- Made destructors for vector wrappers collections in STLInterface virtual.
16th November 1999 Gabriele Cosmo (STLInterface-V00-01-02)
- Includes global migration RWT->G4RWT:
o Moved all wrapper files from STLInterface/rw to STLInterface/g4rw.
o Changed RW to G4RW everywhere, except: RWBoolean to G4Bool,
RWCString to G4String, RWTokenizer to G4Tokenizer.
o Removed definition of RW_NPOS from defs.h.
- Removed wrappers for Dictionaries: tvhdict.h, tphdict.h, rwstlhash.h.
Removed also hash_map wrappers.
6th October 1999 Frank Behner (STLInterface-V00-01-01)
- Changed tolower/toupper to old implementation in cstring.h.
4th August 1999 Frank Behner (STLInterface-V00-01-00)
- Implementation of RWCString::hash(const RWCString&).
6th July 1999 Gunter Folger
- name for hash_map for WIN32 is hashmap.h ONLY with Object space;
other implementations on WIN32 should use hash_map.h
@@ -39,12 +81,12 @@ committal in the CVS repository !
- Tagged Frank's fixes to tpordvec re insertAt(0,...) and similar.
20th June 1999 John Allison (STLInterface-18)
- Removed RWTPtrHashDictionary(size_t n):fhm(n){}.
- Implemented RWTPtrHashDictionary::clearAndDestroy of values *and*
- Removed G4RWTPtrHashDictionary(size_t n):fhm(n){}.
- Implemented G4RWTPtrHashDictionary::clearAndDestroy of values *and*
keys, protecting against duplicate entries.
- Reimplemented RWTPtrOrderedVector::clearAndDestroy with vector<T*>
- Reimplemented G4RWTPtrOrderedVector::clearAndDestroy with vector<T*>
instead of set<T*>.
- Prevented RWTPtrOrderedVector::resize and RWTValOrderedVector::resize
- Prevented G4RWTPtrOrderedVector::resize and G4RWTValOrderedVector::resize
from reducing the size below the number if items.
20th June 1999 John Allison
+173
View File
@@ -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
+440
View File
@@ -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();
}
+84
View File
@@ -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
+117
View File
@@ -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
+30
View File
@@ -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);
}
-443
View File
@@ -1,443 +0,0 @@
#ifndef __cstring
#define __cstring
#include <string>
#if defined(G4USE_NAMESPACE)
using std::string;
#endif
#ifndef G4USE_OLDSTL
#include <cstring>
#else
#include <string.h>
#endif
#include "rw/defs.h"
#if defined(__KCC)
#include <istream>
#define std_string std::string
#define std_istream std::istream
#define std_ws std::ws
#else
#define std_string string
#define std_istream istream
#define std_ws ws
#endif
#if defined(WIN32)
#define strcasecmp _stricmp
#endif
class RWCString;
class RWCSubString
{
public:
inline RWCSubString(const RWCSubString&);
inline RWCSubString& operator=(const char*);
inline RWCSubString& operator=(const RWCString&s);
inline RWCSubString& operator=(const RWCSubString&s);
inline char& operator()(size_t i);
inline char operator()(size_t i) const;
inline char& operator[](size_t i);
inline char operator[](size_t i) const;
size_t length() const{return extent;}
size_t start() const{return mystart;}
//void toLower();
//void toUpper();
// For detecting null substrings:
RWBoolean isNull() const
{return extent==0 ? true : false;}
int operator!() const
{return extent==0 ? 1 : 0;}
inline RWBoolean operator==(RWCString) const;
inline RWBoolean operator==(const char*) const;
inline RWBoolean operator!=(RWCString) const;
inline RWBoolean operator!=(const char*) const;
private:
RWCSubString(RWCString&str,size_t s,size_t e):
mystring(&str),mystart(s),extent(e){}
RWCString* mystring;
size_t mystart;
size_t extent;
friend class RWCString;
};
//#define std
class RWCString : public std_string {
public:
enum caseCompare { exact, ignoreCase };
enum stripType { leading, trailing, both };
inline RWCString ( const char * );
RWCString ( char c )
{
char str[2];
str[0]=c;
str[1]='\0';
std_string::operator=(str);
}
RWCString (){}
RWCString ( const RWCString& s):std_string(s){}
RWCString( const RWCSubString&s ):std_string(*(s.mystring),s.mystart,s.extent){}
RWCString ( const std_string s ):std_string(s){}
RWCString& operator=(const RWCString&s)
{
std_string::operator=(s);
return *this;
}
RWCString& operator=(const std_string&s)
{
std_string::operator=(s);
return *this;
}
RWCString& operator=(const char* s)
{
std_string::operator=(s);
return *this;
}
virtual ~RWCString (){}
inline char operator () (size_t) const;
char& operator () (size_t i){return std_string::operator[](i);}
int compareTo(const char*s,caseCompare mode=exact)
{
//GB:OSF1-cxx if(mode=exact)
if(mode==exact)
return strcmp(c_str(),s);
else
return strcasecmp(c_str(),s);
}
int compareTo(const RWCString&s,caseCompare mode=exact)
{
//GB:OSF1-cxx if(mode=exact)
if(mode==exact)
return strcmp(data(),s.data());
else
return strcasecmp(data(),s.data());
}
RWCString& operator+=(const RWCSubString&s)
{
RWCString tmp(s);
std_string::operator+=(tmp);
return *this;
}
RWCString& operator+=(const char*s)
{
std_string::operator+=(s);
return *this;
}
RWCString& operator+=(const std_string &s)
{
std_string::operator+=(s);
return *this;
}
RWCString& operator+=(const char &c)
{
std_string::operator+=(c);
return *this;
}
RWBoolean operator==(const RWCString &s) const
{
const string *a=this;
const string *b=&s;
return *a==*b;
}
RWBoolean operator==(const char* s) const
{
const string *a=this;
const string b=s;
return *a==b;
}
RWBoolean operator!=(const RWCString &s) const
{
const string *a=this;
const string *b=&s;
return *a!=*b;
}
RWBoolean operator!=(const char* s) const
{
const string *a=this;
const string b=s;
return *a!=b;
}
//inline RWCString operator () (unsigned int, unsigned int);
inline operator const char*() const {return c_str();};
RWCString& prepend (const char*str)
{
insert(0,str);
return *this;
}
RWCString& append(const RWCString&s)
{
std_string::operator+=(s);
return *this;
}
inline std_istream& readLine ( std_istream&, RWBoolean skipWhite=true);
inline RWCString& replace (unsigned int, unsigned int,
const char*, unsigned int );
RWCString& replace(size_t pos,size_t n,const char*s)
{
std_string::replace(pos,n,s);
return *this;
}
RWCString& remove(size_t n)
{
if(n<size())
erase(n,size()-n);
return *this;
}
RWCString& remove(size_t pos,size_t N)
{
erase(pos,N+pos);
return *this;
}
int first(char c) const{return find(c);}
int last(char c) const{return rfind(c);}
RWBoolean contains(std_string s) const
{
int i=find(s);
if(i!=std_string::npos) return true;
return false;
}
RWBoolean contains(char c) const
{
int i=find(c);
if(i!=std_string::npos) return true;
return false;
}
//
// stripType = 0 beginning
// stripType = 1 end
// stripType = 2 both
//
inline RWCString strip ( int stripType, char );
inline void toLower ( void );
inline void toUpper ( void );
inline RWBoolean isNull() const {return empty ();}
inline size_t index (const char*,int pos=0) const;
inline size_t index (char,int pos=0) const;
inline size_t index( const RWCString&, size_t, size_t, caseCompare ) const;
RWCSubString operator()(size_t start, size_t extent)
{
return RWCSubString(*this,start,extent);
}
const char* data() const{return c_str();}
unsigned int hash( caseCompare cmp = exact ) const
{
const char*s=c_str();
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
return size_t(h);
}
unsigned int stlhash() const
{
const char*s=c_str();
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
return size_t(h);
}
// useful for supplying hash functions to template hash collection ctors:
static unsigned hash(const RWCString&);
};
RWCSubString::RWCSubString(const RWCSubString&s)
{
mystring=s.mystring;
mystart=s.mystart;
extent=s.extent;
}
RWCSubString& RWCSubString::operator=(const RWCString&s)
{
RWCString str(s);
return operator=(str);
}
RWCSubString& RWCSubString::operator=(const RWCSubString&s)
{
mystring->replace(mystart,extent,s.mystring->data(),s.length());
extent=s.length();
return *this;
}
RWCSubString& RWCSubString::operator=(const char*s)
{
mystring->replace(mystart,extent,s,strlen(s));
extent=strlen(s);
return *this;
}
char& RWCSubString::operator()(size_t i)
{return mystring->operator[](mystart+i);}
char RWCSubString::operator()(size_t i) const
{return mystring->operator[](mystart+i);}
char& RWCSubString::operator[](size_t i)
{return mystring->operator[](mystart+i);}
char RWCSubString::operator[](size_t i) const
{return mystring->operator[](mystart+i);}
RWBoolean RWCSubString::operator==(RWCString s) const
{
return mystring->substr(mystart,extent)==s ? true:false;
}
RWBoolean RWCSubString::operator==(const char* s) const
{
return mystring->substr(mystart,extent)==string(s) ? true:false;
}
RWBoolean RWCSubString::operator!=(RWCString s) const
{
return mystring->substr(mystart,extent)!=string(s) ? true:false;
}
RWBoolean RWCSubString::operator!=(const char* s) const
{
return mystring->substr(mystart,extent)!=string(s) ? true:false;
}
//#include <rw/cstring.icc>
//GB:OSF1-cxx : #include <cstring>
RWCString::RWCString ( const char * astring ) : std_string ( astring ) {}
void RWCString::toLower ( void ) {
for (int i=0; i<=size();i++) {
//GB:HP-UX-aCC,Linux-KCC (*this)[i] = tolower((*this)[i]);
at(i) = tolower(at(i));
}
}
void RWCString::toUpper ( void ) {
for (int i=0; i<=size();i++) {
//GB:HP-UX-aCC,Linux-KCC (*this)[i] = toupper((*this)[i]);
at(i) = toupper(at(i));
}
}
std_istream& RWCString::readLine ( std_istream& s, RWBoolean skipWhite/*GB:OSF1-cxx =true*/ ) {
char tmp[256];
if ( skipWhite ) {
s >> std_ws;
s.getline(tmp,256);
*this=tmp;
}
else {
s.getline(tmp,256);
*this=tmp;
}
return s;
}
RWCString& RWCString::replace (unsigned int start, unsigned int nbytes,
const char* buff, unsigned int n2 ) {
std_string::replace ( start, nbytes, buff, n2 );
return *this;
}
RWCString RWCString::strip ( int stripType=trailing, char c=' ' ) {
RWCString 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;
RWCString 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;
}
// "cs" optional parameter is NOT implemented !
size_t RWCString::index( const RWCString& s, size_t ln,
size_t st, RWCString::caseCompare cs ) const {
return std_string::find( s.c_str(), st, ln );
}
// "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 RWCString::operator () (size_t i) const
{
return operator[](i);
}
size_t RWCString::index (const char* str,int pos) const
{
return std_string::find(str,pos);
}
size_t RWCString::index (char c,int pos) const
{
return std_string::find(c,pos);
}
#endif
-61
View File
@@ -1,61 +0,0 @@
#ifndef __ctoken
#define __ctoken
#include <string>
#include "rw/defs.h"
#include "rw/cstring.h"
class RWCTokenizer
{
public:
RWCTokenizer(const RWCString& s):string2tokenize(s),actual(0){}
RWCSubString operator()(const char* str=" \t\n",size_t l=0)
{
size_t i,j,tmp;
RWBoolean 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:
RWCString string2tokenize;
size_t actual;
};
#endif
-115
View File
@@ -1,115 +0,0 @@
#ifndef __defs
#define __defs
#ifndef G4USE_OLDSTL
# include <cstdio>
# include <cstring>
#else
# include <stdio.h>
# include <string.h>
#endif
#define RWDEFAULT_CAPACITY (64)
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
const size_t RW_NPOS = ~(size_t)0;
#define CLHEP_MAX_MIN_DEFINED
#include <CLHEP/config/TemplateFunctions.h>
#ifdef G4_HAVE_BOOL
typedef bool RWBoolean;
#else
typedef HepBoolean RWBoolean;
#endif
class RWBoundsErr
{
public:
RWBoundsErr(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);
}
RWBoundsErr(const RWBoundsErr&e)
{
str=new char[strlen(e.str)+1];
strcpy(str,e.str);
}
~RWBoundsErr()
{
delete str;
}
const char * why() const
{
return str;
}
private:
char* str;
};
class RWGeneralException
{
public:
RWGeneralException(const char* s)
{
str=new char[strlen(s)+1];
strcpy(str,s);
}
RWGeneralException(const RWGeneralException&e)
{
str=new char[strlen(e.str)+1];
strcpy(str,e.str);
}
~RWGeneralException()
{
delete str;
}
const char * why() const
{
return str;
}
private:
char* str;
};
#define RWTHROW(a) throw a
#endif
-14
View File
@@ -1,14 +0,0 @@
#ifndef __rstream
#define __rstream
#include "rw/defs.h"
#ifndef G4USE_OLDSTL
#include <iostream>
#else
#include <iostream.h>
#endif
inline istream& rwEatwhite(istream& stream) {return stream >> ws;}
#endif
@@ -1,20 +0,0 @@
#ifndef rw2stl_algo_h
#define rw2stl_algo_h
#include "rw/defs.h"
template <class T>
class RW2STL_LessPtr
{
public:
RWBoolean operator()(const T* a, const T* b) const
{
if(a==0) return false;
if(b==0) return true;
return *a<*b;
}
};
#endif
-29
View File
@@ -1,29 +0,0 @@
#ifndef rwstlhash_h
#define rwstlhash_h
class G4ParticleDefinition;
class _WidgetRec;
inline unsigned HashDefault( const G4ParticleDefinition* const & p)
{
return (unsigned) p;
}
inline unsigned HashDefault( _WidgetRec* const & p)
{
return (unsigned) p;
}
inline unsigned HashDefault( const int& p)
{
return p;
}
template < class K >
unsigned HashDefault( const K& p)
{
return p.stlhash();
}
#endif
-296
View File
@@ -1,296 +0,0 @@
#ifndef __tphdict
#define __tphdict
#include "rw/defs.h"
#ifndef G4USE_OLDSTL
#include <vector>
#else
#include <vector.h>
#endif
#ifndef G4USE_OLDSTL
#include <hash_map>
#include <set>
#include <functional>
#else
# include <set.h>
# include <function.h>
# if defined(WIN32) && defined(OS_WIN_NT_4_0)
// OBJECT Space on WIN32 choose to change this name..
# include <hashmap.h>
# else
# include <hash_map.h>
# endif
#endif
template <class PK>
class Equal_Ptr_To
{
public:
Equal_Ptr_To(){}
RWBoolean operator()(const PK*a,const PK*b) const
{return *a==*b;}
};
#if defined(G4USE_NAMESPACE)
using std::set;
#endif
#include "rw/rwstlhash.h"
template < class PK >
class HashPtr {
public:
HashPtr(unsigned (*f)( const PK &)=HashDefault):fhashfun(f){}
HashPtr(const HashPtr<PK>&s):fhashfun(s.fhashfun){}
unsigned operator()( PK* key ) const;
void SetHashFun( unsigned (*hashfun)( const PK& ) );
private:
unsigned (*fhashfun)( const PK & );
};
#define hash_dict_t hash_map< K*, V*, HashPtr<K>,Equal_Ptr_To<K> >
template < class K, class V >
class RWTPtrHashDictionary
{
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef os_hash_table_iterator
<
OS_PAIR( K*, V* ),
OS_DIFF_TYPE( OS_PAIR( K*, V* ) )
> iterator;
typedef os_hash_table_const_iterator
<
OS_PAIR( K*, V* ),
OS_DIFF_TYPE( OS_PAIR( K*, V* ) )
> const_iterator;
#else
typedef hash_dict_t::iterator iterator;
typedef hash_dict_t::const_iterator const_iterator;
#endif
public:
RWTPtrHashDictionary( unsigned (*hashfun)( const K& key ),size_t n=100)
:fhm(n,HashPtr<K>(hashfun),Equal_Ptr_To<K>()){}
// Default copy constructor ?
RWTPtrHashDictionary( const RWTPtrHashDictionary<K,V>& aPtrHashDict ):
fhm( aPtrHashDict.fhm ){}
V*& operator[]( K*& key ) {return fhm[key]; }
void clear() { fhm.clear(); }
void clearAndDestroy( void )
{
//We are deleting in reverse order
set<K*,greater<K*> > ktmp;
set<V*,greater<V*> > vtmp;
for(iterator it=fhm.begin();
it!=fhm.end();it++)
{
K* kcurrent;
V* vcurrent;
kcurrent=((*it).first);
vcurrent=((*it).second);
if ( kcurrent )
ktmp.insert(kcurrent);
if ( vcurrent )
vtmp.insert(vcurrent);
}
typename set<K*,greater<K*> >::iterator kit;
for(kit=ktmp.begin();kit!=ktmp.end();kit++)
{
delete *kit;
}
typename set<V*,greater<V*> >::iterator vit;
for(vit=vtmp.begin();vit!=vtmp.end();vit++)
{
delete *vit;
}
fhm.clear();
}
void clearAndDestroyKey(void)
{
//We are deleting in reverse order
set<K*,greater<K*> > ktmp;
for(iterator it=fhm.begin();
it!=fhm.end();it++)
{
K* kcurrent;
kcurrent=((*it).first);
if ( kcurrent )
ktmp.insert(kcurrent);
}
typename set<K*,greater<K*> >::iterator kit;
for(kit=ktmp.begin();kit!=ktmp.end();kit++)
{
delete *kit;
}
fhm.clear();
}
K* find ( const K* key )
{
iterator it;
// The STL RW const problem
K tval(*key);
K* tptr=&tval;
it=fhm.find(tptr);
if(it!=fhm.end())
return (*it).first;
else
return 0;
}
V* findValue( const K* key )
{
iterator it;
// The STL RW const problem
K tval(*key);
K* tptr=&tval;
it=fhm.find(tptr);
if(it!=fhm.end())
return (*it).second;
else
return 0;
}
void insertKeyAndValue (K* key, V* value) {fhm[key]=value;}
K* remove(const K* key) {
iterator i;
K tmp(*key);
K* ptr=&tmp;
i = fhm.find(ptr);
if ( i == fhm.end() ) { return NULL; }
else {
ptr=(*i).first;
fhm.erase( i );
return ptr;
}
};
void resize( unsigned N ) { fhm.resize(N); }
K* findKeyAndValue( const K* key, V*& retval )
{
iterator i;
K tmp(*key);
K* ptr=&tmp;
i = fhm.find(ptr );
if ( i == fhm.end() ) { return false; }
else {
retval = (*i).second;
return (*i).first;
}
}
size_t entries() const {return fhm.size();}
size_t max_size() const {return fhm.max_size();}
size_t bucket_count() const {return fhm.bucket_count();}
RWBoolean contains(const K* Key) const
{
const_iterator it;
// The STL RW const problem
K tval(*Key);
K* tptr=&tval;
it=fhm.find(tptr);
if(it!=fhm.end())
return true;
else
return false;
}
//This is STL, so will not be used by RW
iterator begin(){return fhm.begin();}
iterator end(){return fhm.end();}
private:
hash_dict_t fhm;
};
template < class K, class V >
class RWTPtrHashDictionaryIterator {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef os_hash_table_iterator
<
OS_PAIR( K*, V* ),
OS_DIFF_TYPE( OS_PAIR( K*, V* ) )
> iterator;
typedef os_hash_table_const_iterator
<
OS_PAIR( K*, V* ),
OS_DIFF_TYPE( OS_PAIR( K*, V* ) )
> const_iterator;
#else
typedef hash_dict_t::iterator iterator;
typedef hash_dict_t::const_iterator const_iterator;
#endif
public:
RWTPtrHashDictionaryIterator(RWTPtrHashDictionary<K,V>&adict):
mydict(&adict),it(adict.begin()),defined(false){}
RWBoolean operator++ ()
{
if(!defined) return false;
it++;
return it!=mydict->end() ? true : false;
}
RWBoolean operator()()
{
if(defined)
return operator++();
else
{
defined=true;
it=mydict->begin();
return it!=mydict->end() ? true : false;
}
}
K* key () const {return (*it).first;}
void reset (){defined=false;}
V* value () const{return (*it).second;}
private:
iterator it;
RWTPtrHashDictionary<K,V>* mydict;
RWBoolean defined;
};
template< class PK >
unsigned HashPtr<PK>::operator()( PK * key ) const {
return fhashfun( *key );
}
template< class PK >
void HashPtr<PK>::SetHashFun( unsigned (*hashfun)( const PK& ) ) {
fhashfun = hashfun;
}
#undef hash_dict_t
#endif
-378
View File
@@ -1,378 +0,0 @@
#ifndef __tpordvec
#define __tpordvec
#ifndef G4USE_OLDSTL
# include <vector>
# include <set>
# include <functional>
#else
# include <vector.h>
# include <set.h>
# include <function.h>
#endif
#include "rw/defs.h"
#if defined(G4USE_NAMESPACE)
using std::vector;
using std::set;
#endif
template<class T> class RWTPtrOrderedVector : public vector<T*> {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef T** iterator;
typedef T* const* const_iterator;
#endif
public:
RWTPtrOrderedVector(size_t capacity=RWDEFAULT_CAPACITY):
vector<T*>(capacity,(T*)0),rwsize(0){}
RWTPtrOrderedVector(const RWTPtrOrderedVector<T>& v):
vector<T*>(v),rwsize(v.rwsize){}
RWTPtrOrderedVector<T>& operator=(const RWTPtrOrderedVector<T>& v)
{
vector<T*>::operator=(v),
rwsize=v.rwsize;
return *this;
}
~RWTPtrOrderedVector(){}
T*& operator()(size_t i)
{
//if(i<0 || i>=rwsize)
// RWTHROW(RWBoundsErr("RWTPtrOrderedVector ()",rwsize,i));
if(i<vector<T*>::size() && rwsize<=i) rwsize=i+1;
return vector<T*>::operator[](i);
}
T* const& operator()(size_t i) const
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector const ()",rwsize,i));
return vector<T*>::operator[](i);
}
T*& operator[](size_t i)
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector []",rwsize,i));
//if(i<vector<T*>::size() && rwsize<=i) rwsize=i+1;
return vector<T*>::operator[](i);
}
T* const& operator[](size_t i) const
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector const []",rwsize,i));
return vector<T*>::operator[](i);
}
void clearAndDestroy();
void clear();
size_t index ( const T*) const;
void resize(size_t);
void insert ( T* a )
{
if(rwsize<vector<T*>::size())
{
vector<T*>::operator[](rwsize)=a;
rwsize++;
}
else
{
vector<T*>::push_back(a);
rwsize=vector<T*>::size();
}
}
//
// insertAt should throw an exception of type RWBoundsErr if you try
// to insert out of range
//
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;
size_t entries() const { return rwsize; }
void append ( T* a )
{
insert( a );
}
size_t length() const { return rwsize; }
T*& at ( size_t i )
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector at",rwsize,i));
return operator()(i);
}
T*const& at ( size_t i ) const
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector const at",rwsize,i));
return operator()(i);
}
RWBoolean contains ( const T* a) const;
RWBoolean isEmpty()const {return rwsize==0;}
T* first() const
{
if(!rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector front",rwsize,0));
return vector<T*>::front();
}
T* last() const
{
if(rwsize)
return vector<T*>::operator[](rwsize-1);
else
return 0;
}
void prepend(T* const ptr)
{
vector<T*>::insert(vector<T*>::begin(),ptr);
rwsize++;
}
private:
size_t rwsize;
};
template<class T > void RWTPtrOrderedVector<T>::clear()
{
//vector<T*>::erase(vector<T*>::begin(), vector<T*>::end());
rwsize=0;
}
template<class T > void RWTPtrOrderedVector<T>::clearAndDestroy()
{
int sz;
set<T*,greater<T*> > tmp;
for (sz=0;sz<rwsize;sz++)
{
T* current;
current=vector<T*>::operator[](sz);
if ( current )
tmp.insert(current);
}
typename set<T*,greater<T*> >::iterator it;
for(it=tmp.begin();it!=tmp.end();it++)
{
delete *it;
}
//vector<T*>::erase(vector<T*>::begin(), vector<T*>::end());
rwsize=0;
}
template<class T> size_t RWTPtrOrderedVector<T>::index( const T* a ) const
{
const_iterator i;
size_t ptn = 0;
for (i = vector<T*>::begin();ptn<rwsize; i++,ptn++)
{
if (**i==*a) return ptn;
}
return (ptn=~(size_t)0);
}
template<class T>
size_t RWTPtrOrderedVector<T>::occurrencesOf( const T* a ) const
{
const_iterator i;
size_t ptn = 0;
size_t sz=0;
for (i = vector<T*>::begin();sz<rwsize; i++,sz++)
{
if (**i==*a) ptn++;
}
return ptn;
}
template<class T>
RWBoolean RWTPtrOrderedVector<T>::contains( const T* a ) const
{
const_iterator i;
size_t ptn=0;
for (i = vector<T*>::begin(); ptn<rwsize; i++,ptn++)
{
if (**i==*a) return true;
}
return false;
}
template<class T> T* RWTPtrOrderedVector<T>::remove( const T* a )
{
iterator i;
size_t ptn=0;
size_t rwsz=rwsize;
for (i = vector<T*>::begin();ptn<rwsz; i++,ptn++)
{
if (**i==*a)
{
T* tmp=*i;
vector<T*>::erase(i);
rwsize--;
return tmp;
}
}
return 0;
}
template<class T>
size_t RWTPtrOrderedVector<T>::removeAll( const T* a )
{
iterator i;
size_t ptn = 0;
size_t sz=0;
size_t rwsz=rwsize;
for (i = vector<T*>::begin();sz<rwsz; i++,sz++)
{
if (**i==*a)
{
vector<T*>::erase(i);
rwsize--;
i--;
ptn++;
}
}
return ptn;
}
// should throw exception if ...
template<class T>
T* RWTPtrOrderedVector<T>::removeAt( size_t i )
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector removeAt",rwsize,i));
iterator it=vector<T*>::begin();
int j;
for(j=0;j<rwsize && j<i;j++) it++;
if(it!=vector<T*>::end())
{
T* tmp = operator[](i);
vector<T*>::erase(it);
rwsize--;
return tmp;
}
else
return 0;
}
template<class T>
T* RWTPtrOrderedVector<T>::find(const T* a) const
{
const_iterator i;
size_t ptn=0;
for (i = vector<T*>::begin(); ptn<rwsize; i++,ptn++)
{
if (**i==*a)
{
return *i;
}
}
return 0;
}
template<class T>
void RWTPtrOrderedVector<T>::resize(size_t N)
{
if(N>vector<T*>::size())
{
int e=N-vector<T*>::size();
for(int i=0;i<e;i++)
vector<T*>::push_back(0);
}
else if(N>rwsize)
{
iterator it=vector<T*>::begin();
for(int i=0;i<N;i++,it++);
vector<T*>::erase(it,vector<T*>::end());
}
}
template<class T>
void RWTPtrOrderedVector<T>::insertAt ( size_t i, T* a )
{
if(i<0 || i>rwsize)
RWTHROW(RWBoundsErr("RWTPtrOrderedVector insertAt",rwsize,i));
if(rwsize<vector<T*>::size())
{
for(int j=rwsize;j>i;j--)
vector<T*>::operator[](j)=vector<T*>::operator[](j-1);
vector<T*>::operator[](i)=a;
rwsize++;
}
else
{
iterator it=vector<T*>::begin();
for(int j=0;j<i;j++,it++);
vector<T*>::insert(it,a);
rwsize++;
}
}
template<class T>
T* RWTPtrOrderedVector<T>::removeFirst ()
{
if(rwsize!=0)
{
T* tmp=vector<T*>::front();
vector<T*>::erase(vector<T*>::begin());
rwsize--;
return tmp;
}
else
return 0;
}
template<class T>
T* RWTPtrOrderedVector<T>::removeLast ()
{
if(rwsize==0) return (T*) 0;
rwsize--;
T* tmp=vector<T*>::operator[](rwsize);
vector<T*>::operator[](rwsize)=0;
return tmp;
}
#endif
-241
View File
@@ -1,241 +0,0 @@
#ifndef __tpsrtvec
#define __tpsrtvec
#include "rw/rw2stl_algo.h"
#ifndef G4USE_OLDSTL
#include <vector>
#include <algorithm>
#else
#include <vector.h>
#include <algo.h>
#endif
#if defined(G4USE_NAMESPACE)
using std::vector;
using std::sort;
#endif
#include "rw/defs.h"
template <class T>
class RWTPtrSortedVector : public vector<T*> {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef T** iterator;
typedef T* const* const_iterator;
#endif
public:
RWTPtrSortedVector(size_t n=RWDEFAULT_CAPACITY):vector<T*>(n),rwsize(0)
{
for(int i=0;i<n;i++)
vector<T*>::operator[](i)=0;
}
RWTPtrSortedVector(const RWTPtrSortedVector<T>& v):vector<T*>(v),
rwsize(v.rwsize){}
RWTPtrSortedVector<T>& operator=(const RWTPtrSortedVector<T>& v)
{
vector<T*>::operator=(v);
rwsize=v.rwsize;
return *this;
}
~RWTPtrSortedVector(){}
T* const& operator [] (size_t n) const
{
if(n<0 || n>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrSortedVector",rwsize,n));
return vector<T*>::operator[](n);
}
T* const& operator () (size_t n) const
{
return vector<T*>::operator[](n);
}
T*& at(size_t n )
{
if(n<0 || n>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrSortedVector",rwsize,n));
if(n<vector<T*>::size() && rwsize<=n) rwsize=n+1;
return vector<T*>::operator[](n);
}
T* at(size_t n ) const
{
if(n<0 || n>=rwsize)
RWTHROW(RWBoundsErr("RWTPtrSortedVector",rwsize,n));
return vector<T*>::operator[](n);
}
void clear()
{
vector<T*>::erase(vector<T*>::begin(),vector<T*>::end());
rwsize=0;
}
void clearAndDestroy ()
{
size_t sz=0;
for(iterator it=vector<T*>::begin();sz<rwsize;it++,sz++)
delete *it;
vector<T*>::erase(vector<T*>::begin(),vector<T*>::end());
rwsize=0;
}
T* find (const T* a) const {
if(!a || vector<T*>::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;
}
size_t entries () const {return rwsize;}
void insert ( T* a )
{
if(rwsize<vector<T*>::size())
{
//We have empty entries
iterator it=vector<T*>::begin();
for(int i=0;i<rwsize;i++,it++);
*it=a;
it++;
sort(vector<T*>::begin(),it,sorter);
}
else
{
vector<T*>::push_back(a);
//This makes it a sorted thing;
sort(vector<T*>::begin(),vector<T*>::end(),sorter);
}
rwsize++;
}
size_t index ( const T* a ) const
{
T*const* ii = vector<T*>::begin();
size_t cnt = 0;
for (T*const* it = ii;cnt<rwsize; ++it,cnt++)
{
if ( **it == *a ) return cnt;
}
return 0;
}
RWBoolean isEmpty () const{return rwsize==0;}
T* const & first () const
{
if(!rwsize)
RWTHROW(RWBoundsErr("RWTPtrSortedVector first()",rwsize,0));
return vector<T*>::front();
}
T* const & last () const
{
if(rwsize)
return vector<T*>::operator[](rwsize-1);
else
RWTHROW(RWBoundsErr("RWTPtrSortedVector last()",rwsize,0));
}
size_t occurrencesOf(const T* a) const
{
size_t cnt = 0;
size_t sz = 0;
for (const_iterator it = vector<T*>::begin();sz<rwsize; ++it,sz++)
{
if ( **it == *a ) cnt++;
}
return cnt;
}
T* remove ( const T* a )
{
iterator retval;
size_t sz=0;
for(retval=vector<T*>::begin();sz<rwsize;retval++,sz++)
if(**retval==*a) break;
if(sz<rwsize && retval!=vector<T*>::end())
{
T* tmp=*retval;
vector<T*>::erase(retval);
rwsize--;
return tmp;
}
else
return 0;
}
size_t removeAll ( const T* a)
{
iterator s=vector<T*>::end();
iterator e=vector<T*>::end();
iterator r;
size_t sz=0;
int i=0;
for(r=vector<T*>::begin();sz<rwsize;r++,sz++)
{
if(i==0)
{
if(**r==*a)
{
s=r;
i++;
}
}
else
{
if(**r!=*a)
{
e=r;
break;
}
else
i++;
}
}
vector<T*>::erase(s,e);
rwsize-=i;
return i;
}
private:
size_t rwsize;
RW2STL_LessPtr<T> sorter;
};
#endif
@@ -1,20 +0,0 @@
template<class T> T* RWTPtrSortedVector<T>::remove( const T* a ) {
iterator i = multimap<T,T*>::find (*a);
T* retval = (*i).second;
erase ( i );
return retval;
}
template<class T> size_t RWTPtrSortedVector<T>::removeAll( const T* a ) {
pair<iterator,iterator> p = equal_range ( *a );
iterator i1 = p.first;
iterator i2 = p.second;
iterator i;
size_t cnt = 0;
for (i=i1; i!=i2; i++) {
cout << "remove all : " << (*i).first << " " << (*i).second << endl;
erase ( i );
cnt++;
}
return cnt;
}
-51
View File
@@ -1,51 +0,0 @@
#ifndef __tpvector
#define __tpvector
#ifndef G4USE_OLDSTL
#include <vector>
#else
#include <vector.h>
#endif
#if defined(G4USE_NAMESPACE)
using std::vector;
#endif
template<class T> class RWTPtrVector : public vector<T*> {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef T** iterator;
typedef T* const* const_iterator;
#endif
public:
RWTPtrVector ();
RWTPtrVector (unsigned int n);
RWTPtrVector (unsigned int n, T* const & iPtr);
RWTPtrVector (const RWTPtrVector<T>& iPtr);
~RWTPtrVector(){}
// Copy constructor and assignment operator inherited from vector<T*>.
RWTPtrVector<T>& operator = (T* p) {
for(iterator i = vector<T*>::begin();
i != vector<T*>::end();
++i) {
*i = p;
}
return *this;
}
T* operator () ( size_t n ) const { return vector<T*>::operator[](n);}
T*& operator () ( size_t n ) { return vector<T*>::operator[](n);}
//
// The [] operator should perform bound checking
//
T* operator [] ( size_t n ) const { return vector<T*>::operator[](n);}
T*& operator [] ( size_t n ) { return vector<T*>::operator[](n);}
T* const * data() const { return &(vector<T*>::front()); }
size_t length() { return vector<T*>::size();}
void reshape( size_t n );
};
#include "rw/tpvector.icc"
#endif
@@ -1,16 +0,0 @@
template<class T> RWTPtrVector<T>::RWTPtrVector (): vector<T*>(){};
template<class T> RWTPtrVector<T>::RWTPtrVector (unsigned int n) : vector<T*>(n){}
template<class T> RWTPtrVector<T>::RWTPtrVector (unsigned int n,
T* const & iPtr)
: vector<T*>(n, iPtr){}
template<class T> RWTPtrVector<T>::RWTPtrVector (const RWTPtrVector<T>& iPtr)
: vector<T*> ( iPtr ){}
template<class T> void RWTPtrVector<T>::reshape( size_t n )
{
vector<T*>::resize(n);
}
-178
View File
@@ -1,178 +0,0 @@
#ifndef __tvhdict
#define __tvhdict
#include "rw/defs.h"
#ifndef G4USE_OLDSTL
#include <hash_map>
#else
# if defined(WIN32) && defined(OS_WIN_NT_4_0)
// OBJECT Space on WIN32 choose to change this name..
# include <hashmap.h>
# else
# include <hash_map.h>
# endif
#endif
#include "rw/rwstlhash.h"
template < class K >
class Hash {
public:
Hash(unsigned (*f)( const K& )=HashDefault):fhashfun(f){}
unsigned operator()( const K& key ) const;
void SetHashFun( unsigned (*hashfun )( const K& ) );
private:
unsigned (*fhashfun)( const K& );
};
#define hash_dict_t hash_map< K, V, Hash<K>,equal_to<K> >
template < class K, class V >
class RWTValHashDictionary {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef os_hash_table_iterator
<
OS_PAIR( K, V ),
OS_DIFF_TYPE( OS_PAIR( K, V ) )
> iterator;
typedef os_hash_table_const_iterator
<
OS_PAIR( K, V ),
OS_DIFF_TYPE( OS_PAIR( K, V ) )
> const_iterator;
#else
typedef hash_dict_t::iterator iterator;
typedef hash_dict_t::const_iterator const_iterator;
#endif
public:
RWTValHashDictionary(){}
RWTValHashDictionary( unsigned (*hashfun)( const K& key) ,size_t n=100):
fhm(n,Hash<K>(hashfun),equal_to<K>()){}
//pair<iterator, RWBoolean> insert(const pair<K,V>& x);
V& operator[]( const K& key ) { return fhm[key]; }
void clear() { fhm.clear(); }
RWBoolean findValue( const K& key, V& retval )
{
iterator i;
i = fhm.find( key );
if ( i == fhm.end() ) { return false; }
else {
retval = (*i).second;
return true;
}
}
RWBoolean contains(const K& key) const
{
const_iterator i=fhm.find(key);
if(i==fhm.end()) return false;
return true;
}
RWBoolean remove(const K& key)
{
iterator i=fhm.find(key);
if(i==fhm.end()) return false;
fhm.erase(i);
return true;
}
RWBoolean isEmpty() const
{
if(fhm.empty()) return true;
return false;
}
size_t entries()const{return fhm.size();}
void insertKeyAndValue(const K&key,const V&value)
{
fhm[key]=value;
}
//This is STL, so will not be used by RW
iterator begin(){return fhm.begin();}
iterator end(){return fhm.end();}
private:
hash_dict_t fhm;
};
template < class K, class V >
class RWTValHashDictionaryIterator {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef os_hash_table_iterator
<
OS_PAIR( K, V ),
OS_DIFF_TYPE( OS_PAIR( K, V ) )
> iterator;
typedef os_hash_table_const_iterator
<
OS_PAIR( K, V ),
OS_DIFF_TYPE( OS_PAIR( K, V ) )
> const_iterator;
#else
typedef hash_dict_t::iterator iterator;
typedef hash_dict_t::const_iterator const_iterator;
#endif
public:
RWTValHashDictionaryIterator(RWTValHashDictionary<K,V>&adict):
mydict(&adict),it(adict.begin()),defined(false){}
RWBoolean operator++()
{
if(!defined) return false;
it++;
return it!=mydict->end() ? true : false;
}
RWBoolean operator++(int)
{
if(!defined) return false;
it++;
return it!=mydict->end() ? true : false;
}
RWBoolean operator()()
{
if(defined)
return operator++();
else
{
defined=true;
it=mydict->begin();
return it!=mydict->end() ? true : false;
}
}
K key () const {return (*it).first;}
void reset (){defined=false;}
void reset (RWTValHashDictionary<K,V>&adict)
{
mydict=adict;
defined=false;
}
V value () const{return (*it).second;}
private:
iterator it;
RWTValHashDictionary<K,V>* mydict;
RWBoolean defined;
};
#include "rw/tvhdict.icc"
#undef hash_dict_t
#endif
-19
View File
@@ -1,19 +0,0 @@
template< class K >
unsigned Hash<K>::operator()( const K& key ) const {
return Hash<K>::fhashfun( key );
}
template < class K >
void Hash<K>::SetHashFun( unsigned (*hashfun)( const K& ) ) {
fhashfun = hashfun;
}
/*
template < class K, class V >
pair< hash_map< K, V, Hash<K>,equal_to<K> >::iterator, RWBoolean >
RWTValHashDictionary<K,V>::insert( const pair<K,V>& x ) {
fhm.insert( x );
}
*/
-297
View File
@@ -1,297 +0,0 @@
#ifndef __tvordvec
#define __tvordvec
#ifndef G4USE_OLDSTL
#include <vector>
#include <algorithm>
#else
#include <vector.h>
#include <algo.h>
#endif
#include "rw/defs.h"
#include "rw/tvvector.h"
template<class T> class RWTValOrderedVector : public vector<T>
{
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef T* iterator;
typedef const T* const_iterator;
#endif
public:
RWTValOrderedVector(size_t capacity=RWDEFAULT_CAPACITY):vector<T>(capacity),rwsize(0){}
RWTValOrderedVector(const RWTValOrderedVector<T>& v):
vector<T>(v),rwsize(v.rwsize){}
RWTValOrderedVector<T>& operator=(const RWTValOrderedVector<T>& v)
{
vector<T>::operator=(v);
rwsize=v.rwsize;
return *this;
}
~RWTValOrderedVector(){}
T& operator()(size_t i)
{
//if(i<0 || i>=rwsize)
// RWTHROW(RWBoundsErr("RWTValOrderedVector ()",rwsize,i));
if(i<vector<T>::size() && rwsize<=i) rwsize=i+1;
return vector<T>::operator[](i);
}
const T& operator()(size_t i) const
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector const()",rwsize,i));
return vector<T>::operator[](i);
}
T& operator[](size_t i)
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector []",rwsize,i));
// if(i<vector<T>::size() && rwsize<=i) rwsize=i+1;
return vector<T>::operator[](i);
}
const T& operator[](size_t i) const
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector const []",rwsize,i));
return vector<T>::operator[](i);
}
T& at(size_t n )
{
if(n<0 || n>=rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector at",rwsize,n));
return operator()(n);
}
T at(size_t n ) const
{
if(n<0 || n>=rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector const at",rwsize,n));
return operator()(n);
}
void resize(size_t);
void clear( void )
{
//vector<T>::erase(vector<T>::begin(), vector<T>::end());
for(size_t i=0;i<rwsize;i++)
vector<T>::operator[](i)=T();
rwsize=0;
}
RWBoolean contains( const T) const;
size_t length() const{ return rwsize;}
size_t index ( const T&);
RWBoolean insert ( const T&);
//
// insertAt should throw an exception of type RWBoundsErr if you try
// to insert out of range
//
void insertAt ( size_t, const T&);
size_t occurrencesOf ( const T& a ) const;
RWBoolean remove ( const T& a );
size_t removeAll ( const T& a );
T removeAt ( size_t i );
size_t entries () const { return rwsize; }
void append ( const T& a )
{
insert ( a );
}
T first() const
{
if(!rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector first",rwsize,0));
return vector<T>::front();
}
T last() const
{
if(rwsize)
return vector<T>::operator[](rwsize-1);
else
RWTHROW(RWBoundsErr("RWTValOrderedVector last",rwsize,0));
}
private:
size_t rwsize;
};
template<class T>
size_t RWTValOrderedVector<T>::index( const T& a )
{
iterator i;
size_t ptn = 0;
for (i = vector<T>::begin();ptn<rwsize; i++,ptn++)
{
if (*i==a) return ptn;
}
return (ptn=~(size_t)0);
}
template<class T>
size_t RWTValOrderedVector<T>::occurrencesOf( const T& a ) const
{
const_iterator i;
size_t ptn = 0;
size_t sz=0;
for (i = vector<T>::begin(); sz<rwsize; i++,sz++)
{
if (*i==a) ptn++;
}
return ptn;
}
template<class T>
RWBoolean RWTValOrderedVector<T>::remove( const T& a )
{
iterator i;
size_t sz=0;
size_t rwsz=rwsize;
for (i = vector<T>::begin(); sz<rwsz; i++,sz++)
{
if (*i==a)
{
vector<T>::erase(i);
rwsize--;
return true;
}
}
return false;
}
template<class T> size_t RWTValOrderedVector<T>::removeAll
( const T& a )
{
iterator i;
size_t ptn = 0;
size_t sz=0;
size_t rwsz=rwsize;
for (i = vector<T>::begin();sz<rwsz; i++,sz++)
{
if (*i==a)
{
vector<T>::erase(i);
ptn++;
i--;
rwsize--;
}
}
return ptn;
}
template<class T>
T RWTValOrderedVector<T>::removeAt( size_t i )
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector removeAt",rwsize,i));
T tmp = operator[](i);
iterator it=vector<T>::begin();
int j;
for(j=0;j<rwsize && j<i;j++) it++;
if(it!=vector<T>::end())
{
vector<T>::erase(it);
rwsize--;
}
return tmp;
}
template<class T>
void RWTValOrderedVector<T>::resize(size_t N)
{
if(N>vector<T>::size())
{
int e=N-vector<T>::size();
for(int i=0;i<e;i++)
vector<T>::push_back(T());
}
else if(N>rwsize )
{
iterator it=vector<T>::begin();
for(int i=0;i<N;i++,it++);
vector<T>::erase(it,vector<T>::end());
}
}
template<class T>
RWBoolean RWTValOrderedVector<T>::contains( const T a ) const
{
const_iterator i;
size_t sz=0;
for (i = vector<T>::begin();sz<rwsize; i++,sz++)
{
if (*i==a) return true;
}
return false;
}
template<class T>
RWBoolean RWTValOrderedVector<T>::insert ( const T& a )
{
if(rwsize<vector<T>::size())
{
this->vector<T>::operator[](rwsize)=a;
rwsize++;
}
else
{
vector<T>::push_back(a);
rwsize=vector<T>::size();
}
return true;
}
template<class T>
void RWTValOrderedVector<T>::insertAt ( size_t i, const T& a )
{
if(i<0 || i>rwsize)
RWTHROW(RWBoundsErr("RWTValOrderedVector insertAt",rwsize,i));
if(rwsize<vector<T>::size())
{
for(int j=rwsize;j>i;j--)
vector<T>::operator[](j)=this->vector<T>::operator[](j-1);
vector<T>::operator[](i)=a;
rwsize++;
}
else
{
iterator it=vector<T>::begin();
for(int j=0;j<i;j++,it++);
vector<T>::insert(it,a);
rwsize++;
}
}
#endif
-101
View File
@@ -1,101 +0,0 @@
#ifndef __tvvector
#define __tvvector
#ifndef G4USE_OLDSTL
#include <vector>
#else
#include <vector.h>
#endif
#if defined(G4USE_NAMESPACE)
using std::vector;
#endif
#include "rw/defs.h"
template<class T> class RWTValVector : public vector<T> {
#ifdef G4USE_EXPLICIT_TYPES_IN_TEMPLATES
typedef T* iterator;
typedef const T* const_iterator;
#endif
public:
RWTValVector ():rwsize(0){}
RWTValVector (size_t n):vector<T>(n),rwsize(n){}
RWTValVector (size_t n, const T& ival):vector<T>(n,ival),rwsize(n){}
RWTValVector (const RWTValVector<T>& ival):vector<T>(ival),rwsize(ival.rwsize){}
~RWTValVector(){};
RWTValVector<T>& operator= ( const RWTValVector<T>& v)
{
vector<T>::operator=(v);
rwsize=v.rwsize;
return *this;
}
size_t length() const { return vector<T>::size();}
T& operator()(size_t i)
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValVector operator()",rwsize,i));
if(i<vector<T>::size() && rwsize<i) rwsize=i+1;
return vector<T>::operator[](i);
}
const T& operator()(size_t i) const { return vector<T>::operator[](i); }
T& operator[](size_t i)
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValVector operator[]",rwsize,i));
if(i<vector<T>::size() && rwsize<i) rwsize=i+1;
return vector<T>::operator[](i);
}
const T& operator[](size_t i) const
{
if(i<0 || i>=rwsize)
RWTHROW(RWBoundsErr("RWTValVector const operator[]",rwsize,i));
return vector<T>::operator[](i);
}
const T* data() const { return &(vector<T>::front()); };
void resize(size_t N)
{
if(N>vector<T>::size())
{
int e=N-vector<T>::size();
for(int i=0;i<e;i++)
vector<T>::push_back(T());
}
else
{
iterator it=vector<T>::begin();
for(int i=1;i<=N;i++,it++);
vector<T>::erase(it,vector<T>::end());
}
rwsize=N;
}
void reshape( size_t n )
{
resize(n);
}
const T& ref(size_t i) const{return vector<T>::operator[](i);}
private:
size_t rwsize;
};
#endif
@@ -1,28 +0,0 @@
#ifndef HASH_MAP_H
#define HASH_MAP_H
// wrapper for Objectspace hash map...
#include <hashmap.h>
#ifndef HASHCHARSTAR_H
#define HASHCHARSTAR_H
inline size_t __stl_hash_string(const char* s)
{
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
return size_t(h);
}
struct hash<const char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
struct hash<char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
#endif // HASHCHARSTAR_H
#endif // HASH_MAP_H
@@ -1 +1 @@
#include<stdio.h>
#include <stdio.h>
@@ -1 +1 @@
#include <string.h>
#include <string>
@@ -1,28 +0,0 @@
#ifndef HASH_MAP_H
#define HASH_MAP_H
// wrapper for Objectspace hash map...
#include <hashmap.h>
#ifndef HASHCHARSTAR_H
#define HASHCHARSTAR_H
inline size_t __stl_hash_string(const char* s)
{
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
return size_t(h);
}
struct hash<const char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
struct hash<char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
#endif // HASHCHARSTAR_H
#endif // HASH_MAP_H
@@ -1,28 +0,0 @@
#ifndef HASH_MAP_H
#define HASH_MAP_H
// wrapper for Objectspace hash map...
#include <hashmap.h>
#ifndef HASHCHARSTAR_H
#define HASHCHARSTAR_H
inline size_t __stl_hash_string(const char* s)
{
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
return size_t(h);
}
struct hash<const char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
struct hash<char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
#endif // HASHCHARSTAR_H
#endif // HASH_MAP_H
@@ -0,0 +1 @@
#include <iomanip.h>
@@ -0,0 +1 @@
#include <iostream.h>
@@ -0,0 +1 @@
#include <strstream.h>
@@ -0,0 +1 @@
#include <iostream.h>
@@ -1,28 +0,0 @@
#ifndef HASH_MAP_H
#define HASH_MAP_H
// wrapper for Objectspace hash map...
#include <hashmap.h>
#ifndef HASHCHARSTAR_H
#define HASHCHARSTAR_H
inline size_t __stl_hash_string(const char* s)
{
unsigned long h = 0;
for ( ; *s; ++s)
h = 5*h + *s;
return size_t(h);
}
struct hash<const char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
struct hash<char*>
{
size_t operator()(const char* s) const { return __stl_hash_string(s); }
};
#endif // HASHCHARSTAR_H
#endif // HASH_MAP_H