Operation.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. Author: Juan Rada-Vilela, Ph.D.
  3. Copyright (C) 2010-2014 FuzzyLite Limited
  4. All rights reserved
  5. This file is part of fuzzylite.
  6. fuzzylite is free software: you can redistribute it and/or modify it under
  7. the terms of the GNU Lesser General Public License as published by the Free
  8. Software Foundation, either version 3 of the License, or (at your option)
  9. any later version.
  10. fuzzylite is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  13. for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with fuzzylite. If not, see <http://www.gnu.org/licenses/>.
  16. fuzzylite™ is a trademark of FuzzyLite Limited.
  17. */
  18. #ifndef FL_OPERATION_H
  19. #define FL_OPERATION_H
  20. #include "fl/fuzzylite.h"
  21. #include "fl/Exception.h"
  22. #include <string>
  23. #include <vector>
  24. namespace fl {
  25. class FL_API Operation {
  26. public:
  27. template <typename T>
  28. static T min(T a, T b);
  29. template <typename T>
  30. static T max(T a, T b);
  31. template <typename T>
  32. static T bound(T x, T min, T max);
  33. template <typename T>
  34. static bool in(T x, T min, T max, bool geq = true, bool leq = true);
  35. template <typename T>
  36. static bool isInf(T x);
  37. template <typename T>
  38. static bool isNaN(T x);
  39. template <typename T>
  40. static bool isFinite(T x);
  41. //Is less than
  42. static bool isLt(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
  43. static bool isLE(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
  44. static bool isEq(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
  45. static bool isGt(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
  46. static bool isGE(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
  47. static scalar scale(scalar x, scalar fromMin, scalar fromMax,
  48. scalar toMin, scalar toMax, bool bounded = false);
  49. static scalar add(scalar a, scalar b);
  50. static scalar subtract(scalar a, scalar b);
  51. static scalar multiply(scalar a, scalar b);
  52. static scalar divide(scalar a, scalar b);
  53. static scalar modulo(scalar a, scalar b);
  54. static scalar logicalAnd(scalar a, scalar b);
  55. static scalar logicalOr(scalar a, scalar b);
  56. static scalar logicalNot(scalar a);
  57. static scalar negate(scalar a);
  58. static scalar round(scalar x);
  59. //greater than
  60. static scalar gt(scalar a, scalar b);
  61. //greater than or equal to
  62. static scalar ge(scalar a, scalar b);
  63. //equal to
  64. static scalar eq(scalar a, scalar b);
  65. //not equal to
  66. static scalar neq(scalar a, scalar b);
  67. //less than or equal to
  68. static scalar le(scalar a, scalar b);
  69. //less than
  70. static scalar lt(scalar a, scalar b);
  71. static bool increment(std::vector<int>& x, std::vector<int>& min, std::vector<int>& max);
  72. static bool increment(std::vector<int>& x, int position, std::vector<int>& min, std::vector<int>& max);
  73. static double mean(const std::vector<scalar>& x);
  74. static double variance(const std::vector<scalar>& x);
  75. static double variance(const std::vector<scalar>& x, scalar mean);
  76. static double standardDeviation(const std::vector<scalar>& x);
  77. static double standardDeviation(const std::vector<scalar>& x, scalar mean);
  78. static std::string validName(const std::string& name);
  79. static int isValidForName(int character);
  80. static std::string findReplace(const std::string& str, const std::string& find,
  81. const std::string& replace, bool replaceAll = true);
  82. static std::vector<std::string> split(const std::string& str,
  83. const std::string& delimiter = " ", bool ignoreEmpty = true);
  84. static std::string trim(const std::string& text);
  85. static std::string format(const std::string& text, int matchesChar(int),
  86. const std::string& replacement = "");
  87. //Intentionally results in a compiler error in C++11, or linker error in C++98
  88. //in order to avoid the deprecated usage of this method from version 4.0
  89. static scalar toScalar(const std::string& x, bool quiet,
  90. scalar alternative = fl::nan) FL_IDELETE;
  91. static scalar toScalar(const std::string& x); //throws fl::Exception
  92. static scalar toScalar(const std::string& x, scalar alternative) FL_INOEXCEPT;
  93. static bool isNumeric(const std::string& x);
  94. template <typename T>
  95. static std::string str(T x, int decimals = fuzzylite::decimals());
  96. template <typename T>
  97. static std::string join(const std::vector<T>& x, const std::string& separator);
  98. template <typename T>
  99. static std::string join(int items, const std::string& separator, T first, ...);
  100. };
  101. typedef Operation Op;
  102. }
  103. #endif /* FL_OPERATION_H */