fuzzylite.h 5.0 KB

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