tape.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. private:
  21. size_t index_{0}; // transient
  22. serial_type entries_;
  23. public:
  24. Tape() = default;
  25. Tape(serial_type serial) : entries_(std::move(serial)) {}
  26. explicit operator serial_type() const { return entries_; }
  27. IMPLEMENT_DEVICE(DECLARE_TAPE)
  28. private:
  29. result_type operator()() final { throw; }
  30. template <typename T> T poll(std::string const & dist);
  31. template <typename T> T operator()(Distribution<T> const & dist);
  32. };
  33. }
  34. #undef DECLARE_TAPE