api.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. Filter* lookup_filter(const std::string& name){
  17. Filter* f = dynamic_cast<Filter*>(GenValue::get_value(name));
  18. if(f == nullptr){
  19. CRITICAL("Filter: "+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 T1, typename T2>
  28. Pair<T1, T2>* pair(Value<T1>* val1, Value<T2>* val2, const std::string& alias=""){
  29. return new Pair<T1,T2>(val1, val2, alias);
  30. }
  31. template <typename T1, typename T2>
  32. Pair<T1, T2>* pair(const std::string& name1, const std::string& name2, const std::string& alias=""){
  33. return pair<T1,T2>(lookup<T1>(name1), lookup<T2>(name2), alias);
  34. }
  35. template <typename Ret, typename... ArgTypes>
  36. MapOver<Ret(ArgTypes...)>* map_over(Function<Ret(ArgTypes...)>& fn,
  37. Zip<ArgTypes...>* arg, const std::string& alias=""){
  38. return new MapOver<Ret(ArgTypes...)>(fn, arg, alias);
  39. }
  40. template <typename T>
  41. Max<T>* max(Value<std::vector<T>>* v, const std::string alias){
  42. return new Max<T>(v, alias);
  43. }
  44. template <typename T>
  45. Max<T>* max(const std::string& v_name, const std::string alias){
  46. return max(lookup<std::vector<T>>(v_name), alias);
  47. }
  48. template <typename T>
  49. Min<T>* min(Value<std::vector<T>>* v, const std::string alias){
  50. return new Min<T>(v, alias);
  51. }
  52. template <typename T>
  53. Min<T>* min(const std::string& v_name, const std::string alias){
  54. return min(lookup<std::vector<T>>(v_name), alias);
  55. }
  56. template <typename T>
  57. Range<T>* range(Value<std::vector<T>>* v, const std::string alias){
  58. return new Range<T>(v, alias);
  59. }
  60. template <typename T>
  61. Range<T>* range(const std::string& v_name, const std::string alias){
  62. return range(lookup<std::vector<T>>(v_name), alias);
  63. }
  64. template <typename T>
  65. Mean<T>* mean(Value<std::vector<T>>* v, const std::string alias){
  66. return new Mean<T>(v, alias);
  67. }
  68. template <typename T>
  69. Mean<T>* mean(const std::string& v_name, const std::string alias){
  70. return mean(lookup<std::vector<T>>(v_name), alias);
  71. }
  72. template <typename T>
  73. Count<T>* count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias){
  74. return new Count<T>(selector, v, alias);
  75. }
  76. template <typename T>
  77. Count<T>* count(Function<bool(T)>& selector, const std::string& v_name, const std::string alias){
  78. return count<T>(selector, lookup<std::vector<T>>(v_name), alias);
  79. }
  80. Filter* filter(const std::string& name, std::function<bool()> filter_function, const std::string& impl=""){
  81. return new Filter(name, filter_function, impl);
  82. }
  83. }
  84. #endif // API_HPP