blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005, Vintela, Inc. All rights reserved. 00003 * Copyright (C) 2006, Novell, Inc. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of 00014 * Vintela, Inc., 00015 * nor Novell, Inc., 00016 * nor the names of its contributors or employees may be used to 00017 * endorse or promote products derived from this software without 00018 * specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE. 00031 *******************************************************************************/ 00032 00033 00039 #ifndef BLOCXX_CHAR16_HPP_INCLUDE_GUARD_ 00040 #define BLOCXX_CHAR16_HPP_INCLUDE_GUARD_ 00041 #include "blocxx/BLOCXX_config.h" 00042 #include "blocxx/ArrayFwd.hpp" 00043 #include "blocxx/Types.hpp" 00044 #include "blocxx/Bool.hpp" 00045 #include "blocxx/CommonFwd.hpp" 00046 #include "blocxx/SafeBool.hpp" 00047 #include <iosfwd> 00048 00049 namespace BLOCXX_NAMESPACE 00050 { 00051 00052 class String; 00056 class BLOCXX_COMMON_API Char16 00057 { 00058 public: 00062 Char16() : m_value(0) {} 00067 Char16(const Char16& arg) : m_value(arg.m_value) {} 00072 explicit Char16(char c) : m_value(c) {} 00078 explicit Char16(const String& x); 00085 Char16(UInt16 val) : m_value(val) {} 00090 explicit Char16(Int16 val) : m_value(val) {} 00095 explicit Char16(UInt8 val) : m_value(val) {} 00100 explicit Char16(Int8 val) : m_value(val) {} 00105 explicit Char16(UInt32 val) : m_value(val) {} 00110 explicit Char16(Int32 val) : m_value(val) {} 00115 explicit Char16(UInt64 val) : m_value(static_cast<UInt16>(val)) {} 00120 explicit Char16(Int64 val) : m_value(static_cast<UInt16>(val)) {} 00125 explicit Char16(Real32 val) : m_value(static_cast<UInt16>(val)) {} 00130 explicit Char16(Real64 val) : m_value(static_cast<UInt16>(val)) {} 00135 explicit Char16(Bool val) : m_value(val) {} 00139 UInt16 getValue() const { return m_value; } 00143 operator UInt16() const { return getValue(); } 00149 Char16& operator= (const Char16& arg) 00150 { 00151 m_value = arg.m_value; 00152 return *this; 00153 } 00159 bool operator== (const Char16& arg) const 00160 { 00161 return m_value == arg.m_value; 00162 } 00168 bool operator!= (const Char16& arg) const 00169 { 00170 return m_value != arg.m_value; 00171 } 00177 bool operator< (const Char16& arg) const 00178 { 00179 return m_value < arg.m_value; 00180 } 00187 bool operator<= (const Char16& arg) const 00188 { 00189 return m_value <= arg.m_value; 00190 } 00196 bool operator> (const Char16& arg) const 00197 { 00198 return m_value > arg.m_value; 00199 } 00206 bool operator>= (const Char16& arg) const 00207 { 00208 return m_value >= arg.m_value; 00209 } 00215 Char16& operator+= (const Char16& arg) 00216 { 00217 m_value += arg.m_value; 00218 return *this; 00219 } 00225 Char16& operator-= (const Char16& arg) 00226 { 00227 m_value -= arg.m_value; 00228 return *this; 00229 } 00235 Char16& operator*= (const Char16& arg) 00236 { 00237 m_value *= arg.m_value; 00238 return *this; 00239 } 00245 Char16& operator/= (const Char16& arg) 00246 { 00247 m_value /= arg.m_value; 00248 return *this; 00249 } 00250 00251 BLOCXX_SAFE_BOOL_IMPL(Char16, UInt16, Char16::m_value, m_value) 00252 00253 00256 String toUTF8() const BLOCXX_DEPRECATED; // in 3.1.0 00260 String toString() const; 00265 void writeObject(std::streambuf & ostrm) const; 00270 void readObject(std::streambuf & istrm); 00271 private: 00272 UInt16 m_value; 00273 }; 00274 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, Array, Char16); 00275 00276 inline bool operator== (char c, const Char16& arg) 00277 { 00278 return Char16(c) == arg; 00279 } 00280 inline bool operator== (const Char16& arg, int v) 00281 { 00282 return (arg.getValue() == v); 00283 } 00284 inline bool operator== (int v, const Char16& arg) 00285 { 00286 return (arg.getValue() == v); 00287 } 00288 inline bool operator!= (const Char16& arg, int v) 00289 { 00290 return (arg.getValue() != v); 00291 } 00292 inline bool operator!= (int v, const Char16& arg) 00293 { 00294 return (arg.getValue() != v); 00295 } 00296 inline bool operator!= (char c, const Char16& arg) 00297 { 00298 return Char16(c) != arg; 00299 } 00300 inline bool operator< (char c, const Char16& arg) 00301 { 00302 return Char16(c) < arg; 00303 } 00304 inline bool operator<= (char c, const Char16& arg) 00305 { 00306 return Char16(c) <= arg; 00307 } 00308 inline bool operator> (char c, const Char16& arg) 00309 { 00310 return Char16(c) > arg; 00311 } 00312 inline bool operator>= (char c, const Char16& arg) 00313 { 00314 return Char16(c) >= arg; 00315 } 00316 inline Char16 operator+ (const Char16& arg1, const Char16& arg2) 00317 { 00318 return Char16(UInt16(arg1.getValue() + arg2.getValue())); 00319 } 00320 inline Char16 operator- (const Char16& arg1, const Char16& arg2) 00321 { 00322 return Char16(UInt16(arg1.getValue() - arg2.getValue())); 00323 } 00324 inline Char16 operator* (const Char16& arg1, const Char16& arg2) 00325 { 00326 return Char16(UInt16(arg1.getValue() * arg2.getValue())); 00327 } 00328 inline Char16 operator/ (const Char16& arg1, const Char16& arg2) 00329 { 00330 return Char16(UInt16(arg1.getValue() / arg2.getValue())); 00331 } 00332 BLOCXX_COMMON_API std::ostream& operator<< (std::ostream& ostrm, const Char16& arg); 00333 00334 } // end namespace BLOCXX_NAMESPACE 00335 00336 #endif