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$
00028 //
00029 // 
00030 //---------------------------------------------------------------
00031 //  GEANT 4 class header file
00032 //
00033 //  G4String
00034 //
00035 //  Class description:
00036 //
00037 //  Definition of a Geant4 string.
00038 //  Derived from the Rogue Wave implementation of RWCString;
00039 //  it uses intrinsically STL string.
00040 
00041 //---------------------------------------------------------------
00042 
00043 #ifndef __G4String
00044 #define __G4String
00045 
00046 #include <stdio.h>
00047 #include <string>
00048 #include <cstring>
00049 
00050 #include "G4Types.hh"
00051 #include <iostream>
00052 
00053 #ifdef WIN32
00054   #define strcasecmp _stricmp
00055 #endif
00056 
00057 typedef std::string::size_type str_size;
00058 
00059 class G4String;
00060 
00061 class G4SubString
00062 {
00063 public:
00064 
00065   inline G4SubString(const G4SubString&);
00066 
00067   inline G4SubString& operator=(const char*);         
00068 
00069   inline G4SubString& operator=(const G4String&);
00070   inline G4SubString& operator=(const G4SubString&);
00071  
00072   inline char& operator()(str_size);
00073   inline char  operator()(str_size) const;
00074   inline char& operator[](str_size);
00075   inline char  operator[](str_size) const;
00076 
00077   inline G4int operator!() const;
00078 
00079   inline G4bool operator==(const G4String&) const;
00080   inline G4bool operator==(const char*) const;
00081   inline G4bool operator!=(const G4String&) const;
00082   inline G4bool operator!=(const char*) const;
00083 
00084   inline str_size length() const;
00085   inline str_size start() const;
00086 
00087   // For detecting null substrings
00088   //
00089   inline G4bool isNull() const;
00090 
00091 private:
00092 
00093   inline G4SubString(G4String&, str_size, str_size);
00094 
00095   G4String*    mystring;     
00096   str_size     mystart;
00097   str_size     extent;
00098 
00099   friend class G4String;
00100 
00101 };
00102  
00103 
00104 class G4String : public std::string
00105 {
00106 
00107   typedef std::string std_string;
00108 
00109 public: 
00110 
00111   enum caseCompare { exact, ignoreCase };
00112   enum stripType { leading, trailing, both };
00113 
00114   inline G4String ();
00115   inline G4String ( char );
00116   inline G4String ( const char * );
00117   inline G4String ( const char *, str_size );
00118   inline G4String ( const G4String& );
00119   inline G4String ( const G4SubString& );
00120   inline G4String ( const std::string & );
00121   ~G4String () {}
00122 
00123   inline G4String& operator=(const G4String&);
00124   inline G4String& operator=(const std::string &);
00125   inline G4String& operator=(const char*);
00126 
00127   inline char operator () (str_size) const; 
00128   inline char& operator () (str_size);
00129 
00130   inline G4String& operator+=(const G4SubString&);
00131   inline G4String& operator+=(const char*);
00132   inline G4String& operator+=(const std::string &);
00133   inline G4String& operator+=(const char&);
00134   inline G4bool operator==(const G4String&) const;
00135   inline G4bool operator==(const char*) const;
00136   inline G4bool operator!=(const G4String&) const;
00137   inline G4bool operator!=(const char*) const;
00138 
00139   inline operator const char*() const;
00140   inline G4SubString operator()(str_size, str_size);
00141 
00142   inline G4int compareTo(const char*, caseCompare mode=exact) const;
00143   inline G4int compareTo(const G4String&, caseCompare mode=exact) const;
00144 
00145   inline G4String& prepend (const char*);
00146   inline G4String& append (const G4String&);
00147 
00148   inline std::istream& readLine (std::istream&, G4bool skipWhite=true);
00149   
00150   inline G4String& replace (unsigned int, unsigned int, 
00151                              const char*, unsigned int );
00152   inline G4String& replace(str_size, str_size, const char*);
00153 
00154   inline G4String& remove(str_size);
00155   inline G4String& remove(str_size, str_size);
00156 
00157   inline G4int first(char) const;
00158   inline G4int last(char) const;
00159 
00160   inline G4bool contains(const std::string&) const;
00161   inline G4bool contains(char) const;
00162 
00163   // stripType = 0 beginning
00164   // stripType = 1 end
00165   // stripType = 2 both
00166   //
00167   inline G4String strip (G4int strip_Type=trailing, char c=' ');
00168 
00169   inline void toLower ();
00170   inline void toUpper ();
00171 
00172   inline G4bool isNull() const;
00173 
00174   inline str_size index (const char*, G4int pos=0) const; 
00175   inline str_size index (char, G4int pos=0) const; 
00176   inline str_size index (const G4String&, str_size, str_size, caseCompare) const;
00177 
00178   inline const char* data() const;
00179 
00180   inline G4int strcasecompare(const char*, const char*) const;
00181 
00182   inline unsigned int hash( caseCompare cmp = exact ) const;
00183   inline unsigned int stlhash() const;
00184 };
00185 
00186 #include "G4String.icc"
00187 
00188 #endif

Generated on Mon May 27 17:49:55 2013 for Geant4 by  doxygen 1.4.7