Click here to Skip to main content
15,894,740 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.
//

#include "stdafx.h"

namespace Acf {

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

// Static Fields

const float Single::DefValue = 0;
const float Single::MaxValue = FLT_MAX;
const float Single::MinValue = FLT_MIN;
const float Single::Epsilon = FLT_EPSILON;

// Static Methods

/*static*/ float Single::Parse(String* s, NumberStyles style)
{
    if (s == null)
        throw ArgumentNullException();

    const wchar_t* format = L"%f";

    float value = 0;
    int ret = swscanf(s->GetCString(), format, &value);
    if (ret == 0 || ret == EOF)
        throw FormatException();

    return value;
}

/*static*/ StringPtr Single::ToString(float value, String* format, 
    IFormatProvider* provider)
{
    wchar_t fmt[10];

    if (format == null || format->Length == 0)
    {
        wcscpy(fmt, L"%g");
    }
    else
    {
        fmt[0] = L'%';
        wcscpy(fmt + 1, format->GetCString());
    }

    wchar_t buf[_MAX_EXP_DIG + _MAX_SIG_DIG + 64];
    swprintf(buf, fmt, (double)value);

    return new String(buf);
}

/*static*/ StringPtr Single::ToString(float value, const wchar_t* format, 
    IFormatProvider* provider)
{
    StringPtr format2 = new String(format);
    return ToString(value, format2, provider);
}

// Methods

StringPtr Single::ToString(String* format, IFormatProvider* provider)
{
    return ToString(this->Value, format, provider);
}

StringPtr Single::ToString(const wchar_t* format, IFormatProvider* provider)
{
    return ToString(this->Value, format, provider);
}

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

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

/*override*/ int SingleObject::GetHashCode()
{
    return (int) this->Value;
}

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

/*virtual*/ StringPtr SingleObject::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