#ifndef RIGSTATEH #define RIGSTATEH #include #include #include #include #include #include #include "rigcommander.h" #include "rigidentities.h" #include "wfviewtypes.h" //* std::static_pointer_cast(data) struct value { bool _valid = false; bool _updated = false; QDateTime _dateUpdated; std::shared_ptr _value = Q_NULLPTR; }; class rigstate { public: void invalidate(stateTypes s) { map[s]._valid = false; } bool isValid(stateTypes s) { return map[s]._valid; } bool isUpdated(stateTypes s) { return map[s]._updated; } QDateTime whenUpdated(stateTypes s) { return map[s]._dateUpdated; } void set(stateTypes s, quint64 x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new quint64(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, qint32 x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new qint32(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, qint16 x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new qint16(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, quint16 x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new quint16(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, quint8 x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new quint8(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, bool x, bool u) { auto d = std::static_pointer_cast(map[s]._value); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new bool(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, duplexMode x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new duplexMode(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, rigInput x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new rigInput(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } void set(stateTypes s, QString x, bool u) { auto d = (std::static_pointer_cast(map[s]._value)); if (d == Q_NULLPTR || *d != x) { _mutex.lock(); map[s]._value = std::shared_ptr(new QString(x)); map[s]._valid = true; map[s]._updated = u; map[s]._dateUpdated = QDateTime::currentDateTime(); _mutex.unlock(); } } bool getBool(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return false; } quint8 getChar(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return 0; } qint16 getInt16(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return 0;} quint16 getUInt16(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return 0;} qint32 getInt32(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return 0;} quint32 getUInt32(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return 0;} quint64 getInt64(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return 0;} duplexMode getDuplex(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return dmSplitOff;} rigInput getInput(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return inputACC; } QString getString(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast(map[s]._value); else return QString(""); } QMap map; private: //std::map > values; QMutex _mutex; }; #endif