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
38
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
49namespace BLOCXX_NAMESPACE
50{
51
52class String;
56class BLOCXX_COMMON_API Char16
57{
58public:
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 }
154
159 bool operator== (const Char16& arg) const
160 {
161 return m_value == arg.m_value;
162 }
163
168 bool operator!= (const Char16& arg) const
169 {
170 return m_value != arg.m_value;
171 }
172
177 bool operator< (const Char16& arg) const
178 {
179 return m_value < arg.m_value;
180 }
181
187 bool operator<= (const Char16& arg) const
188 {
189 return m_value <= arg.m_value;
190 }
191
196 bool operator> (const Char16& arg) const
197 {
198 return m_value > arg.m_value;
199 }
200
206 bool operator>= (const Char16& arg) const
207 {
208 return m_value >= arg.m_value;
209 }
210
215 Char16& operator+= (const Char16& arg)
216 {
217 m_value += arg.m_value;
218 return *this;
219 }
220
225 Char16& operator-= (const Char16& arg)
226 {
227 m_value -= arg.m_value;
228 return *this;
229 }
230
235 Char16& operator*= (const Char16& arg)
236 {
237 m_value *= arg.m_value;
238 return *this;
239 }
240
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);
271private:
272 UInt16 m_value;
273};
275
276inline bool operator== (char c, const Char16& arg)
277{
278 return Char16(c) == arg;
279}
280inline bool operator== (const Char16& arg, int v)
281{
282 return (arg.getValue() == v);
283}
284inline bool operator== (int v, const Char16& arg)
285{
286 return (arg.getValue() == v);
287}
288inline bool operator!= (const Char16& arg, int v)
289{
290 return (arg.getValue() != v);
291}
292inline bool operator!= (int v, const Char16& arg)
293{
294 return (arg.getValue() != v);
295}
296inline bool operator!= (char c, const Char16& arg)
297{
298 return Char16(c) != arg;
299}
300inline bool operator< (char c, const Char16& arg)
301{
302 return Char16(c) < arg;
303}
304inline bool operator<= (char c, const Char16& arg)
305{
306 return Char16(c) <= arg;
307}
308inline bool operator> (char c, const Char16& arg)
309{
310 return Char16(c) > arg;
311}
312inline bool operator>= (char c, const Char16& arg)
313{
314 return Char16(c) >= arg;
315}
316inline Char16 operator+ (const Char16& arg1, const Char16& arg2)
317{
318 return Char16(UInt16(arg1.getValue() + arg2.getValue()));
319}
320inline Char16 operator- (const Char16& arg1, const Char16& arg2)
321{
322 return Char16(UInt16(arg1.getValue() - arg2.getValue()));
323}
324inline Char16 operator* (const Char16& arg1, const Char16& arg2)
325{
326 return Char16(UInt16(arg1.getValue() * arg2.getValue()));
327}
328inline Char16 operator/ (const Char16& arg1, const Char16& arg2)
329{
330 return Char16(UInt16(arg1.getValue() / arg2.getValue()));
331}
332BLOCXX_COMMON_API std::ostream& operator<< (std::ostream& ostrm, const Char16& arg);
333
334} // end namespace BLOCXX_NAMESPACE
335
336#endif
#define BLOCXX_SAFE_BOOL_IMPL(classname, type, variable, test)
Definition SafeBool.hpp:58
Array<> wraps std::vector<> in COWReference<> adding ref counting and copy on write capability.
Definition ArrayFwd.hpp:46
The Bool class is an abstraction for the boolean data type.
Definition Bool.hpp:57
The Char16 class is an abstraction for a double byte character.
Definition Char16.hpp:57
Char16(UInt8 val)
Create a new Char16 object of an unsigned 8 bit value.
Definition Char16.hpp:95
void readObject(std::streambuf &istrm)
Read this object from an input stream.
Definition Char16.cpp:84
Char16(Int32 val)
Create a new Char16 object of an signed 32 bit value.
Definition Char16.hpp:110
Char16(Int16 val)
Create a new Char16 object of an signed 16 bit value.
Definition Char16.hpp:90
String toString() const
Convert this to UTF8.
Definition Char16.cpp:72
Char16()
Create a new Char16 object with a value of zero.
Definition Char16.hpp:62
Char16(UInt32 val)
Create a new Char16 object of an unsigned 32 bit value.
Definition Char16.hpp:105
void writeObject(std::streambuf &ostrm) const
Write this object to an output stream.
Definition Char16.cpp:78
Char16(Real64 val)
Create a new Char16 object from a real 64 value.
Definition Char16.hpp:130
Char16(const Char16 &arg)
Copy constructor.
Definition Char16.hpp:67
Char16(UInt64 val)
Create a new Char16 object of an unsigned 64 bit value.
Definition Char16.hpp:115
Char16(Int64 val)
Create a new Char16 object of an signed 64 bit value.
Definition Char16.hpp:120
Char16(Real32 val)
Create a new Char16 object from a real 32 value.
Definition Char16.hpp:125
Char16(char c)
Create a new Char16 object from a single byte character.
Definition Char16.hpp:72
Char16(Bool val)
Create a new Char16 object from a boolean value.
Definition Char16.hpp:135
UInt16 getValue() const
Definition Char16.hpp:139
Char16(UInt16 val)
Create a new Char16 object of an unsigned 16 bit value.
Definition Char16.hpp:85
String toUTF8() const BLOCXX_DEPRECATED
Deprecated in favor of toString()
Definition Char16.cpp:66
Char16(Int8 val)
Create a new Char16 object of an signed 8 bit value.
Definition Char16.hpp:100
This String class is an abstract data type that represents as NULL terminated string of characters.
Definition String.hpp:67
Taken from RFC 1321.
unsigned char UInt8
Definition Types.hpp:66
signed char Int8
Definition Types.hpp:67
BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, Array, Bool)