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 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  static size_t _npos ( void );
130  virtual void swap ( gcstring &Right );
131 
132 
133  // Operators
134  // -------------------------------------------------------------------------
135  public:
136  bool operator != ( const gcstring &str ) const;
137  bool operator != ( const char *pc ) const;
138  gcstring & operator += ( const gcstring &str );
139  gcstring operator += ( const gcstring &str ) const;
140  gcstring & operator += ( const char *pc );
141 
142  gcstring & operator += ( char ch );
143  gcstring operator += ( char ch ) const;
144  gcstring & operator = ( const gcstring &str );
145 # if defined(_MSC_VER) && !defined(PHARLAP_WIN32)
146  gcstring & operator = ( const wchar_t *pStringUTF16 );
147 # endif
148  bool operator == ( const gcstring &str ) const;
149  bool operator == ( const char *pc ) const;
150  bool operator < ( const gcstring &str ) const;
151  bool operator > ( const gcstring &str ) const;
152  operator const char * ( void ) const;
153  void operator delete ( void *pWhere );
154  void operator delete ( void *pWhere, void *pNewWhere );
155  void * operator new ( size_t uiSize );
156  void * operator new ( size_t uiSize, void *pWhere );
157  GCBASE_API
158  friend gcstring operator + ( const gcstring &left, const gcstring &right );
159  GCBASE_API
160  friend gcstring operator + ( const gcstring &left, const char *right );
161  GCBASE_API
162  friend gcstring operator + ( const char *left, const gcstring &right );
163 
164  // Member
165  // -------------------------------------------------------------------------
166  private:
167  // redundant pointer to make the possible to see the contents of the string in the debugger
168  const char* m_psz;
169  // actual std::string object
170  uint8_t m_opaqueData[64];
171 
172  // Constants
173  // -------------------------------------------------------------------------
174  public:
175  // Beware : this static member prevents delay loading
176  // use _npos() instead
177  static const size_t npos;
178  };
179 }
180 
181 namespace GENICAM_NAMESPACE
182 {
183  // this is necessary due to the circular dependency between string/exception
184  GCBASE_API void ThrowBadAlloc(const char *source, int line);
185 
188  inline std::istream & getline(std::istream& is, GENICAM_NAMESPACE::gcstring& str)
189  {
190  try
191  {
192  std::string tmp;
193  std::getline(is, tmp);
194  str.assign(tmp.c_str(), tmp.size());
195  }
196  catch(std::bad_alloc &)
197  {
198  ThrowBadAlloc(__FILE__, __LINE__);
199  }
200  return is;
201  }
202 
205  inline std::istream & getline(std::istream& is, GENICAM_NAMESPACE::gcstring& str, char delim)
206  {
207  try
208  {
209  std::string tmp;
210  std::getline(is, tmp, delim);
211  str.assign(tmp.c_str(), tmp.size());
212  }
213  catch(std::bad_alloc &)
214  {
215  ThrowBadAlloc(__FILE__, __LINE__);
216  }
217  return is;
218  }
219 }
220 
221 
222 
225 inline std::ostream & operator <<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
226 {
227  try
228  {
229  // use formatted output operator of std::string
230  ostr << str.c_str();
231  }
232  catch(std::bad_alloc &)
233  {
234  GENICAM_NAMESPACE::ThrowBadAlloc(__FILE__, __LINE__);
235  }
236  return ostr;
237 }
238 
241 inline std::istream & operator >>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
242 {
243  try
244  {
245  std::string tmp;
246  istr >> tmp;
247  str.assign(tmp.c_str(), tmp.size());
248  }
249  catch(std::bad_alloc &)
250  {
251  GENICAM_NAMESPACE::ThrowBadAlloc(__FILE__, __LINE__);
252  }
253  return istr;
254 }
255 
256 #pragma pack(pop)
257 
258 #endif // GENICAM_GCSTRING_H
bool operator!=(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:103
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
STL getline.
Definition: GCString.h:188
virtual void operator=(bool Value)
Set node value.
Definition: IBoolean.h:64
static const size_t npos
Definition: GCString.h:177
bool operator==(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:98
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str, char delim)
STL getline.
Definition: GCString.h:205
std::ostream & operator<<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
STL operator out.
Definition: GCString.h:225
LOG4CPP_EXPORT CategoryStream & left(CategoryStream &os)
left manipulator
virtual gcstring & assign(const gcstring &str)
std::istream & operator>>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
STL operator in.
Definition: GCString.h:241
A string class which is a clone of std::string.
Definition: GCString.h:52
GCBASE_API void ThrowBadAlloc(const char *source, int line)
#define GCSTRING_NPOS
Indicates either &#39;not found&#39; or &#39;all remaining characters&#39;.
Definition: GCString.h:44
virtual const char * c_str(void) const
Platform-dependent type definitions.


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:40