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.8 2008/03/13 09:35:08 gcosmo Exp $ |
---|
28 | // GEANT4 tag $Name: HEAD $ |
---|
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 | |
---|
58 | typedef std::string::size_type str_size; |
---|
59 | |
---|
60 | class G4String; |
---|
61 | |
---|
62 | class G4SubString |
---|
63 | { |
---|
64 | public: |
---|
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 | |
---|
92 | private: |
---|
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 | |
---|
105 | class G4String : public std::string |
---|
106 | { |
---|
107 | |
---|
108 | typedef std::string std_string; |
---|
109 | |
---|
110 | public: |
---|
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 G4String& ); |
---|
119 | inline G4String ( const G4SubString& ); |
---|
120 | inline G4String ( const std::string & ); |
---|
121 | ~G4String () {} |
---|
122 | |
---|
123 | inline G4String& operator=(const G4String&); |
---|
124 | inline G4String& operator=(const std::string &); |
---|
125 | inline G4String& operator=(const char*); |
---|
126 | |
---|
127 | inline char operator () (str_size) const; |
---|
128 | inline char& operator () (str_size); |
---|
129 | |
---|
130 | inline G4String& operator+=(const G4SubString&); |
---|
131 | inline G4String& operator+=(const char*); |
---|
132 | inline G4String& operator+=(const std::string &); |
---|
133 | inline G4String& operator+=(const char&); |
---|
134 | inline G4bool operator==(const G4String&) const; |
---|
135 | inline G4bool operator==(const char*) const; |
---|
136 | inline G4bool operator!=(const G4String&) const; |
---|
137 | inline G4bool operator!=(const char*) const; |
---|
138 | |
---|
139 | //inline G4String operator () (unsigned int, unsigned int); |
---|
140 | inline operator const char*() const; |
---|
141 | inline G4SubString operator()(str_size, str_size); |
---|
142 | |
---|
143 | inline G4int compareTo(const char*, caseCompare mode=exact); |
---|
144 | inline G4int compareTo(const G4String&, caseCompare mode=exact); |
---|
145 | |
---|
146 | inline G4String& prepend (const char*); |
---|
147 | inline G4String& append (const G4String&); |
---|
148 | |
---|
149 | inline std::istream& readLine (std::istream&, G4bool skipWhite=true); |
---|
150 | |
---|
151 | inline G4String& replace (unsigned int, unsigned int, |
---|
152 | const char*, unsigned int ); |
---|
153 | inline G4String& replace(str_size, str_size, const char*); |
---|
154 | |
---|
155 | inline G4String& remove(str_size); |
---|
156 | inline G4String& remove(str_size, str_size); |
---|
157 | |
---|
158 | inline G4int first(char) const; |
---|
159 | inline G4int last(char) const; |
---|
160 | |
---|
161 | inline G4bool contains(std::string) const; |
---|
162 | inline G4bool contains(char) const; |
---|
163 | |
---|
164 | // stripType = 0 beginning |
---|
165 | // stripType = 1 end |
---|
166 | // stripType = 2 both |
---|
167 | // |
---|
168 | inline G4String strip (G4int strip_Type=trailing, char c=' '); |
---|
169 | |
---|
170 | inline void toLower (); |
---|
171 | inline void toUpper (); |
---|
172 | |
---|
173 | inline G4bool isNull() const; |
---|
174 | |
---|
175 | inline str_size index (const char*, G4int pos=0) const; |
---|
176 | inline str_size index (char, G4int pos=0) const; |
---|
177 | inline str_size index (const G4String&, str_size, str_size, caseCompare) const; |
---|
178 | |
---|
179 | inline const char* data() const; |
---|
180 | |
---|
181 | inline G4int strcasecompare(const char*, const char*) const; |
---|
182 | |
---|
183 | inline unsigned int hash( caseCompare cmp = exact ) const; |
---|
184 | inline unsigned int stlhash() const; |
---|
185 | |
---|
186 | // useful for supplying hash functions to template hash collection ctors |
---|
187 | // |
---|
188 | static inline unsigned int hash(const G4String&); |
---|
189 | |
---|
190 | }; |
---|
191 | |
---|
192 | #include "G4String.icc" |
---|
193 | |
---|
194 | #endif |
---|