source: trunk/source/global/management/include/G4String.hh@ 1109

Last change on this file since 1109 was 1058, checked in by garnier, 17 years ago

file release beta

File size: 5.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4String.hh,v 1.10 2008/12/08 14:16:05 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31//---------------------------------------------------------------
32// GEANT 4 class header file
33//
34// G4String
35//
36// Class description:
37//
38// Definition of a Geant4 string.
39// Derived from the Rogue Wave implementation of RWCString;
40// it uses intrinsically STL string.
41
42//---------------------------------------------------------------
43
44#ifndef __G4String
45#define __G4String
46
47#include <stdio.h>
48#include <string>
49#include <cstring>
50
51#include "G4Types.hh"
52#include <iostream>
53
54#ifdef WIN32
55 #define strcasecmp _stricmp
56#endif
57
58typedef std::string::size_type str_size;
59
60class G4String;
61
62class G4SubString
63{
64public:
65
66 inline G4SubString(const G4SubString&);
67
68 inline G4SubString& operator=(const char*);
69
70 inline G4SubString& operator=(const G4String&);
71 inline G4SubString& operator=(const G4SubString&);
72
73 inline char& operator()(str_size);
74 inline char operator()(str_size) const;
75 inline char& operator[](str_size);
76 inline char operator[](str_size) const;
77
78 inline G4int operator!() const;
79
80 inline G4bool operator==(G4String) const;
81 inline G4bool operator==(const char*) const;
82 inline G4bool operator!=(G4String) const;
83 inline G4bool operator!=(const char*) const;
84
85 inline str_size length() const;
86 inline str_size start() const;
87
88 // For detecting null substrings
89 //
90 inline G4bool isNull() const;
91
92private:
93
94 inline G4SubString(G4String&, str_size, str_size);
95
96 G4String* mystring;
97 str_size mystart;
98 str_size extent;
99
100 friend class G4String;
101
102};
103
104
105class G4String : public std::string
106{
107
108 typedef std::string std_string;
109
110public:
111
112 enum caseCompare { exact, ignoreCase };
113 enum stripType { leading, trailing, both };
114
115 inline G4String ();
116 inline G4String ( char );
117 inline G4String ( const char * );
118 inline G4String ( const char *, str_size );
119 inline G4String ( const G4String& );
120 inline G4String ( const G4SubString& );
121 inline G4String ( const std::string & );
122 ~G4String () {}
123
124 inline G4String& operator=(const G4String&);
125 inline G4String& operator=(const std::string &);
126 inline G4String& operator=(const char*);
127
128 inline char operator () (str_size) const;
129 inline char& operator () (str_size);
130
131 inline G4String& operator+=(const G4SubString&);
132 inline G4String& operator+=(const char*);
133 inline G4String& operator+=(const std::string &);
134 inline G4String& operator+=(const char&);
135 inline G4bool operator==(const G4String&) const;
136 inline G4bool operator==(const char*) const;
137 inline G4bool operator!=(const G4String&) const;
138 inline G4bool operator!=(const char*) const;
139
140 //inline G4String operator () (unsigned int, unsigned int);
141 inline operator const char*() const;
142 inline G4SubString operator()(str_size, str_size);
143
144 inline G4int compareTo(const char*, caseCompare mode=exact);
145 inline G4int compareTo(const G4String&, caseCompare mode=exact);
146
147 inline G4String& prepend (const char*);
148 inline G4String& append (const G4String&);
149
150 inline std::istream& readLine (std::istream&, G4bool skipWhite=true);
151
152 inline G4String& replace (unsigned int, unsigned int,
153 const char*, unsigned int );
154 inline G4String& replace(str_size, str_size, const char*);
155
156 inline G4String& remove(str_size);
157 inline G4String& remove(str_size, str_size);
158
159 inline G4int first(char) const;
160 inline G4int last(char) const;
161
162 inline G4bool contains(std::string) const;
163 inline G4bool contains(char) const;
164
165 // stripType = 0 beginning
166 // stripType = 1 end
167 // stripType = 2 both
168 //
169 inline G4String strip (G4int strip_Type=trailing, char c=' ');
170
171 inline void toLower ();
172 inline void toUpper ();
173
174 inline G4bool isNull() const;
175
176 inline str_size index (const char*, G4int pos=0) const;
177 inline str_size index (char, G4int pos=0) const;
178 inline str_size index (const G4String&, str_size, str_size, caseCompare) const;
179
180 inline const char* data() const;
181
182 inline G4int strcasecompare(const char*, const char*) const;
183
184 inline unsigned int hash( caseCompare cmp = exact ) const;
185 inline unsigned int stlhash() const;
186
187 // useful for supplying hash functions to template hash collection ctors
188 //
189 static inline unsigned int hash(const G4String&);
190
191};
192
193#include "G4String.icc"
194
195#endif
Note: See TracBrowser for help on using the repository browser.