Click here to Skip to main content
15,893,968 members
Articles / Desktop Programming / MFC

Introduction to ACF (Another C++ Framework)

Rate me:
Please Sign up or sign in to vote.
4.86/5 (36 votes)
27 May 200411 min read 136.3K   739   49  
This article introduces ACF, a C++ framework which brings the .NET framework to standard C++.
//---------------------------------------------------------------------
//
// Copyright (C) 2004 Yingle Jia
//
// Permission to copy, use, modify, sell and distribute this software is 
// granted provided this copyright notice appears in all copies. 
// This software is provided "as is" without express or implied warranty, 
// and with no claim as to its suitability for any purpose.
//
// AcfPrimitiveTypes.h
//

#ifndef __Acf_PrimitiveTypes__
#define __Acf_PrimitiveTypes__

namespace Acf {
    namespace Globalization {

//---------------------------------------------------------------------
// enum NumberStyles: used for the Parse methods

ACF_DECLARE_ENUM(NumberStyles)
    None				  = 0x00000000, 
    AllowLeadingWhite     = 0x00000001, 
    AllowTrailingWhite    = 0x00000002, // Bitflag indicating trailing whitespace is allowed.
    AllowLeadingSign      = 0x00000004, // Can the number start with a sign char.  
    AllowTrailingSign     = 0x00000008, // Allow the number to end with a sign char
    AllowParentheses      = 0x00000010, // Allow the number to be enclosed in parens
    AllowDecimalPoint     = 0x00000020, // Allow a decimal point
    AllowThousands        = 0x00000040, // Allow thousands separators (more properly, allow group separators)
    AllowExponent         = 0x00000080, // Allow an exponent
    AllowCurrencySymbol   = 0x00000100, // Allow a currency symbol.
    AllowHexSpecifier	  = 0x00000200, // Allow specifiying hexadecimal.

    Integer  = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign,
    HexNumber = AllowLeadingWhite | AllowTrailingWhite | AllowHexSpecifier,
    Number   = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
        AllowDecimalPoint | AllowThousands,
    Float    = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | 
        AllowDecimalPoint | AllowExponent,
    Currency = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
        AllowParentheses  | AllowDecimalPoint | AllowThousands | AllowCurrencySymbol,
    Any      = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
        AllowParentheses  | AllowDecimalPoint | AllowThousands | AllowCurrencySymbol | AllowExponent,
END_ENUM()

    } // namespace Globalization
} // namespace Acf

namespace Acf {

using namespace Acf::Globalization;

//---------------------------------------------------------------------
// struct Boolean

#include <pshpack1.h>

struct Boolean
{
// Static Fields
public:
    static const bool DefValue = false;
    static const bool MaxValue = true;
    static const bool MinValue = false;

// Fields
public:
    bool Value;

// Constructors
public:
    Boolean(bool value = DefValue) : Value(value) { }

// Static Methods
public:
    static bool Parse(String* s);
    static bool Parse(const wchar_t* s);
    static StringPtr ToString(bool value);

// Methods
public:
    StringPtr ToString()
    {
        return ToString(this->Value);
    }

// Operators
public:
    Boolean& operator=(bool value)
    {
        this->Value = value;
        return *this;
    }
    operator bool() const
    {
        return this->Value;
    }
    operator bool&()
    {
        return this->Value;
    }
    bool* operator&()
    {
        return &this->Value;
    }
};

#include <poppack.h> // resume normal packing

//---------------------------------------------------------------------
// class BooleanObject

class BooleanObject : public Object
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Boolean Value;

// Constructors
public:
    BooleanObject(const Boolean& value) : Value(value) { }

// Destructor
private:
    virtual ~BooleanObject() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();
};

inline RefPtr<BooleanObject> box(bool value)
{
    return new BooleanObject(value);
}

template <>
inline bool unbox<bool>(Object* obj)
{
    BooleanObject* o = dynamic_cast<BooleanObject*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct SByte

#include <pshpack1.h>

struct SByte
{
// Static Fields
public:
    static const sbyte DefValue = 0;
    static const sbyte MaxValue = 127;
    static const sbyte MinValue = -128;

// Fields
public:
    sbyte Value;

// Constructors
public:
    SByte(sbyte value = DefValue) : Value(value) { }

// Static Methods
public:
    static sbyte Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(sbyte value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(sbyte value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    SByte& operator=(sbyte value)
    {
        this->Value = value;
        return *this;
    }
    operator sbyte() const
    {
        return this->Value;
    }
    operator sbyte&()
    {
        return this->Value;
    }
    sbyte* operator&()
    {
        return &this->Value;
    }
};

#include <poppack.h> // resume normal packing

//---------------------------------------------------------------------
// class SByteObject

class SByteObject : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    SByte Value;

// Constructors
public:
    SByteObject(const SByte& value) : Value(value) { }

// Destructor
private:
    virtual ~SByteObject() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<SByteObject> box(sbyte value)
{
    return new SByteObject(value);
}

template <>
inline sbyte unbox<sbyte>(Object* obj)
{
    SByteObject* o = dynamic_cast<SByteObject*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Byte

#include <pshpack1.h>

struct Byte
{
// Static Fields
public:
    static const byte DefValue = 0;
    static const byte MaxValue = 0xff;
    static const byte MinValue = 0;

// Fields
public:
    byte Value;

// Constructors
public:
    Byte(byte value = DefValue) : Value(value) { }

// Static Methods
public:
    static byte Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(byte value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(byte value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    Byte& operator=(byte value)
    {
        this->Value = value;
        return *this;
    }
    operator byte() const
    {
        return this->Value;
    }
    operator byte&()
    {
        return this->Value;
    }
    byte* operator&()
    {
        return &this->Value;
    }
};

#include <poppack.h> // resume normal packing

//---------------------------------------------------------------------
// class ByteObject

class ByteObject : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Byte Value;

// Constructors
public:
    ByteObject(const Byte& value) : Value(value) { }

// Destructor
private:
    virtual ~ByteObject() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<ByteObject> box(byte value)
{
    return new ByteObject(value);
}

template <>
inline byte unbox<byte>(Object* obj)
{
    ByteObject* o = dynamic_cast<ByteObject*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Char

#include <pshpack1.h>

struct Char
{
// Static Fields
public:
    static const wchar_t DefValue = 0;
    static const wchar_t MaxValue = 0xffff;
    static const wchar_t MinValue = 0;

// Fields
public:
    wchar_t Value;

// Constructors
public:
    Char(wchar_t value = DefValue) : Value(value) { }

// Static Methods
public:
    static wchar_t Parse(String* s);
    static wchar_t Parse(const wchar_t* s);
    static StringPtr ToString(wchar_t value);

    static bool IsWhiteSpace(wchar_t c);
    static wchar_t ToLower(wchar_t c);
    static wchar_t ToUpper(wchar_t c);

// Methods
public:
    StringPtr ToString()
    {
        return ToString(this->Value);
    }

// Operators
public:
    Char& operator=(wchar_t value)
    {
        this->Value = value;
        return *this;
    }
    operator wchar_t() const
    {
        return this->Value;
    }
    operator wchar_t&()
    {
        return this->Value;
    }
    wchar_t* operator&()
    {
        return &this->Value;
    }
};

#include <poppack.h> // resume normal packing

//---------------------------------------------------------------------
// class CharObject

class CharObject : public Object
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Char Value;

// Constructors
public:
    CharObject(const Char& value) : Value(value) { }

// Destructor
private:
    virtual ~CharObject() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();
};

inline RefPtr<CharObject> box(wchar_t value)
{
    return new CharObject(value);
}

template <>
inline wchar_t unbox<wchar_t>(Object* obj)
{
    CharObject* o = dynamic_cast<CharObject*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Int16

#include <pshpack1.h>

struct Int16
{
// Static Fields
public:
    static const short DefValue = 0;
    static const short MaxValue = 0x7FFF;
    static const short MinValue = (short) 0x8000;

// Fields
public:
    short Value;

// Constructors
public:
    Int16(short value = DefValue) : Value(value) { }

// Static Methods
public:
    static short Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(short value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(short value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    Int16& operator=(short value)
    {
        this->Value = value;
        return *this;
    }
    operator short() const
    {
        return this->Value;
    }
    operator short&()
    {
        return this->Value;
    }
    short* operator&()
    {
        return &this->Value;
    }
};

#include <poppack.h> // resume normal packing

//---------------------------------------------------------------------
// class Int16Object

class Int16Object : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Int16 Value;

// Constructors
public:
    Int16Object(const Int16& value) : Value(value) { }

// Destructor
private:
    virtual ~Int16Object() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<Int16Object> box(short value)
{
    return new Int16Object(value);
}

template <>
inline short unbox<short>(Object* obj)
{
    Int16Object* o = dynamic_cast<Int16Object*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct UInt16

#include <pshpack1.h>

struct UInt16
{
// Static Fields
public:
    static const ushort DefValue = 0;
    static const ushort MaxValue = 0xffff;
    static const ushort MinValue = 0;

// Fields
public:
    ushort Value;

// Constructors
public:
    UInt16(ushort value = DefValue) : Value(value) { }

// Static Methods
public:
    static ushort Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(ushort value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(ushort value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    UInt16& operator=(ushort value)
    {
        this->Value = value;
        return *this;
    }
    operator ushort() const
    {
        return this->Value;
    }
    operator ushort&()
    {
        return this->Value;
    }
    ushort* operator&()
    {
        return &this->Value;
    }
};

#include <poppack.h> // resume normal packing

//---------------------------------------------------------------------
// class UInt16Object

class UInt16Object : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    UInt16 Value;

// Constructors
public:
    UInt16Object(const UInt16& value) : Value(value) { }

// Destructor
private:
    virtual ~UInt16Object() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<UInt16Object> box(ushort value)
{
    return new UInt16Object(value);
}

template <>
inline ushort unbox<ushort>(Object* obj)
{
    UInt16Object* o = dynamic_cast<UInt16Object*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Int32

struct Int32
{
// Static Fields
public:
    static const int DefValue = 0;
    static const int MaxValue = 2147483647;
    static const int MinValue = (-2147483647 - 1);

// Fields
public:
    int Value;

// Constructors
public:
    Int32(int value = DefValue) : Value(value) { }

// Static Methods
public:
    static int Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(int value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(int value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    Int32& operator=(int value)
    {
        this->Value = value;
        return *this;
    }
    operator int() const
    {
        return this->Value;
    }
    operator int&()
    {
        return this->Value;
    }
    int* operator&()
    {
        return &this->Value;
    }
};

//---------------------------------------------------------------------
// class Int32Object

class Int32Object : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Int32 Value;

// Constructors
public:
    Int32Object(const Int32& value) : Value(value) { }

// Destructor
private:
    virtual ~Int32Object() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<Int32Object> box(int value)
{
    return new Int32Object(value);
}

template <>
inline int unbox<int>(Object* obj)
{
    Int32Object* o = dynamic_cast<Int32Object*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct UInt32

struct UInt32
{
// Static Fields
public:
    static const uint DefValue = 0;
    static const uint MaxValue = 0xffffffff;
    static const uint MinValue = 0;

// Fields
public:
    uint Value;

// Constructors
public:
    UInt32(uint value = DefValue) : Value(value) { }

// Static Methods
public:
    static uint Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(uint value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(uint value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    UInt32& operator=(uint value)
    {
        this->Value = value;
        return *this;
    }
    operator uint() const
    {
        return this->Value;
    }
    operator uint&()
    {
        return this->Value;
    }
    uint* operator&()
    {
        return &this->Value;
    }
};

//---------------------------------------------------------------------
// class UInt32Object

class UInt32Object : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    UInt32 Value;

// Constructors
public:
    UInt32Object(const UInt32& value) : Value(value) { }

// Destructor
private:
    virtual ~UInt32Object() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<UInt32Object> box(uint value)
{
    return new UInt32Object(value);
}

template <>
inline uint unbox<uint>(Object* obj)
{
    UInt32Object* o = dynamic_cast<UInt32Object*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Int64

struct Int64
{
// Static Fields
public:
    static const int64 DefValue = 0;
    static const int64 MaxValue = 9223372036854775807i64;
    static const int64 MinValue = (-9223372036854775807i64 - 1);

// Fields
public:
    int64 Value;

// Constructors
public:
    Int64(int64 value = DefValue) : Value(value) { }

// Static Methods
public:
    static int64 Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(int64 value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(int64 value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    Int64& operator=(int64 value)
    {
        this->Value = value;
        return *this;
    }
    operator int64() const
    {
        return this->Value;
    }
    operator int64&()
    {
        return this->Value;
    }
    int64* operator&()
    {
        return &this->Value;
    }
};

//---------------------------------------------------------------------
// class Int64Object

class Int64Object : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Int64 Value;

// Constructors
public:
    Int64Object(const Int64& value) : Value(value) { }

// Destructor
private:
    virtual ~Int64Object() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<Int64Object> box(int64 value)
{
    return new Int64Object(value);
}

template <>
inline int64 unbox<int64>(Object* obj)
{
    Int64Object* o = dynamic_cast<Int64Object*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct UInt64

struct UInt64
{
// Static Fields
public:
    static const uint64 DefValue = 0;
    static const uint64 MaxValue = 0xffffffffffffffff;
    static const uint64 MinValue = 0;

// Fields
public:
    uint64 Value;

// Constructors
public:
    UInt64(uint64 value = DefValue) : Value(value) { }

// Static Methods
public:
    static uint64 Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(uint64 value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(uint64 value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    UInt64& operator=(uint64 value)
    {
        this->Value = value;
        return *this;
    }
    operator uint64() const
    {
        return this->Value;
    }
    operator uint64&()
    {
        return this->Value;
    }
    uint64* operator&()
    {
        return &this->Value;
    }
};

//---------------------------------------------------------------------
// class UInt64Object

class UInt64Object : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    UInt64 Value;

// Constructors
public:
    UInt64Object(const UInt64& value) : Value(value) { }

// Destructor
private:
    virtual ~UInt64Object() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<UInt64Object> box(uint64 value)
{
    return new UInt64Object(value);
}

template <>
inline uint64 unbox<uint64>(Object* obj)
{
    UInt64Object* o = dynamic_cast<UInt64Object*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Single

struct Single
{
// Static Fields
public:
    static const float DefValue;
    static const float MaxValue;
    static const float MinValue;
    static const float Epsilon;

// Fields
public:
    float Value;

// Constructors
public:
    Single(float value = DefValue) : Value(value) { }

// Static Methods
public:
    static float Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(float value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(float value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    Single& operator=(float value)
    {
        this->Value = value;
        return *this;
    }
    operator float() const
    {
        return this->Value;
    }
    operator float&()
    {
        return this->Value;
    }
    float* operator&()
    {
        return &this->Value;
    }
};

//---------------------------------------------------------------------
// class SingleObject

class SingleObject : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Single Value;

// Constructors
public:
    SingleObject(const Single& value) : Value(value) { }

// Destructor
private:
    virtual ~SingleObject() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<SingleObject> box(float value)
{
    return new SingleObject(value);
}

template <>
inline float unbox<float>(Object* obj)
{
    SingleObject* o = dynamic_cast<SingleObject*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

//---------------------------------------------------------------------
// struct Double

struct Double
{
// Static Fields
public:
    static const double DefValue;
    static const double MaxValue;
    static const double MinValue;
    static const double Epsilon;

// Fields
public:
    double Value;

// Constructors
public:
    Double(double value = DefValue) : Value(value) { }

// Static Methods
public:
    static double Parse(String* s, NumberStyles style = NumberStyles::Integer);
    static StringPtr ToString(double value, String* format = null, 
        IFormatProvider* provider = null);
    static StringPtr ToString(double value, const wchar_t* format, 
        IFormatProvider* provider = null);

// Methods
public:
    StringPtr ToString(String* format = null, IFormatProvider* provider = null);
    StringPtr ToString(const wchar_t* format, IFormatProvider* provider = null);

// Operators
public:
    Double& operator=(double value)
    {
        this->Value = value;
        return *this;
    }
    operator double() const
    {
        return this->Value;
    }
    operator double&()
    {
        return this->Value;
    }
    double* operator&()
    {
        return &this->Value;
    }
};

//---------------------------------------------------------------------
// class DoubleObject

class DoubleObject : public Object, public IFormattable
{
public:
    using Object::AddRef;
    using Object::Release;

// Fields
public:
    Double Value;

// Constructors
public:
    DoubleObject(const Double& value) : Value(value) { }

// Destructor
private:
    virtual ~DoubleObject() { }

// Methods
public:
    //
    // Object Members
    //
    override bool Equals(Object* obj);
    override int GetHashCode();
    override StringPtr ToString();

    //
    // IFormattable Members
    //
    virtual StringPtr ToString(String* format, IFormatProvider* provider);
};

inline RefPtr<DoubleObject> box(double value)
{
    return new DoubleObject(value);
}

template <>
inline double unbox<double>(Object* obj)
{
    DoubleObject* o = dynamic_cast<DoubleObject*>(obj);
    if (o == null)
        throw InvalidCastException();
    else
        return o->Value;
}

} // namespace Acf

#endif // #ifndef __Acf_PrimitiveTypes__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
China China
Yingle Jia is a software engineer located in Beijing, China. He currently works at IBM CSDL (China Software Development Lab). His interests include C++/COM/C#/.NET/XML, etc. He likes coding and writing.

He is the creator of ACF (Another C++ Framework) project. See http://acfproj.sourceforge.net/.

He also has a blog at http://blogs.wwwcoder.com/yljia/

Comments and Discussions