api.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef API_HPP
  2. #define API_HPP
  3. #include <string>
  4. #include <vector>
  5. #include "filval/value.hpp"
  6. namespace fv{
  7. template<typename T>
  8. Value<T>* lookup(const std::string& name){
  9. GenValue* gv = GenValue::get_value(name);
  10. Value<T>* tv = dynamic_cast<Value<T>*>(gv);
  11. if(tv == nullptr){
  12. CRITICAL("Value: "+gv->get_name() + "has improper type.",-1);
  13. }
  14. return tv;
  15. }
  16. ObsFilter* lookup_obs_filter(const std::string& name){
  17. ObsFilter* f = dynamic_cast<ObsFilter*>(GenValue::get_value(name));
  18. if(f == nullptr){
  19. CRITICAL("ObsFilter: "+f->get_name() + "has improper type.",-1);
  20. }
  21. return f;
  22. }
  23. template <typename... ArgTypes>
  24. Zip<ArgTypes...>* zip(Value<std::vector<ArgTypes>>*... args, const std::string& alias=""){
  25. return new Zip<ArgTypes...>(args..., alias);
  26. }
  27. template <typename Ret, typename... ArgTypes>
  28. Map<Ret(ArgTypes...)>* map(Function<Ret(ArgTypes...)>& fn,
  29. Zip<ArgTypes...>* arg, const std::string& alias=""){
  30. return new Map<Ret(ArgTypes...)>(fn, arg, alias);
  31. }
  32. template <typename... ArgTypes>
  33. Tuple<ArgTypes...>* tuple(Value<ArgTypes>*... args, const std::string& alias=""){
  34. return new Tuple<ArgTypes...>(args..., alias);
  35. }
  36. template <typename Ret, typename... ArgTypes>
  37. Apply<Ret(ArgTypes...)>* apply(Function<Ret(ArgTypes...)>& fn,
  38. Tuple<ArgTypes...>* arg, const std::string& alias=""){
  39. return new Apply<Ret(ArgTypes...)>(fn, arg, alias);
  40. }
  41. template <typename T1, typename T2>
  42. Pair<T1, T2>* pair(Value<T1>* val1, Value<T2>* val2, const std::string& alias=""){
  43. return new Pair<T1,T2>(val1, val2, alias);
  44. }
  45. template <typename T1, typename T2>
  46. Pair<T1, T2>* pair(const std::string& name1, const std::string& name2, const std::string& alias=""){
  47. return pair<T1,T2>(lookup<T1>(name1), lookup<T2>(name2), alias);
  48. }
  49. template <typename T>
  50. Max<T>* max(Value<std::vector<T>>* v, const std::string alias){
  51. return new Max<T>(v, alias);
  52. }
  53. template <typename T>
  54. Max<T>* max(const std::string& v_name, const std::string alias){
  55. return max(lookup<std::vector<T>>(v_name), alias);
  56. }
  57. template <typename T>
  58. Min<T>* min(Value<std::vector<T>>* v, const std::string alias){
  59. return new Min<T>(v, alias);
  60. }
  61. template <typename T>
  62. Min<T>* min(const std::string& v_name, const std::string alias){
  63. return min(lookup<std::vector<T>>(v_name), alias);
  64. }
  65. template <typename T>
  66. Range<T>* range(Value<std::vector<T>>* v, const std::string alias){
  67. return new Range<T>(v, alias);
  68. }
  69. template <typename T>
  70. Range<T>* range(const std::string& v_name, const std::string alias){
  71. return range(lookup<std::vector<T>>(v_name), alias);
  72. }
  73. template <typename T>
  74. Mean<T>* mean(Value<std::vector<T>>* v, const std::string alias){
  75. return new Mean<T>(v, alias);
  76. }
  77. template <typename T>
  78. Mean<T>* mean(const std::string& v_name, const std::string alias){
  79. return mean(lookup<std::vector<T>>(v_name), alias);
  80. }
  81. template <typename T>
  82. Count<T>* count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias){
  83. return new Count<T>(selector, v, alias);
  84. }
  85. template <typename T>
  86. Count<T>* count(Function<bool(T)>& selector, const std::string& v_name, const std::string alias){
  87. return count<T>(selector, lookup<std::vector<T>>(v_name), alias);
  88. }
  89. ObsFilter* obs_filter(const std::string& name, std::function<bool()> filter_function, const std::string& impl=""){
  90. return new ObsFilter(name, filter_function, impl);
  91. }
  92. }
  93. #endif // API_HPP