fuzzylite.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_FUZZYLITE_H
  19. #define FL_FUZZYLITE_H
  20. #include <algorithm>
  21. #include <cmath>
  22. #include <iostream>
  23. #include <sstream>
  24. #include <limits>
  25. #include <memory>
  26. #ifndef FL_VERSION
  27. #define FL_VERSION "?"
  28. #endif
  29. #ifndef FL_DATE
  30. #define FL_DATE "?"
  31. #endif
  32. #ifndef FL_BUILD_PATH
  33. #define FL_BUILD_PATH ""
  34. #endif
  35. #define FL__FILE__ std::string(__FILE__).substr(std::string(FL_BUILD_PATH).size())
  36. #define FL_LOG_PREFIX FL__FILE__ << " [" << __LINE__ << "]:"
  37. #define FL_AT FL__FILE__, __LINE__, __FUNCTION__
  38. #define FL_LOG(message) {if (fl::fuzzylite::logging()){std::cout << FL_LOG_PREFIX << message << std::endl;}}
  39. #define FL_LOGP(message) {if (fl::fuzzylite::logging()){std::cout << message << std::endl;}}
  40. #define FL_DEBUG_BEGIN if (fl::fuzzylite::debug()){
  41. #define FL_DEBUG_END }
  42. #define FL_DBG(message) FL_DEBUG_BEGIN\
  43. std::cout << FL__FILE__ << "::" << __FUNCTION__ << "[" << __LINE__ << "]:" \
  44. << message << std::endl;\
  45. FL_DEBUG_END
  46. #ifdef FL_WINDOWS
  47. #include <ciso646> //alternative operator spellings:
  48. //#define and &&
  49. //#define or ||
  50. //#define not !
  51. //#define bitand &
  52. //#define bitor |
  53. //TODO: Address warning 4251 by exporting members?
  54. //http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
  55. #ifdef _MSC_VER
  56. #pragma warning (disable:4251)
  57. #endif
  58. //fuzzylite as a shared library is exported
  59. //Applications linking with fuzzylite as a shared library need to import
  60. //fuzzylite as a static library does not export or import
  61. //Applications linking with fuzzylite as a static library do not import
  62. #if defined(FL_EXPORT_LIBRARY)
  63. #define FL_API __declspec(dllexport)
  64. #elif defined(FL_IMPORT_LIBRARY)
  65. #define FL_API __declspec(dllimport)
  66. #else
  67. #define FL_API
  68. #endif
  69. #else
  70. #define FL_API
  71. #endif
  72. namespace fl {
  73. #ifdef FL_USE_FLOAT
  74. typedef float scalar;
  75. #else
  76. typedef double scalar;
  77. #endif
  78. const scalar nan = std::numeric_limits<scalar>::quiet_NaN();
  79. const scalar inf = std::numeric_limits<scalar>::infinity();
  80. #ifdef FL_CPP11
  81. //C++11 defines
  82. //Pointers
  83. const std::nullptr_t null = nullptr;
  84. #define FL_unique_ptr std::unique_ptr
  85. #define FL_move_ptr(x) std::move(x)
  86. //Identifiers
  87. #define FL_IOVERRIDE override
  88. #define FL_IFINAL final
  89. #define FL_IDEFAULT = default
  90. #define FL_IDELETE = delete
  91. #define FL_INOEXCEPT noexcept
  92. //Constructors
  93. #define FL_DEFAULT_COPY(Class) \
  94. Class(const Class&) = default; \
  95. Class& operator=(const Class&) = default;
  96. #define FL_DEFAULT_MOVE(Class) \
  97. Class(Class&&) = default; \
  98. Class& operator=(Class&&) = default;
  99. #define FL_DEFAULT_COPY_AND_MOVE(Class) \
  100. Class(const Class&) = default; \
  101. Class& operator=(const Class&) = default;\
  102. Class(Class&&) = default; \
  103. Class& operator=(Class&&) = default;
  104. #define FL_DISABLE_COPY(Class) \
  105. Class(const Class &) = delete;\
  106. Class &operator=(const Class &) = delete;
  107. #else
  108. //C++98 defines
  109. //Pointers
  110. const long null = 0L;
  111. #define FL_unique_ptr std::auto_ptr
  112. #define FL_move_ptr(x) x
  113. //Identifiers
  114. #define FL_IOVERRIDE
  115. #define FL_IFINAL
  116. #define FL_IDEFAULT
  117. #define FL_IDELETE
  118. #define FL_INOEXCEPT throw()
  119. //Constructors
  120. #define FL_DEFAULT_COPY(Class)
  121. #define FL_DEFAULT_MOVE(Class)
  122. #define FL_DEFAULT_COPY_AND_MOVE(Class)
  123. #define FL_DISABLE_COPY(Class) \
  124. Class(const Class &);\
  125. Class &operator=(const Class &);
  126. #endif
  127. }
  128. namespace fl {
  129. class FL_API fuzzylite {
  130. protected:
  131. static int _decimals;
  132. static scalar _macheps;
  133. static bool _debug;
  134. static bool _logging;
  135. public:
  136. static std::string name();
  137. static std::string fullname();
  138. static std::string version();
  139. static std::string longVersion();
  140. static std::string license();
  141. static std::string author();
  142. static std::string company();
  143. static std::string website();
  144. static std::string date();
  145. static std::string platform();
  146. static std::string floatingPoint();
  147. static bool debug();
  148. static void setDebug(bool debug);
  149. static int decimals();
  150. static void setDecimals(int decimals);
  151. static scalar macheps();
  152. static void setMachEps(scalar macheps);
  153. static bool logging();
  154. static void setLogging(bool logging);
  155. };
  156. }
  157. #endif /* FL_FUZZYLITE_H */