Feature Selection Toolbox
FST4
UTIA · Czech Academy of Sciences
Home
Introduction
Usage
FST4 CLI
Demos
API Reference
Download
History
References
Legacy
FAQ
Contacts
Toggle main menu visibility
Loading...
Searching...
No Matches
_src_global
global.hpp
Go to the documentation of this file.
1
#ifndef FSTGLOBAL_H
2
#define FSTGLOBAL_H
3
/*
27
=========================================================================
28
Copyright 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
64
namespace
FST
{
65
67
enum
OutputDetail
{
68
SILENT
=0,
69
NORMAL
=1,
70
DETAILED
=2
71
};
72
80
class
syncout
81
{
82
public
:
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
}
93
private
:
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.
112
inline
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
127
inline
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
144
inline
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
163
inline
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
177
template
<
typename
VALUE>
178
inline
VALUE
maxf
(
const
VALUE &x,
const
VALUE &y)
179
{
180
return
(x>y)?x:y;
181
}
182
186
template
<
typename
VALUE>
187
inline
VALUE
minf
(
const
VALUE &x,
const
VALUE &y)
188
{
189
return
(x<y)?x:y;
190
}
191
192
}
//namespace
193
#endif
// FSTGLOBAL_H ///:~
FST::syncout
Serializes textual reporting from concurrent threads.
Definition
global.hpp:81
FST::syncout::print
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
FST::syncout::get_io_mutex
static std::mutex & get_io_mutex()
Returns the process-wide mutex guarding concurrent output via print() (FST_THREADED builds only).
Definition
global.hpp:96
FST
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition
data_accessor.hpp:80
FST::OutputDetail
OutputDetail
search algorithms' output extent
Definition
global.hpp:67
FST::NORMAL
@ NORMAL
informs about new found solutions and time elapsed etc.
Definition
global.hpp:69
FST::DETAILED
@ DETAILED
includes much detail including variable contents etc. (may render output unreadably cluttered)
Definition
global.hpp:70
FST::SILENT
@ SILENT
completely silent operation
Definition
global.hpp:68
FST::notify
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
FST::minf
VALUE minf(const VALUE &x, const VALUE &y)
Returns the smaller of x and y (strict '<' comparison; ties return y).
Definition
global.hpp:187
FST::maxf
VALUE maxf(const VALUE &x, const VALUE &y)
Returns the greater of x and y (strict '>' comparison; ties return y).
Definition
global.hpp:178
Generated by
1.17.0