fuzzylite.h 5.0 KB

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