global/management/include/G4String.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4String.hh,v 1.7 2007/11/13 17:35:06 gcosmo Exp $
00028 // GEANT4 tag $Name: geant4-09-01-patch-01 $
00029 //
00030 // 
00031 //---------------------------------------------------------------
00032 //  GEANT 4 class header file
00033 //
00034 //  G4String
00035 //
00036 //  Class description:
00037 //
00038 //  Definition of a Geant4 string.
00039 //  Derived from the Rogue Wave implementation of RWCString;
00040 //  it uses intrinsically STL string.
00041 
00042 //---------------------------------------------------------------
00043 
00044 #ifndef __G4String
00045 #define __G4String
00046 
00047 #include <stdio.h>
00048 #include <string>
00049 #include "G4Types.hh"
00050 #include <iostream>
00051 
00052 #ifdef WIN32
00053   #define strcasecmp _stricmp
00054 #endif
00055 
00056 typedef std::string::size_type str_size;
00057 
00058 class G4String;
00059 
00060 class G4SubString
00061 {
00062 public:
00063 
00064   inline G4SubString(const G4SubString&);
00065 
00066   inline G4SubString& operator=(const char*);         
00067 
00068   inline G4SubString& operator=(const G4String&);
00069   inline G4SubString& operator=(const G4SubString&);
00070  
00071   inline char& operator()(str_size);
00072   inline char  operator()(str_size) const;
00073   inline char& operator[](str_size);
00074   inline char  operator[](str_size) const;
00075 
00076   inline G4int operator!() const;
00077 
00078   inline G4bool operator==(G4String) const;
00079   inline G4bool operator==(const char*) const;
00080   inline G4bool operator!=(G4String) const;
00081   inline G4bool operator!=(const char*) const;
00082 
00083   inline str_size length() const;
00084   inline str_size start() const;
00085 
00086   // For detecting null substrings
00087   //
00088   inline G4bool isNull() const;
00089 
00090 private:
00091 
00092   inline G4SubString(G4String&, str_size, str_size);
00093 
00094   G4String*    mystring;     
00095   str_size     mystart;
00096   str_size     extent;
00097 
00098   friend class G4String;
00099 
00100 };
00101  
00102 
00103 class G4String : public std::string
00104 {
00105 
00106   typedef std::string std_string;
00107 
00108 public: 
00109 
00110   enum caseCompare { exact, ignoreCase };
00111   enum stripType { leading, trailing, both };
00112 
00113   inline G4String ();
00114   inline G4String ( char );
00115   inline G4String ( const char * );
00116   inline G4String ( const G4String& );
00117   inline G4String ( const G4SubString& );
00118   inline G4String ( const std::string & );
00119   ~G4String () {}
00120 
00121   inline G4String& operator=(const G4String&);
00122   inline G4String& operator=(const std::string &);
00123   inline G4String& operator=(const char*);
00124 
00125   inline char operator () (str_size) const; 
00126   inline char& operator () (str_size);
00127 
00128   inline G4String& operator+=(const G4SubString&);
00129   inline G4String& operator+=(const char*);
00130   inline G4String& operator+=(const std::string &);
00131   inline G4String& operator+=(const char&);
00132   inline G4bool operator==(const G4String&) const;
00133   inline G4bool operator==(const char*) const;
00134   inline G4bool operator!=(const G4String&) const;
00135   inline G4bool operator!=(const char*) const;
00136 
00137   //inline G4String operator () (unsigned int, unsigned int);
00138   inline operator const char*() const;
00139   inline G4SubString operator()(str_size, str_size);
00140 
00141   inline G4int compareTo(const char*, caseCompare mode=exact);
00142   inline G4int compareTo(const G4String&, caseCompare mode=exact);
00143 
00144   inline G4String& prepend (const char*);
00145   inline G4String& append (const G4String&);
00146 
00147   inline std::istream& readLine (std::istream&, G4bool skipWhite=true);
00148   
00149   inline G4String& replace (unsigned int, unsigned int, 
00150                              const char*, unsigned int );
00151   inline G4String& replace(str_size, str_size, const char*);
00152 
00153   inline G4String& remove(str_size);
00154   inline G4String& remove(str_size, str_size);
00155 
00156   inline G4int first(char) const;
00157   inline G4int last(char) const;
00158 
00159   inline G4bool contains(std::string) const;
00160   inline G4bool contains(char) const;
00161 
00162   // stripType = 0 beginning
00163   // stripType = 1 end
00164   // stripType = 2 both
00165   //
00166   inline G4String strip (G4int strip_Type=trailing, char c=' ');
00167 
00168   inline void toLower ();
00169   inline void toUpper ();
00170 
00171   inline G4bool isNull() const;
00172 
00173   inline str_size index (const char*, G4int pos=0) const; 
00174   inline str_size index (char, G4int pos=0) const; 
00175   inline str_size index (const G4String&, str_size, str_size, caseCompare) const;
00176 
00177   inline const char* data() const;
00178 
00179   inline G4int strcasecompare(const char*, const char*) const;
00180 
00181   inline unsigned int hash( caseCompare cmp = exact ) const;
00182   inline unsigned int stlhash() const;
00183 
00184   // useful for supplying hash functions to template hash collection ctors
00185   //
00186   static inline unsigned int hash(const G4String&);
00187 
00188 };
00189 
00190 #include "G4String.icc"
00191 
00192 #endif

Generated on Fri Apr 11 17:09:57 2008 for Geant4 by  doxygen 1.4.7