6#ifndef YARP_OS_LOGSTREAM_H
7#define YARP_OS_LOGSTREAM_H
53 std::ostringstream oss;
74 const double externaltime,
77 stream(new Stream(type, file, line, func, id, externaltime, pred, comp))
90 if (!stream->pred || stream->pred()) {
91 std::string s = stream->oss.str();
96 if (s.back() ==
' ') {
99 yarp::os::Log(stream->file, stream->line, stream->func,
nullptr, yarp::os::Log::logInternalComponent()).
warning(
100 "' ' was expected. Some `operator<<` does not add an extra space at the end");
103 if (s.back() ==
'\n') {
104 yarp::os::Log(stream->file, stream->line, stream->func,
nullptr, yarp::os::Log::logInternalComponent()).
warning(
105 "Removing extra \\n (stream-style)");
109 Log::do_log(stream->type,
116 stream->externaltime,
132 stream->oss << (
t ?
"true" :
"false");
133 if (!stream->nospace) {
141 if (!stream->nospace) {
149 if (!stream->nospace) {
157 if (!stream->nospace) {
165 if (!stream->nospace) {
173 if (!stream->nospace) {
181 if (!stream->nospace) {
189 if (!stream->nospace) {
197 if (!stream->nospace) {
205 if (!stream->nospace) {
213 if (!stream->nospace) {
221 if (!stream->nospace) {
229 if (!stream->nospace) {
237 if (!stream->nospace) {
245 stream->oss <<
t.c_str();
246 if (!stream->nospace) {
253 template <
typename T1,
typename T2>
256 bool nospace = stream->nospace;
257 stream->nospace =
true;
261 *
this <<
t.second <<
'}';
262 stream->nospace = nospace;
263 if (!stream->nospace) {
269 template <
typename Container,
typename =
typename Container::value_type>
272 return streamInternal(cont);
275 template <
typename Arr,
typename std::enable_if_t<std::is_array_v<Arr>,
bool> = true>
278 return streamInternal(arr);
281 template <
typename... Args>
284 bool nospace = stream->nospace;
285 stream->nospace =
true;
286 return tupleInternal<0>(
t, nospace);
290 template <
typename C>
291 inline LogStream& streamInternal(
const C& c)
293 bool nospace = stream->nospace;
294 stream->nospace =
true;
296 for (
auto it = std::begin(c); it != std::end(c); ++it) {
297 if (it != std::begin(c)) {
303 stream->nospace = nospace;
304 if (!stream->nospace) {
311 inline LogStream& tupleInternal(
const std::tuple<Args...>&
t,
bool nospace)
313 if constexpr (I == 0) {
316 if constexpr (I <
sizeof...(Args)) {
317 if constexpr (I != 0) {
320 *this << std::get<I>(
t);
321 return tupleInternal<I + 1>(
t, nospace);
324 stream->nospace = nospace;
325 if (!stream->nospace) {
void yarp_print_trace(FILE *out, const char *file, unsigned int line)
Low level function for printing a stack trace, if implemented (ACE or gcc/Linux).
LogStream & operator<<(const std::pair< T1, T2 > &t)
LogStream & operator<<(signed short t)
LogStream & operator<<(const Arr &arr)
LogStream & operator<<(bool t)
LogStream & operator<<(double t)
LogStream & operator<<(const std::tuple< Args... > &t)
LogStream & operator<<(signed long long t)
LogStream(Log::LogType type, const char *file, unsigned int line, const char *func, const char *id, const double externaltime, const yarp::os::Log::Predicate pred=nullptr, const LogComponent &comp=Log::defaultLogComponent())
LogStream & operator<<(unsigned short t)
LogStream & operator<<(const char *t)
LogStream & operator<<(float t)
LogStream & operator<<(unsigned int t)
LogStream(const LogStream &o)
LogStream & operator<<(char t)
LogStream & operator<<(unsigned long long t)
LogStream & operator<<(const void *t)
LogStream & operator<<(signed long t)
LogStream & operator<<(const std::string &t)
LogStream & operator<<(unsigned long t)
LogStream & operator<<(signed int t)
LogStream & operator<<(const Container &cont)
void warning(const char *msg,...) const
static double nowSystem()
bool isClockInitialized()
Check if YARP clock is initialized.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
bool isSystemClock()
Check if YARP is providing system time.
An interface to the operating system, including Port based communication.