Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilhem Saurel
hpp-util
Commits
ca83eca8
Commit
ca83eca8
authored
Apr 02, 2016
by
Joseph Mirabel
Committed by
Joseph Mirabel
Apr 02, 2016
Browse files
Merge remote-tracking branch 'jmirabel/devel'
Conflicts: README.md
parents
50b5a437
1b722759
Changes
8
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
ca83eca8
...
...
@@ -33,8 +33,6 @@ IF (HPP_DEBUG)
SET
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DHPP_DEBUG"
)
ENDIF
()
PKG_CONFIG_APPEND_LIBS
(
"hpp-util"
)
# Search for Boost.
SET
(
BOOST_COMPONENTS filesystem system
)
SEARCH_FOR_BOOST
()
...
...
@@ -63,4 +61,6 @@ ADD_REQUIRED_DEPENDENCY("tinyxml >= 2.6")
ADD_SUBDIRECTORY
(
src
)
ADD_SUBDIRECTORY
(
tests
)
PKG_CONFIG_APPEND_LIBS
(
"hpp-util"
)
SETUP_PROJECT_FINALIZE
()
cmake
@
8e9b4644
Compare
b33522ed
...
8e9b4644
Subproject commit
b33522ed6acea8c8045affe529040bc54625d710
Subproject commit
8e9b46446f92899025173f047b3950fcd21b89f4
include/hpp/util/debug.hh
View file @
ca83eca8
...
...
@@ -94,6 +94,13 @@ namespace hpp
char
const
*
function
,
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:
std
::
ostream
&
writePrefix
(
std
::
ostream
&
stream
,
...
...
@@ -127,6 +134,11 @@ namespace hpp
char
const
*
function
,
const
std
::
string
&
data
);
void
write
(
char
const
*
file
,
int
line
,
char
const
*
function
,
const
std
::
stringstream
&
data
);
const
char
*
label
()
const
;
private:
const
char
*
label_
;
...
...
@@ -146,6 +158,12 @@ namespace hpp
char
const
*
function
,
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
;
private:
...
...
@@ -165,6 +183,11 @@ namespace hpp
int
line
,
char
const
*
function
,
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.
...
...
@@ -229,7 +252,7 @@ namespace hpp
std::stringstream __ss; \
__ss << data << iendl; \
logging.channel.write (__FILE__, __LINE__, __PRETTY_FUNCTION__, \
__ss
.str ()
); \
__ss);
\
} while (0)
# define hppDoutFatal(channel, data) \
...
...
@@ -239,7 +262,7 @@ namespace hpp
std::stringstream __ss; \
__ss << data << iendl; \
logging.channel.write ( __FILE__, __LINE__, __PRETTY_FUNCTION__, \
__ss
.str ()
); \
__ss);
\
::std::exit(EXIT_FAILURE); \
} while (1)
...
...
include/hpp/util/parser.hh
View file @
ca83eca8
...
...
@@ -23,6 +23,8 @@
# include <iostream>
# include <tinyxml.h>
# include <boost/function.hpp>
namespace
hpp
{
namespace
util
{
namespace
parser
{
...
...
@@ -220,7 +222,8 @@ namespace hpp {
/// To extend its capabilities, see ObjectFactory.
class
Parser
{
public:
typedef
ObjectFactory
*
(
*
FactoryType
)
(
ObjectFactory
*
,
const
XMLElement
*
);
typedef
boost
::
function
<
ObjectFactory
*
(
ObjectFactory
*
,
const
XMLElement
*
)
>
FactoryType
;
/// Constructor
/// \param defaultFactory The factory used when a tag is not known.
...
...
include/hpp/util/timer.hh
View file @
ca83eca8
...
...
@@ -118,8 +118,8 @@ namespace hpp
std::stringstream __ss; \
__ss << #name << " last: " \
<< _##name##_timecounter_.last() << iendl; \
logging.benchmark.write (__FILE__, __LINE__,
__PRETTY_FUNCTION__,
\
__ss.str ());
\
logging.benchmark.write (__FILE__, __LINE__,
\
__PRETTY_FUNCTION__, __ss);
\
} while (0)
# define HPP_DISPLAY_TIMECOUNTER(name) \
do { \
...
...
@@ -127,8 +127,8 @@ namespace hpp
using namespace ::hpp::debug; \
std::stringstream __ss; \
__ss << _##name##_timecounter_ << iendl; \
logging.benchmark.write (__FILE__, __LINE__,
__PRETTY_FUNCTION__,
\
__ss.str ());
\
logging.benchmark.write (__FILE__, __LINE__,
\
__PRETTY_FUNCTION__, __ss);
\
} while (0)
# define HPP_RESET_TIMECOUNTER(name) \
_##name##_timecounter_.reset();
...
...
@@ -146,6 +146,10 @@ namespace hpp
os
# 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 hpp
...
...
src/debug.cc
View file @
ca83eca8
...
...
@@ -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
()
{}
...
...
@@ -168,6 +180,17 @@ namespace hpp
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
{
HPP_UTIL_LOCAL
std
::
string
...
...
@@ -181,11 +204,7 @@ namespace hpp
JournalOutput
::
JournalOutput
(
std
::
string
filename
)
:
filename
(
filename
),
lastFunction
(),
#ifdef HPP_DEBUG
stream
(
makeLogFile
(
*
this
).
c_str
())
#else
stream
()
#endif
{}
JournalOutput
::~
JournalOutput
()
...
...
@@ -212,6 +231,8 @@ namespace hpp
char
const
*
function
,
const
std
::
string
&
data
)
{
if
(
!
stream
.
is_open
())
stream
.
open
(
makeLogFile
(
*
this
).
c_str
());
if
(
lastFunction
!=
function
)
{
if
(
!
lastFunction
.
empty
())
...
...
@@ -229,6 +250,31 @@ namespace hpp
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
()
:
console
(),
journal
(
"journal"
),
...
...
tests/CMakeLists.txt
View file @
ca83eca8
...
...
@@ -37,3 +37,4 @@ ENDMACRO(DEFINE_TEST)
DEFINE_TEST
(
simple-test hpp-util
)
DEFINE_TEST
(
assertion hpp-util
)
DEFINE_TEST
(
exception hpp-util
)
DEFINE_TEST
(
debug hpp-util
)
tests/debug.cc
0 → 100644
View file @
ca83eca8
// 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
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment