dataflow_producer-snippet.h 327 Bytes
Newer Older
1 2 3
template <typename T>
class Producer {
 public:
4 5
  explicit Producer(int seed) : seed_(seed), count_(4) {}
  bool Run(T& x) {
6 7 8 9 10 11 12 13
    if (count_ >= 0) {
      // produce a new value x
      x = SimpleRand(seed_);
      count_--;
      return true;
    } else {
      return false;
    }
14 15 16 17
  }

 private:
  int seed_;
18
  int count_;
19
};