1 #ifndef MARISA_CONTAINER_H_ 2 #define MARISA_CONTAINER_H_ 3 4 #include <vector> 5 6 #include "base.h" 7 8 namespace marisa { 9 10 template <typename T> 11 class Container; 12 13 template <typename T> 14 class Container<std::vector<T> *> { 15 public: Container(std::vector<T> * vec)16 Container(std::vector<T> *vec) : vec_(vec) {} Container(const Container & container)17 Container(const Container &container) : vec_(container.vec_) {} 18 insert(std::size_t,const T & value)19 void insert(std::size_t, const T &value) const { 20 vec_->push_back(value); 21 } 22 is_valid()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: Container(T * ptr)37 explicit Container(T *ptr) : ptr_(ptr) {} Container(const Container & container)38 Container(const Container &container) : ptr_(container.ptr_) {} 39 insert(std::size_t i,const T & value)40 void insert(std::size_t i, const T &value) { 41 ptr_[i] = value; 42 } 43 is_valid()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> MakeContainer(T * ptr)56inline Container<T *> MakeContainer(T *ptr) { 57 return Container<T *>(ptr); 58 } 59 60 } // namespace marisa 61 62 #endif // MARISA_CONTAINER_H_ 63