src: Refactoring common.hpp and minimizing exposed includes
Face class has relatively large rewrite to hide internals using
Implementor pattern. As of this commit, <boost/asio.hpp> is not
automatically included whenever ndn-cxx/face.hpp is included. If it is
needed to directly work with io_service, asio.hpp should be specifically
included.
Change-Id: Ie742b851025b4e3da634eb981319df0f42937855
diff --git a/src/util/command-interest-validator.hpp b/src/util/command-interest-validator.hpp
index 6bd3250..2dcc947 100644
--- a/src/util/command-interest-validator.hpp
+++ b/src/util/command-interest-validator.hpp
@@ -17,6 +17,8 @@
#include "../security/identity-certificate.hpp"
#include "../security/sec-rule-specific.hpp"
+#include <list>
+
namespace ndn {
class CommandInterestValidator : public Validator
diff --git a/src/util/config-file.hpp b/src/util/config-file.hpp
index 8d49d26..880657a 100644
--- a/src/util/config-file.hpp
+++ b/src/util/config-file.hpp
@@ -15,6 +15,8 @@
#include "../common.hpp"
+#include <fstream>
+
#include <boost/property_tree/ptree.hpp>
#include <boost/filesystem.hpp>
diff --git a/src/util/crypto.cpp b/src/util/crypto.cpp
index 29cbe9d..6e559dd 100644
--- a/src/util/crypto.cpp
+++ b/src/util/crypto.cpp
@@ -13,6 +13,7 @@
#include "../common.hpp"
#include "crypto.hpp"
+#include "../encoding/buffer-stream.hpp"
#include "../security/cryptopp.hpp"
namespace ndn {
diff --git a/src/util/io.hpp b/src/util/io.hpp
index 6ca861f..c61dccf 100644
--- a/src/util/io.hpp
+++ b/src/util/io.hpp
@@ -16,6 +16,7 @@
#include "../common.hpp"
#include "../encoding/block.hpp"
+#include "../encoding/buffer-stream.hpp"
#include <string>
#include <iostream>
diff --git a/src/util/regex/regex-backref-manager.hpp b/src/util/regex/regex-backref-manager.hpp
index 9ca95ea..a87640c 100644
--- a/src/util/regex/regex-backref-manager.hpp
+++ b/src/util/regex/regex-backref-manager.hpp
@@ -17,6 +17,8 @@
#include "../../common.hpp"
+#include <vector>
+
namespace ndn {
class RegexMatcher;
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index 8e0e908..6bccffe 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -20,6 +20,8 @@
#include "regex-matcher.hpp"
#include "regex-component-matcher.hpp"
+#include <set>
+
namespace ndn {
class RegexComponentSetMatcher : public RegexMatcher
diff --git a/src/util/regex/regex-top-matcher.cpp b/src/util/regex/regex-top-matcher.cpp
index e2317c7..3c95959 100644
--- a/src/util/regex/regex-top-matcher.cpp
+++ b/src/util/regex/regex-top-matcher.cpp
@@ -17,6 +17,8 @@
#include "regex-backref-manager.hpp"
#include "regex-pattern-list-matcher.hpp"
+#include <boost/lexical_cast.hpp>
+
namespace ndn {
RegexTopMatcher::RegexTopMatcher(const std::string& expr, const std::string& expand)
diff --git a/src/util/scheduler.hpp b/src/util/scheduler.hpp
index 89892e1..b2a7831 100644
--- a/src/util/scheduler.hpp
+++ b/src/util/scheduler.hpp
@@ -16,6 +16,8 @@
#include "../common.hpp"
#include "monotonic_deadline_timer.hpp"
+#include <set>
+
namespace ndn {
struct EventIdImpl; ///< \brief Private storage of information about the event
diff --git a/src/util/time.cpp b/src/util/time.cpp
new file mode 100644
index 0000000..3dacbc6
--- /dev/null
+++ b/src/util/time.cpp
@@ -0,0 +1,93 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California.
+ * All rights reserved.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * This file licensed under New BSD License. See COPYING for detailed information about
+ * ndn-cxx library copyright, permissions, and redistribution restrictions.
+ */
+
+#include "time.hpp"
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+namespace ndn {
+namespace time {
+
+std::string
+toIsoString(const system_clock::TimePoint& timePoint)
+{
+ namespace bpt = boost::posix_time;
+ bpt::ptime ptime = bpt::from_time_t(system_clock::to_time_t(timePoint));
+
+ uint64_t micro = duration_cast<microseconds>(timePoint - getUnixEpoch()).count() % 1000000;
+ if (micro > 0)
+ {
+ ptime += bpt::microseconds(micro);
+ return bpt::to_iso_string(ptime);
+ }
+ else
+ return bpt::to_iso_string(ptime);
+}
+
+
+system_clock::TimePoint
+fromIsoString(const std::string& isoString)
+{
+ namespace bpt = boost::posix_time;
+ static bpt::ptime posixTimeEpoch = bpt::from_time_t(0);
+
+ bpt::ptime ptime = bpt::from_iso_string(isoString);
+
+ system_clock::TimePoint point =
+ system_clock::from_time_t((ptime - posixTimeEpoch).total_seconds());
+ point += microseconds((ptime - posixTimeEpoch).total_microseconds() % 1000000);
+ return point;
+}
+
+
+std::string
+toString(const system_clock::TimePoint& timePoint,
+ const std::string& format/* = "%Y-%m-%d %H:%M:%S"*/,
+ const std::locale& locale/* = std::locale("C")*/)
+{
+ namespace bpt = boost::posix_time;
+ bpt::ptime ptime = bpt::from_time_t(system_clock::to_time_t(timePoint));
+
+ uint64_t micro = duration_cast<microseconds>(timePoint - getUnixEpoch()).count() % 1000000;
+ ptime += bpt::microseconds(micro);
+
+ bpt::time_facet* facet = new bpt::time_facet(format.c_str());
+ std::ostringstream formattedTimePoint;
+ formattedTimePoint.imbue(std::locale(locale, facet));
+ formattedTimePoint << ptime;
+
+ return formattedTimePoint.str();
+}
+
+
+system_clock::TimePoint
+fromString(const std::string& formattedTimePoint,
+ const std::string& format/* = "%Y-%m-%d %H:%M:%S"*/,
+ const std::locale& locale/* = std::locale("C")*/)
+{
+ namespace bpt = boost::posix_time;
+ static bpt::ptime posixTimeEpoch = bpt::from_time_t(0);
+
+ bpt::time_input_facet* facet = new bpt::time_input_facet(format);
+ std::istringstream is(formattedTimePoint);
+
+ is.imbue(std::locale(locale, facet));
+ bpt::ptime ptime;
+ is >> ptime;
+
+ system_clock::TimePoint point =
+ system_clock::from_time_t((ptime - posixTimeEpoch).total_seconds());
+ point += microseconds((ptime - posixTimeEpoch).total_microseconds() % 1000000);
+ return point;
+}
+
+} // namespace time
+} // namespace ndn
diff --git a/src/util/time.hpp b/src/util/time.hpp
index 3bc4e4f..98d27e8 100644
--- a/src/util/time.hpp
+++ b/src/util/time.hpp
@@ -15,7 +15,6 @@
#include "../common.hpp"
#include <boost/chrono.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
namespace ndn {
namespace time {
@@ -138,21 +137,8 @@
* - with fractional milliseconds: 20020131T100001,123
* - without fractional seconds: 20020131T100001
*/
-inline std::string
-toIsoString(const system_clock::TimePoint& timePoint)
-{
- namespace bpt = boost::posix_time;
- bpt::ptime ptime = bpt::from_time_t(system_clock::to_time_t(timePoint));
-
- uint64_t micro = duration_cast<microseconds>(timePoint - getUnixEpoch()).count() % 1000000;
- if (micro > 0)
- {
- ptime += bpt::microseconds(micro);
- return bpt::to_iso_string(ptime);
- }
- else
- return bpt::to_iso_string(ptime);
-}
+std::string
+toIsoString(const system_clock::TimePoint& timePoint);
/**
* \brief Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation
@@ -166,19 +152,8 @@
* - without fractional seconds: 20020131T100001
*
*/
-inline system_clock::TimePoint
-fromIsoString(const std::string& isoString)
-{
- namespace bpt = boost::posix_time;
- static bpt::ptime posixTimeEpoch = bpt::from_time_t(0);
-
- bpt::ptime ptime = bpt::from_iso_string(isoString);
-
- system_clock::TimePoint point =
- system_clock::from_time_t((ptime - posixTimeEpoch).total_seconds());
- point += microseconds((ptime - posixTimeEpoch).total_microseconds() % 1000000);
- return point;
-}
+system_clock::TimePoint
+fromIsoString(const std::string& isoString);
/**
* \brief Convert time point to string with specified format
@@ -193,24 +168,10 @@
* \sa http://www.boost.org/doc/libs/1_48_0/doc/html/date_time/date_time_io.html#date_time.format_flags
* described possible formatting flags
**/
-inline std::string
+std::string
toString(const system_clock::TimePoint& timePoint,
const std::string& format = "%Y-%m-%d %H:%M:%S",
- const std::locale& locale = std::locale("C"))
-{
- namespace bpt = boost::posix_time;
- bpt::ptime ptime = bpt::from_time_t(system_clock::to_time_t(timePoint));
-
- uint64_t micro = duration_cast<microseconds>(timePoint - getUnixEpoch()).count() % 1000000;
- ptime += bpt::microseconds(micro);
-
- bpt::time_facet* facet = new bpt::time_facet(format.c_str());
- std::ostringstream formattedTimePoint;
- formattedTimePoint.imbue(std::locale(locale, facet));
- formattedTimePoint << ptime;
-
- return formattedTimePoint.str();
-}
+ const std::locale& locale = std::locale("C"));
/**
* \brief Convert from string of specified format into time point
@@ -225,26 +186,10 @@
* \sa http://www.boost.org/doc/libs/1_48_0/doc/html/date_time/date_time_io.html#date_time.format_flags
* described possible formatting flags
*/
-inline system_clock::TimePoint
+system_clock::TimePoint
fromString(const std::string& formattedTimePoint,
const std::string& format = "%Y-%m-%d %H:%M:%S",
- const std::locale& locale = std::locale("C"))
-{
- namespace bpt = boost::posix_time;
- static bpt::ptime posixTimeEpoch = bpt::from_time_t(0);
-
- bpt::time_input_facet* facet = new bpt::time_input_facet(format);
- std::istringstream is(formattedTimePoint);
-
- is.imbue(std::locale(locale, facet));
- bpt::ptime ptime;
- is >> ptime;
-
- system_clock::TimePoint point =
- system_clock::from_time_t((ptime - posixTimeEpoch).total_seconds());
- point += microseconds((ptime - posixTimeEpoch).total_microseconds() % 1000000);
- return point;
-}
+ const std::locale& locale = std::locale("C"));
} // namespace time
} // namespace ndn