50 #include <initializer_list> 87 inline static std::map<const std::string, GenValue*>
values;
93 const std::string& get_name(){
97 for (
auto val : values){
101 static GenValue* get_value(
const std::string& name){
102 return values.at(name);
104 static void summary(){
105 std::cout <<
"The following values have been created: " << std::endl;
106 for (
auto value : values){
107 std::cout <<
"\t\"" << value.first <<
"\" at address " << value.second << std::endl;
111 typedef std::map<std::string, GenValue*> ValueSet;
123 template <
typename T>
130 virtual T& get_value() = 0;
143 template <
typename T>
173 template <
typename T>
191 virtual void update_value() = 0;
195 value_valid(
false) { }
217 template <
typename T>
226 this->value.resize(n);
227 for (
int i=0; i<n; i++){
228 this->value[i] = *(data_ref+i);
235 size(_size), data(_data){ }
237 WrapperVector(
const std::string& name,
const std::string &label_size,
const std::string &label_data)
246 template <
typename T1,
typename T2>
249 std::pair<Value<T1>*,
Value<T2>* > value_pair;
251 this->value.first = value_pair.first->get_value();
252 this->value.second = value_pair.second->get_value();
257 value_pair(value1, value2){ }
258 Pair(
const std::string& name,
const std::string& label1,
const std::string& label2)
277 template <
typename R,
typename T>
280 std::function<R(T, T, T, T)> f;
293 std::tie(n, std::ignore) = std::minmax({v1_val.size(), v2_val.size(), v3_val.size(), v4_val.size()});
294 this->value.resize(n);
295 for (
int i=0; i<n; i++){
296 this->value[i] = f(v1_val[i], v2_val[i], v3_val[i], v4_val[i]);
301 ZipMapFour(
const std::string&
name, std::function<R(T, T, T, T)> f,
302 Value<std::vector<T> >* v1,
Value<std::vector<T> >* v2,
303 Value<std::vector<T> >* v3,
Value<std::vector<T> >* v4)
305 f(f), v1(v1), v2(v2), v3(v3), v4(v4) { }
308 std::function<R(T, T, T, T)> f,
309 const std::string &label1,
const std::string &label2,
310 const std::string &label3,
const std::string &label4)
324 template <
typename T>
327 std::function<T(std::vector<T>)> reduce;
333 Reduce(
const std::string&
name, std::function<T(std::vector<T>)> reduce,
Value<std::vector<T> >* v)
335 reduce(reduce), v(v) { }
337 Reduce(
const std::string& name, std::function<T(std::vector<T>)> reduce,
const std::string& v_name)
344 template <
typename T>
347 Max(
const std::string&
name,
const std::string& v_name)
348 :
Reduce<T>(
name, [](std::vector<T> vec){
return std::max(vec.begin(), vec.end());}, v_name) { }
354 template <
typename T>
357 Min(
const std::string&
name,
const std::string& v_name)
358 :
Reduce<T>(
name, [](std::vector<T> vec){
return std::min(vec.begin(), vec.end());}, v_name) { }
364 template <
typename T>
367 Mean(
const std::string&
name,
const std::string& v_name)
369 [](std::vector<T> vec){
370 int n = 0; T sum = 0;
371 for (T e : vec){ n++; sum += e; }
372 return n>0 ? sum / n : 0; },
379 template <
typename T>
384 ElementOf(
const std::string& name,
int index,
const std::string& v_name)
385 :
Reduce<T>(
name, [index](std::vector<T> vec){
return vec[index];}, v_name) { }
393 template <
typename T>
396 std::function<std::pair<T,int>(std::vector<T>)> reduce;
399 this->value = reduce(v->get_value());
402 ReduceIndex(
const std::string&
name, std::function<std::pair<T,int>(std::vector<T>)> reduce,
Value<std::vector<T> >* v)
404 reduce(reduce), v(v) { }
406 ReduceIndex(
const std::string& name, std::function<std::pair<T,int>(std::vector<T>)> reduce,
const std::string& v_name)
413 template <
typename T>
416 MaxIndex(
const std::string&
name,
const std::string& v_name)
418 [](std::vector<T> vec){
419 auto elptr = std::max_element(vec.begin(), vec.end());
420 return std::pair<T,int>(*elptr, int(elptr-vec.begin()));},
427 template <
typename T>
430 MinIndex(
const std::string&
name,
const std::string& v_name)
432 [](std::vector<T> vec){
433 auto elptr = std::min_element(vec.begin(), vec.end());
434 return std::pair<T,int>(*elptr, int(elptr-vec.begin()));},
442 template <
typename R,
typename... T>
445 std::function<R(T...)> f;
446 std::tuple<T...> value_tuple;
449 this->value = f(value_tuple);
453 MultiFunc(
const std::string&
name, std::function<R(std::tuple<T...>)> f, T... varargs)
456 value_tuple(varargs...){ }
464 template <
typename T>
467 std::function<T()> f;
480 template <
typename T>
485 this->value = const_value;
490 const_value(const_value) { }
void update_value()
Updates the internal value.
Definition: value.hpp:329
std::string name
The name of the value.
Definition: value.hpp:71
virtual T & get_value()=0
Calculate, if necessary, and return the value held by this object.
A type-agnostic value.
Definition: value.hpp:64
Calculate the mean value of a vector.
Definition: value.hpp:365
A generic, derived, value.
Definition: value.hpp:174
T & get_value()
Calculate, if necessary, and return the value held by this object.
Definition: value.hpp:152
A variadic.
Definition: value.hpp:443
void _reset()
Mark the internal value as invalid.
Definition: value.hpp:147
A Value which always returns the same value, supplied in the constructor.
Definition: value.hpp:481
The namespace containing all filval classes and functions.
Definition: container.hpp:7
A generic value owning only a function object.
Definition: value.hpp:465
A std::vector wrapper around a C-style array.
Definition: value.hpp:218
void update_value()
Updates the internal value.
Definition: value.hpp:223
void update_value()
Updates the internal value.
Definition: value.hpp:398
Creates a std::pair type from a two other Value objects.
Definition: value.hpp:247
Find and return the minimum value of a vector.
Definition: value.hpp:355
Find and return the maximum value of a vector.
Definition: value.hpp:345
Takes a set of four Value<std::vector<T> > objects and a function of four Ts and returns a std::vecto...
Definition: value.hpp:278
void update_value()
Updates the internal value.
Definition: value.hpp:484
Similar to Reduce, but returns a pair of a T and an int.
Definition: value.hpp:394
A generic value.
Definition: value.hpp:124
Find and return the maximum value of a vector and its index.
Definition: value.hpp:414
static std::map< const std::string, GenValue * > values
A static mapping containing all created Value objects.
Definition: value.hpp:87
void update_value()
Updates the internal value.
Definition: value.hpp:448
Reduce a Value of type vector<T> to just a T.
Definition: value.hpp:325
Find and return the minimum value of a vector and its index.
Definition: value.hpp:428
void update_value()
Updates the internal value.
Definition: value.hpp:250
A generic, observed, value.
Definition: value.hpp:144
void update_value()
Updates the internal value.
Definition: value.hpp:468
void _reset()
Mark the internal value as invalid.
Definition: value.hpp:176
T & get_value()
Calculate, if necessary, and return the value held by this object.
Definition: value.hpp:197
Extract the element at a specific index from a vector.
Definition: value.hpp:380
virtual void _reset()=0
Mark the internal value as invalid.
void update_value()
Updates the internal value.
Definition: value.hpp:286