Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
global.hpp
Go to the documentation of this file.
1#ifndef FSTGLOBAL_H
2#define FSTGLOBAL_H
3 /*
27=========================================================================
28Copyright and license:
29 * FST4 software (with the exception of any bundled or externally linked
30 third-party components) is Copyright (C) 2000-present Institute of
31 Information Theory and Automation of the Czech Academy of Sciences (UTIA).
32 * FST4 is free software: you can redistribute it and/or modify it under
33 the terms of the GNU Affero General Public License as published by the
34 Free Software Foundation, version 3. The full text of the license is in
35 the file LICENSE in the distribution root and at
36 https://www.gnu.org/licenses/agpl-3.0.html.
37 * FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
38 WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
40 License for more details.
41 * Closed-source use without the AGPL's copyleft obligations requires a
42 commercial license from UTIA; in case of interest write to
43 utia@utia.cas.cz. LICENSING.md in the distribution root explains both
44 options, the contributor license agreement that every contribution
45 requires, and the contacts (technical questions and pull requests:
46 somol@utia.cas.cz, with "FST" in the subject line).
47========================================================================== */
48
49#include <string>
50#include <ostream>
51#include <iostream> // std::cout in the inline notify() bodies (DEBUG builds)
52#include <sstream>
53#ifdef FST_THREADED
54#include <mutex>
55#endif
56
64namespace FST {
65
72
80class syncout
81{
82public:
86 static void print(std::ostream& os, std::ostringstream &sos)
87 {
88#ifdef FST_THREADED
89 std::unique_lock<std::mutex> lockio(get_io_mutex());
90#endif
91 os << sos.str() << std::flush;
92 }
93private:
94#ifdef FST_THREADED
96 static std::mutex& get_io_mutex()
97 {
98 static std::mutex io_mutex;
99 return io_mutex;
100 }
101#endif
102 syncout();
103};
104
105// notify(): DEBUG-mode-only diagnostic output. The overloads are inline, so the library is
106// header-only and needs no compiled translation unit; _src_global/global.cpp is an empty
107// compatibility stub for build setups that still list it.
112inline void notify(const std::string msg)
113{
114#ifdef DEBUG
115 std::ostringstream ss;
116 ss << msg << std::endl;
117 syncout::print(std::cout,ss);
118#else
119 (void)msg;
120#endif
121}
122
127inline void notify(const std::string msg1, const double num, const std::string msg2="")
128{
129#ifdef DEBUG
130 std::ostringstream ss;
131 ss << msg1 << num << msg2 << std::endl;
132 syncout::print(std::cout,ss);
133#else
134 (void)msg1; (void)num; (void)msg2;
135#endif
136}
137
144inline void notify(const std::string msg1, const double num1, const std::string msg2, const double num2, const std::string msg3="")
145{
146#ifdef DEBUG
147 std::ostringstream ss;
148 ss << msg1 << num1 << msg2 << num2 << msg3 << std::endl;
149 syncout::print(std::cout,ss);
150#else
151 (void)msg1; (void)num1; (void)msg2; (void)num2; (void)msg3;
152#endif
153}
154
163inline void notify(const std::string msg1, const double num1, const std::string msg2, const double num2, const std::string msg3, const double num3, const std::string msg4="")
164{
165#ifdef DEBUG
166 std::ostringstream ss;
167 ss << msg1 << num1 << msg2 << num2 << msg3 << num3 << msg4 << std::endl;
168 syncout::print(std::cout,ss);
169#else
170 (void)msg1; (void)num1; (void)msg2; (void)num2; (void)msg3; (void)num3; (void)msg4;
171#endif
172}
173
177template<typename VALUE>
178inline VALUE maxf(const VALUE &x, const VALUE &y)
179{
180 return (x>y)?x:y;
181}
182
186template<typename VALUE>
187inline VALUE minf(const VALUE &x, const VALUE &y)
188{
189 return (x<y)?x:y;
190}
191
192} //namespace
193#endif // FSTGLOBAL_H ///:~
Serializes textual reporting from concurrent threads.
Definition global.hpp:81
static void print(std::ostream &os, std::ostringstream &sos)
Writes sos's buffered content to os, serializing concurrent writers under FST_THREADED via a shared m...
Definition global.hpp:86
static std::mutex & get_io_mutex()
Returns the process-wide mutex guarding concurrent output via print() (FST_THREADED builds only).
Definition global.hpp:96
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
OutputDetail
search algorithms' output extent
Definition global.hpp:67
@ NORMAL
informs about new found solutions and time elapsed etc.
Definition global.hpp:69
@ DETAILED
includes much detail including variable contents etc. (may render output unreadably cluttered)
Definition global.hpp:70
@ SILENT
completely silent operation
Definition global.hpp:68
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
VALUE minf(const VALUE &x, const VALUE &y)
Returns the smaller of x and y (strict '<' comparison; ties return y).
Definition global.hpp:187
VALUE maxf(const VALUE &x, const VALUE &y)
Returns the greater of x and y (strict '>' comparison; ties return y).
Definition global.hpp:178
Copyright © 2000–present ÚTIA, Institute of Information Theory and Automation of the Czech Academy of Sciences · Contacts · This site sets no cookies and uses no analytics.