MHAA Timer Core v1.0.0
Wrapping timer counts and optional control
Loading...
Searching...
No Matches
Run the Timer Core example

The Core borrows a 16-bit fake, snapshots its initial ticks, starts it, asks for elapsed ticks and stops it. The simulated counter does not advance by itself, so elapsed ticks are zero. Use the behavior test to follow an eight-bit wrap, a 32-bit wrap and optional capture from a different implementation.

Example program

The program uses the local fake to demonstrate injection. A concrete Adapter implementing the same Contract can be supplied to the same facade.

#include <timer/timer.hpp>
#include "fake.hpp"
using namespace mhaa::timer;
using namespace example;
int main()
{
Fake counter(16);
Timer timer(counter);
const Count start = timer.ticks();
timer.start();
const Count elapsed = timer.elapsed_since(start);
timer.stop();
return elapsed == 0 ? 0 : 1;
}
Operates a borrowed up counter and computes elapsed ticks across a wrap.
Definition timer.hpp:17

Build and run

Build from this repository root. Set contract_include to the matching Contract's include/ directory. The value below applies to the MHAA development workspace. Both programs exit with status 0 on success and print no output. On Windows execute example.exe and behavior.exe.

contract_include=../../contracts/timer-contract/include
g++ -std=c++11 -Wall -Wextra -Wpedantic -Werror -fno-rtti -fno-exceptions -Iinclude -I"$contract_include" examples/example.cpp -o example
./example
g++ -std=c++11 -Wall -Wextra -Wpedantic -Werror -fno-rtti -fno-exceptions -Iinclude -I"$contract_include" tests/behavior.cpp -o behavior
./behavior

See the behavior test for the additional cases described above.