]> granicus.if.org Git - icinga2/commitdiff
Add Array::FromVector() method
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 21 Jul 2015 14:09:19 +0000 (16:09 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 21 Jul 2015 14:09:19 +0000 (16:09 +0200)
fixes #9693

lib/base/array.hpp

index f28d66b4be156009194f02e55d36faeeeb0742a8..b224fba31a7445ee42ce28ba6cbae94cca1e55bc 100644 (file)
@@ -21,6 +21,7 @@
 #define ARRAY_H
 
 #include "base/i2-base.hpp"
+#include "base/objectlock.hpp"
 #include "base/value.hpp"
 #include <boost/range/iterator.hpp>
 #include <vector>
@@ -100,6 +101,15 @@ public:
 
        static Object::Ptr GetPrototype(void);
 
+       template<typename T>
+       static Array::Ptr FromVector(const std::vector<T>& v)
+       {
+               Array::Ptr result = new Array();
+               ObjectLock olock(result);
+               std::copy(v.begin(), v.end(), std::back_inserter(result->m_Data));
+               return result;
+       }
+
 private:
        std::vector<Value> m_Data; /**< The data for the array. */
 };