The Gaudi Framework  master (37c0b60a)
MsgStream.h File Reference
#include <GaudiKernel/IMessageSvc.h>
#include <GaudiKernel/SerializeSTL.h>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <string>
Include dependency graph for MsgStream.h:

Go to the source code of this file.

Classes

class  MsgStream
 

Namespaces

 MSG
 Print levels enumeration.
 

Functions

MsgStreamendmsg (MsgStream &s)
 MsgStream Modifier: endmsg. Calls the output method of the MsgStream. More...
 
GAUDI_API std::string format (const char *,...)
 MsgStream format utility "a la sprintf(...)". More...
 
template<class _Tm >
MsgStreamoperator<< (MsgStream &s, const std::smanip< _Tm > &manip)
 I/O Manipulator for setfill. More...
 
MsgStreamMSG::dec (MsgStream &log)
 
MsgStreamMSG::hex (MsgStream &log)
 
MsgStreamoperator<< (MsgStream &s, const char *arg)
 Specialization to avoid the generation of implementations for char[]. More...
 
template<typename T >
MsgStreamoperator<< (MsgStream &lhs, const T &arg)
 General templated stream operator. More...
 

Function Documentation

◆ endmsg()

MsgStream& endmsg ( MsgStream s)
inline

MsgStream Modifier: endmsg. Calls the output method of the MsgStream.

Definition at line 202 of file MsgStream.h.

202 { return s.doOutput(); }

◆ format()

GAUDI_API std::string format ( const char *  ,
  ... 
)

MsgStream format utility "a la sprintf(...)".

Definition at line 119 of file MsgStream.cpp.

119  {
120  const int buffsize = 2048;
121  static char buffer[buffsize];
122  va_list arguments;
123  va_start( arguments, fmt );
124  if ( vsnprintf( buffer, buffsize, fmt, arguments ) >= buffsize ) {
125  va_end( arguments );
126  throw GaudiException( "Insufficient buffer size (" + std::to_string( buffsize ) + ") when formatting message",
127  "MsgStream", StatusCode::FAILURE );
128  }
129  va_end( arguments );
130  return std::string( buffer );
131 }

◆ operator<<() [1/3]

template<typename T >
MsgStream& operator<< ( MsgStream lhs,
const T &  arg 
)

General templated stream operator.

Definition at line 299 of file MsgStream.h.

299  {
300  using namespace GaudiUtils;
301  if ( lhs.isActive() ) try {
302  // this may throw, and we cannot afford it if the stream is used in a catch block
303  lhs.stream() << arg;
304  } catch ( ... ) {}
305  return lhs;
306 }

◆ operator<<() [2/3]

MsgStream& operator<< ( MsgStream s,
const char *  arg 
)
inline

Specialization to avoid the generation of implementations for char[].

See also
{bug #87340}

Definition at line 289 of file MsgStream.h.

289  {
290  try {
291  // this may throw, and we cannot afford it if the stream is used in a catch block
292  if ( s.isActive() ) s.stream() << arg;
293  } catch ( ... ) {}
294  return s;
295 }

◆ operator<<() [3/3]

template<class _Tm >
MsgStream& operator<< ( MsgStream s,
const std::smanip< _Tm > &  manip 
)
inline

I/O Manipulator for setfill.

Definition at line 267 of file MsgStream.h.

267  {
268  try {
269  // this may throw, and we cannot afford it if the stream is used in a catch block
270  if ( s.isActive() ) s.stream() << manip;
271  } catch ( ... ) {}
272  return s;
273 }
std::string
STL class.
gaudirun.s
string s
Definition: gaudirun.py:346
GaudiException
Definition: GaudiException.h:31
std::to_string
T to_string(T... args)
fmt
std::vsnprintf
T vsnprintf(T... args)
va_list
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
GaudiUtils
Definition: Allocator.h:72
MsgStream::isActive
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:120
MsgStream::stream
std::ostringstream & stream()
Access string MsgStream.
Definition: MsgStream.h:103