summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/Algorithm.h26
-rw-r--r--Swiften/Base/LRUCache.h16
-rw-r--r--Swiften/Base/Override.h34
-rw-r--r--Swiften/Base/SimpleIDGenerator.h7
-rw-r--r--Swiften/Base/StdRandomGenerator.h3
-rw-r--r--Swiften/Base/URL.cpp14
-rw-r--r--Swiften/Base/URL.h10
-rw-r--r--Swiften/Base/UnitTest/URLTest.cpp26
8 files changed, 62 insertions, 74 deletions
diff --git a/Swiften/Base/Algorithm.h b/Swiften/Base/Algorithm.h
index 108dbe3..ee761b7 100644
--- a/Swiften/Base/Algorithm.h
+++ b/Swiften/Base/Algorithm.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2014 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -160,4 +160,28 @@ namespace Swift {
return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin(), pred);
}
+
+ /**
+ * Ranges
+ */
+ template <typename T>
+ class range_t {
+ public:
+ range_t(T b, T e) : b_(b), e_(e) {}
+
+ T begin() {
+ return b_;
+ }
+ T end() {
+ return e_;
+ }
+ private:
+ T b_;
+ T e_;
+ };
+
+ template <typename T>
+ range_t<T> range(T b, T e) {
+ return range_t<T>(b, e);
+ }
}
diff --git a/Swiften/Base/LRUCache.h b/Swiften/Base/LRUCache.h
index e4e652f..1f92612 100644
--- a/Swiften/Base/LRUCache.h
+++ b/Swiften/Base/LRUCache.h
@@ -19,9 +19,9 @@ namespace Swift {
/**
- * The \ref LRUCache templaged class implements a lookup cache which removes
+ * The \ref LRUCache template class implements a lookup cache which removes
* the least recently used cached item from the cache, if the cache size hits
- * the \ref MAX_SIZE limit.
+ * the \p MAX_SIZE limit.
*
* An example use is a cache for entity capabilities hash to DiscoInfo.
*/
@@ -32,9 +32,9 @@ public:
public:
/**
- * Inserts the key/value pair in the front of the cache. If the \ref key
+ * Inserts the key/value pair in the front of the cache. If the \p key
* already exists in the cache, it is moved to the front instead. If
- * afterwards, the cahe size exceeds the \ref MAX_SIZE limit, the least
+ * afterwards, the cahe size exceeds the \p MAX_SIZE limit, the least
* recently item is removed from the cache.
*/
void insert(const KEY_TYPE& key, VALUE_TYPE value) {
@@ -48,11 +48,11 @@ public:
}
/**
- * Looks up a cache entry based on the provided \ref key and moves it back
+ * Looks up a cache entry based on the provided \p key and moves it back
* to the front of the cache. If there is no cache entry for the provided
- * \ref key, an uninitialized \ref boost::optional is returned.
- * If the optional \ref missFunction is provided, it is called on a cache miss.
- * If the \ref missFunction returns an initialized \ref boost::optional, the
+ * \p key, an uninitialized \p boost::optional is returned.
+ * If the optional \p missFunction is provided, it is called on a cache miss.
+ * If the \p missFunction returns an initialized \p boost::optional, the
* value is inserted in the cache.
*/
boost::optional<VALUE_TYPE> get(const KEY_TYPE& key, cacheMissFunction missFunction = cacheMissFunction()) {
diff --git a/Swiften/Base/Override.h b/Swiften/Base/Override.h
deleted file mode 100644
index 2806aae..0000000
--- a/Swiften/Base/Override.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2012 Isode Limited.
- * All rights reserved.
- * See the COPYING file for more information.
- */
-
-#pragma once
-
-#if defined(__clang__)
-# if __has_feature(cxx_override_control) || __has_extension(cxx_override_control)
-# define SWIFTEN_OVERRIDE override
-# else
-# define SWIFTEN_OVERRIDE
-# endif
-
-#elif defined(__GNUC__)
-# if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) && defined(__GXX_EXPERIMENTAL_CXX0X__)
-# define SWIFTEN_OVERRIDE override
-# else
-# define SWIFTEN_OVERRIDE
-# endif
-
-#elif defined(_MSC_VER)
-// Actually, 1700 is the first version that supports the C++11 override, but
-// older versions apparently support a similar keyword.
-# if _MSC_VER >= 1400
-# define SWIFTEN_OVERRIDE override
-# else
-# define SWIFTEN_OVERRIDE
-# endif
-
-#else
-# define SWIFTEN_OVERRIDE
-#endif
diff --git a/Swiften/Base/SimpleIDGenerator.h b/Swiften/Base/SimpleIDGenerator.h
index ff645b1..09e01de 100644
--- a/Swiften/Base/SimpleIDGenerator.h
+++ b/Swiften/Base/SimpleIDGenerator.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -10,7 +10,6 @@
#include <Swiften/Base/API.h>
#include <Swiften/Base/IDGenerator.h>
-#include <Swiften/Base/Override.h>
namespace Swift {
@@ -22,9 +21,9 @@ namespace Swift {
class SWIFTEN_API SimpleIDGenerator : public IDGenerator {
public:
SimpleIDGenerator();
- ~SimpleIDGenerator();
+ ~SimpleIDGenerator() override;
- std::string generateID() SWIFTEN_OVERRIDE;
+ std::string generateID() override;
private:
std::string currentID;
diff --git a/Swiften/Base/StdRandomGenerator.h b/Swiften/Base/StdRandomGenerator.h
index 4cc5e95..159d361 100644
--- a/Swiften/Base/StdRandomGenerator.h
+++ b/Swiften/Base/StdRandomGenerator.h
@@ -9,7 +9,6 @@
#include <random>
#include <Swiften/Base/API.h>
-#include <Swiften/Base/Override.h>
#include <Swiften/Base/RandomGenerator.h>
namespace Swift {
@@ -17,7 +16,7 @@ namespace Swift {
public:
StdRandomGenerator();
- int generateRandomInteger(int max) SWIFTEN_OVERRIDE;
+ int generateRandomInteger(int max) override;
private:
std::mt19937 generator;
diff --git a/Swiften/Base/URL.cpp b/Swiften/Base/URL.cpp
index 4a47a11..5c0f0d7 100644
--- a/Swiften/Base/URL.cpp
+++ b/Swiften/Base/URL.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -11,7 +11,7 @@
namespace Swift {
-int URL::getPortOrDefaultPort(const URL& url) {
+unsigned short URL::getPortOrDefaultPort(const URL& url) {
if (url.getPort()) {
return *url.getPort();
}
@@ -62,7 +62,7 @@ URL URL::fromString(const std::string& urlString) {
}
std::string host;
- boost::optional<int> port;
+ boost::optional<unsigned short> port;
if (hostAndPort[0] == '[') {
// handle IPv6 address literals
size_t addressEndIndex = hostAndPort.find(']');
@@ -71,9 +71,9 @@ URL URL::fromString(const std::string& urlString) {
colonIndex = hostAndPort.find(':', addressEndIndex);
if (colonIndex != std::string::npos) {
try {
- port = boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1));
+ port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)));
}
- catch (const boost::bad_lexical_cast&) {
+ catch (...) {
return URL();
}
}
@@ -87,7 +87,7 @@ URL URL::fromString(const std::string& urlString) {
if (colonIndex != std::string::npos) {
host = unescape(hostAndPort.substr(0, colonIndex));
try {
- port = boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1));
+ port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)));
}
catch (const boost::bad_lexical_cast&) {
return URL();
@@ -132,7 +132,7 @@ std::string URL::toString() const {
}
if (port) {
result += ":";
- result += boost::lexical_cast<std::string>(*port);
+ result += std::to_string(*port);
}
result += path;
return result;
diff --git a/Swiften/Base/URL.h b/Swiften/Base/URL.h
index 1a03efe..8fdb018 100644
--- a/Swiften/Base/URL.h
+++ b/Swiften/Base/URL.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -21,7 +21,7 @@ class SWIFTEN_API URL {
URL() : scheme(""), user(""), password(""), host(""), path(""), empty(true) {
}
- URL(const std::string& scheme, const std::string& host, int port, const std::string& path) : scheme(scheme), user(), password(), host(host), port(port), path(path), empty(false) {
+ URL(const std::string& scheme, const std::string& host, unsigned short port, const std::string& path) : scheme(scheme), user(), password(), host(host), port(port), path(path), empty(false) {
}
URL(const std::string& scheme, const std::string& host, const std::string& path) : scheme(scheme), user(), password(), host(host), path(path), empty(false) {
@@ -51,7 +51,7 @@ class SWIFTEN_API URL {
/**
* Port number
*/
- boost::optional<int> getPort() const {
+ boost::optional<unsigned short> getPort() const {
return port;
}
@@ -64,7 +64,7 @@ class SWIFTEN_API URL {
std::string toString() const;
- static int getPortOrDefaultPort(const URL& url);
+ static unsigned short getPortOrDefaultPort(const URL& url);
static URL fromString(const std::string&);
static std::string unescape(const std::string&);
@@ -74,7 +74,7 @@ class SWIFTEN_API URL {
std::string user;
std::string password;
std::string host;
- boost::optional<int> port;
+ boost::optional<unsigned short> port;
std::string path;
bool empty;
};
diff --git a/Swiften/Base/UnitTest/URLTest.cpp b/Swiften/Base/UnitTest/URLTest.cpp
index c38398a..da9f15c 100644
--- a/Swiften/Base/UnitTest/URLTest.cpp
+++ b/Swiften/Base/UnitTest/URLTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2016 Isode Limited.
+ * Copyright (c) 2012-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -66,7 +66,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1234), *url.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
}
@@ -75,7 +75,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(11440, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(11440), *url.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("/http-bind/"), url.getPath());
}
@@ -84,7 +84,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1234), *url.getPort());
CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
}
@@ -121,7 +121,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(12345, url.getPort().get_value_or(0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(12345), url.getPort().get_value_or(0));
CPPUNIT_ASSERT_EQUAL(std::string("/foobar"), url.getPath());
}
@@ -137,7 +137,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("fdf8:f53b:82e4::53"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(12435, url.getPort().get_value_or(0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(12435), url.getPort().get_value_or(0));
}
void test_FromString_ToString_IPv6RFC2732() {
@@ -147,7 +147,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(80, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(80), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -159,7 +159,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("1080:0:0:0:8:800:200C:417A"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -171,7 +171,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("3ffe:2a00:100:7031::1"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -183,7 +183,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("1080::8:800:200C:417A"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string("/foo"), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -195,7 +195,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("::192.9.5.5"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string("/ipng"), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -207,7 +207,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("::FFFF:129.144.52.38"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(80, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(80), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -219,7 +219,7 @@ class URLTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("2010:836B:4179::836B:4179"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
CPPUNIT_ASSERT_EQUAL(std::string(), url.getPath());
CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());