Import Geant4 0.1.0 source tree
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
$Id: History,v 1.8 1999/07/06 15:02:39 gunter Exp $
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=========================================================
|
||||
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
|
||||
=========================================================
|
||||
|
||||
Sub-Category History file
|
||||
-------------------------
|
||||
|
||||
This file should be used by G4 developers and category coordinators
|
||||
to briefly summarize all major modifications introduced in the code
|
||||
and keep track of all category-tags.
|
||||
It DOES NOT substitute the CVS log-message one should put at every
|
||||
committal in the CVS repository !
|
||||
|
||||
----------------------------------------------------------
|
||||
* Reverse chronological order (last date on top), please *
|
||||
----------------------------------------------------------
|
||||
|
||||
STL Interface
|
||||
-------------
|
||||
|
||||
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
|
||||
|
||||
5th July 1999 Gunter Folger, John Allison (STLInterface-23)
|
||||
- Added operator= to tpsrtvec and tvvector.
|
||||
|
||||
28th June 1999 John Allison (STLInterface-21a)
|
||||
- Fixed rwsize=N in tvalvec::resize(N) (Gunter).
|
||||
|
||||
24th June 1999 John Allison (STLInterface-21)
|
||||
- Fixed clear problem (which wrongly made STL size 0).
|
||||
- Added bounds checking.
|
||||
|
||||
23rd June 1999 John Allison (STLInterface-20)
|
||||
- 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*
|
||||
keys, protecting against duplicate entries.
|
||||
- Reimplemented RWTPtrOrderedVector::clearAndDestroy with vector<T*>
|
||||
instead of set<T*>.
|
||||
- Prevented RWTPtrOrderedVector::resize and RWTValOrderedVector::resize
|
||||
from reducing the size below the number if items.
|
||||
|
||||
20th June 1999 John Allison
|
||||
- Started this file.
|
||||
@@ -0,0 +1,443 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#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
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#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
|
||||
@@ -0,0 +1,20 @@
|
||||
#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
|
||||
@@ -0,0 +1,29 @@
|
||||
#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
|
||||
@@ -0,0 +1,296 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,378 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#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
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#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
|
||||
@@ -0,0 +1,19 @@
|
||||
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 );
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#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
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef __CMATH__
|
||||
#define __CMATH__
|
||||
|
||||
#include <math.h>
|
||||
inline float abs (float x) { return fabs (x); }
|
||||
inline double abs (double x) { return fabs (x); }
|
||||
inline long double abs (long double x) { return fabs (x); }
|
||||
|
||||
|
||||
#endif // __CMATH__
|
||||
@@ -0,0 +1 @@
|
||||
#include<stdio.h>
|
||||
@@ -0,0 +1,8 @@
|
||||
// The -*- C++ -*- standard library header.
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifndef __CSTDLIB__
|
||||
#define __CSTDLIB__
|
||||
#include <stdlib.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef __STD_CSTRING
|
||||
#define __STD_CSTRING
|
||||
|
||||
#include <string.h>
|
||||
int strcasecmp(const char *s1, const char *s2) { return strcmp(s1,s2); }
|
||||
|
||||
#endif /*__STD_CSTRING*/
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#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,10 @@
|
||||
#ifndef __CMATH__
|
||||
#define __CMATH__
|
||||
|
||||
#include <math.h>
|
||||
inline float abs (float x) { return fabs (x); }
|
||||
inline double abs (double x) { return fabs (x); }
|
||||
inline long double abs (long double x) { return fabs (x); }
|
||||
|
||||
|
||||
#endif // __CMATH__
|
||||
@@ -0,0 +1 @@
|
||||
#include<stdio.h>
|
||||
@@ -0,0 +1,8 @@
|
||||
// The -*- C++ -*- standard library header.
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifndef __CSTDLIB__
|
||||
#define __CSTDLIB__
|
||||
#include <stdlib.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include <string.h>
|
||||
@@ -0,0 +1,28 @@
|
||||
#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,28 @@
|
||||
#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,10 @@
|
||||
#ifndef __CMATH__
|
||||
#define __CMATH__
|
||||
|
||||
#include <math.h>
|
||||
inline float abs (float x) { return fabs (x); }
|
||||
inline double abs (double x) { return fabs (x); }
|
||||
inline long double abs (long double x) { return fabs (x); }
|
||||
|
||||
|
||||
#endif // __CMATH__
|
||||
@@ -0,0 +1 @@
|
||||
#include<stdio.h>
|
||||
@@ -0,0 +1,8 @@
|
||||
// The -*- C++ -*- standard library header.
|
||||
// This file is part of the GNU ANSI C++ Library.
|
||||
|
||||
#ifndef __CSTDLIB__
|
||||
#define __CSTDLIB__
|
||||
#include <stdlib.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include <string.h>
|
||||
@@ -0,0 +1,28 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user