Commit 90950688 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

added function for printing to stdout and stderr for consistency, moved...

added function for printing to stdout and stderr for consistency, moved function between output namespaces
parent 26651ced
#include "cdoDebugOutput.h"
namespace CdoLog
{
void StdOut(std::stringstream & p_message)
{
std::cout << p_message.str();
}
}
namespace CdoDebug
{
int PTHREAD;
int PSTREAM;
bool PROCESS;
bool PIPE;
int ARGUMENT;
namespace CdoDebug{
std::string outfile = "";
bool print_to_seperate_file = false;
std::fstream outfile_stream;
#if defined(DEBUG_PSTREAM) || defined(DEBUG)
int PSTREAM = 1;
#else
int PSTREAM = 0;
#endif
std::string
get_padding(const char *p_func)
{
size_t len = strlen(p_func);
#if defined(DEBUG_PROCESS) || defined(DEBUG)
bool PROCESS = true;
#else
bool PROCESS = false;
#endif
return std::string(30 - len, ' ');
}
std::string outfile = "";
bool print_to_seperate_file = false;
}
void
CdoStartMessage()
{
std::stringstream message;
outfile_stream = std::fstream(outfile, std::fstream::in | std::fstream::app);
message << std::string(30, ' ') << " == CDO Start ==" << std::endl;
printMessage(message);
}
void
CdoEndMessage()
{
std::stringstream message;
message << std::string(30, ' ') << " == CDO End ==" << std::endl;
printMessage(message);
outfile_stream.close();
}
}
......@@ -4,52 +4,96 @@
#include <sstream>
#include <fstream>
#include <string.h>
namespace CdoLog
{
void StdOut(std::stringstream &message);
template <typename ...T>
void expand(std::stringstream &p_message, T&& ...args)
{
//for showing that the dummy array is never used
using expander = int[];
//creating dummy array with expanding the parameter pack in its
//initializer list while writing each element of the pack into message
expander{0,(void(p_message << std::forward<T>(args)),0)...};
p_message << std::endl;
}
template <typename ...T>
void StdOut(T&& ...args)
{
std::stringstream message;
expand(message, args...);
std::cout << message.str();
}
template <typename ...T>
void StdErr(T&& ...args)
{
std::stringstream message;
expand(message, args...);
std::cout << message.str();
}
}
namespace CdoDebug
{
extern int PSTREAM;
extern bool PROCESS;
extern bool PIPE;
extern int ARGUMENT;
extern std::string outfile;
extern bool print_to_seperate_file;
extern std::fstream outfile_stream;
extern int PTHREAD;
std::string get_padding(const char *p_func);
void CdoStartMessage();
void CdoEndMessage();
namespace{
void printMessageToFile(std::stringstream &p_message)
void printMessage(std::stringstream &p_message)
{
if(!print_to_seperate_file)
{
std::cout << p_message.str();
}
else
{
if(!outfile.empty()){
std::fstream outfile_stream(outfile,std::fstream::in | std::fstream::app );
outfile_stream << p_message.str();
}
}
}
template <typename ...T>
void Message_ (std::stringstream &p_message, T&& ...args)
{
//for showing that the dummy array is never used
using expander = int[];
//creating dummy array with expanding the parameter pack in its
//initializer list while writing each element of the pack into message
expander{0,(void(p_message << std::forward<T>(args)),0)...};
p_message << std::endl;
}
template <typename ...T>
void Message_ (const char * p_func, T&& ...args)
{
std::stringstream message;
message << p_func <<": ";
Message_(message, args...);
if(print_to_seperate_file)
{
printMessageToFile(message);
message << p_func <<": " << get_padding(p_func);
CdoLog::expand(message, args...);
printMessage(message);
}
else
template <typename ...T>
void Warning_(T&& ...args)
{
std::stringstream message;
message << "Warning: ";
CdoLog::expand(message, args...);
std::cout << message.str();
}
}
}
namespace CdoError{
......@@ -60,21 +104,13 @@ namespace CdoError{
{
std::stringstream message;
message << "Error in: " << p_file << ":" << p_line << " ";
CdoDebug::Message_(message, args...);
std::cout << message.str();
CdoLog::expand(message, args...);
CdoLog::StdOut(message);
if ( CdoError::_ExitOnError )
{
exit(EXIT_FAILURE);
}
}
template <typename ...T>
void Warning_(T&& ...args)
{
std::stringstream message;
message << "Warning: ";
CdoDebug::Message_(message, args...);
std::cout << message.str();
}
template <typename ...T>
void SysError_(const char* p_file, const int p_line, const char* p_func, T&& ...args)
......@@ -83,8 +119,8 @@ namespace CdoError{
std::stringstream message;
message << "SysError in:" << p_file << std::endl;
message << " " << "in function: p_func ,line: " << p_line << std::endl;
CdoDebug::Message_(message, args...);
CdoLog::StdOut(message, args...);
CdoLog::StdOut(message);
if(saved_errno)
{
errno = saved_errno;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment