Parcourir la source

Adds documentation deployment make target, additional values relating to
leading objects

Caleb Fangmeier il y a 7 ans
Parent
commit
8be6413ed7
2 fichiers modifiés avec 19 ajouts et 5 suppressions
  1. 10 0
      api.hpp
  2. 9 5
      value.hpp

+ 10 - 0
api.hpp

@@ -164,6 +164,16 @@ namespace fv{
         return pair<T1,T2>(lookup<T1>(name1), lookup<T2>(name2), alias);
     }
 
+    template <typename T>
+    decltype(auto)
+    reduce(Function<T(std::vector<T>)>& fn, Value<std::vector<T>>* v, const std::string& alias=""){
+        typedef T type;
+        const std::string& name = Reduce<T>::fmt_name(fn, v);
+        if (check_exists<type>(name))
+            return lookup<type>(name);
+        else
+            return (Value<type>*)new Reduce<T>(fn, v, alias);
+    }
 
     template <typename T>
     decltype(auto)

+ 9 - 5
value.hpp

@@ -950,19 +950,23 @@ class TupFilter : public DerivedValue<std::vector<std::tuple<ArgTypes...>>>{
 template <typename T>
 class Reduce : public DerivedValue<T>{
     private:
-        Function<T(std::vector<T>)>& reduce;
+        Function<T(std::vector<T>)>& reduce_fn;
 
         void update_value(){
-            this->value = reduce(v->get_value());
+            this->value = reduce_fn(v->get_value());
         }
 
     protected:
         Value<std::vector<T> >* v;
 
     public:
-        Reduce(Function<T(std::vector<T>)>& reduce, Value<std::vector<T> >* v, const std::string alias)
-          :DerivedValue<T>("reduceWith("+reduce.get_name()+":"+v->get_name()+")", alias),
-           reduce(reduce), v(v) { }
+        static std::string fmt_name(Function<T(std::vector<T>)>& reduce_fn, Value<std::vector<T>>* v){
+            return "reduce("+reduce_fn.get_name()+":"+v->get_name()+")";
+        }
+
+        Reduce(Function<T(std::vector<T>)>& reduce_fn, Value<std::vector<T> >* v, const std::string alias)
+          :DerivedValue<T>(fmt_name(reduce_fn, v), alias),
+           reduce_fn(reduce_fn), v(v) { }
 };
 
 /**