build: use C++11
Change-Id: I0e58ac4e9cb42d07a9b58125d761875f91c7744c
Refs: #1930
diff --git a/src/common.hpp b/src/common.hpp
index 317789c..ee122d3 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -43,6 +43,8 @@
#include <list>
#include <algorithm>
#include <iostream>
+#include <functional>
+#include <memory>
namespace repo {
@@ -58,13 +60,11 @@
using ndn::Scheduler;
using ndn::ValidatorConfig;
-using ndn::bind;
-using ndn::shared_ptr;
-using ndn::make_shared;
-using ndn::enable_shared_from_this;
-
-using std::vector;
-using std::string;
+using std::shared_ptr;
+using std::make_shared;
+using std::bind;
+using std::placeholders::_1;
+using std::placeholders::_2;
using boost::noncopyable;
diff --git a/src/handles/base-handle.hpp b/src/handles/base-handle.hpp
index 44ac4a8..95b8caa 100644
--- a/src/handles/base-handle.hpp
+++ b/src/handles/base-handle.hpp
@@ -110,7 +110,7 @@
inline void
BaseHandle::reply(const Interest& commandInterest, const RepoCommandResponse& response)
{
- shared_ptr<Data> rdata = make_shared<Data>(commandInterest.getName());
+ std::shared_ptr<Data> rdata = std::make_shared<Data>(commandInterest.getName());
rdata->setContent(response.wireEncode());
m_keyChain.sign(*rdata);
m_face.put(*rdata);
diff --git a/src/handles/delete-handle.cpp b/src/handles/delete-handle.cpp
index c6ad7c5..5cd0506 100644
--- a/src/handles/delete-handle.cpp
+++ b/src/handles/delete-handle.cpp
@@ -92,7 +92,8 @@
}
void
-DeleteHandle::onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason)
+DeleteHandle::onValidationFailed(const shared_ptr<const Interest>& interest,
+ const std::string& reason)
{
std::cerr << reason << std::endl;
negativeReply(*interest, 401);
diff --git a/src/handles/delete-handle.hpp b/src/handles/delete-handle.hpp
index 91ff244..5493d2e 100644
--- a/src/handles/delete-handle.hpp
+++ b/src/handles/delete-handle.hpp
@@ -25,8 +25,6 @@
namespace repo {
-using std::vector;
-
class DeleteHandle : public BaseHandle
{
@@ -56,10 +54,10 @@
onRegisterFailed(const Name& prefix, const std::string& reason);
void
- onValidated(const shared_ptr<const Interest>& interest, const Name& prefix);
+ onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
- onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason);
+ onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
/**
* @todo delete check has not been realized due to the while loop of segmented data deletion.
diff --git a/src/handles/tcp-bulk-insert-handle.hpp b/src/handles/tcp-bulk-insert-handle.hpp
index ef1cbdd..62ced11 100644
--- a/src/handles/tcp-bulk-insert-handle.hpp
+++ b/src/handles/tcp-bulk-insert-handle.hpp
@@ -59,7 +59,7 @@
private:
void
handleAccept(const boost::system::error_code& error,
- const shared_ptr<boost::asio::ip::tcp::socket>& socket);
+ const std::shared_ptr<boost::asio::ip::tcp::socket>& socket);
private:
boost::asio::ip::tcp::acceptor m_acceptor;
diff --git a/src/handles/watch-handle.cpp b/src/handles/watch-handle.cpp
index 15a82fa..9e80212 100644
--- a/src/handles/watch-handle.cpp
+++ b/src/handles/watch-handle.cpp
@@ -98,7 +98,8 @@
}
void
-WatchHandle::onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason)
+WatchHandle::onValidationFailed(const shared_ptr<const Interest>& interest,
+ const std::string& reason)
{
std::cerr << reason << std::endl;
negativeReply(*interest, 401);
diff --git a/src/handles/watch-handle.hpp b/src/handles/watch-handle.hpp
index 10cddda..2fde3cf 100644
--- a/src/handles/watch-handle.hpp
+++ b/src/handles/watch-handle.hpp
@@ -71,10 +71,10 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onValidated(const shared_ptr<const Interest>& interest, const Name& prefix);
+ onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
- onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason);
+ onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
void
onRegistered(const Name& prefix);
@@ -96,14 +96,14 @@
onTimeout(const Interest& interest, const Name& name);
void
- onDataValidated(const Interest& interest, const shared_ptr<const Data>& data,
+ onDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
const Name& name);
/**
* @brief failure of validation
*/
void
- onDataValidationFailed(const Interest& interest, const shared_ptr<const Data>& data,
+ onDataValidationFailed(const Interest& interest, const std::shared_ptr<const Data>& data,
const std::string& reason, const Name& name);
@@ -121,10 +121,11 @@
onCheckInterest(const Name& prefix, const Interest& interest);
void
- onCheckValidated(const shared_ptr<const Interest>& interest, const Name& prefix);
+ onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
- onCheckValidationFailed(const shared_ptr<const Interest>& interest, const std::string& reason);
+ onCheckValidationFailed(const std::shared_ptr<const Interest>& interest,
+ const std::string& reason);
private: // watch stop command
/**
@@ -134,10 +135,11 @@
onStopInterest(const Name& prefix, const Interest& interest);
void
- onStopValidated(const shared_ptr<const Interest>& interest, const Name& prefix);
+ onStopValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
- onStopValidationFailed(const shared_ptr<const Interest>& interest, const std::string& reason);
+ onStopValidationFailed(const std::shared_ptr<const Interest>& interest,
+ const std::string& reason);
private:
void
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index 0bc4e12..08e951b 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.cpp
@@ -20,7 +20,6 @@
#include "write-handle.hpp"
namespace repo {
-using namespace ndn::time;
static const int RETRY_TIMEOUT = 3;
static const int DEFAULT_CREDIT = 12;
@@ -72,7 +71,7 @@
}
void
-WriteHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WriteHandle::onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix)
{
//m_validResult = 1;
RepoCommandParameter parameter;
@@ -99,14 +98,15 @@
}
void
-WriteHandle::onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason)
+WriteHandle::onValidationFailed(const std::shared_ptr<const Interest>& interest,
+ const std::string& reason)
{
std::cerr << reason << std::endl;
negativeReply(*interest, 401);
}
void
-WriteHandle::onData(const Interest& interest, ndn::Data& data, ProcessId processId)
+WriteHandle::onData(const Interest& interest, Data& data, ProcessId processId)
{
m_validator.validate(data,
bind(&WriteHandle::onDataValidated, this, interest, _1, processId),
@@ -114,7 +114,8 @@
}
void
-WriteHandle::onDataValidated(const Interest& interest, const shared_ptr<const Data>& data,
+WriteHandle::onDataValidated(const Interest& interest,
+ const std::shared_ptr<const Data>& data,
ProcessId processId)
{
if (m_processes.count(processId) == 0) {
@@ -135,7 +136,8 @@
}
void
-WriteHandle::onDataValidationFailed(const shared_ptr<const Data>& data, const std::string& reason)
+WriteHandle::onDataValidationFailed(const std::shared_ptr<const Data>& data,
+ const std::string& reason)
{
std::cerr << reason << std::endl;
}
@@ -150,7 +152,7 @@
void
WriteHandle::onSegmentDataValidated(const Interest& interest,
- const shared_ptr<const Data>& data,
+ const std::shared_ptr<const Data>& data,
ProcessId processId)
{
if (m_processes.count(processId) == 0) {
@@ -182,7 +184,7 @@
}
void
-WriteHandle::onTimeout(const ndn::Interest& interest, ProcessId processId)
+WriteHandle::onTimeout(const Interest& interest, ProcessId processId)
{
std::cerr << "Timeout" << std::endl;
m_processes.erase(processId);
diff --git a/src/handles/write-handle.hpp b/src/handles/write-handle.hpp
index bbbfe28..1c64437 100644
--- a/src/handles/write-handle.hpp
+++ b/src/handles/write-handle.hpp
@@ -109,10 +109,10 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onValidated(const shared_ptr<const Interest>& interest, const Name& prefix);
+ onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
- onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason);
+ onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
/**
* @brief insert command prefix register failed
@@ -128,7 +128,7 @@
onData(const Interest& interest, Data& data, ProcessId processId);
void
- onDataValidated(const Interest& interest, const shared_ptr<const Data>& data,
+ onDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
ProcessId processId);
/**
@@ -148,7 +148,7 @@
onSegmentData(const Interest& interest, Data& data, ProcessId processId);
void
- onSegmentDataValidated(const Interest& interest, const shared_ptr<const Data>& data,
+ onSegmentDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
ProcessId processId);
/**
@@ -183,7 +183,7 @@
* @brief failure of validation for both one or segmented data
*/
void
- onDataValidationFailed(const shared_ptr<const Data>& data, const std::string& reason);
+ onDataValidationFailed(const std::shared_ptr<const Data>& data, const std::string& reason);
/**
* @brief extends noEndTime of process if not noEndTimeout, set StatusCode 405
@@ -208,10 +208,11 @@
onCheckRegisterFailed(const Name& prefix, const std::string& reason);
void
- onCheckValidated(const shared_ptr<const Interest>& interest, const Name& prefix);
+ onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
- onCheckValidationFailed(const shared_ptr<const Interest>& interest, const std::string& reason);
+ onCheckValidationFailed(const std::shared_ptr<const Interest>& interest,
+ const std::string& reason);
private:
void
diff --git a/src/main.cpp b/src/main.cpp
index 3a1be07..9713943 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,9 +20,7 @@
#include "config.hpp"
#include "repo.hpp"
-using namespace repo;
-
-static const string ndnRepoUsageMessage =
+static const std::string ndnRepoUsageMessage =
/* argv[0] */ " - Next generation of NDN repository\n"
"-h: show help message\n"
"-c: set config file path\n"
@@ -46,15 +44,16 @@
else
{
/// \todo May be try to reload config file
- signalSet.async_wait(bind(&terminate, boost::ref(ioService), _1, _2,
- boost::ref(signalSet)));
+ signalSet.async_wait(std::bind(&terminate, std::ref(ioService),
+ std::placeholders::_1, std::placeholders::_2,
+ std::ref(signalSet)));
}
}
int
main(int argc, char** argv)
{
- string configPath = DEFAULT_CONFIG_FILE;
+ std::string configPath = DEFAULT_CONFIG_FILE;
int opt;
while ((opt = getopt(argc, argv, "hc:")) != -1) {
switch (opt) {
@@ -62,7 +61,7 @@
std::cout << argv[0] << ndnRepoUsageMessage << std::endl;
return 1;
case 'c':
- configPath = string(optarg);
+ configPath = std::string(optarg);
break;
default:
break;
@@ -71,7 +70,7 @@
try {
boost::asio::io_service ioService;
- Repo repoInstance(ioService, parseConfig(configPath));
+ repo::Repo repoInstance(ioService, repo::parseConfig(configPath));
boost::asio::signal_set signalSet(ioService);
signalSet.add(SIGINT);
@@ -79,8 +78,9 @@
signalSet.add(SIGHUP);
signalSet.add(SIGUSR1);
signalSet.add(SIGUSR2);
- signalSet.async_wait(bind(&terminate, boost::ref(ioService), _1, _2,
- boost::ref(signalSet)));
+ signalSet.async_wait(std::bind(&terminate, std::ref(ioService),
+ std::placeholders::_1, std::placeholders::_2,
+ std::ref(signalSet)));
repoInstance.initializeStorage();
diff --git a/src/repo.cpp b/src/repo.cpp
index 02c80da..64287e2 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -19,6 +19,7 @@
#include "repo.hpp"
#include "storage/sqlite-storage.hpp"
+
namespace repo {
RepoConfig
@@ -114,7 +115,7 @@
: m_config(config)
, m_scheduler(ioService)
, m_face(ioService)
- , m_store(make_shared<SqliteStorage>(config.dbPath))
+ , m_store(std::make_shared<SqliteStorage>(config.dbPath))
, m_storageHandle(config.nMaxPackets, *m_store)
, m_validator(m_face)
, m_readHandle(m_face, m_storageHandle, m_keyChain, m_scheduler)
@@ -142,7 +143,7 @@
Repo::enableListening()
{
// Enable "listening" on Data prefixes
- for (vector<ndn::Name>::iterator it = m_config.dataPrefixes.begin();
+ for (auto it = m_config.dataPrefixes.begin();
it != m_config.dataPrefixes.end();
++it)
{
@@ -150,7 +151,7 @@
}
// Enable "listening" on control prefixes
- for (vector<ndn::Name>::iterator it = m_config.repoPrefixes.begin();
+ for (auto it = m_config.repoPrefixes.begin();
it != m_config.repoPrefixes.end();
++it)
{
@@ -160,7 +161,7 @@
}
// Enable listening on TCP bulk insert addresses
- for (vector<pair<string, string> >::iterator it = m_config.tcpBulkInsertEndpoints.begin();
+ for (auto it = m_config.tcpBulkInsertEndpoints.begin();
it != m_config.tcpBulkInsertEndpoints.end();
++it)
{
diff --git a/src/repo.hpp b/src/repo.hpp
index e1feea6..3e7e89d 100644
--- a/src/repo.hpp
+++ b/src/repo.hpp
@@ -37,18 +37,14 @@
namespace repo {
-using std::string;
-using std::vector;
-using std::pair;
-
struct RepoConfig
{
- string repoConfigPath;
+ std::string repoConfigPath;
//StorageMethod storageMethod; This will be implemtented if there is other method.
std::string dbPath;
- vector<ndn::Name> dataPrefixes;
- vector<ndn::Name> repoPrefixes;
- vector<pair<string, string> > tcpBulkInsertEndpoints;
+ std::vector<ndn::Name> dataPrefixes;
+ std::vector<ndn::Name> repoPrefixes;
+ std::vector<std::pair<std::string, std::string> > tcpBulkInsertEndpoints;
int64_t nMaxPackets;
boost::property_tree::ptree validatorNode;
};
@@ -86,7 +82,7 @@
RepoConfig m_config;
ndn::Scheduler m_scheduler;
ndn::Face m_face;
- shared_ptr<Storage> m_store;
+ std::shared_ptr<Storage> m_store;
RepoStorage m_storageHandle;
KeyChain m_keyChain;
ValidatorConfig m_validator;
diff --git a/src/storage/repo-storage.hpp b/src/storage/repo-storage.hpp
index ed0ce9d..bc2ecbe 100644
--- a/src/storage/repo-storage.hpp
+++ b/src/storage/repo-storage.hpp
@@ -84,15 +84,14 @@
/**
* @brief read data from repo
* @param interest used to request data
- * @return std::pair<bool,shared_ptr<Data> >
+ * @return std::shared_ptr<Data>
*/
- shared_ptr<Data>
+ std::shared_ptr<Data>
readData(const Interest& interest) const;
private:
Index m_index;
Storage& m_storage;
-
};
} // namespace repo
diff --git a/src/storage/skiplist.hpp b/src/storage/skiplist.hpp
index 34c7c57..e6dd6a0 100644
--- a/src/storage/skiplist.hpp
+++ b/src/storage/skiplist.hpp
@@ -397,7 +397,7 @@
m_head->prevs.resize(newLevel + 1, m_head);
insertPositions.resize(newLevel + 1, m_head);
}
- for (int i = 0; i <= newLevel; i++) {
+ for (size_t i = 0; i <= newLevel; i++) {
newNode->nexts[i] = insertPositions[i]->nexts[i];
newNode->prevs[i] = insertPositions[i];
insertPositions[i]->nexts[i] = newNode;
diff --git a/src/storage/sqlite-storage.cpp b/src/storage/sqlite-storage.cpp
index 78b1792..7edcda7 100644
--- a/src/storage/sqlite-storage.cpp
+++ b/src/storage/sqlite-storage.cpp
@@ -25,6 +25,8 @@
namespace repo {
+using std::string;
+
SqliteStorage::SqliteStorage(const string& dbPath)
: m_size(0)
{
diff --git a/src/storage/sqlite-storage.hpp b/src/storage/sqlite-storage.hpp
index 73579c7..168cc41 100755
--- a/src/storage/sqlite-storage.hpp
+++ b/src/storage/sqlite-storage.hpp
@@ -48,7 +48,7 @@
};
explicit
- SqliteStorage(const string& dbPath);
+ SqliteStorage(const std::string& dbPath);
virtual
~SqliteStorage();
@@ -72,7 +72,7 @@
* @brief get the data from database
* @para id id number of each entry in the database, used to find the data
*/
- virtual shared_ptr<Data>
+ virtual std::shared_ptr<Data>
read(const int64_t id);
/**
@@ -86,7 +86,7 @@
* insertItemToIndex to reubuild index from database
*/
void
- fullEnumerate(const ndn::function<void(const Storage::ItemMeta)>& f);
+ fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f);
private:
void
@@ -94,7 +94,7 @@
private:
sqlite3* m_db;
- string m_dbPath;
+ std::string m_dbPath;
int64_t m_size;
};
diff --git a/src/storage/storage.hpp b/src/storage/storage.hpp
index 04f366f..bf75306 100755
--- a/src/storage/storage.hpp
+++ b/src/storage/storage.hpp
@@ -76,7 +76,7 @@
* @brief get the data from database
* @param id id number of each entry in the database, used to find the data
*/
- virtual shared_ptr<Data>
+ virtual std::shared_ptr<Data>
read(const int64_t id) = 0;
/**
@@ -90,7 +90,7 @@
* insertItemToIndex to reubuild index from database
*/
virtual void
- fullEnumerate(const ndn::function<void(const Storage::ItemMeta)>& f) = 0;
+ fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f) = 0;
};