Commit 2b29c1da authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Reduce dependency to boost.

parent f62f8730
......@@ -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>
......
......@@ -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 boost::function <ObjectFactory* (ObjectFactory*, const XMLElement*)>
typedef std::function <ObjectFactory* (ObjectFactory*, const XMLElement*)>
FactoryType;
/// Constructor
......
......@@ -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 {\
......
......@@ -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 boost::posix_time::ptime ptime;
typedef boost::posix_time::time_duration time_duration;
typedef boost::posix_time::time_period time_period;
typedef std::chrono::high_resolution_clock clock_type;
typedef clock_type::time_point time_point;
typedef std::chrono::duration<double> duration_type;
explicit Timer (bool autoStart = false);
Timer (const Timer&);
Timer& operator= (const Timer&);
~Timer ();
const ptime& start ();
const ptime& stop ();
time_duration duration () const;
const time_point& start ();
const time_point& stop ();
double duration () const;
const ptime& getStart () const;
const ptime& getStop () const;
const time_point& getStart () const;
const time_point& getStop () const;
std::ostream& print (std::ostream&) const;
private:
ptime start_;
ptime 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_;
ptime s_;
duration_type t_, last_, min_, max_;
time_point s_;
};
std::ostream& operator<< (std::ostream& os, const TimeCounter& tc);
......
......@@ -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";
boost::format fmter ("%1%.%2%.log");
fmter % filename % getpid ();
return debug::getFilename (fmter.str (), packageName);
std::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 ()
......
......@@ -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;
}
......
......@@ -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::ptime&
const Timer::time_point&
Timer::start ()
{
return start_ = boost::posix_time::microsec_clock::universal_time ();
return start_ = clock_type::now();
}
const Timer::ptime&
const Timer::time_point&
Timer::stop ()
{
return end_ = boost::posix_time::microsec_clock::universal_time ();
return end_ = clock_type::now();
}
const Timer::ptime&
const Timer::time_point&
Timer::getStart () const
{
return start_;
}
const Timer::ptime&
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
......
......@@ -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;
......
......@@ -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);
......
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