container.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef container_hpp
  2. #define container_hpp
  3. #include "value.hpp"
  4. #include "filter.hpp"
  5. #include <vector>
  6. namespace filval{
  7. class GenContainer{
  8. private:
  9. std::string name;
  10. std::string desc;
  11. std::vector<Filter*> filters;
  12. protected:
  13. virtual void _fill() = 0;
  14. public:
  15. GenContainer(const std::string name)
  16. :name(name){ }
  17. void add_filter(GenValue* filter){
  18. filters.push_back(dynamic_cast<Filter*>(filter));
  19. }
  20. void fill(){
  21. for (auto filter : filters){
  22. if (!filter->get_value()){
  23. return;
  24. }
  25. }
  26. _fill();
  27. }
  28. void set_description(const std::string& description){
  29. desc = description;
  30. }
  31. const std::string& get_name(){
  32. return name;
  33. }
  34. };
  35. typedef std::map<std::string, GenContainer*> ContainerSet;
  36. template <typename H>
  37. class Container : public GenContainer{
  38. protected:
  39. H* container;
  40. public:
  41. Container(H* container, const std::string name)
  42. :GenContainer(name),
  43. container(container){ }
  44. virtual H* get_container(){
  45. return container;
  46. }
  47. };
  48. template <typename T>
  49. class ContainerVector : public Container<std::vector<T> >{
  50. private:
  51. Value<T>* value;
  52. void _fill(){
  53. this->container->push_back(value->get_value());
  54. }
  55. public:
  56. ContainerVector(std::vector<T> *container, Value<T>* value, const std::string name)
  57. :Container<std::vector<T> >(container, name),
  58. value(value){ }
  59. ContainerVector(Value<T>* value, const std::string name)
  60. :Container<std::vector<T> >(NULL, name),
  61. value(value){
  62. this->container = new std::vector<T>();
  63. }
  64. };
  65. }
  66. #endif // container_hpp