Browse Source

move definition of vector to vector.h

Fabian Peter Hammerle 7 years ago
parent
commit
6a549b5f4d
2 changed files with 28 additions and 18 deletions
  1. 1 18
      main.cpp
  2. 27 0
      vector.h

+ 1 - 18
main.cpp

@@ -1,3 +1,4 @@
+#include "vector.h"
 #include "yaml.h"
 
 #include <assert.h>
@@ -9,7 +10,6 @@
 #include <linux/rtnetlink.h>
 #include <sstream>
 #include <string>
-#include <vector>
 
 // https://netfilter.org/projects/libmnl/doxygen/html/modules.html
 
@@ -57,23 +57,6 @@ struct Link : public YamlObject {
   }
 };
 
-template <class T> class vector : public std::vector<T>, YamlObject {
-public:
-  void write_yaml(std::ostream &stream,
-                  const yaml_indent_level_t indent_level = 0) const {
-    if (this->empty()) {
-      stream << "[]";
-    } else {
-      const std::string indent(indent_level, ' ');
-      stream << "\n";
-      for (auto it = this->begin(); it != this->end(); it++) {
-        stream << indent << "- ";
-        it->write_yaml(stream, indent_level + 2);
-      }
-    }
-  }
-};
-
 static int link_attr_cb(const nlattr *attr, void *data) {
   Link *link = (Link *)data;
   // /usr/include/linux/if_link.h

+ 27 - 0
vector.h

@@ -0,0 +1,27 @@
+#ifndef _IPYML_VECTOR_H
+#define _IPYML_VECTOR_H
+
+#include "yaml.h"
+
+#include <ostream>
+#include <string>
+#include <vector>
+
+template <class T> class vector : public std::vector<T>, YamlObject {
+public:
+  void write_yaml(std::ostream &stream,
+                  const yaml_indent_level_t indent_level = 0) const {
+    if (this->empty()) {
+      stream << "[]";
+    } else {
+      const std::string indent(indent_level, ' ');
+      stream << "\n";
+      for (auto it = this->begin(); it != this->end(); it++) {
+        stream << indent << "- ";
+        it->write_yaml(stream, indent_level + 2);
+      }
+    }
+  }
+};
+
+#endif