testbuf.cpp 745 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "timebuf.hh"
  2. #include <iostream>
  3. using namespace std;
  4. class MyClass
  5. {
  6. private:
  7. int value;
  8. public:
  9. MyClass(): value(0xdeadbeef) {};
  10. int getv() { return value; }
  11. void setv(int v) { value = v; }
  12. };
  13. int main()
  14. {
  15. // we can access data generated in the last 3 time units
  16. // and 0 time units in the future
  17. TimeBuffer<MyClass> mybuf(3, 0);
  18. TimeBuffer<MyClass>::wire toNext = mybuf.getWire(0);
  19. TimeBuffer<MyClass>::wire fromPrev = mybuf.getWire(-3);
  20. toNext->setv(0x55aaaa55);
  21. cout << fromPrev->getv() << endl;
  22. mybuf.advance();
  23. cout << fromPrev->getv() << endl;
  24. mybuf.advance();
  25. cout << fromPrev->getv() << endl;
  26. mybuf.advance();
  27. cout << fromPrev->getv() << endl;
  28. mybuf.advance();
  29. cout << fromPrev->getv() << endl;
  30. }