vector.h 680 B

123456789101112131415161718192021222324252627282930
  1. #ifndef _IPYML_VECTOR_H
  2. #define _IPYML_VECTOR_H
  3. #include "yaml.h"
  4. #include <ostream>
  5. #include <string>
  6. #include <vector>
  7. template <class T> class vector : public std::vector<T>, YamlObject {
  8. public:
  9. void write_yaml(std::ostream &stream,
  10. yaml_indent_level_t indent_level = 0) const {
  11. if (this->empty()) {
  12. stream << "[]";
  13. } else {
  14. if (indent_level > 2) {
  15. indent_level -= 2;
  16. }
  17. const std::string indent(indent_level, ' ');
  18. stream << "\n";
  19. for (auto it = this->begin(); it != this->end(); it++) {
  20. stream << indent << "- ";
  21. it->write_yaml(stream, indent_level + 2);
  22. }
  23. }
  24. }
  25. };
  26. #endif