blocxx
Char16.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2005, Vintela, Inc. All rights reserved.
3 * Copyright (C) 2006, Novell, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of
14 * Vintela, Inc.,
15 * nor Novell, Inc.,
16 * nor the names of its contributors or employees may be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *******************************************************************************/
32 
33 
39 #ifndef BLOCXX_CHAR16_HPP_INCLUDE_GUARD_
40 #define BLOCXX_CHAR16_HPP_INCLUDE_GUARD_
41 #include "blocxx/BLOCXX_config.h"
42 #include "blocxx/ArrayFwd.hpp"
43 #include "blocxx/Types.hpp"
44 #include "blocxx/Bool.hpp"
45 #include "blocxx/CommonFwd.hpp"
46 #include "blocxx/SafeBool.hpp"
47 #include <iosfwd>
48 
49 namespace BLOCXX_NAMESPACE
50 {
51 
52 class String;
56 class BLOCXX_COMMON_API Char16
57 {
58 public:
62  Char16() : m_value(0) {}
67  Char16(const Char16& arg) : m_value(arg.m_value) {}
72  explicit Char16(char c) : m_value(c) {}
78  explicit Char16(const String& x);
85  Char16(UInt16 val) : m_value(val) {}
90  explicit Char16(Int16 val) : m_value(val) {}
95  explicit Char16(UInt8 val) : m_value(val) {}
100  explicit Char16(Int8 val) : m_value(val) {}
105  explicit Char16(UInt32 val) : m_value(val) {}
110  explicit Char16(Int32 val) : m_value(val) {}
115  explicit Char16(UInt64 val) : m_value(static_cast<UInt16>(val)) {}
120  explicit Char16(Int64 val) : m_value(static_cast<UInt16>(val)) {}
125  explicit Char16(Real32 val) : m_value(static_cast<UInt16>(val)) {}
130  explicit Char16(Real64 val) : m_value(static_cast<UInt16>(val)) {}
135  explicit Char16(Bool val) : m_value(val) {}
139  UInt16 getValue() const { return m_value; }
143  operator UInt16() const { return getValue(); }
149  Char16& operator= (const Char16& arg)
150  {
151  m_value = arg.m_value;
152  return *this;
153  }
159  bool operator== (const Char16& arg) const
160  {
161  return m_value == arg.m_value;
162  }
168  bool operator!= (const Char16& arg) const
169  {
170  return m_value != arg.m_value;
171  }
177  bool operator< (const Char16& arg) const
178  {
179  return m_value < arg.m_value;
180  }
187  bool operator<= (const Char16& arg) const
188  {
189  return m_value <= arg.m_value;
190  }
196  bool operator> (const Char16& arg) const
197  {
198  return m_value > arg.m_value;
199  }
206  bool operator>= (const Char16& arg) const
207  {
208  return m_value >= arg.m_value;
209  }
215  Char16& operator+= (const Char16& arg)
216  {
217  m_value += arg.m_value;
218  return *this;
219  }
225  Char16& operator-= (const Char16& arg)
226  {
227  m_value -= arg.m_value;
228  return *this;
229  }
235  Char16& operator*= (const Char16& arg)
236  {
237  m_value *= arg.m_value;
238  return *this;
239  }
245  Char16& operator/= (const Char16& arg)
246  {
247  m_value /= arg.m_value;
248  return *this;
249  }
250 
252 
253 
256  String toUTF8() const BLOCXX_DEPRECATED; // in 3.1.0
260  String toString() const;
265  void writeObject(std::streambuf & ostrm) const;
270  void readObject(std::streambuf & istrm);
271 private:
272  UInt16 m_value;
273 };
274 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, Array, Char16);
275 
276 inline bool operator== (char c, const Char16& arg)
277 {
278  return Char16(c) == arg;
279 }
280 inline bool operator== (const Char16& arg, int v)
281 {
282  return (arg.getValue() == v);
283 }
284 inline bool operator== (int v, const Char16& arg)
285 {
286  return (arg.getValue() == v);
287 }
288 inline bool operator!= (const Char16& arg, int v)
289 {
290  return (arg.getValue() != v);
291 }
292 inline bool operator!= (int v, const Char16& arg)
293 {
294  return (arg.getValue() != v);
295 }
296 inline bool operator!= (char c, const Char16& arg)
297 {
298  return Char16(c) != arg;
299 }
300 inline bool operator< (char c, const Char16& arg)
301 {
302  return Char16(c) < arg;
303 }
304 inline bool operator<= (char c, const Char16& arg)
305 {
306  return Char16(c) <= arg;
307 }
308 inline bool operator> (char c, const Char16& arg)
309 {
310  return Char16(c) > arg;
311 }
312 inline bool operator>= (char c, const Char16& arg)
313 {
314  return Char16(c) >= arg;
315 }
316 inline Char16 operator+ (const Char16& arg1, const Char16& arg2)
317 {
318  return Char16(UInt16(arg1.getValue() + arg2.getValue()));
319 }
320 inline Char16 operator- (const Char16& arg1, const Char16& arg2)
321 {
322  return Char16(UInt16(arg1.getValue() - arg2.getValue()));
323 }
324 inline Char16 operator* (const Char16& arg1, const Char16& arg2)
325 {
326  return Char16(UInt16(arg1.getValue() * arg2.getValue()));
327 }
328 inline Char16 operator/ (const Char16& arg1, const Char16& arg2)
329 {
330  return Char16(UInt16(arg1.getValue() / arg2.getValue()));
331 }
332 BLOCXX_COMMON_API std::ostream& operator<< (std::ostream& ostrm, const Char16& arg);
333 
334 } // end namespace BLOCXX_NAMESPACE
335 
336 #endif