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
Humanoid Path Planner
hpp-util
Commits
2b29c1da
Commit
2b29c1da
authored
Dec 16, 2020
by
Joseph Mirabel
Browse files
Reduce dependency to boost.
parent
f62f8730
Changes
9
Hide whitespace changes
Inline
Side-by-side
include/hpp/util/assertion.hh
View file @
2b29c1da
...
...
@@ -10,8 +10,6 @@
#ifndef HPP_UTIL_ASSERTION_HH
# define HPP_UTIL_ASSERTION_HH
# include <boost/scope_exit.hpp>
# include <hpp/util/config.hh>
# include <hpp/util/exception.hh>
...
...
include/hpp/util/parser.hh
View file @
2b29c1da
...
...
@@ -21,9 +21,9 @@
# include <list>
# include <string>
# include <iostream>
# include <
tinyxml.h
>
# include <
functional
>
# include <
boost/function.hpp
>
# include <
tinyxml.h
>
namespace
hpp
{
namespace
util
{
...
...
@@ -222,7 +222,7 @@ namespace hpp {
/// To extend its capabilities, see ObjectFactory.
class
Parser
{
public:
typedef
boo
st
::
function
<
ObjectFactory
*
(
ObjectFactory
*
,
const
XMLElement
*
)
>
typedef
st
d
::
function
<
ObjectFactory
*
(
ObjectFactory
*
,
const
XMLElement
*
)
>
FactoryType
;
/// Constructor
...
...
include/hpp/util/pointer.hh
View file @
2b29c1da
...
...
@@ -13,6 +13,17 @@
# include <boost/smart_ptr.hpp>
namespace
hpp
{
using
boost
::
shared_ptr
;
using
boost
::
weak_ptr
;
using
boost
::
static_pointer_cast
;
using
boost
::
dynamic_pointer_cast
;
using
boost
::
const_pointer_cast
;
using
boost
::
make_shared
;
}
// namespace hpp
/// Defines the four types of smart pointers associated with type <tt>\a t</tt>.
/// If <tt>\a t</tt> is \c CMyClass then
/// - the type of a shared pointer to <tt>\a t</tt> is \c CMyClassShPtr
...
...
@@ -23,8 +34,8 @@
/// \c CMyClassConstWkPtr_t
# define HPP_POINTER_DEFS(t) \
typedef
boost
::weak_ptr <t> t##WkPtr_t; \
typedef
boost
::weak_ptr <const t> t##ConstWkPtr_t; \
typedef
hpp
::weak_ptr <t> t##WkPtr_t; \
typedef
hpp
::weak_ptr <const t> t##ConstWkPtr_t; \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
/** Makes a forward declaration of class <tt>\a t</tt> and of the four
...
...
@@ -35,8 +46,8 @@
HPP_POINTER_DEFS(t); \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
# define HPP_STATIC_PTR_CAST(t, x)
boost
::static_pointer_cast < t > (x)
# define HPP_DYNAMIC_PTR_CAST(t, x)
boost
::dynamic_pointer_cast < t > (x)
# define HPP_STATIC_PTR_CAST(t, x)
hpp
::static_pointer_cast < t > (x)
# define HPP_DYNAMIC_PTR_CAST(t, x)
hpp
::dynamic_pointer_cast < t > (x)
# ifndef NDEBUG
# define HPP_STATIC_CAST_REF_CHECK(t, x)\
try {\
...
...
include/hpp/util/timer.hh
View file @
2b29c1da
...
...
@@ -18,11 +18,7 @@
#ifndef HPP_UTIL_TIMER_HH
# define HPP_UTIL_TIMER_HH
# include "boost/date_time/posix_time/posix_time_types.hpp"
# ifdef HPP_ENABLE_BENCHMARK
# include <boost/date_time/posix_time/posix_time.hpp>
# endif // HPP_ENABLE_BENCHMARK
# include <chrono>
# include <hpp/util/config.hh>
# include <hpp/util/debug.hh>
...
...
@@ -34,26 +30,26 @@ namespace hpp
class
HPP_UTIL_DLLAPI
Timer
{
public:
typedef
boo
st
::
posix_time
::
ptime
ptim
e
;
typedef
boost
::
posix_time
::
time_duration
time_duration
;
typedef
boo
st
::
posix_time
::
time_period
time_period
;
typedef
st
d
::
chrono
::
high_resolution_clock
clock_typ
e
;
typedef
clock_type
::
time_point
time_point
;
typedef
st
d
::
chrono
::
duration
<
double
>
duration_type
;
explicit
Timer
(
bool
autoStart
=
false
);
Timer
(
const
Timer
&
);
Timer
&
operator
=
(
const
Timer
&
);
~
Timer
();
const
p
time
&
start
();
const
p
time
&
stop
();
time_duration
duration
()
const
;
const
time
_point
&
start
();
const
time
_point
&
stop
();
double
duration
()
const
;
const
p
time
&
getStart
()
const
;
const
p
time
&
getStop
()
const
;
const
time
_point
&
getStart
()
const
;
const
time
_point
&
getStop
()
const
;
std
::
ostream
&
print
(
std
::
ostream
&
)
const
;
private:
p
time
start_
;
p
time
end_
;
time
_point
start_
;
time
_point
end_
;
};
# ifdef HPP_ENABLE_BENCHMARK
...
...
@@ -99,28 +95,29 @@ namespace hpp
TimeCounter
&
tc
;
};
typedef
boost
::
posix_time
::
ptime
ptime
;
typedef
boost
::
posix_time
::
time_duration
time_duration
;
typedef
std
::
chrono
::
high_resolution_clock
clock_type
;
typedef
clock_type
::
time_point
time_point
;
typedef
std
::
chrono
::
duration
<
double
>
duration_type
;
TimeCounter
(
const
std
::
string
&
name
);
void
start
();
time_duration
stop
();
time_duration
last
();
double
stop
();
double
last
();
void
reset
();
time_duration
min
()
const
;
time_duration
max
()
const
;
time_duration
mean
()
const
;
time_duration
totalTime
()
const
;
double
min
()
const
;
double
max
()
const
;
double
mean
()
const
;
double
totalTime
()
const
;
std
::
ostream
&
print
(
std
::
ostream
&
os
)
const
;
private:
std
::
string
n_
;
unsigned
long
c_
;
time_
duration
t_
,
last_
,
min_
,
max_
;
p
time
s_
;
duration
_type
t_
,
last_
,
min_
,
max_
;
time
_point
s_
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
TimeCounter
&
tc
);
...
...
src/debug.cc
View file @
2b29c1da
...
...
@@ -22,10 +22,7 @@
#include
<fstream>
#include
<sstream>
#include
<boost/assign/list_of.hpp>
#include
<boost/filesystem.hpp>
#include
<boost/foreach.hpp>
#include
<boost/format.hpp>
#include
<boost/filesystem.hpp>
// Need C++ 17 to remove this.
#include
"hpp/util/indent.hh"
#include
"hpp/util/debug.hh"
...
...
@@ -145,7 +142,7 @@ namespace hpp
char
const
*
function
,
const
std
::
string
&
data
)
{
BOOST_FOREACH
(
Output
*
o
,
subscribers_
)
for
(
Output
*
o
:
subscribers_
)
if
(
o
)
o
->
write
(
*
this
,
file
,
line
,
function
,
data
);
}
...
...
@@ -157,7 +154,7 @@ namespace hpp
char
const
*
function
,
const
std
::
stringstream
&
data
)
{
BOOST_FOREACH
(
Output
*
o
,
subscribers_
)
for
(
Output
*
o
:
subscribers_
)
if
(
o
)
o
->
write
(
*
this
,
file
,
line
,
function
,
data
);
}
...
...
@@ -220,9 +217,9 @@ namespace hpp
{
static
const
std
::
string
packageName
=
"hpp"
;
boo
st
::
format
fmter
(
"%1%.%2%.log"
)
;
fmter
%
filename
%
getpid
();
return
debug
::
getFilename
(
fmter
.
str
(),
packageName
);
st
d
::
stringstream
name
;
name
<<
filename
<<
'.'
<<
getpid
()
<<
".log"
;
return
debug
::
getFilename
(
name
.
str
(),
packageName
);
}
void
...
...
@@ -282,15 +279,15 @@ namespace hpp
journal
(
"journal"
),
benchmarkJournal
(
"benchmark"
),
error
(
"ERROR"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
journal
)
(
&
console
)
),
(
"ERROR"
,
{
&
journal
,
&
console
}
),
warning
(
"WARNING"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
journal
)
(
&
console
)
),
(
"WARNING"
,
{
&
journal
,
&
console
}
),
notice
(
"NOTICE"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
journal
)
(
&
console
)
),
(
"NOTICE"
,
{
&
journal
,
&
console
}
),
info
(
"INFO"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
journal
)
),
(
"INFO"
,
{
&
journal
}
),
benchmark
(
"BENCHMARK"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
benchmarkJournal
)
)
(
"BENCHMARK"
,
{
&
benchmarkJournal
}
)
{}
Logging
::~
Logging
()
...
...
src/exception.cc
View file @
2b29c1da
...
...
@@ -9,7 +9,6 @@
// See the COPYING file for more information.
#include
<iostream>
#include
<boost/format.hpp>
#ifdef HPP_LOG_EXCEPTION
# include "hpp/util/debug.hh"
...
...
@@ -65,8 +64,7 @@ namespace hpp
std
::
ostream
&
Exception
::
print
(
std
::
ostream
&
o
)
const
throw
()
{
using
boost
::
format
;
o
<<
(
format
(
"%1%:%2%: %3%"
)
%
file_
%
line_
%
message_
);
o
<<
file_
<<
':'
<<
line_
<<
": "
<<
message_
;
return
o
;
}
...
...
src/timer.cc
View file @
2b29c1da
...
...
@@ -16,12 +16,12 @@
// along with hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include
<iostream>
//#include <boost/date_time/microsec_time_clock.hpp>
#include
<boost/date_time/posix_time/posix_time.hpp>
#include
<boost/format.hpp>
#include
<iomanip>
#include
"hpp/util/timer.hh"
using
namespace
std
::
chrono
;
namespace
hpp
{
namespace
debug
...
...
@@ -52,98 +52,96 @@ namespace hpp
Timer
::~
Timer
()
{}
const
Timer
::
p
time
&
const
Timer
::
time
_point
&
Timer
::
start
()
{
return
start_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
();
return
start_
=
clock_type
::
now
();
}
const
Timer
::
p
time
&
const
Timer
::
time
_point
&
Timer
::
stop
()
{
return
end_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
();
return
end_
=
clock_type
::
now
();
}
const
Timer
::
p
time
&
const
Timer
::
time
_point
&
Timer
::
getStart
()
const
{
return
start_
;
}
const
Timer
::
p
time
&
const
Timer
::
time
_point
&
Timer
::
getStop
()
const
{
return
end_
;
}
Timer
::
time_duration
double
Timer
::
duration
()
const
{
time_period
duration
(
start_
,
end_
);
return
duration
.
length
();
return
duration_type
(
end_
-
start_
).
count
();
}
std
::
ostream
&
Timer
::
print
(
std
::
ostream
&
o
)
const
{
using
boost
::
format
;
return
o
<<
(
format
(
"timer started at ``%1%'' and ended at ``%2%'' (elapsed time ``%3%''"
)
%
start_
%
end_
%
duration
());
auto
time
=
clock_type
::
to_time_t
(
start_
);
return
o
<<
"timer started at "
<<
std
::
put_time
(
std
::
localtime
(
&
time
),
"%F %T"
)
<<
" and elapsed time "
"is "
<<
duration
();
}
TimeCounter
::
TimeCounter
(
const
std
::
string
&
name
)
:
n_
(
name
),
c_
(
0
),
t_
(
0
,
0
,
0
,
0
),
min_
(
boost
::
date_time
::
pos_infin
),
max_
(
0
,
0
,
0
,
0
)
n_
(
name
),
c_
(
0
),
t_
(
duration_type
::
zero
()
),
min_
(
duration_type
::
max
()),
max_
(
duration_type
::
min
()
)
{}
void
TimeCounter
::
start
()
{
s_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
();
s_
=
clock_type
::
now
();
}
TimeCounter
::
time_duration
TimeCounter
::
stop
()
double
TimeCounter
::
stop
()
{
last_
=
boost
::
posix_time
::
microsec_clock
::
universal_time
()
-
s_
;
last_
=
clock_type
::
now
()
-
s_
;
min_
=
std
::
min
(
last_
,
min_
);
max_
=
std
::
max
(
last_
,
max_
);
t_
+=
last_
;
++
c_
;
return
last_
;
return
last_
.
count
()
;
}
TimeCounter
::
time_duration
TimeCounter
::
last
()
double
TimeCounter
::
last
()
{
return
last_
;
return
last_
.
count
()
;
}
void
TimeCounter
::
reset
()
{
t_
=
time_
duration
(
0
,
0
,
0
,
0
);
t_
=
duration
_type
::
zero
(
);
c_
=
0
;
min_
=
time_
duration
(
boost
::
date_time
::
pos_infin
);
max_
=
time_
duration
(
0
,
0
,
0
,
0
);
min_
=
duration
_type
::
max
(
);
max_
=
duration
_type
::
min
(
);
}
TimeCounter
::
time_duration
TimeCounter
::
min
()
const
double
TimeCounter
::
min
()
const
{
return
min_
;
return
min_
.
count
()
;
}
TimeCounter
::
time_duration
TimeCounter
::
max
()
const
double
TimeCounter
::
max
()
const
{
return
max_
;
return
max_
.
count
()
;
}
TimeCounter
::
time_duration
TimeCounter
::
mean
()
const
double
TimeCounter
::
mean
()
const
{
return
(
c_
>
0
)
?
t_
/
(
int
)
c_
:
time_duration
(
0
,
0
,
0
,
0
)
;
return
(
c_
>
0
)
?
(
t_
/
(
int
)
c_
).
count
()
:
0
;
}
TimeCounter
::
time_duration
TimeCounter
::
totalTime
()
const
double
TimeCounter
::
totalTime
()
const
{
return
t_
;
return
t_
.
count
()
;
}
std
::
ostream
&
TimeCounter
::
print
(
std
::
ostream
&
os
)
const
...
...
tests/debug.cc
View file @
2b29c1da
...
...
@@ -17,7 +17,6 @@
#include
"config.h"
#include
<iostream>
#include
<boost/assign/list_of.hpp>
#include
<hpp/util/debug.hh>
#include
"common.hh"
...
...
@@ -28,7 +27,7 @@ int run_test ()
{
ConsoleOutput
console
;
JournalOutput
out
(
"debug.test.log"
);
Channel
channel
(
"TEST"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
out
)(
&
console
)
);
Channel
channel
(
"TEST"
,
{
&
out
,
&
console
}
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
std
::
stringstream
ss
;
ss
<<
i
<<
hpp
::
iendl
;
...
...
tests/timer.cc
View file @
2b29c1da
...
...
@@ -14,7 +14,6 @@
// received a copy of the GNU Lesser General Public License along with
// hpp-util. If not, see <http://www.gnu.org/licenses/>.
#include
<boost/assign/list_of.hpp>
#include
<cstdlib>
#include
"config.h"
...
...
@@ -41,7 +40,7 @@ HPP_DEFINE_TIMECOUNTER(testCounter2);
int
run_test
()
{
int
N
=
10
;
logging
.
benchmark
=
Channel
(
"BENCHMARK"
,
boost
::
assign
::
list_of
<
Output
*>
(
&
logging
.
console
)
);
logging
.
benchmark
=
Channel
(
"BENCHMARK"
,
{
&
logging
.
console
}
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
HPP_START_TIMECOUNTER
(
testCounter
);
int
k
=
1
+
(
std
::
rand
()
%
10
);
...
...
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