Merge pull request #353 from svost/c++11
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Mon, 3 Oct 2016 00:03:24 +0000 (04:03 +0400)
committerGitHub <noreply@github.com>
Mon, 3 Oct 2016 00:03:24 +0000 (04:03 +0400)
Minor restyle whith std=c++11

src/bitcoinrpc.cpp
src/checkqueue.h
src/netbase.cpp
src/util.cpp

index adaa354..0c7e278 100644 (file)
@@ -452,7 +452,7 @@ int ReadHTTPHeader(std::basic_istream<char>& stream, map<string, string>& mapHea
         {
             auto strHeader = str.substr(0, nColon);
             boost::trim(strHeader);
-            boost::to_lower(strHeader);
+            transform(strHeader.begin(), strHeader.end(), strHeader.begin(), ::tolower);
             auto strValue = str.substr(nColon+1);
             boost::trim(strValue);
             mapHeadersRet[strHeader] = strValue;
index da85af0..8d3bfc3 100644 (file)
@@ -7,37 +7,34 @@
 
 #include <algorithm>
 #include <vector>
-
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/mutex.hpp>
+#include <mutex>
 
 extern bool fShutdown;
 
 template<typename T> class CCheckQueueControl;
 
-/** Queue for verifications that have to be performed.
-  * The verifications are represented by a type T, which must provide an
-  * operator(), returning a bool.
-  *
-  * One thread (the master) is assumed to push batches of verifications
-  * onto the queue, where they are processed by N-1 worker threads. When
-  * the master is done adding work, it temporarily joins the worker pool
-  * as an N'th worker, until all jobs are done.
-  */
+// Queue for verifications that have to be performed.
+// The verifications are represented by a type T, which must provide an
+// operator(), returning a bool.
+//
+// One thread (the master) is assumed to push batches of verifications
+// onto the queue, where they are processed by N-1 worker threads. When
+// the master is done adding work, it temporarily joins the worker pool
+// as an N'th worker, until all jobs are done.
+//
 template<typename T> class CCheckQueue {
 private:
     // Mutex to protect the inner state
-    boost::mutex mutex;
+    std::mutex mutex;
 
     // Worker threads block on this when out of work
-    boost::condition_variable condWorker;
+    std::condition_variable condWorker;
 
     // Master thread blocks on this when out of work
-    boost::condition_variable condMaster;
+    std::condition_variable condMaster;
 
     // Quit method blocks on this until all workers are gone
-    boost::condition_variable condQuit;
+    std::condition_variable condQuit;
 
     // The queue of elements to be processed.
     // As the order of booleans doesn't matter, it is used as a LIFO (stack)
@@ -65,14 +62,14 @@ private:
 
     // Internal function that does bulk of the verification work.
     bool Loop(bool fMaster = false) {
-        boost::condition_variable &cond = fMaster ? condMaster : condWorker;
+        std::condition_variable &cond = fMaster ? condMaster : condWorker;
         std::vector<T> vChecks;
         vChecks.reserve(nBatchSize);
         unsigned int nNow = 0;
         bool fOk = true;
         do {
             {
-                boost::unique_lock<boost::mutex> lock(mutex);
+                std::unique_lock<std::mutex> lock(mutex);
                 // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
                 if (nNow) {
                     fAllOk &= fOk;
@@ -143,7 +140,7 @@ public:
 
     // Add a batch of checks to the queue
     void Add(std::vector<T> &vChecks) {
-        boost::unique_lock<boost::mutex> lock(mutex);
+        std::unique_lock<std::mutex> lock(mutex);
         for(T &check :  vChecks) {
             queue.push_back(T());
             check.swap(queue.back());
@@ -157,7 +154,7 @@ public:
 
     // Shut the queue down
     void Quit() {
-        boost::unique_lock<boost::mutex> lock(mutex);
+        std::unique_lock<std::mutex> lock(mutex);
         fQuit = true;
         // No need to wake the master, as he will quit automatically when all jobs are
         // done.
@@ -173,14 +170,14 @@ public:
 
     bool IsIdle()
     {
-        boost::unique_lock<boost::mutex> lock(mutex);
+        std::unique_lock<std::mutex> lock(mutex);
         return (nTotal == nIdle && nTodo == 0 && fAllOk == true);
     }
 };
 
-/** RAII-style controller object for a CCheckQueue that guarantees the passed
- *  queue is finished before continuing.
- */
+// RAII-style controller object for a CCheckQueue that guarantees the passed
+// queue is finished before continuing.
+//
 template<typename T> class CCheckQueueControl {
 private:
     CCheckQueue<T> *pqueue;
@@ -189,14 +186,14 @@ private:
 public:
     CCheckQueueControl(CCheckQueue<T> *pqueueIn) : pqueue(pqueueIn), fDone(false) {
         // passed queue is supposed to be unused, or NULL
-        if (pqueue != NULL) {
+        if (pqueue != nullptr) {
             bool isIdle = pqueue->IsIdle();
             assert(isIdle);
         }
     }
 
     bool Wait() {
-        if (pqueue == NULL)
+        if (pqueue == nullptr)
             return true;
         bool fRet = pqueue->Wait();
         fDone = true;
@@ -204,7 +201,7 @@ public:
     }
 
     void Add(std::vector<T> &vChecks) {
-        if (pqueue != NULL)
+        if (pqueue != nullptr)
             pqueue->Add(vChecks);
     }
 
index 3f0d981..ebc5f9f 100644 (file)
@@ -21,8 +21,6 @@
 typedef SSIZE_T ssize_t;
 #endif
 
-#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
-
 using namespace std;
 
 // Settings
@@ -35,7 +33,7 @@ bool fNameLookup = false;
 static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
 
 enum Network ParseNetwork(std::string net) {
-    boost::to_lower(net);
+    transform(net.begin(), net.end(), net.begin(), ::tolower);
     if (net == "ipv4") return NET_IPV4;
     if (net == "ipv6") return NET_IPV6;
     if (net == "tor" || net == "onion")  return NET_TOR;
@@ -127,7 +125,7 @@ bool LookupHost(const string& strName, std::vector<CNetAddr>& vIP, unsigned int
     std::string strHost(strName);
     if (strHost.empty())
         return false;
-    if ((strHost.compare(0,1, "[") == 0) && (strHost.compare(strHost.length()-1,1, "]") == 0))
+    if ((strHost.front() == '[') && (strHost.back() == ']'))
     {
         strHost = strHost.substr(1, strHost.size() - 2);
     }
@@ -140,7 +138,7 @@ bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nM
     std::string strHost(pszName);
     if (strHost.empty())
         return false;
-    if ((strHost.compare(0,1, "[") == 0) && (strHost.compare(strHost.length()-1,1, "]") == 0))
+    if ((strHost.front() == '[') && (strHost.back() == ']'))
     {
         strHost = strHost.substr(1, strHost.size() - 2);
     }
index 4be37a2..f798da6 100644 (file)
@@ -11,7 +11,6 @@
 #include <random>
 
 #include <boost/algorithm/string/join.hpp>
-#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
 #include <boost/program_options/detail/config_file.hpp>
 #include <boost/program_options/parsers.hpp>
 #include <boost/filesystem.hpp>
@@ -514,7 +513,7 @@ void ParseParameters(int argc, const char* const argv[])
             str = str.substr(0, is_index);
         }
 #ifdef WIN32
-        boost::to_lower(str);
+        transform(str.begin(), str.end(), str.begin(), ::tolower);
         if (str.compare(0,1, "/") == 0)
             str = "-" + str.substr(1);
 #endif