list.h 659 B

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