Click here to Skip to main content
15,896,912 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.4K   739   49  
This article introduces ACF, a C++ framework which brings the .NET framework to standard C++.
// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"

using namespace Acf;
using namespace Acf::Threading;

class StatusChecker : public Object
{
    int _invokeCount, _maxCount;

public:
    StatusChecker(int count)
    {
        this->_invokeCount = 0;
        this->_maxCount = count;
    }

    // This method is called by the timer delegate.
    void CheckStatus(Object* stateInfo)
    {
        AutoResetEvent* autoEvent = (AutoResetEvent*)stateInfo;

        Console::WriteLine(L"{0} Checking status {1, 2}.", 
            DateTime::get_Now().ToString(L"h:mm:ss.fff"), 
            str(++this->_invokeCount));

        if (this->_invokeCount == this->_maxCount)
        {
            // Reset the counter and signal Main.
            this->_invokeCount = 0;
            autoEvent->Set();
        }
    }
};

typedef RefPtr<StatusChecker>    StatusCheckerPtr;


int _tmain()
{
    AutoResetEventPtr autoEvent = new AutoResetEvent(false);
    StatusCheckerPtr statusChecker = new StatusChecker(10);

    // Create the delegate that invokes methods for the timer.
    TimerCallbackPtr timerDelegate = 
        new TimerCallback(statusChecker, &StatusChecker::CheckStatus);

    // Create a timer that signals the delegate to invoke 
    // CheckStatus after one second, and every 1/4 second 
    // thereafter.
    Console::WriteLine(L"{0} Creating timer.\n", 
        DateTime::get_Now().ToString(L"h:mm:ss.fff"));
    TimerPtr stateTimer = 
            new Timer(timerDelegate, autoEvent, 1000, 250);

    // When autoEvent signals, change the period to every 
    // 1/2 second.
    autoEvent->WaitOne(5000);
    stateTimer->Change(0, 500);
    Console::WriteLine(L"\nChanging period.\n");

    // When autoEvent signals the second time, dispose of 
    // the timer.
    autoEvent->WaitOne(5000);
    stateTimer->Dispose();
    Console::WriteLine(L"\nDestroying timer.");
}

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