TTTT Analysis  0.1
api.hpp
1 #ifndef API_HPP
2 #define API_HPP
3 #include <string>
4 #include <vector>
5 #include "filval/value.hpp"
6 namespace fv{
7 
8  template<typename T>
9  Value<T>* lookup(const std::string& name){
10  GenValue* gv = GenValue::get_value(name);
11  Value<T>* tv = dynamic_cast<Value<T>*>(gv);
12  if(tv == nullptr){
13  CRITICAL("Value: \""+gv->get_name() + "\" has improper type.",-1);
14  }
15  return tv;
16  }
17 
18  ObsFilter* lookup_obs_filter(const std::string& name){
19  ObsFilter* f = dynamic_cast<ObsFilter*>(GenValue::get_value(name));
20  if(f == nullptr){
21  CRITICAL("ObsFilter: "+f->get_name() + "has improper type.",-1);
22  }
23  return f;
24  }
25 
26  template <typename... ArgTypes>
27  Value<std::vector<std::tuple<ArgTypes...>>>*
28  zip(Value<std::vector<ArgTypes>>*... args, const std::string& alias=""){
29  return new Zip<ArgTypes...>(args..., alias);
30  }
31 
32  template <typename Ret, typename... ArgTypes>
33  Map<Ret(ArgTypes...)>*
34  map(Function<Ret(ArgTypes...)>& fn,
35  Value<std::vector<std::tuple<ArgTypes...>>>* arg, const std::string& alias=""){
36  return new Map<Ret(ArgTypes...)>(fn, arg, alias);
37  }
38 
39 
40  template <typename... ArgTypes>
41  Tuple<ArgTypes...>*
42  tuple(Value<ArgTypes>*... args, const std::string& alias=""){
43  return new Tuple<ArgTypes...>(args..., alias);
44  }
45 
46  template <typename Ret, typename... ArgTypes>
47  Apply<Ret(ArgTypes...)>*
48  apply(Function<Ret(ArgTypes...)>& fn,
49  Tuple<ArgTypes...>* arg, const std::string& alias=""){
50  return new Apply<Ret(ArgTypes...)>(fn, arg, alias);
51  }
52 
53  template <typename T1, typename T2>
55  pair(Value<T1>* val1, Value<T2>* val2, const std::string& alias=""){
56  return new Pair<T1,T2>(val1, val2, alias);
57  }
58 
59  template <typename T1, typename T2>
61  pair(const std::string& name1, const std::string& name2, const std::string& alias=""){
62  return pair<T1,T2>(lookup<T1>(name1), lookup<T2>(name2), alias);
63  }
64 
65 
66  template <typename T>
67  Max<T>*
68  max(Value<std::vector<T>>* v, const std::string alias){
69  return new Max<T>(v, alias);
70  }
71 
72  template <typename T>
73  Max<T>*
74  max(const std::string& v_name, const std::string alias){
75  return max(lookup<std::vector<T>>(v_name), alias);
76  }
77 
78  template <typename T>
79  Min<T>*
80  min(Value<std::vector<T>>* v, const std::string alias){
81  return new Min<T>(v, alias);
82  }
83 
84  template <typename T>
85  Min<T>*
86  min(const std::string& v_name, const std::string alias){
87  return min(lookup<std::vector<T>>(v_name), alias);
88  }
89 
90  template <typename T>
91  Range<T>*
92  range(Value<std::vector<T>>* v, const std::string alias){
93  return new Range<T>(v, alias);
94  }
95 
96  template <typename T>
97  Range<T>*
98  range(const std::string& v_name, const std::string alias){
99  return range(lookup<std::vector<T>>(v_name), alias);
100  }
101 
102  template <typename T>
103  Mean<T>*
104  mean(Value<std::vector<T>>* v, const std::string alias){
105  return new Mean<T>(v, alias);
106  }
107 
108  template <typename T>
109  Mean<T>*
110  mean(const std::string& v_name, const std::string alias){
111  return mean(lookup<std::vector<T>>(v_name), alias);
112  }
113 
114  template <typename T>
115  Count<T>*
116  count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias){
117  return new Count<T>(selector, v, alias);
118  }
119 
120  template <typename T>
121  Count<T>*
122  count(Function<bool(T)>& selector, const std::string& v_name, const std::string alias){
123  return count<T>(selector, lookup<std::vector<T>>(v_name), alias);
124  }
125 
126  template <typename FST, typename SND>
128  cart_product(Value<std::vector<FST>>* val1, Value<std::vector<SND>>* val2, const std::string alias){
129  return new CartProduct<FST, SND>(val1, val2, alias);
130  }
131 
132  template <typename FST, typename SND>
134  cart_product(const std::string& val1_name, const std::string& val2_name, const std::string alias = ""){
135  return cart_product<FST,SND>(lookup<std::vector<FST>>(val1_name), lookup<std::vector<SND>>(val2_name), alias);
136  }
137 
138  ObsFilter* obs_filter(const std::string& name, std::function<bool()> filter_function, const std::string& impl=""){
139  return new ObsFilter(name, filter_function, impl);
140  }
141 }
142 #endif // API_HPP
Find and return the maximum value of a vector.
Definition: value.hpp:788
Zips a series of vectors together.
Definition: value.hpp:546
Calculate the range of the values in a vector.
Definition: value.hpp:829
Takes a series of Value objects and bundles them together into a std::tuple object.
Definition: value.hpp:670
Returns the count of elements in the input vector passing a test function.
Definition: value.hpp:717
Find and return the minimum value of a vector.
Definition: value.hpp:801
Creates a std::pair type from a two other Value objects.
Definition: value.hpp:467
The namespace containing all filval classes and functions.
Definition: api.hpp:6
Calculate the mean value of a vector.
Definition: value.hpp:814
A generic value.
Definition: value.hpp:352
Find and return the minimum value of a vector and its index.
Definition: value.hpp:904