1 #ifndef MARISA_ALPHA_CONTAINER_H_ 2 #define MARISA_ALPHA_CONTAINER_H_ 3 4 #include <vector> 5 6 #include "base.h" 7 8 namespace marisa_alpha { 9 10 template <typename T> 11 class Container; 12 13 template <typename T> 14 class Container<std::vector<T> *> { 15 public: 16 Container(std::vector<T> *vec) : vec_(vec) {} 17 Container(const Container &container) : vec_(container.vec_) {} 18 19 void insert(std::size_t, const T &value) const { 20 vec_->push_back(value); 21 } 22 23 bool is_valid() const { 24 return vec_ != NULL; 25 } 26 27 private: 28 std::vector<T> *vec_; 29 30 // Disallows assignment. 31 Container &operator=(const Container &query); 32 }; 33 34 template <typename T> 35 class Container<T *> { 36 public: 37 explicit Container(T *ptr) : ptr_(ptr) {} 38 Container(const Container &container) : ptr_(container.ptr_) {} 39 40 void insert(std::size_t i, const T &value) { 41 ptr_[i] = value; 42 } 43 44 bool is_valid() const { 45 return ptr_ != NULL; 46 } 47 48 private: 49 T *ptr_; 50 51 // Disallows assignment. 52 Container &operator=(const Container &); 53 }; 54 55 template <typename T> 56 inline Container<T *> MakeContainer(T *ptr) { 57 return Container<T *>(ptr); 58 } 59 60 } // namespace marisa_alpha 61 62 #endif // MARISA_ALPHA_CONTAINER_H_ 63