All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
22 ****************************************************************************/
23 
27 
28 
29 #ifndef GENICAM_GCSTRING_H
30 #define GENICAM_GCSTRING_H
31 
32 #include <new>
33 #include <string>
34 #include <iostream>
35 #include <Base/GCTypes.h>
36 
37 #pragma pack(push, 8)
38 
39 
44 #define GCSTRING_NPOS size_t(-1)
45 
46 namespace GENICAM_NAMESPACE
47 {
52  class GCBASE_API gcstring
53  {
54 # if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
55  public:
57  class GCBASE_API gcwchar
58  {
59  public:
61  explicit gcwchar( size_t n );
62 
63  // copy constructor
64  gcwchar( const gcwchar &rhs );
65 
66  // assignment operator
67  gcwchar & operator = (const gcwchar &rhs);
68 
70  const wchar_t * c_str() const;
71 
73  size_t length() const;
74 
76  ~gcwchar();
77  private:
78  class impl;
79  impl *m_pimpl;
80  };
81 
82 # endif
83 
84  // Ctor / Dtor
85  // -------------------------------------------------------------------------
86  public:
87  gcstring ();
88  gcstring ( const char *pc );
89  gcstring ( const char *pc, size_t n );
90  gcstring ( size_t count, char ch );
91  gcstring ( const gcstring &str );
92 # if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
93  explicit gcstring ( const wchar_t *pBufferUTF16 );
94  gcstring ( const wchar_t *pBufferUTF16, size_t n );
95 # endif
96  virtual ~gcstring ( void );
97 
98  // Data access
99  // -------------------------------------------------------------------------
100  public:
101  virtual gcstring & append ( const gcstring &str );
102  virtual gcstring & append ( size_t count, char ch );
103  virtual gcstring & assign ( const gcstring &str );
104  virtual gcstring & assign ( size_t count, char ch );
105  virtual gcstring & assign ( const char *pc );
106  virtual gcstring & assign ( const char *pc, size_t n );
107 # if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
108  virtual gcstring & assign ( const wchar_t *pStringUTF16 );
109  virtual gcstring & assign ( const wchar_t *pStringUTF16, int n );
110 # endif
111  virtual int compare ( const gcstring &str ) const;
112 # if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
113  virtual gcwchar w_str ( void ) const;
114 # endif
115  virtual const char *c_str ( void ) const;
116  virtual bool empty ( void ) const;
117  virtual size_t find ( char ch, size_t offset = 0 ) const;
118  virtual size_t find ( const gcstring &str, size_t offset = 0 ) const;
119  virtual size_t find ( const gcstring &str, size_t offset, size_t count ) const;
120  virtual size_t find ( const char* pc, size_t offset = 0) const;
121  virtual size_t find ( const char* pc, size_t offset, size_t count ) const;
122  virtual size_t length ( void ) const;
123  virtual size_t size ( void ) const;
124  virtual void resize ( size_t n );
125  virtual void reserve ( size_t n = 0 );
126  virtual gcstring & erase ( size_t pos, size_t len = GCSTRING_NPOS );
127  virtual size_t max_size ( ) const;
128  virtual gcstring substr ( size_t offset = 0, size_t count = GCSTRING_NPOS ) const;
129  virtual size_t find_first_of ( const gcstring &str, size_t offset = 0 ) const;
130  virtual size_t find_first_not_of ( const gcstring &str, size_t offset = 0 ) const;
131  virtual size_t find_last_of ( const gcstring& str, size_t offset = GCSTRING_NPOS ) const;
132  virtual size_t find_last_of ( char c, size_t offset = GCSTRING_NPOS ) const;
133  virtual size_t find_last_not_of ( const gcstring& str, size_t offset = GCSTRING_NPOS ) const;
134  virtual size_t find_last_not_of ( char c, size_t offset = GCSTRING_NPOS ) const;
135  static size_t _npos ( void );
136  virtual void swap ( gcstring &Right );
137 
138 
139  // Operators
140  // -------------------------------------------------------------------------
141  public:
142  bool operator != ( const gcstring &str ) const;
143  bool operator != ( const char *pc ) const;
144  gcstring & operator += ( const gcstring &str );
145  gcstring operator += ( const gcstring &str ) const;
146  gcstring & operator += ( const char *pc );
147 
148  gcstring & operator += ( char ch );
149  gcstring operator += ( char ch ) const;
150  gcstring & operator = ( const gcstring &str );
151 # if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
152  gcstring & operator = ( const wchar_t *pStringUTF16 );
153 # endif
154  bool operator == ( const gcstring &str ) const;
155  bool operator == ( const char *pc ) const;
156  bool operator < ( const gcstring &str ) const;
157  bool operator > ( const gcstring &str ) const;
158  operator const char * ( void ) const;
159  void operator delete ( void *pWhere );
160  void operator delete ( void *pWhere, void *pNewWhere );
161  void * operator new ( size_t uiSize );
162  void * operator new ( size_t uiSize, void *pWhere );
163  GCBASE_API
164  friend gcstring operator + ( const gcstring &left, const gcstring &right );
165  GCBASE_API
166  friend gcstring operator + ( const gcstring &left, const char *right );
167  GCBASE_API
168  friend gcstring operator + ( const char *left, const gcstring &right );
169 
170  // Member
171  // -------------------------------------------------------------------------
172  private:
173  // redundant pointer to make the possible to see the contents of the string in the debugger
174  const char* m_psz;
175  // actual std::string object
176  uint8_t m_opaqueData[64];
177 
178  // Constants
179  // -------------------------------------------------------------------------
180  public:
181  // Beware : this static member prevents delay loading
182  // use _npos() instead
183  static const size_t npos;
184  };
185 }
186 
187 namespace GENICAM_NAMESPACE
188 {
189  // this is necessary due to the circular dependency between string/exception
190  GCBASE_API void ThrowBadAlloc(const char *source, int line);
191 
194  inline std::istream & getline(std::istream& is, GENICAM_NAMESPACE::gcstring& str)
195  {
196  try
197  {
198  std::string tmp;
199  std::getline(is, tmp);
200  str.assign(tmp.c_str(), tmp.size());
201  }
202  catch(std::bad_alloc &)
203  {
204  ThrowBadAlloc(__FILE__, __LINE__);
205  }
206  return is;
207  }
208 
211  inline std::istream & getline(std::istream& is, GENICAM_NAMESPACE::gcstring& str, char delim)
212  {
213  try
214  {
215  std::string tmp;
216  std::getline(is, tmp, delim);
217  str.assign(tmp.c_str(), tmp.size());
218  }
219  catch(std::bad_alloc &)
220  {
221  ThrowBadAlloc(__FILE__, __LINE__);
222  }
223  return is;
224  }
225 }
226 
227 
228 
231 inline std::ostream & operator <<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
232 {
233  try
234  {
235  // use formatted output operator of std::string
236  ostr << str.c_str();
237  }
238  catch(std::bad_alloc &)
239  {
240  GENICAM_NAMESPACE::ThrowBadAlloc(__FILE__, __LINE__);
241  }
242  return ostr;
243 }
244 
247 inline std::istream & operator >>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
248 {
249  try
250  {
251  std::string tmp;
252  istr >> tmp;
253  str.assign(tmp.c_str(), tmp.size());
254  }
255  catch(std::bad_alloc &)
256  {
257  GENICAM_NAMESPACE::ThrowBadAlloc(__FILE__, __LINE__);
258  }
259  return istr;
260 }
261 
262 #pragma pack(pop)
263 
264 #endif // GENICAM_GCSTRING_H
GCSTRING_NPOS
#define GCSTRING_NPOS
Indicates either 'not found' or 'all remaining characters'.
Definition: GCString.h:44
GENICAM_NAMESPACE::gcstring::m_psz
const char * m_psz
Definition: GCString.h:174
GENICAM_NAMESPACE
Definition: GCArray.h:32
GENICAM_NAMESPACE::gcstring
A string class which is a clone of std::string.
Definition: GCString.h:52
GENICAM_NAMESPACE::gcstring::npos
static const size_t npos
Definition: GCString.h:183
GENICAM_NAMESPACE::gcstring::assign
virtual gcstring & assign(const gcstring &str)
GENICAM_NAMESPACE::getline
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str, char delim)
STL getline.
Definition: GCString.h:211
operator<<
std::ostream & operator<<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
STL operator out.
Definition: GCString.h:231
GENICAM_NAMESPACE::getline
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
STL getline.
Definition: GCString.h:194
GENAPI_NAMESPACE::operator==
bool operator==(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:98
GCTypes.h
Platform-dependent type definitions.
GENICAM_NAMESPACE::ThrowBadAlloc
GCBASE_API void ThrowBadAlloc(const char *source, int line)
GENICAM_NAMESPACE::gcstring::c_str
virtual const char * c_str(void) const
GENAPI_NAMESPACE::operator!=
bool operator!=(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:103
GENAPI_NAMESPACE::operator=
virtual IBoolean & operator=(bool Value)
Set node value.
Definition: IBoolean.h:64
left
LOG4CPP_EXPORT CategoryStream & left(CategoryStream &os)
left manipulator
operator>>
std::istream & operator>>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
STL operator in.
Definition: GCString.h:247


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11