A class for managing timestamps of various objects by using names. Dependencies between objects can be specified and checked for being up-to-date. More...
#include <Timestamp.hpp>
Classes | |
class | ObjectInfo |
This class is a helper class for the Timestamp class and holds various information of an object like the timestamp, its dependencies etc. More... | |
Public Member Functions | |
Timestamp () | |
virtual | ~Timestamp () |
ObjectInfo & | operator[] (const std::string &object) |
A class for managing timestamps of various objects by using names. Dependencies between objects can be specified and checked for being up-to-date.
This class provides means to assign timestamps to arbitrary objects such as instances of classes, functions etc. Dependencies between objects can also be specified. The purpose is to check whether one or more dependencies were already set up or are up-to-date and to skip them where appropriate. The aim is to avoid potentially expensive recomputations.
Here is a more elaborate example showing the programming idiom for the timestamp class (you might interprete the wait function as some time consuming code):
#include <ctime> #include <iostream> #include <TRTK/Timestamp.hpp> void wait(const double seconds) { clock_t time = std::clock(); while (double(std::clock() - time) / CLOCKS_PER_SEC < seconds) { // do nothing } } class Demo { public: Demo() { // Initialize the object dependencies. timestamp["B"].addDependency("A"); timestamp["D"].addDependency("B"); timestamp["D"].addDependency("C"); } void A() { std::cout << " A is called." << std::endl; wait(0.5); timestamp["A"].update(); } void B() { std::cout << " B is called." << std::endl; if (timestamp["B"].dependenciesHaveChanged()) { if (timestamp["B"].dependencyHasChanged("A")) A(); wait(0.5); timestamp["B"].update(); } } void C() { std::cout << " C is called." << std::endl; wait(0.5); timestamp["C"].update(); } void D() { std::cout << " D is called." << std::endl; if (timestamp["D"].dependenciesHaveChanged()) { if (timestamp["D"].dependencyHasChanged("B")) B(); if (timestamp["D"].dependencyHasChanged("C")) C(); wait(0.5); timestamp["D"].update(); } } private: TRTK::Timestamp timestamp; }; int main() { Demo demo; std::cout << "Call D:" << std::endl; demo.D(); std::cout << "Call D:" << std::endl; demo.D(); std::cout << "Call A:" << std::endl; demo.A(); std::cout << "Call D:" << std::endl; demo.D(); std::cout << "Call D:" << std::endl; demo.D(); return 0; }
The output is
Call D: D is called. B is called. A is called. C is called. Call D: D is called. Call A: A is called. Call D: D is called. B is called. A is called. Call D: D is called.
Definition at line 194 of file Timestamp.hpp.
TRTK::Timestamp::Timestamp | ( | ) |
Constructs an Timestamp object.
Definition at line 43 of file Timestamp.cpp.
TRTK::Timestamp::~Timestamp | ( | ) | [virtual] |
Destroys an Timestamp object.
Definition at line 50 of file Timestamp.cpp.
Documentation generated by Doxygen