Click here to Skip to main content
15,886,799 members
Articles / Desktop Programming / MFC

What's New in ACF 0.3

Rate me:
Please Sign up or sign in to vote.
3.39/5 (7 votes)
23 Jun 20043 min read 40.4K   193   8  
This article introduces what's new in ACF (Another C++ Framework) version 0.3.
//---------------------------------------------------------------------
//
// 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.
//

#include "stdafx.h"

namespace Acf {

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

// Static Methods

/*static*/ int Int32::Parse(String* s, IFormatProvider* provider)
{
    return Parse(s, NumberStyles::Integer, provider);
}

/*static*/ int Int32::Parse(String* s, NumberStyles style, IFormatProvider* provider)
{
    NumberFormatInfoPtr nfi = NumberFormatInfo::GetInstance(provider);

    Number number;
    number.Parse(s, style, nfi);

    int result;

    if ((style & NumberStyles::AllowHexSpecifier) != 0)
    {
        if (!number.TryHexToUInt32((uint*)&result))
            throw OverflowException();
    }
    else
    {
        if (!number.TryToInt32(&result))
            throw OverflowException();
    }

    return result;
}

/*static*/ bool Int32::TryParse(String* s, int* result)
{
    return TryParse(s, NumberStyles::Integer, null, result);
}

/*static*/ bool Int32::TryParse(String* s, NumberStyles style, IFormatProvider* provider, 
    int* result)
{
    NumberFormatInfoPtr nfi = NumberFormatInfo::GetInstance(provider);

    Number number;
    if (!number.TryParse(s, style, nfi))
        return false;

    if ((style & NumberStyles::AllowHexSpecifier) != 0)
    {
        if (!number.TryHexToUInt32((uint*)result))
            return false;
    }
    else
    {
        if (!number.TryToInt32(result))
            return false;
    }

    return true;
}

// Methods

int Int32::GetHashCode()
{
    return this->Value;
}

StringPtr Int32::ToString(IFormatProvider* provider)
{
    return ToString((String*)null, provider);
}

StringPtr Int32::ToString(String* format, IFormatProvider* provider)
{
    NumberFormatInfoPtr nfi = NumberFormatInfo::GetInstance(provider);

    int precision = -1;
    wchar_t specifier = Number::ParseFormat(format, &precision);

    if (specifier != 0)
    {
        switch (specifier)
        {
        case L'D':
        case L'd':
            return Number::FormatDecimal(this->Value, precision, nfi);
        case L'X':
            return Number::FormatHexadecimal((uint)this->Value, precision, true);
        case L'x':
            return Number::FormatHexadecimal((uint)this->Value, precision, false);
        default:
            {
                Number number(this->Value);
                return number.Format(specifier, precision, nfi);
            }
        }
    }
    else
    {
        Number number(this->Value);
        return number.FormatCustom(format, nfi);
    }
}

StringPtr Int32::ToString(const wchar_t* format, IFormatProvider* provider)
{
    return ToString(str(format), provider);
}

// Operators

Int32::operator int() const
{
    return this->Value;
}

Int32::operator int&()
{
    return this->Value;
}

int* Int32::operator&()
{
    return &this->Value;
}


//---------------------------------------------------------------------
// class Boxed<Int32>

// Methods

//
// Object Members
//

/*override*/ bool Boxed<Int32>::Equals(Object* obj)
{
    Boxed<Int32>* o = dynamic_cast<Boxed<Int32>*>(obj);
    if (o == null)
        return false;
    else
        return (this->Value == o->Value);
}

/*override*/ int Boxed<Int32>::GetHashCode()
{
    return this->Value.GetHashCode();
}

/*override*/ StringPtr Boxed<Int32>::ToString()
{
    return this->Value.ToString();
}

//
// IFormattable Members
//

/*virtual*/ StringPtr Boxed<Int32>::ToString(String* format, IFormatProvider* provider)
{
    return this->Value.ToString(format, provider);
}

} // namespace Acf

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