tape.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // tape.hpp
  3. // shared_random_generator
  4. //
  5. // Created by Sam Jaffe on 3/19/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <utility>
  10. #include <vector>
  11. #include <random/device.h>
  12. #define DECLARE_TAPE(T) \
  13. T apply(Distribution<T> const & dist) final; \
  14. T apply(Distribution<T> const & dist, T value);
  15. namespace engine::random {
  16. class Tape : public Device {
  17. public:
  18. // Allow for the serialization and de-serialization of this Tape
  19. using serial_type = std::vector<std::pair<std::string, uint64_t>>;
  20. friend class Random;
  21. private:
  22. size_t index_{0}; // transient
  23. serial_type entries_;
  24. std::shared_ptr<Tape> child_{nullptr};
  25. public:
  26. Tape() = default;
  27. Tape(std::shared_ptr<Tape> child) : child_(child) {}
  28. Tape(serial_type serial) : entries_(std::move(serial)) {}
  29. explicit operator serial_type() const { return entries_; }
  30. private:
  31. IMPLEMENT_DEVICE(DECLARE_TAPE)
  32. result_type operator()() final { throw; }
  33. template <typename T> T poll(std::string const & dist);
  34. template <typename T> T operator()(Distribution<T> const & dist);
  35. };
  36. }
  37. #undef DECLARE_TAPE