GenApi 3.5.1
GCString.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// (c) 2005 by STEMMER IMAGING
3//
4// License: This file is published under the license of the EMVA GenICam Standard Group.
5// A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
6// If for some reason you are missing this file please contact the EMVA or visit the website
7// (http://www.genicam.org) for a full copy.
8//
9// THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
10// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
11// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
13// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
14// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
15// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
16// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
17// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
18// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
19// POSSIBILITY OF SUCH DAMAGE.
20//
21//-----------------------------------------------------------------------------
25
26
27#ifndef GENICAM_GCSTRING_H
28#define GENICAM_GCSTRING_H
29
30#include <new>
31#include <string>
32#include <iostream>
33#include <Base/GCTypes.h>
34
35#pragma pack(push, 8)
36
37
42#define GCSTRING_NPOS size_t(-1)
43
44namespace GENICAM_NAMESPACE
45{
50 class GCBASE_API gcstring
51 {
52# if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
53 public:
55 class GCBASE_API gcwchar
56 {
57 public:
59 explicit gcwchar( size_t n );
60
61 // copy constructor
62 gcwchar( const gcwchar &rhs );
63
64 // assignment operator
65 gcwchar & operator = (const gcwchar &rhs);
66
68 const wchar_t * c_str() const;
69
71 size_t length() const;
72
74 ~gcwchar();
75 private:
76 class impl;
77 impl *m_pimpl;
78 };
79
80# endif
81
82 // Ctor / Dtor
83 // -------------------------------------------------------------------------
84 public:
85 gcstring ();
86 gcstring ( const char *pc );
87 gcstring ( const char *pc, size_t n );
88 gcstring ( size_t count, char ch );
89 gcstring ( const gcstring &str );
90# if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
91 explicit gcstring ( const wchar_t *pBufferUTF16 );
92 gcstring ( const wchar_t *pBufferUTF16, size_t n );
93# endif
94 virtual ~gcstring ( void );
95
96 // Data access
97 // -------------------------------------------------------------------------
98 public:
99 virtual gcstring & append ( const gcstring &str );
100 virtual gcstring & append ( size_t count, char ch );
101 virtual gcstring & assign ( const gcstring &str );
102 virtual gcstring & assign ( size_t count, char ch );
103 virtual gcstring & assign ( const char *pc );
104 virtual gcstring & assign ( const char *pc, size_t n );
105# if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
106 virtual gcstring & assign ( const wchar_t *pStringUTF16 );
107 virtual gcstring & assign ( const wchar_t *pStringUTF16, int n );
108# endif
109 virtual int compare ( const gcstring &str ) const;
110# if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
111 virtual gcwchar w_str ( void ) const;
112# endif
113 virtual const char *c_str ( void ) const;
114 virtual bool empty ( void ) const;
115 virtual size_t find ( char ch, size_t offset = 0 ) const;
116 virtual size_t find ( const gcstring &str, size_t offset = 0 ) const;
117 virtual size_t find ( const gcstring &str, size_t offset, size_t count ) const;
118 virtual size_t find ( const char* pc, size_t offset = 0) const;
119 virtual size_t find ( const char* pc, size_t offset, size_t count ) const;
120 virtual size_t length ( void ) const;
121 virtual size_t size ( void ) const;
122 virtual void resize ( size_t n );
123 virtual void reserve ( size_t n = 0 );
124 virtual gcstring & erase ( size_t pos, size_t len = GCSTRING_NPOS );
125 virtual size_t max_size ( ) const;
126 virtual gcstring substr ( size_t offset = 0, size_t count = GCSTRING_NPOS ) const;
127 virtual size_t find_first_of ( const gcstring &str, size_t offset = 0 ) const;
128 virtual size_t find_first_not_of ( const gcstring &str, size_t offset = 0 ) const;
129 virtual size_t find_last_of ( const gcstring& str, size_t offset = GCSTRING_NPOS ) const;
130 virtual size_t find_last_of ( char c, size_t offset = GCSTRING_NPOS ) const;
131 virtual size_t find_last_not_of ( const gcstring& str, size_t offset = GCSTRING_NPOS ) const;
132 virtual size_t find_last_not_of ( char c, size_t offset = GCSTRING_NPOS ) const;
133 static size_t _npos ( void );
134 virtual void swap ( gcstring &Right );
135
136
137 // Operators
138 // -------------------------------------------------------------------------
139 public:
140 bool operator != ( const gcstring &str ) const;
141 bool operator != ( const char *pc ) const;
142 gcstring & operator += ( const gcstring &str );
143 gcstring operator += ( const gcstring &str ) const;
144 gcstring & operator += ( const char *pc );
145
146 gcstring & operator += ( char ch );
147 gcstring operator += ( char ch ) const;
148 gcstring & operator = ( const gcstring &str );
149# if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
150 gcstring & operator = ( const wchar_t *pStringUTF16 );
151# endif
152 bool operator == ( const gcstring &str ) const;
153 bool operator == ( const char *pc ) const;
154 bool operator < ( const gcstring &str ) const;
155 bool operator > ( const gcstring &str ) const;
156 operator const char * ( void ) const;
157 void operator delete ( void *pWhere );
158 void operator delete ( void *pWhere, void *pNewWhere );
159 void * operator new ( size_t uiSize );
160 void * operator new ( size_t uiSize, void *pWhere );
161 GCBASE_API
162 friend gcstring operator + ( const gcstring &left, const gcstring &right );
163 GCBASE_API
164 friend gcstring operator + ( const gcstring &left, const char *right );
165 GCBASE_API
166 friend gcstring operator + ( const char *left, const gcstring &right );
167
168 // Member
169 // -------------------------------------------------------------------------
170 private:
171 // redundant pointer to make the possible to see the contents of the string in the debugger
172 const char* m_psz;
173 // actual std::string object
174 uint8_t m_opaqueData[64];
175
176 // Constants
177 // -------------------------------------------------------------------------
178 public:
179 // Beware : this static member prevents delay loading
180 // use _npos() instead
181 static const size_t npos;
182 };
183}
184
185namespace GENICAM_NAMESPACE
186{
187 // this is necessary due to the circular dependency between string/exception
188 GCBASE_API void ThrowBadAlloc(const char *source, int line);
189
192 inline std::istream & getline(std::istream& is, GENICAM_NAMESPACE::gcstring& str)
193 {
194 try
195 {
196 std::string tmp;
197 std::getline(is, tmp);
198 str.assign(tmp.c_str(), tmp.size());
199 }
200 catch(std::bad_alloc &)
201 {
202 ThrowBadAlloc(__FILE__, __LINE__);
203 }
204 return is;
205 }
206
209 inline std::istream & getline(std::istream& is, GENICAM_NAMESPACE::gcstring& str, char delim)
210 {
211 try
212 {
213 std::string tmp;
214 std::getline(is, tmp, delim);
215 str.assign(tmp.c_str(), tmp.size());
216 }
217 catch(std::bad_alloc &)
218 {
219 ThrowBadAlloc(__FILE__, __LINE__);
220 }
221 return is;
222 }
223}
224
225
226
229inline std::ostream & operator <<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
230{
231 try
232 {
233 // use formatted output operator of std::string
234 ostr << str.c_str();
235 }
236 catch(std::bad_alloc &)
237 {
238 GENICAM_NAMESPACE::ThrowBadAlloc(__FILE__, __LINE__);
239 }
240 return ostr;
241}
242
245inline std::istream & operator >>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
246{
247 try
248 {
249 std::string tmp;
250 istr >> tmp;
251 str.assign(tmp.c_str(), tmp.size());
252 }
253 catch(std::bad_alloc &)
254 {
255 GENICAM_NAMESPACE::ThrowBadAlloc(__FILE__, __LINE__);
256 }
257 return istr;
258}
259
260#pragma pack(pop)
261
262#endif // GENICAM_GCSTRING_H
#define GCSTRING_NPOS
Indicates either 'not found' or 'all remaining characters'.
Definition GCString.h:42
Platform-dependent type definitions.
A string class which is a clone of std::string.
Definition GCString.h:51
std::istream & operator>>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
Definition GCString.h:245
std::ostream & operator<<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
Definition GCString.h:229
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
Definition GCString.h:192