cleaning & doc
This commit is contained in:
parent
9fc61f5a3b
commit
a0464934cb
3 changed files with 11 additions and 80 deletions
|
|
@ -41,10 +41,6 @@ Caner Candan <caner.candan@thalesgroup.com>
|
|||
|
||||
#include "eoLogger.h"
|
||||
|
||||
/* TODO?
|
||||
add a possibility to redirect to several streams
|
||||
add_redirect/remove_redirect
|
||||
*/
|
||||
|
||||
#ifdef USE_SET
|
||||
typedef std::set<std::ostream*>::iterator StreamIter;
|
||||
|
|
@ -85,7 +81,6 @@ eoLogger::eoLogger() :
|
|||
|
||||
eoLogger::~eoLogger()
|
||||
{
|
||||
//redirect(NULL);
|
||||
if (_obuf._ownedFileStream != NULL) {
|
||||
delete _obuf._ownedFileStream;
|
||||
}
|
||||
|
|
@ -187,7 +182,6 @@ void eoLogger::doRedirect(std::ostream* os)
|
|||
}
|
||||
_obuf._outStreams.clear();
|
||||
if (os != NULL)
|
||||
//_obuf._outStreams.push_back(os);
|
||||
#ifdef USE_SET
|
||||
_obuf._outStreams.insert(os);
|
||||
#else
|
||||
|
|
@ -197,13 +191,7 @@ void eoLogger::doRedirect(std::ostream* os)
|
|||
|
||||
void eoLogger::addRedirect(std::ostream& os)
|
||||
{
|
||||
/*
|
||||
if (tryRemoveRedirect(&os))
|
||||
//throw eoWrongParamTypeException("Cannot redirect the logger to a stream it is already redirected to");
|
||||
//eo::log << eo::warnings << "Cannot redirect the logger to a stream it is already redirected to.";
|
||||
{ eo::log << eo::warnings << "Cannot redirect the logger to a stream it is already redirected to."; std::cout << "OK!!!" << std::endl; }*/
|
||||
bool already_there = tryRemoveRedirect(&os);
|
||||
//_obuf._outStreams.push_back(&os);
|
||||
#ifdef USE_SET
|
||||
_obuf._outStreams.insert(&os);
|
||||
#else
|
||||
|
|
@ -216,33 +204,11 @@ void eoLogger::addRedirect(std::ostream& os)
|
|||
void eoLogger::removeRedirect(std::ostream& os)
|
||||
{
|
||||
if (!tryRemoveRedirect(&os))
|
||||
//throw eoWrongParamTypeException("Cannot remove from the logger a stream it was not redirected to");
|
||||
//throw eoWrongParamTypeException(std::string("Cannot remove from the logger a stream it was not redirected to"));
|
||||
eo::log << eo::warnings << "Cannot remove from the logger a stream it was not redirected to.";
|
||||
}
|
||||
|
||||
bool eoLogger::tryRemoveRedirect(std::ostream* os)
|
||||
{
|
||||
/*
|
||||
std::vector<std::ostream*>::iterator it = find(_obuf._outStreams.begin(), _obuf._outStreams.end(), os);
|
||||
//std::cout << _obuf._outStreams.size() << " " << (void*)&*_obuf._outStreams.begin() << " " << (void*)&*_obuf._outStreams.end() << std::endl;
|
||||
//std::cout << "it: " << (void*)&*it << " " << (void*)os << std::endl;
|
||||
if (it == _obuf._outStreams.end())
|
||||
return false;
|
||||
_obuf._outStreams.erase(it);
|
||||
return true;*/
|
||||
/*
|
||||
#ifdef USE_SET
|
||||
std::set<std::ostream*>::iterator it = find(_obuf._outStreams.begin(), _obuf._outStreams.end(), os);
|
||||
if (it == _obuf._outStreams.end())
|
||||
return false;
|
||||
_obuf._outStreams.erase(it);
|
||||
#else
|
||||
std::vector<std::ostream*>::iterator it = find(_obuf._outStreams.begin(), _obuf._outStreams.end(), os);
|
||||
if (it == _obuf._outStreams.end())
|
||||
return false;
|
||||
_obuf._outStreams.erase(it);
|
||||
#endif*/
|
||||
StreamIter it = find(_obuf._outStreams.begin(), _obuf._outStreams.end(), os);
|
||||
if (it == _obuf._outStreams.end())
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -48,8 +48,12 @@ Caner Candan <caner.candan@thalesgroup.com>
|
|||
#include "eoObject.h"
|
||||
#include "eoParser.h"
|
||||
|
||||
#define USE_SET
|
||||
//#undef USE_SET
|
||||
#define USE_SET // defines if a set is to be used instead of a vector for storing streams the logger is redirected to
|
||||
#undef USE_SET
|
||||
/* expriments have shown that here a vector is by far faster than a set even if O(n),
|
||||
* because it needs less dynamic allocations, uses less memory and less instructions
|
||||
*/
|
||||
|
||||
|
||||
#ifdef USE_SET
|
||||
#include <set>
|
||||
|
|
@ -71,16 +75,6 @@ namespace eo
|
|||
debug,
|
||||
xdebug};
|
||||
|
||||
/**
|
||||
* file
|
||||
* this structure combined with the friend operator<< below is an easy way to select a file as output.
|
||||
*
|
||||
struct file
|
||||
{
|
||||
explicit file(const std::string f);
|
||||
const std::string _f;
|
||||
};*/
|
||||
|
||||
/**
|
||||
* setlevel
|
||||
* this structure combined with the friend operator<< below is an easy way to set a verbose level.
|
||||
|
|
|
|||
|
|
@ -9,27 +9,10 @@
|
|||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
// TODO test multiple redirection
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void test();
|
||||
|
||||
static void test2()
|
||||
{
|
||||
#define NB 100
|
||||
std::ostream* os = (std::ostream*) 1;
|
||||
eo::log.redirect(*os);
|
||||
for (int i = 0; i < NB; i++)
|
||||
eo::log.addRedirect(*(++os));
|
||||
/*
|
||||
for (int i = 0; i < NB; i++)
|
||||
eo::log.removeRedirect(*(os--));*/
|
||||
os = (std::ostream*) 1;
|
||||
for (int i = 0; i < NB; i++)
|
||||
eo::log.removeRedirect(*(++os));
|
||||
}
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
eoParser parser(ac, av);
|
||||
|
|
@ -43,9 +26,7 @@ int main(int ac, char** av)
|
|||
make_help(parser);
|
||||
make_verbose(parser);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
//test();
|
||||
test2();
|
||||
test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -59,37 +40,28 @@ static void test()
|
|||
eo::log << "We are writing on the default output stream" << std::endl;
|
||||
|
||||
{
|
||||
/*std::ofstream ofs("logtest.txt");
|
||||
eo::log.redirect(ofs);
|
||||
eo::log << "In FILE" << std::endl;
|
||||
eo::log.redirect("logtest2.txt");
|
||||
eo::log << "In FILE 2" << std::endl;*/
|
||||
eo::log.redirect("logtest.txt");
|
||||
eo::log << "In FILE" << std::endl;
|
||||
std::ofstream ofs("logtest2.txt");
|
||||
std::ofstream ofs("logtest2.txt"); // closed and destroyed at the en of the scope
|
||||
eo::log.addRedirect(ofs);
|
||||
eo::log << "In FILE 2" << std::endl;
|
||||
eo::log.removeRedirect(ofs);
|
||||
eo::log.removeRedirect(ofs); // must be removed because the associated stream is closed
|
||||
}
|
||||
|
||||
std::ifstream ifs("logtest2.txt");
|
||||
//ifs >> str;
|
||||
std::ifstream ifs("logtest2.txt"); // stream to logtest2.txt is closed, we can start reading
|
||||
std::string line;
|
||||
assert(std::getline(ifs, line));
|
||||
//std::cout << line << std::endl;
|
||||
assert(line == "In FILE 2");
|
||||
//std::cout << (line == "In FILE") << std::endl;
|
||||
assert(!std::getline(ifs, line));
|
||||
|
||||
std::ostringstream oss;
|
||||
eo::log.addRedirect(oss);
|
||||
//eo::log << oss << "In STRINGSTREAM";
|
||||
eo::log << "In STRINGSTREAM";
|
||||
|
||||
std::cout << "Content of ostringstream: " << oss.str() << std::endl;
|
||||
assert(oss.str() == "In STRINGSTREAM");
|
||||
|
||||
eo::log.redirect(std::cout);
|
||||
eo::log.redirect(std::cout); // removes all previously redirected streams; closes the file logtest.txt
|
||||
eo::log << "on COUT" << std::endl;
|
||||
|
||||
|
||||
|
|
@ -102,7 +74,6 @@ static void test()
|
|||
assert(std::getline(ifs, line));
|
||||
assert(line == "In STRINGSTREAM");
|
||||
assert(!std::getline(ifs, line));
|
||||
//assert(false);
|
||||
|
||||
|
||||
eo::log << eo::setlevel("errors");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue