1 /* 2 * Copyright 2021, Andrew Lindesay <apl@lindesay.co.nz> 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef COLLECTOR_H 6 #define COLLECTOR_H 7 8 9 #include <vector> 10 11 12 template <typename T> 13 class Collector { 14 public: 15 virtual void Add(T value) = 0; 16 }; 17 18 19 template <typename T> 20 class VectorCollector : public Collector<T> { 21 public: 22 VectorCollector(std::vector<T>& target) 23 : 24 fTarget(target) 25 { 26 } 27 28 virtual void Add(T value) { 29 fTarget.push_back(value); 30 } 31 32 private: 33 std::vector<T>& fTarget; 34 }; 35 36 37 #endif // COLLECTOR_H 38