fuzzylite  6.0
A Fuzzy Logic Control Library in C++
fuzzylite.h
Go to the documentation of this file.
1 /*
2  fuzzylite (R), a fuzzy logic control library in C++.
3  Copyright (C) 2010-2016 FuzzyLite Limited. All rights reserved.
4  Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com>
5 
6  This file is part of fuzzylite.
7 
8  fuzzylite is free software: you can redistribute it and/or modify it under
9  the terms of the FuzzyLite License included with the software.
10 
11  You should have received a copy of the FuzzyLite License along with
12  fuzzylite. If not, see <http://www.fuzzylite.com/license/>.
13 
14  fuzzylite is a registered trademark of FuzzyLite Limited.
15  */
16 
17 #ifndef FL_FUZZYLITE_H
18 #define FL_FUZZYLITE_H
19 
20 #include <algorithm>
21 #include <cmath>
22 #include <iostream>
23 #include <sstream>
24 #include <limits>
25 #include <memory>
26 #include <cstddef>
27 
28 #ifndef FL_BUILD_PATH
29 #define FL_BUILD_PATH ""
30 #endif
31 
32 #if defined(_WIN32) || defined(WIN32)
33 #define FL_WINDOWS
34 #endif
35 
36 #if defined(unix) || defined(__unix__) || defined(__unix)
37 #define FL_UNIX
38 #endif
39 
40 #ifdef __APPLE__
41 #define FL_APPLE
42 #ifndef FL_UNIX
43 #define FL_UNIX
44 #endif
45 #endif
46 
47 #define FL__FILE__ std::string(__FILE__).substr(std::string(FL_BUILD_PATH).size())
48 
49 #define FL_LOG_PREFIX FL__FILE__ << " (" << __LINE__ << "):"
50 
51 #define FL_AT FL__FILE__, __LINE__, __FUNCTION__
52 
53 #define FL_LOG(message) {if (fl::fuzzylite::isLogging()){std::cout << FL_LOG_PREFIX << message << std::endl;}}
54 #define FL_LOGP(message) {if (fl::fuzzylite::isLogging()){std::cout << message << std::endl;}}
55 
56 #define FL_DEBUG_BEGIN if (fl::fuzzylite::isDebugging()){
57 #define FL_DEBUG_END }
58 
59 #define FL_DBG(message) FL_DEBUG_BEGIN\
60  std::cout << FL__FILE__ << "::" << __FUNCTION__ << "[" << __LINE__ << "]:" \
61  << message << std::endl;\
62  FL_DEBUG_END
63 
64 
65 #ifdef FL_WINDOWS
66 #include <ciso646> //alternative operator spellings:
67 //#define and &&
68 //#define or ||
69 //#define not !
70 //#define bitand &
71 //#define bitor |
72 
73 //@todo: Address warning 4251 by exporting members?
74 //http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
75 #ifdef _MSC_VER
76 #pragma warning (disable:4251)
77 #endif
78 
79 //fuzzylite as a shared library is exported
80 //Applications linking with fuzzylite as a shared library need to import
81 
82 //fuzzylite as a static library does not export or import
83 //Applications linking with fuzzylite as a static library do not import
84 
85 #if defined(FL_EXPORT_LIBRARY)
86 #define FL_API __declspec(dllexport)
87 #elif defined(FL_IMPORT_LIBRARY)
88 #define FL_API __declspec(dllimport)
89 #else
90 #define FL_API
91 #endif
92 
93 #else
94 #define FL_API
95 #endif
96 
104 namespace fl {
108 #ifdef FL_USE_FLOAT
109  typedef float scalar;
110 #else
111 
114  typedef double scalar;
115 #endif
116 
117 #define FL_IUNUSED(x) (void) (x)
118 
119 #ifdef __GNUC__
120 #define FL_IUNUSED_DECL __attribute__((unused))
121 #else
122 #define FL_IUNUSED_DECL
123 #endif
124 
128  const scalar nan FL_IUNUSED_DECL = std::numeric_limits<scalar>::quiet_NaN();
132  const scalar inf FL_IUNUSED_DECL = std::numeric_limits<scalar>::infinity();
133 
134 #ifdef FL_CPP98
135  //C++98 defines
136 
137  //Pointers
142  const long null = 0L;
143 #define FL_unique_ptr std::auto_ptr
144 #define FL_move_ptr(x) x
145 
146  //Identifiers
147 #define FL_IOVERRIDE
148 #define FL_IFINAL
149 #define FL_IDEFAULT
150 #define FL_IDELETE
151 #define FL_INOEXCEPT throw()
152 #define FL_ITHREAD_LOCAL
153 
154  //Constructors
155 #define FL_DEFAULT_COPY(Class)
156 #define FL_DEFAULT_MOVE(Class)
157 #define FL_DEFAULT_COPY_AND_MOVE(Class)
158 
159 #define FL_DISABLE_COPY(Class) \
160  Class(const Class &);\
161  Class &operator=(const Class &);
162 
163 #else
164  //C++11 defines
165 
166  //Pointers
171  const std::nullptr_t null = nullptr;
172 #define FL_unique_ptr std::unique_ptr
173 #define FL_move_ptr(x) std::move(x)
174 
175  //Identifiers
176 #define FL_IOVERRIDE override
177 #define FL_IFINAL final
178 #define FL_IDEFAULT = default
179 #define FL_IDELETE = delete
180 #define FL_INOEXCEPT noexcept
181 #define FL_ITHREAD_LOCAL /*thread_local (commented for performance)*/
182 
183  //Constructors
184 #define FL_DEFAULT_COPY(Class) \
185  Class(const Class&) = default; \
186  Class& operator=(const Class&) = default;
187 #define FL_DEFAULT_MOVE(Class) \
188  Class(Class&&) = default; \
189  Class& operator=(Class&&) = default;
190 #define FL_DEFAULT_COPY_AND_MOVE(Class) \
191  Class(const Class&) = default; \
192  Class& operator=(const Class&) = default;\
193  Class(Class&&) = default; \
194  Class& operator=(Class&&) = default;
195 
196 #define FL_DISABLE_COPY(Class) \
197  Class(const Class &) = delete;\
198  Class &operator=(const Class &) = delete;
199 
200 #endif
201 
202 }
203 
204 
205 namespace fl {
206 
218  friend class Operation;
219  private:
220  static int _decimals;
221  static scalar _macheps;
222  static std::ios_base::fmtflags _scalarFormat;
223  static bool _logging;
224  static bool _debugging;
225  public:
230  static std::string name();
235  static std::string version();
240  static std::string library();
241 
246  static std::string license();
247 
252  static std::string author();
253 
258  static std::string company();
259 
264  static std::string website();
265 
271  static int decimals();
272 
278  static void setDecimals(int decimals);
279 
286  static scalar macheps();
287 
294  static void setMachEps(scalar macheps);
295 
302  static void setScalarFormat(std::ios_base::fmtflags scalarFormat);
303 
309  static std::ios_base::fmtflags scalarFormat();
310 
317  static bool isLogging();
318 
325  static void setLogging(bool logging);
326 
332  static bool isDebugging();
333 
338  static void setDebugging(bool debugging);
339 
344  static std::string platform();
345 
350  static std::string floatingPoint();
351  };
352 }
353 
354 
355 namespace fl {
356 
357  inline std::string fuzzylite::name() {
358  return "fuzzylite";
359  }
360 
361  inline std::string fuzzylite::library() {
362  return name() + " " + version();
363  }
364 
365  inline std::string fuzzylite::version() {
366  return "6.0";
367  }
368 
369  inline std::string fuzzylite::license() {
370  return "FuzzyLite License";
371  }
372 
373  inline std::string fuzzylite::author() {
374  return "Juan Rada-Vilela, Ph.D.";
375  }
376 
377  inline std::string fuzzylite::company() {
378  return "FuzzyLite Limited";
379  }
380 
381  inline std::string fuzzylite::website() {
382  return "http://www.fuzzylite.com/";
383  }
384 
385  inline void fuzzylite::setDebugging(bool debugging) {
386  _debugging = debugging;
387  }
388 
389  inline bool fuzzylite::isDebugging() {
390  return _debugging;
391  }
392 
393  inline void fuzzylite::setDecimals(int decimals) {
394  _decimals = decimals;
395  }
396 
397  inline int fuzzylite::decimals() {
398  return _decimals;
399  }
400 
401  inline void fuzzylite::setScalarFormat(std::ios_base::fmtflags scalarFormat) {
402  _scalarFormat = scalarFormat;
403  }
404 
405  inline std::ios_base::fmtflags fuzzylite::scalarFormat() {
406  return _scalarFormat;
407  }
408 
409  inline void fuzzylite::setMachEps(scalar macheps) {
410  _macheps = macheps;
411  }
412 
414  return _macheps;
415  }
416 
417  inline void fuzzylite::setLogging(bool logging) {
418  _logging = logging;
419  }
420 
421  inline bool fuzzylite::isLogging() {
422  return _logging;
423  }
424 }
425 
426 #endif /* FL_FUZZYLITE_H */
427 
static std::ios_base::fmtflags scalarFormat()
Gets the default format to be utilized for every fl::scalar passed to Op::str()
Definition: fuzzylite.h:405
static std::string library()
Returns the name of the fuzzylite library including the version.
Definition: fuzzylite.h:361
const std::nullptr_t null
Represents the C++11 or C++98 null pointer depending on whether the compilation flag -DFL_CPP98 is se...
Definition: fuzzylite.h:171
The fuzzylite class contains global settings and information about the library.
Definition: fuzzylite.h:217
static void setMachEps(scalar macheps)
Sets the minimum difference at which two floating-point values are considered equivalent.
Definition: fuzzylite.h:409
double scalar
Represents floating-point values (typedef to float or double).
Definition: fuzzylite.h:114
static std::string version()
Returns the version of the fuzzylite library.
Definition: fuzzylite.h:365
Template implementation.
Definition: Activation.h:24
static std::string name()
Returns the name of the fuzzylite library.
Definition: fuzzylite.h:357
The Operation class contains methods for numeric operations, string manipulation, and other functions...
Definition: Operation.h:37
static int decimals()
Returns the number of decimals utilized when formatting scalar values.
Definition: fuzzylite.h:397
static bool isDebugging()
Indicates whether the library is running in debug mode.
Definition: fuzzylite.h:389
static void setScalarFormat(std::ios_base::fmtflags scalarFormat)
Sets the default format to be utilized for every fl::scalar passed to Op::str()
Definition: fuzzylite.h:401
static void setDebugging(bool debugging)
Sets whether the library is set to run in debug mode.
Definition: fuzzylite.h:385
static std::string website()
Returns the website of the fuzzylite library.
Definition: fuzzylite.h:381
static void setDecimals(int decimals)
Sets the number of decimals utilized when formatting scalar values.
Definition: fuzzylite.h:393
static std::string license()
Returns the license under which the fuzzylite library is released.
Definition: fuzzylite.h:369
static std::string author()
Returns the name of the author of the fuzzylite library.
Definition: fuzzylite.h:373
static void setLogging(bool logging)
Sets whether the library is set to log information using the macro FL_LOG
Definition: fuzzylite.h:417
static scalar macheps()
Returns the minimum difference at which two floating-point values are considered equivalent.
Definition: fuzzylite.h:413
static bool isLogging()
Returns whether the library is logging information via the FL_LOG macro.
Definition: fuzzylite.h:421
#define FL_API
Definition: fuzzylite.h:94
static std::string company()
Returns the name of the company that owns the fuzzylite library.
Definition: fuzzylite.h:377
const scalar nan FL_IUNUSED_DECL
Represents the Not-A-Number scalar value.
Definition: fuzzylite.h:128