Project Files/Testing Source/main.cpp
void reusableTask() {
    //Clear the screen
    system("CLS");

    //Create the Task Manager
    if (AsynchTasks::TaskManager::create(1)) {
        //Create the basic input manager
        BasicInput input = BasicInput(VK_ESCAPE, VK_SPACE);

        //Create the base job
        AsynchTasks::Task<unsigned int> stringTask = AsynchTasks::TaskManager::createTask<unsigned int>();

        //Set the callback to occur on main
        stringTask->callbackOnUpdate = true;

        //Set the process function
        stringTask->process = [&]() -> unsigned int {
            //Create a random character string
            unsigned int sum = 0;

            //Loop through and add the totals from 0 to UINT_MAX
            for (unsigned int i = 0; i < UINT_MAX; i++)
                sum++;

            //Return the sum
            return sum;
        };

        //Attach the callback function
        stringTask->callback = [&](unsigned int& pNum) {
            printf("\n\nCounted to: %u\n\n", pNum);
        };

        //Display initial instructions
        printf("Press 'SPACE' to count to UINT_MAX when Task object is available (Reusable Task Test)\n\n");

        //Loop till escape is pressed
        while (!input.keyPressed(VK_ESCAPE)) {
            //Update the input
            input.update();

            //Update the Task Manager
            AsynchTasks::TaskManager::update();

            //Output a single '.'
            if (stringTask->status != AsynchTasks::ETaskStatus::Completed && stringTask->status != AsynchTasks::ETaskStatus::Setup)
                printf(".");

            //Determine if the user has pressed space
            if (input.keyPressed(VK_SPACE)) {
                //Add the task to the Task Manager
                if (AsynchTasks::TaskManager::addTask(stringTask))
                    printf("Starting to count now:\n");
            }

            //Slow main down to viewable pace
            Sleep(100);
        }
    }

    //Display error message
    else printf("Failed to create the Asynchronous Task Manager\n");

    //Destroy the the Task Manager
    AsynchTasks::TaskManager::destroy();
}
/*
    reusableTask - Test reusing Task objects for similar tasks repeatedly
    Author: Mitchell Croft
    Created: 24/08/2016
    Modified: 12/01/2017
*/
Test reusing Task objects for similar tasks repeatedly
Author: Mitchell Croft
Created: 24/08/2016
Modified: 12/01/2017
Test reusing Task objects for similar tasks repeatedly Author : Mitchell Croft Created : 24 / 08 / 2016 Modified : 12 / 01 / 2017
void reusableTask() {
    system("CLS");
    if (AsynchTasks::TaskManager::create(1)) {
        BasicInput input = BasicInput(VK_ESCAPE, VK_SPACE);
        AsynchTasks::Task<unsigned int> stringTask = AsynchTasks::TaskManager::createTask<unsigned int>();
        stringTask->callbackOnUpdate = true;
        stringTask->process = [&]() -> unsigned int {
            unsigned int sum = 0;
            for (unsigned int i = 0; i < UINT_MAX; i++)
                sum++;
            return sum;
        };
        stringTask->callback = [&](unsigned int& pNum) {
            printf("\n\nCounted to: %u\n\n", pNum);
        };
        printf("Press 'SPACE' to count to UINT_MAX when Task object is available (Reusable Task Test)\n\n");
        while (!input.keyPressed(VK_ESCAPE)) {
            input.update();
            AsynchTasks::TaskManager::update();
            if (stringTask->status != AsynchTasks::ETaskStatus::Completed && stringTask->status != AsynchTasks::ETaskStatus::Setup)
                printf(".");
            if (input.keyPressed(VK_SPACE)) {
                if (AsynchTasks::TaskManager::addTask(stringTask))
                    printf("Starting to count now:\n");
            }
            Sleep(100);
        }
    }
    else printf("Failed to create the Asynchronous Task Manager\n");
    AsynchTasks::TaskManager::destroy();
}
void reusableTask ( ) { system ( " " ) ; if ( AsynchTasks :: TaskManager :: create ( 1 ) ) { BasicInput input = BasicInput ( VK_ESCAPE , VK_SPACE ) ; AsynchTasks :: Task < unsigned int > stringTask = AsynchTasks :: TaskManager :: createTask < unsigned int > ( ) ; stringTask -> callbackOnUpdate = true ; stringTask -> process = [ & ] ( ) -> unsigned int { unsigned int sum = 0 ; for ( unsigned int i = 0 ; i < UINT_MAX ; i ++ ) sum ++ ; return sum ; } ; stringTask -> callback = [ & ] ( unsigned int & pNum ) { printf ( " \n \n \n \n " , pNum ) ; } ; printf ( " \n \n " ) ; while ( ! input . keyPressed ( VK_ESCAPE ) ) { input . update ( ) ; AsynchTasks :: TaskManager :: update ( ) ; if ( stringTask -> status != AsynchTasks :: ETaskStatus :: Completed && stringTask -> status != AsynchTasks :: ETaskStatus :: Setup ) printf ( " " ) ; if ( input . keyPressed ( VK_SPACE ) ) { if ( AsynchTasks :: TaskManager :: addTask ( stringTask ) ) printf ( " \n " ) ; } Sleep ( 100 ) ; } } else printf ( " \n " ) ; AsynchTasks :: TaskManager :: destroy ( ) ; }
reusableTask - Test reusing Task objects for similar tasks repeatedly
Author: Mitchell Croft
Created: 24/08/2016
Modified: 12/01/2017
reusableTask - Test reusing Task objects for similar tasks repeatedly Author : Mitchell Croft Created : 24 / 08 / 2016 Modified : 12 / 01 / 2017
//Clear the screen //Create the Task Manager //Create the basic input manager //Create the base job //Set the callback to occur on main //Set the process function //Create a random character string //Loop through and add the totals from 0 to UINT_MAX //Return the sum //Attach the callback function //Display initial instructions //Loop till escape is pressed //Update the input //Update the Task Manager //Output a single '.' //Determine if the user has pressed space //Add the task to the Task Manager //Slow main down to viewable pace //Display error message //Destroy the the Task Manager