Merge branch 'develop' of github.com:smessmer/cpp-utils into develop
This commit is contained in:
commit
b5cb732da0
@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../macros.h"
|
||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
|
|
||||||
class AssertFailed : public std::exception {
|
class AssertFailed final: public std::exception {
|
||||||
public:
|
public:
|
||||||
AssertFailed(const std::string &message) : _message(message) { }
|
AssertFailed(const std::string &message) : _message(message) { }
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
//TODO Test
|
//TODO Test
|
||||||
class RandomPadding {
|
class RandomPadding final {
|
||||||
public:
|
public:
|
||||||
static Data add(const Data &data, size_t targetSize);
|
static Data add(const Data &data, size_t targetSize);
|
||||||
static boost::optional<Data> remove(const Data &data);
|
static boost::optional<Data> remove(const Data &data);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
|
|
||||||
template<size_t KEY_LENGTH>
|
template<size_t KEY_LENGTH>
|
||||||
class DerivedKey {
|
class DerivedKey final {
|
||||||
public:
|
public:
|
||||||
DerivedKey(DerivedKeyConfig config, const FixedSizeData<KEY_LENGTH> &key): _config(std::move(config)), _key(key) {}
|
DerivedKey(DerivedKeyConfig config, const FixedSizeData<KEY_LENGTH> &key): _config(std::move(config)), _key(key) {}
|
||||||
DerivedKey(DerivedKey &&rhs) = default;
|
DerivedKey(DerivedKey &&rhs) = default;
|
||||||
|
@ -13,7 +13,7 @@ namespace cpputils {
|
|||||||
//TODO Test operator==/!=
|
//TODO Test operator==/!=
|
||||||
//TODO Use SCryptSettings as a member here instead of storing _N, _r, _p.
|
//TODO Use SCryptSettings as a member here instead of storing _N, _r, _p.
|
||||||
|
|
||||||
class DerivedKeyConfig {
|
class DerivedKeyConfig final {
|
||||||
public:
|
public:
|
||||||
DerivedKeyConfig(Data salt, uint64_t N, uint32_t r, uint32_t p)
|
DerivedKeyConfig(Data salt, uint64_t N, uint32_t r, uint32_t p)
|
||||||
: _salt(std::move(salt)),
|
: _salt(std::move(salt)),
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
|
|
||||||
class DataFixture {
|
class DataFixture final {
|
||||||
public:
|
public:
|
||||||
static Data generate(size_t size, long long int seed = 1);
|
static Data generate(size_t size, long long int seed = 1);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#include "../macros.h"
|
||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ public:
|
|||||||
virtual void print(const std::string &output) = 0;
|
virtual void print(const std::string &output) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IOStreamConsole: public Console {
|
class IOStreamConsole final: public Console {
|
||||||
public:
|
public:
|
||||||
IOStreamConsole();
|
IOStreamConsole();
|
||||||
IOStreamConsole(std::ostream &output, std::istream &input);
|
IOStreamConsole(std::ostream &output, std::istream &input);
|
||||||
@ -30,6 +31,8 @@ private:
|
|||||||
|
|
||||||
std::ostream &_output;
|
std::ostream &_output;
|
||||||
std::istream &_input;
|
std::istream &_input;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(IOStreamConsole);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
|
|
||||||
class pipestream : public std::streambuf {
|
class pipestream final : public std::streambuf {
|
||||||
private:
|
private:
|
||||||
typedef std::streambuf::traits_type traits_type;
|
typedef std::streambuf::traits_type traits_type;
|
||||||
typedef std::string::size_type string_size_t;
|
typedef std::string::size_type string_size_t;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include "../macros.h"
|
||||||
|
|
||||||
//TODO Test
|
//TODO Test
|
||||||
//TODO Merge lock folder with thread folder
|
//TODO Merge lock folder with thread folder
|
||||||
@ -12,7 +13,7 @@ namespace cpputils {
|
|||||||
// Like a condition variable, but without spurious wakeups.
|
// Like a condition variable, but without spurious wakeups.
|
||||||
// The waiting threads are only woken, when notify() is called.
|
// The waiting threads are only woken, when notify() is called.
|
||||||
// After a call to release(), future calls to wait() will not block anymore.
|
// After a call to release(), future calls to wait() will not block anymore.
|
||||||
class ConditionBarrier {
|
class ConditionBarrier final {
|
||||||
public:
|
public:
|
||||||
ConditionBarrier() :_mutex(), _cv(), _triggered(false) {
|
ConditionBarrier() :_mutex(), _cv(), _triggered(false) {
|
||||||
}
|
}
|
||||||
@ -33,6 +34,8 @@ namespace cpputils {
|
|||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
std::condition_variable _cv;
|
std::condition_variable _cv;
|
||||||
bool _triggered;
|
bool _triggered;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(ConditionBarrier);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
template<class LockName>
|
template<class LockName>
|
||||||
class MutexPoolLock {
|
class MutexPoolLock final {
|
||||||
public:
|
public:
|
||||||
MutexPoolLock(LockPool<LockName> *pool, const LockName &lockName): _pool(pool), _lockName(lockName) {
|
MutexPoolLock(LockPool<LockName> *pool, const LockName &lockName): _pool(pool), _lockName(lockName) {
|
||||||
_pool->lock(_lockName);
|
_pool->lock(_lockName);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
namespace logging {
|
namespace logging {
|
||||||
class Logger {
|
class Logger final {
|
||||||
public:
|
public:
|
||||||
void setLogger(std::shared_ptr<spdlog::logger> logger) {
|
void setLogger(std::shared_ptr<spdlog::logger> logger) {
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
@ -3,15 +3,18 @@
|
|||||||
#define MESSMER_CPPUTILS_PROCESS_SUBPROCESS_H
|
#define MESSMER_CPPUTILS_PROCESS_SUBPROCESS_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../macros.h"
|
||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
//TODO Test
|
//TODO Test
|
||||||
class Subprocess {
|
class Subprocess final {
|
||||||
public:
|
public:
|
||||||
static std::string call(const std::string &command);
|
static std::string call(const std::string &command);
|
||||||
static int callAndGetReturnCode(const std::string &command);
|
static int callAndGetReturnCode(const std::string &command);
|
||||||
private:
|
private:
|
||||||
static FILE* _call(const std::string &command);
|
static FILE* _call(const std::string &command);
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(Subprocess);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ namespace cpputils {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _get(void *target, size_t bytes) override;
|
void _get(void *target, size_t bytes) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(OSRandomGenerator);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline OSRandomGenerator::OSRandomGenerator() {}
|
inline OSRandomGenerator::OSRandomGenerator() {}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
class Random {
|
class Random final {
|
||||||
public:
|
public:
|
||||||
static PseudoRandomPool &PseudoRandom() {
|
static PseudoRandomPool &PseudoRandom() {
|
||||||
std::unique_lock <std::mutex> lock(_mutex);
|
std::unique_lock <std::mutex> lock(_mutex);
|
||||||
@ -25,6 +25,8 @@ namespace cpputils {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static std::mutex _mutex;
|
static std::mutex _mutex;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(Random);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
//TODO Test
|
//TODO Test
|
||||||
class RandomDataBuffer {
|
class RandomDataBuffer final {
|
||||||
public:
|
public:
|
||||||
RandomDataBuffer();
|
RandomDataBuffer();
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
class RandomGenerator {
|
class RandomGenerator {
|
||||||
public:
|
public:
|
||||||
|
RandomGenerator();
|
||||||
|
|
||||||
template<size_t SIZE> FixedSizeData<SIZE> getFixedSize();
|
template<size_t SIZE> FixedSizeData<SIZE> getFixedSize();
|
||||||
Data get(size_t size);
|
Data get(size_t size);
|
||||||
|
|
||||||
@ -14,8 +16,13 @@ namespace cpputils {
|
|||||||
virtual void _get(void *target, size_t bytes) = 0;
|
virtual void _get(void *target, size_t bytes) = 0;
|
||||||
private:
|
private:
|
||||||
static std::mutex _mutex;
|
static std::mutex _mutex;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(RandomGenerator);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline RandomGenerator::RandomGenerator() {
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t SIZE> inline FixedSizeData<SIZE> RandomGenerator::getFixedSize() {
|
template<size_t SIZE> inline FixedSizeData<SIZE> RandomGenerator::getFixedSize() {
|
||||||
FixedSizeData<SIZE> result = FixedSizeData<SIZE>::Null();
|
FixedSizeData<SIZE> result = FixedSizeData<SIZE>::Null();
|
||||||
_get(result.data(), SIZE);
|
_get(result.data(), SIZE);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
//TODO Test
|
//TODO Test
|
||||||
class RandomGeneratorThread {
|
class RandomGeneratorThread final {
|
||||||
public:
|
public:
|
||||||
RandomGeneratorThread(ThreadsafeRandomDataBuffer *buffer, size_t minSize, size_t maxSize);
|
RandomGeneratorThread(ThreadsafeRandomDataBuffer *buffer, size_t minSize, size_t maxSize);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
//TODO Test
|
//TODO Test
|
||||||
class ThreadsafeRandomDataBuffer {
|
class ThreadsafeRandomDataBuffer final {
|
||||||
public:
|
public:
|
||||||
ThreadsafeRandomDataBuffer();
|
ThreadsafeRandomDataBuffer();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user