Commit ca83eca8 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Merge remote-tracking branch 'jmirabel/devel'

Conflicts:
	README.md
parents 50b5a437 1b722759
...@@ -33,8 +33,6 @@ IF (HPP_DEBUG) ...@@ -33,8 +33,6 @@ IF (HPP_DEBUG)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHPP_DEBUG") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHPP_DEBUG")
ENDIF() ENDIF()
PKG_CONFIG_APPEND_LIBS("hpp-util")
# Search for Boost. # Search for Boost.
SET(BOOST_COMPONENTS filesystem system) SET(BOOST_COMPONENTS filesystem system)
SEARCH_FOR_BOOST() SEARCH_FOR_BOOST()
...@@ -63,4 +61,6 @@ ADD_REQUIRED_DEPENDENCY("tinyxml >= 2.6") ...@@ -63,4 +61,6 @@ ADD_REQUIRED_DEPENDENCY("tinyxml >= 2.6")
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
PKG_CONFIG_APPEND_LIBS("hpp-util")
SETUP_PROJECT_FINALIZE() SETUP_PROJECT_FINALIZE()
Subproject commit b33522ed6acea8c8045affe529040bc54625d710 Subproject commit 8e9b46446f92899025173f047b3950fcd21b89f4
...@@ -94,6 +94,13 @@ namespace hpp ...@@ -94,6 +94,13 @@ namespace hpp
char const* function, char const* function,
const std::string& data) = 0; const std::string& data) = 0;
virtual void
write (const Channel& channel,
char const* file,
int line,
char const* function,
const std::stringstream& data) = 0;
protected: protected:
std::ostream& std::ostream&
writePrefix (std::ostream& stream, writePrefix (std::ostream& stream,
...@@ -127,6 +134,11 @@ namespace hpp ...@@ -127,6 +134,11 @@ namespace hpp
char const* function, char const* function,
const std::string& data); const std::string& data);
void write (char const* file,
int line,
char const* function,
const std::stringstream& data);
const char* label () const; const char* label () const;
private: private:
const char* label_; const char* label_;
...@@ -146,6 +158,12 @@ namespace hpp ...@@ -146,6 +158,12 @@ namespace hpp
char const* function, char const* function,
const std::string& data); const std::string& data);
void write (const Channel& channel,
char const* file,
int line,
char const* function,
const std::stringstream& data);
std::string getFilename () const; std::string getFilename () const;
private: private:
...@@ -165,6 +183,11 @@ namespace hpp ...@@ -165,6 +183,11 @@ namespace hpp
int line, int line,
char const* function, char const* function,
const std::string& data); const std::string& data);
void write (const Channel& channel,
char const* file,
int line,
char const* function,
const std::stringstream& data);
}; };
/// \brief Logging class owns all channels and outputs. /// \brief Logging class owns all channels and outputs.
...@@ -229,7 +252,7 @@ namespace hpp ...@@ -229,7 +252,7 @@ namespace hpp
std::stringstream __ss; \ std::stringstream __ss; \
__ss << data << iendl; \ __ss << data << iendl; \
logging.channel.write (__FILE__, __LINE__, __PRETTY_FUNCTION__, \ logging.channel.write (__FILE__, __LINE__, __PRETTY_FUNCTION__, \
__ss.str ()); \ __ss); \
} while (0) } while (0)
# define hppDoutFatal(channel, data) \ # define hppDoutFatal(channel, data) \
...@@ -239,7 +262,7 @@ namespace hpp ...@@ -239,7 +262,7 @@ namespace hpp
std::stringstream __ss; \ std::stringstream __ss; \
__ss << data << iendl; \ __ss << data << iendl; \
logging.channel.write ( __FILE__, __LINE__, __PRETTY_FUNCTION__, \ logging.channel.write ( __FILE__, __LINE__, __PRETTY_FUNCTION__, \
__ss.str ()); \ __ss); \
::std::exit(EXIT_FAILURE); \ ::std::exit(EXIT_FAILURE); \
} while (1) } while (1)
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# include <iostream> # include <iostream>
# include <tinyxml.h> # include <tinyxml.h>
# include <boost/function.hpp>
namespace hpp { namespace hpp {
namespace util { namespace util {
namespace parser { namespace parser {
...@@ -220,7 +222,8 @@ namespace hpp { ...@@ -220,7 +222,8 @@ namespace hpp {
/// To extend its capabilities, see ObjectFactory. /// To extend its capabilities, see ObjectFactory.
class Parser { class Parser {
public: public:
typedef ObjectFactory* (*FactoryType) (ObjectFactory*, const XMLElement*); typedef boost::function <ObjectFactory* (ObjectFactory*, const XMLElement*)>
FactoryType;
/// Constructor /// Constructor
/// \param defaultFactory The factory used when a tag is not known. /// \param defaultFactory The factory used when a tag is not known.
......
...@@ -118,8 +118,8 @@ namespace hpp ...@@ -118,8 +118,8 @@ namespace hpp
std::stringstream __ss; \ std::stringstream __ss; \
__ss << #name << " last: " \ __ss << #name << " last: " \
<< _##name##_timecounter_.last() << iendl; \ << _##name##_timecounter_.last() << iendl; \
logging.benchmark.write (__FILE__, __LINE__, __PRETTY_FUNCTION__,\ logging.benchmark.write (__FILE__, __LINE__, \
__ss.str ()); \ __PRETTY_FUNCTION__, __ss); \
} while (0) } while (0)
# define HPP_DISPLAY_TIMECOUNTER(name) \ # define HPP_DISPLAY_TIMECOUNTER(name) \
do { \ do { \
...@@ -127,8 +127,8 @@ namespace hpp ...@@ -127,8 +127,8 @@ namespace hpp
using namespace ::hpp::debug; \ using namespace ::hpp::debug; \
std::stringstream __ss; \ std::stringstream __ss; \
__ss << _##name##_timecounter_ << iendl; \ __ss << _##name##_timecounter_ << iendl; \
logging.benchmark.write (__FILE__, __LINE__, __PRETTY_FUNCTION__,\ logging.benchmark.write (__FILE__, __LINE__, \
__ss.str ()); \ __PRETTY_FUNCTION__, __ss); \
} while (0) } while (0)
# define HPP_RESET_TIMECOUNTER(name) \ # define HPP_RESET_TIMECOUNTER(name) \
_##name##_timecounter_.reset(); _##name##_timecounter_.reset();
...@@ -146,6 +146,10 @@ namespace hpp ...@@ -146,6 +146,10 @@ namespace hpp
os os
# endif // HPP_ENABLE_BENCHMARK # endif // HPP_ENABLE_BENCHMARK
# define HPP_STOP_AND_DISPLAY_TIMECOUNTER(name) \
HPP_STOP_TIMECOUNTER(name); \
HPP_DISPLAY_TIMECOUNTER(name)
} // end of namespace debug } // end of namespace debug
} // end of namespace hpp } // end of namespace hpp
......
...@@ -151,6 +151,18 @@ namespace hpp ...@@ -151,6 +151,18 @@ namespace hpp
} }
void
Channel::write (char const* file,
int line,
char const* function,
const std::stringstream& data)
{
BOOST_FOREACH (Output* o, subscribers_)
if (o)
o->write (*this, file, line, function, data);
}
ConsoleOutput::ConsoleOutput () ConsoleOutput::ConsoleOutput ()
{} {}
...@@ -168,6 +180,17 @@ namespace hpp ...@@ -168,6 +180,17 @@ namespace hpp
std::cerr << incindent << data << decindent << std::flush; std::cerr << incindent << data << decindent << std::flush;
} }
void
ConsoleOutput::write (const Channel& channel,
char const* file,
int line,
char const* function,
const std::stringstream& data)
{
writePrefix (std::cerr, channel, file, line, function);
std::cerr << incindent << data.rdbuf() << decindent << std::flush;
}
namespace namespace
{ {
HPP_UTIL_LOCAL std::string HPP_UTIL_LOCAL std::string
...@@ -181,11 +204,7 @@ namespace hpp ...@@ -181,11 +204,7 @@ namespace hpp
JournalOutput::JournalOutput (std::string filename) JournalOutput::JournalOutput (std::string filename)
: filename (filename), : filename (filename),
lastFunction (), lastFunction (),
#ifdef HPP_DEBUG
stream (makeLogFile (*this).c_str ())
#else
stream () stream ()
#endif
{} {}
JournalOutput::~JournalOutput () JournalOutput::~JournalOutput ()
...@@ -212,6 +231,8 @@ namespace hpp ...@@ -212,6 +231,8 @@ namespace hpp
char const* function, char const* function,
const std::string& data) const std::string& data)
{ {
if (!stream.is_open ()) stream.open (makeLogFile (*this).c_str ());
if (lastFunction != function) if (lastFunction != function)
{ {
if (!lastFunction.empty ()) if (!lastFunction.empty ())
...@@ -229,6 +250,31 @@ namespace hpp ...@@ -229,6 +250,31 @@ namespace hpp
stream << incindent << data << decindent << std::flush; stream << incindent << data << decindent << std::flush;
} }
void
JournalOutput::write (const Channel& channel,
char const* file,
int line,
char const* function,
const std::stringstream& data)
{
if (!stream.is_open ()) stream.open (makeLogFile (*this).c_str ());
if (lastFunction != function)
{
if (!lastFunction.empty ())
{
writePrefix (stream, channel, file, line, function);
stream << "exiting " << lastFunction << iendl;
}
writePrefix (stream, channel, file, line, function);
stream << "entering " << function << iendl;
lastFunction = function;
}
writePrefix (stream, channel, file, line, function);
stream << incindent << data.rdbuf() << decindent << std::flush;
}
Logging::Logging () Logging::Logging ()
: console (), : console (),
journal ("journal"), journal ("journal"),
......
...@@ -37,3 +37,4 @@ ENDMACRO(DEFINE_TEST) ...@@ -37,3 +37,4 @@ ENDMACRO(DEFINE_TEST)
DEFINE_TEST(simple-test hpp-util) DEFINE_TEST(simple-test hpp-util)
DEFINE_TEST(assertion hpp-util) DEFINE_TEST(assertion hpp-util)
DEFINE_TEST(exception hpp-util) DEFINE_TEST(exception hpp-util)
DEFINE_TEST(debug hpp-util)
// Copyright (c) 2016, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-util.
// hpp-util is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-util is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#include <iostream>
#include <boost/assign/list_of.hpp>
#include <hpp/util/debug.hh>
#include "common.hh"
using namespace hpp::debug;
int run_test ()
{
JournalOutput out ("debug.test.log");
Channel channel ("TEST", boost::assign::list_of<Output*> (&out));
for (int i = 0; i < 100000; ++i) {
std::stringstream ss;
ss << i << hpp::iendl;
out.write (channel, __FILE__, __LINE__, __PRETTY_FUNCTION__, ss.str());
}
return 0;
}
GENERATE_TEST ()
Supports Markdown
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