Char16.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2005 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 *
00011 *  - Redistributions in binary form must reproduce the above copyright notice,
00012 *    this list of conditions and the following disclaimer in the documentation
00013 *    and/or other materials provided with the distribution.
00014 *
00015 *  - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
00016 *    contributors may be used to endorse or promote products derived from this
00017 *    software without specific prior written permission.
00018 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 
00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 *******************************************************************************/
00031 
00032 
00038 #ifndef BLOCXX_CHAR16_HPP_INCLUDE_GUARD_
00039 #define BLOCXX_CHAR16_HPP_INCLUDE_GUARD_
00040 #include "blocxx/BLOCXX_config.h"
00041 #include "blocxx/ArrayFwd.hpp"
00042 #include "blocxx/Types.hpp"
00043 #include "blocxx/Bool.hpp"
00044 #include "blocxx/CommonFwd.hpp"
00045 #include <iosfwd>
00046 
00047 namespace BLOCXX_NAMESPACE
00048 {
00049 
00050 class String;
00054 class BLOCXX_COMMON_API Char16
00055 {
00056 public:
00060    Char16() : m_value(0) {}
00065    Char16(const Char16& arg) : m_value(arg.m_value) {}
00070    explicit Char16(char c) : m_value(c) {}
00076    explicit Char16(const String& x);
00083    Char16(UInt16 val) : m_value(val) {}
00088    explicit Char16(Int16 val) : m_value(val) {}
00093    explicit Char16(UInt8 val) : m_value(val) {}
00098    explicit Char16(Int8 val) : m_value(val) {}
00103    explicit Char16(UInt32 val) : m_value(val) {}
00108    explicit Char16(Int32 val) : m_value(val) {}
00113    explicit Char16(UInt64 val) : m_value(static_cast<UInt16>(val)) {}
00118    explicit Char16(Int64 val) : m_value(static_cast<UInt16>(val)) {}
00123    explicit Char16(Real32 val) : m_value(static_cast<UInt16>(val)) {}
00128    explicit Char16(Real64 val) : m_value(static_cast<UInt16>(val)) {}
00133    explicit Char16(Bool val) : m_value(val) {}
00137    UInt16 getValue() const { return m_value; }
00141    operator UInt16() const { return getValue(); }
00147    Char16& operator= (const Char16& arg)
00148    {
00149       m_value = arg.m_value;
00150       return *this;
00151    }
00157    bool operator== (const Char16& arg) const
00158    {
00159       return m_value == arg.m_value;
00160    }
00166    bool operator!= (const Char16& arg) const
00167    {
00168       return m_value != arg.m_value;
00169    }
00175    bool operator< (const Char16& arg) const
00176    {
00177       return m_value < arg.m_value;
00178    }
00185    bool operator<= (const Char16& arg) const
00186    {
00187       return m_value <= arg.m_value;
00188    }
00194    bool operator> (const Char16& arg) const
00195    {
00196       return m_value > arg.m_value;
00197    }
00204    bool operator>= (const Char16& arg) const
00205    {
00206       return m_value >= arg.m_value;
00207    }
00213    Char16& operator+= (const Char16& arg)
00214    {
00215       m_value += arg.m_value;
00216       return *this;
00217    }
00223    Char16& operator-= (const Char16& arg)
00224    {
00225       m_value -= arg.m_value;
00226       return *this;
00227    }
00233    Char16& operator*= (const Char16& arg)
00234    {
00235       m_value *= arg.m_value;
00236       return *this;
00237    }
00243    Char16& operator/= (const Char16& arg)
00244    {
00245       m_value /= arg.m_value;
00246       return *this;
00247    }
00248    
00249    typedef UInt16 Char16::*safe_bool;
00250    operator safe_bool () const
00251       {  return m_value ? &Char16::m_value : 0; }
00256    bool operator!() const
00257       {  return !m_value; }
00261    String toString() const;
00266    void writeObject(std::ostream& ostrm) const;
00271    void readObject(std::istream& istrm);
00272 private:
00273    UInt16 m_value;
00274 };
00275 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, Array, Char16);
00276 
00277 inline bool operator== (char c, const Char16& arg)
00278 {
00279    return Char16(c) == arg;
00280 }
00281 inline bool operator== (const Char16& arg, int v)
00282 {
00283    return (arg.getValue() == v);
00284 }
00285 inline bool operator== (int v, const Char16& arg)
00286 {
00287    return (arg.getValue() == v);
00288 }
00289 inline bool operator!= (const Char16& arg, int v)
00290 {
00291    return (arg.getValue() != v);
00292 }
00293 inline bool operator!= (int v, const Char16& arg)
00294 {
00295    return (arg.getValue() != v);
00296 }
00297 inline bool operator!= (char c, const Char16& arg)
00298 {
00299    return Char16(c) != arg;
00300 }
00301 inline bool operator< (char c, const Char16& arg)
00302 {
00303    return Char16(c) < arg;
00304 }
00305 inline bool operator<= (char c, const Char16& arg)
00306 {
00307    return Char16(c) <= arg;
00308 }
00309 inline bool operator> (char c, const Char16& arg)
00310 {
00311    return Char16(c) > arg;
00312 }
00313 inline bool operator>= (char c, const Char16& arg)
00314 {
00315    return Char16(c) >= arg;
00316 }
00317 inline Char16 operator+ (const Char16& arg1, const Char16& arg2)
00318 {
00319    return Char16(UInt16(arg1.getValue() + arg2.getValue()));
00320 }
00321 inline Char16 operator- (const Char16& arg1, const Char16& arg2)
00322 {
00323    return Char16(UInt16(arg1.getValue() - arg2.getValue()));
00324 }
00325 inline Char16 operator* (const Char16& arg1, const Char16& arg2)
00326 {
00327    return Char16(UInt16(arg1.getValue() * arg2.getValue()));
00328 }
00329 inline Char16 operator/ (const Char16& arg1, const Char16& arg2)
00330 {
00331    return Char16(UInt16(arg1.getValue() / arg2.getValue()));
00332 }
00333 BLOCXX_COMMON_API std::ostream& operator<< (std::ostream& ostrm, const Char16& arg);
00334 
00335 } // end namespace BLOCXX_NAMESPACE
00336 
00337 #endif

Generated on Fri Jun 16 15:39:08 2006 for blocxx by  doxygen 1.4.6