Tidied structure of all classes within the entire code base
Also some other small bits of tidying
This commit is contained in:
@@ -19,10 +19,6 @@ namespace Bloom
|
||||
template<typename TypeA, typename TypeB>
|
||||
class BiMap
|
||||
{
|
||||
private:
|
||||
std::unordered_map<TypeA, TypeB> map = {};
|
||||
std::unordered_map<TypeB, typename std::unordered_map<TypeA, TypeB>::iterator> flippedMap = {};
|
||||
|
||||
public:
|
||||
BiMap(std::initializer_list<std::pair<TypeA, TypeB>> elements) {
|
||||
for (auto it = elements.begin(); it != elements.end(); ++it) {
|
||||
@@ -75,5 +71,9 @@ namespace Bloom
|
||||
insertResultPair.first
|
||||
));
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<TypeA, TypeB> map = {};
|
||||
std::unordered_map<TypeB, typename std::unordered_map<TypeA, TypeB>::iterator> flippedMap = {};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ namespace Bloom
|
||||
*/
|
||||
class DateTime
|
||||
{
|
||||
private:
|
||||
static inline std::mutex currentDateTimeMutex;
|
||||
|
||||
public:
|
||||
/**
|
||||
* The QDateTime::currentDateTime() static function is not thread-safe. This may be caused by the
|
||||
@@ -38,5 +35,8 @@ namespace Bloom
|
||||
auto lock = std::unique_lock(DateTime::currentDateTimeMutex);
|
||||
return dateTime.timeZoneAbbreviation();
|
||||
}
|
||||
|
||||
private:
|
||||
static inline std::mutex currentDateTimeMutex;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,26 +25,6 @@ namespace Bloom
|
||||
*/
|
||||
class EventNotifier
|
||||
{
|
||||
private:
|
||||
int fileDescriptor = -1;
|
||||
std::atomic<bool> initialised = false;
|
||||
|
||||
void init() {
|
||||
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
||||
|
||||
if (this->fileDescriptor < -1) {
|
||||
throw Exceptions::Exception("Failed to create new eventfd object - error number: "
|
||||
+ std::to_string(errno));
|
||||
}
|
||||
|
||||
this->initialised = true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
::close(this->fileDescriptor);
|
||||
this->initialised = false;
|
||||
}
|
||||
|
||||
public:
|
||||
EventNotifier() {
|
||||
this->init();
|
||||
@@ -78,5 +58,25 @@ namespace Bloom
|
||||
"error number: " + std::to_string(errno));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int fileDescriptor = -1;
|
||||
std::atomic<bool> initialised = false;
|
||||
|
||||
void init() {
|
||||
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
||||
|
||||
if (this->fileDescriptor < -1) {
|
||||
throw Exceptions::Exception("Failed to create new eventfd object - error number: "
|
||||
+ std::to_string(errno));
|
||||
}
|
||||
|
||||
this->initialised = true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
::close(this->fileDescriptor);
|
||||
this->initialised = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,10 +17,6 @@ namespace Bloom
|
||||
template<typename Type>
|
||||
class SyncSafe
|
||||
{
|
||||
private:
|
||||
std::mutex mutex;
|
||||
Type value;
|
||||
|
||||
public:
|
||||
SyncSafe() = default;
|
||||
|
||||
@@ -51,5 +47,9 @@ namespace Bloom
|
||||
std::unique_lock<std::mutex> acquireLock() {
|
||||
return std::unique_lock(this->mutex);
|
||||
};
|
||||
|
||||
private:
|
||||
std::mutex mutex;
|
||||
Type value;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ namespace Bloom
|
||||
|
||||
class Thread
|
||||
{
|
||||
private:
|
||||
SyncSafe<ThreadState> state = SyncSafe<ThreadState>(ThreadState::UNINITIALISED);
|
||||
public:
|
||||
virtual ThreadState getThreadState() {
|
||||
return this->state.getValue();
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void setThreadState(ThreadState state) {
|
||||
@@ -42,9 +44,7 @@ namespace Bloom
|
||||
pthread_setname_np(pthread_self(), name.c_str());
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ThreadState getThreadState() {
|
||||
return this->state.getValue();
|
||||
};
|
||||
private:
|
||||
SyncSafe<ThreadState> state = SyncSafe<ThreadState>(ThreadState::UNINITIALISED);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user