Unified · Split
| @@ -127,31 +127,31 @@ namespace GSF · 126 unmodified lines | ||
| 127 | 127 | return boost::make_shared<T>(); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | − template<class T, typename P1> | |
| 130 | + template<class T, class P1> | |
| 131 | 131 | SharedPtr<T> NewSharedPtr(P1 p1) |
| 132 | 132 | { |
| 133 | 133 | return boost::make_shared<T>(p1); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | − template<class T, typename P1, typename P2> | |
| 136 | + template<class T, class P1, class P2> | |
| 137 | 137 | SharedPtr<T> NewSharedPtr(P1 p1, P2 p2) |
| 138 | 138 | { |
| 139 | 139 | return boost::make_shared<T>(p1, p2); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | − template<class T, typename P1, typename P2, typename P3> | |
| 142 | + template<class T, class P1, class P2, class P3> | |
| 143 | 143 | SharedPtr<T> NewSharedPtr(P1 p1, P2 p2, P3 p3) |
| 144 | 144 | { |
| 145 | 145 | return boost::make_shared<T>(p1, p2, p3); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | − template<class T, typename P1, typename P2, typename P3, typename P4> | |
| 148 | + template<class T, class P1, class P2, class P3, class P4> | |
| 149 | 149 | SharedPtr<T> NewSharedPtr(P1 p1, P2 p2, P3 p3, P4 p4) |
| 150 | 150 | { |
| 151 | 151 | return boost::make_shared<T>(p1, p2, p3, p4); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | − template<class T, typename P1, typename P2, typename P3, typename P4, typename P5> | |
| 154 | + template<class T, class P1, class P2, class P3, class P4, class P5> | |
| 155 | 155 | SharedPtr<T> NewSharedPtr(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) |
| 156 | 156 | { |
| 157 | 157 | return boost::make_shared<T>(p1, p2, p3, p4, p5); |
| @@ -221,7 +221,7 @@ namespace GSF · 63 unmodified lines | ||
| 221 | 221 | template<class T> |
| 222 | 222 | using SortedStringMap = std::map<std::string, T, GSF::StringComparer>; |
| 223 | 223 | |
| 224 | − template<typename TKey, typename TValue> | |
| 224 | + template<class TKey, class TValue> | |
| 225 | 225 | bool TryGetValue(const std::map<TKey, TValue>& dictionary, const TKey& key, TValue& value, const TValue& defaultValue) |
| 226 | 226 | { |
| 227 | 227 | auto iterator = dictionary.find(key); |
| @@ -236,7 +236,7 @@ namespace GSF · 8 unmodified lines | ||
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | − template<typename TKey, typename TValue> | |
| 239 | + template<class TKey, class TValue> | |
| 240 | 240 | bool TryGetValue(const std::unordered_map<TKey, TValue>& dictionary, const TKey& key, TValue& value, const TValue& defaultValue) |
| 241 | 241 | { |
| 242 | 242 | auto iterator = dictionary.find(key); |
| @@ -251,7 +251,7 @@ namespace GSF · 8 unmodified lines | ||
| 251 | 251 | return false; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | − template<typename TValue> | |
| 254 | + template<class TValue> | |
| 255 | 255 | bool TryGetValue(const StringMap<TValue>& dictionary, const std::string& key, TValue& value, const TValue& defaultValue) |
| 256 | 256 | { |
| 257 | 257 | auto iterator = dictionary.find(key); |
| @@ -308,6 +308,28 @@ namespace GSF · 50 unmodified lines | ||
| 308 | 308 | sink.push_back(static_cast<uint8_t>(*it)); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | + template<class T> | |
| 312 | + static uint32_t WriteBytes(std::vector<uint8_t>& buffer, const T& value) | |
| 313 | + { | |
| 314 | + static const int32_t length = sizeof(T); | |
| 315 | + const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&value); | |
| 316 | + | |
| 317 | + for (int32_t i = 0; i < length; i++) | |
| 318 | + buffer.push_back(bytes[i]); | |
| 319 | + | |
| 320 | + return length; | |
| 321 | + } | |
| 322 | + | |
| 323 | + static uint32_t WriteBytes(std::vector<uint8_t>& buffer, const Guid& value) | |
| 324 | + { | |
| 325 | + const uint8_t* bytes = value.data; | |
| 326 | + | |
| 327 | + for (uint32_t i = 0; i < 16; i++) | |
| 328 | + buffer.push_back(bytes[i]); | |
| 329 | + | |
| 330 | + return 16; | |
| 331 | + } | |
| 332 | + | |
| 311 | 333 | Guid NewGuid(); |
| 312 | 334 | |
| 313 | 335 | // Handy string functions (boost wrappers) |
| @@ -43,7 +43,7 @@ namespace GSF · 42 unmodified lines | ||
| 43 | 43 | DateTime LocalFromUtc(const DateTime& timestamp); |
| 44 | 44 | |
| 45 | 45 | // Converts an object to a string |
| 46 | − template <class T> | |
| 46 | + template<class T> | |
| 47 | 47 | std::string ToString(const T& obj) |
| 48 | 48 | { |
| 49 | 49 | std::stringstream stream; |
| @@ -61,11 +61,11 @@ namespace GSF · 11 unmodified lines | ||
| 61 | 61 | std::string ToUTF8(const std::wstring& value); |
| 62 | 62 | |
| 63 | 63 | // Converts an integer value to a hex representation |
| 64 | − template <class T> | |
| 64 | + template<class T> | |
| 65 | 65 | std::string ToHex(const T& value) |
| 66 | 66 | { |
| 67 | 67 | std::stringstream stream; |
| 68 | − stream << "0x" << std::hex << static_cast<int>(value); | |
| 68 | + stream << "0x" << std::hex << static_cast<int32_t>(value); | |
| 69 | 69 | return stream.str(); |
| 70 | 70 | } |
| 71 | 71 | |
| @@ -47,7 +47,7 @@ namespace GSF · 46 unmodified lines | ||
| 47 | 47 | |
| 48 | 48 | // Converts between big endian and |
| 49 | 49 | // the system's native byte order. |
| 50 | − template <class T> | |
| 50 | + template<class T> | |
| 51 | 51 | T ConvertBigEndian(T value) const |
| 52 | 52 | { |
| 53 | 53 | if (m_nativeOrder != EndianConverter::BigEndian) |
| @@ -58,7 +58,7 @@ namespace GSF · 4 unmodified lines | ||
| 58 | 58 | |
| 59 | 59 | // Converts between little endian and |
| 60 | 60 | // the system's native byte order. |
| 61 | − template <class T> | |
| 61 | + template<class T> | |
| 62 | 62 | T ConvertLittleEndian(T value) const |
| 63 | 63 | { |
| 64 | 64 | if (m_nativeOrder != EndianConverter::LittleEndian) |
| @@ -82,39 +82,39 @@ namespace GSF · 17 unmodified lines | ||
| 82 | 82 | static bool IsLittleEndian(); |
| 83 | 83 | static bool IsBigEndian(); |
| 84 | 84 | |
| 85 | − template <class T> | |
| 85 | + template<class T> | |
| 86 | 86 | static T ToBigEndian(const uint8_t* buffer, const uint32_t startIndex) |
| 87 | 87 | { |
| 88 | 88 | return Default.ConvertBigEndian(*reinterpret_cast<T*>(const_cast<uint8_t*>(buffer + startIndex))); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | − template <class T> | |
| 91 | + template<class T> | |
| 92 | 92 | static T ToLittleEndian(const uint8_t* buffer, const uint32_t startIndex) |
| 93 | 93 | { |
| 94 | 94 | return Default.ConvertLittleEndian(*reinterpret_cast<T*>(const_cast<uint8_t*>(buffer + startIndex))); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | − template <class T> | |
| 98 | − static int32_t WriteBigEndianBytes(std::vector<uint8_t>& buffer, T value) | |
| 97 | + template<class T> | |
| 98 | + static uint32_t WriteBigEndianBytes(std::vector<uint8_t>& buffer, T value) | |
| 99 | 99 | { |
| 100 | − int32_t length = sizeof(T); | |
| 100 | + static const uint32_t length = sizeof(T); | |
| 101 | 101 | value = Default.ConvertBigEndian(value); |
| 102 | 102 | uint8_t* bytes = reinterpret_cast<uint8_t*>(&value); |
| 103 | 103 | |
| 104 | − for (int32_t i = 0; i < length; i++) | |
| 104 | + for (uint32_t i = 0; i < length; i++) | |
| 105 | 105 | buffer.push_back(bytes[i]); |
| 106 | 106 | |
| 107 | 107 | return length; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | − template <class T> | |
| 111 | − static int32_t WriteLittleEndianBytes(std::vector<uint8_t>& buffer, T value) | |
| 110 | + template<class T> | |
| 111 | + static uint32_t WriteLittleEndianBytes(std::vector<uint8_t>& buffer, T value) | |
| 112 | 112 | { |
| 113 | − int32_t length = sizeof(T); | |
| 113 | + static const uint32_t length = sizeof(T); | |
| 114 | 114 | value = Default.ConvertLittleEndian(value); |
| 115 | 115 | uint8_t* bytes = reinterpret_cast<uint8_t*>(&value); |
| 116 | 116 | |
| 117 | − for (int32_t i = 0; i < length; i++) | |
| 117 | + for (uint32_t i = 0; i < length; i++) | |
| 118 | 118 | buffer.push_back(bytes[i]); |
| 119 | 119 | |
| 120 | 120 | return length; |
| @@ -25,178 +25,143 @@ · 24 unmodified lines | ||
| 25 | 25 | #ifndef __NULLABLE_H |
| 26 | 26 | #define __NULLABLE_H |
| 27 | 27 | |
| 28 | −#include <cstddef> | |
| 29 | 28 | #include "Convert.h" |
| 30 | 29 | |
| 31 | 30 | namespace GSF |
| 32 | 31 | { |
| 33 | − class NullableType // NOLINT | |
| 34 | − { | |
| 35 | − public: | |
| 36 | − virtual ~NullableType() = default; | |
| 37 | − | |
| 38 | − virtual bool HasValue() const | |
| 39 | − { | |
| 40 | − return false; | |
| 41 | − }; | |
| 42 | − }; | |
| 43 | − | |
| 44 | − template <typename T> | |
| 45 | − class Nullable final : public NullableType // NOLINT | |
| 32 | + template<class T> | |
| 33 | + class Nullable final // NOLINT | |
| 46 | 34 | { |
| 47 | 35 | public: |
| 48 | 36 | Nullable(); |
| 49 | − Nullable(const T &value); | |
| 37 | + Nullable(const T& value); | |
| 50 | 38 | Nullable(nullptr_t nullpointer); |
| 51 | − const Nullable<T> & operator=(const Nullable<T> &value); | |
| 52 | − const Nullable<T> & operator=(const T &value); | |
| 53 | − const Nullable<T> & operator=(nullptr_t nullpointer); | |
| 54 | − bool HasValue() const override; | |
| 55 | − const T & GetValueOrDefault() const; | |
| 56 | − const T & GetValueOrDefault(const T &def) const; | |
| 57 | − bool TryGetValue(T &value) const; | |
| 58 | − | |
| 59 | − public: | |
| 60 | − class NullableValue final | |
| 39 | + const Nullable<T>& operator=(const Nullable<T>& value); // NOLINT | |
| 40 | + const Nullable<T>& operator=(const T& value); // NOLINT | |
| 41 | + const Nullable<T>& operator=(nullptr_t nullpointer); // NOLINT | |
| 42 | + bool HasValue() const; | |
| 43 | + const T& GetValueOrDefault() const; | |
| 44 | + const T& GetValueOrDefault(const T& def) const; | |
| 45 | + bool TryGetValue(T& value) const; | |
| 46 | + | |
| 47 | + class NullableValue final // NOLINT | |
| 61 | 48 | { |
| 62 | − public: | |
| 63 | − friend class Nullable; | |
| 64 | − | |
| 65 | 49 | private: |
| 66 | 50 | NullableValue(); |
| 67 | − NullableValue(const T &value); | |
| 51 | + NullableValue(const T& value); | |
| 68 | 52 | |
| 69 | − public: | |
| 70 | − NullableValue & operator=(const NullableValue &) = delete; | |
| 71 | − operator const T &() const; | |
| 72 | − const T & operator*() const; | |
| 73 | − const T * operator&() const; | |
| 53 | + void checkHasValue() const; | |
| 74 | 54 | |
| 75 | − // https://stackoverflow.com/questions/42183631/inability-to-overload-dot-operator-in-c | |
| 76 | − const T * operator->() const; | |
| 55 | + bool m_hasValue; | |
| 56 | + T m_value; | |
| 77 | 57 | |
| 78 | 58 | public: |
| 79 | − template <typename T2> | |
| 80 | − friend bool operator==(const Nullable<T2> &op1, const Nullable<T2> &op2); | |
| 81 | − | |
| 82 | − template <typename T2> | |
| 83 | − friend bool operator==(const Nullable<T2> &op, const T2 &value); | |
| 84 | − | |
| 85 | − template <typename T2> | |
| 86 | − friend bool operator==(const T2 &value, const Nullable<T2> &op); | |
| 87 | − | |
| 88 | − template <typename T2> | |
| 89 | − friend bool operator==(const Nullable<T2> &op, nullptr_t nullpointer); | |
| 90 | − | |
| 91 | − template <typename T2> | |
| 92 | − friend bool operator!=(const Nullable<T2> &op1, const Nullable<T2> &op2); | |
| 93 | − | |
| 94 | − template <typename T2> | |
| 95 | − friend bool operator!=(const Nullable<T2> &op, const T2 &value); | |
| 96 | − | |
| 97 | − template <typename T2> | |
| 98 | − friend bool operator!=(const T2 &value, const Nullable<T2> &op); | |
| 59 | + NullableValue& operator=(const NullableValue&) = delete; | |
| 60 | + operator const T&() const; | |
| 61 | + const T& operator*() const; | |
| 62 | + const T* operator&() const; // NOLINT | |
| 99 | 63 | |
| 100 | − template <typename T2> | |
| 101 | − friend bool operator==(nullptr_t nullpointer, const Nullable<T2> &op); | |
| 102 | − | |
| 103 | − template <typename T2> | |
| 104 | − friend bool operator!=(const Nullable<T2> &op, nullptr_t nullpointer); | |
| 105 | − | |
| 106 | − template <typename T2> | |
| 107 | − friend bool operator!=(nullptr_t nullpointer, const Nullable<T2> &op); | |
| 108 | − | |
| 109 | − private: | |
| 110 | − void checkHasValue() const; | |
| 64 | + // https://stackoverflow.com/questions/42183631/inability-to-overload-dot-operator-in-c | |
| 65 | + const T* operator->() const; | |
| 111 | 66 | |
| 112 | − private: | |
| 113 | − bool m_hasValue; | |
| 114 | − T m_value; | |
| 67 | + friend class Nullable; | |
| 115 | 68 | }; |
| 116 | 69 | |
| 117 | − public: | |
| 118 | 70 | NullableValue Value; |
| 119 | 71 | }; |
| 120 | 72 | |
| 121 | − template <typename T> | |
| 122 | − Nullable<T>::NullableValue::NullableValue() | |
| 123 | − : m_hasValue(false), m_value(T()) { } | |
| 73 | + template<class T> | |
| 74 | + Nullable<T>::NullableValue::NullableValue() : // NOLINT | |
| 75 | + m_hasValue(false), | |
| 76 | + m_value(T()) | |
| 77 | + { | |
| 78 | + } | |
| 124 | 79 | |
| 125 | − template <typename T> | |
| 126 | − Nullable<T>::NullableValue::NullableValue(const T &value) | |
| 127 | − : m_hasValue(true), m_value(value) { } | |
| 80 | + template<class T> | |
| 81 | + Nullable<T>::NullableValue::NullableValue(const T& value): | |
| 82 | + m_hasValue(true), | |
| 83 | + m_value(value) | |
| 84 | + { | |
| 85 | + } | |
| 128 | 86 | |
| 129 | − template <typename T> | |
| 130 | − Nullable<T>::NullableValue::operator const T &() const | |
| 87 | + template<class T> | |
| 88 | + Nullable<T>::NullableValue::operator const T&() const | |
| 131 | 89 | { |
| 132 | 90 | checkHasValue(); |
| 133 | 91 | return m_value; |
| 134 | 92 | } |
| 135 | 93 | |
| 136 | − template <typename T> | |
| 137 | − const T & Nullable<T>::NullableValue::operator*() const | |
| 94 | + template<class T> | |
| 95 | + const T& Nullable<T>::NullableValue::operator*() const | |
| 138 | 96 | { |
| 139 | 97 | checkHasValue(); |
| 140 | 98 | return m_value; |
| 141 | 99 | } |
| 142 | 100 | |
| 143 | − template <typename T> | |
| 144 | − const T * Nullable<T>::NullableValue::operator&() const | |
| 101 | + template<class T> // NOLINT | |
| 102 | + const T* Nullable<T>::NullableValue::operator&() const // NOLINT | |
| 145 | 103 | { |
| 146 | 104 | checkHasValue(); |
| 147 | 105 | return &m_value; |
| 148 | 106 | } |
| 149 | 107 | |
| 150 | − template <typename T> | |
| 151 | − const T * Nullable<T>::NullableValue::operator->() const | |
| 108 | + template<class T> | |
| 109 | + const T* Nullable<T>::NullableValue::operator->() const | |
| 152 | 110 | { |
| 153 | 111 | checkHasValue(); |
| 154 | 112 | return &m_value; |
| 155 | 113 | } |
| 156 | 114 | |
| 157 | − template <typename T> | |
| 115 | + template<class T> | |
| 158 | 116 | void Nullable<T>::NullableValue::checkHasValue() const |
| 159 | 117 | { |
| 160 | 118 | if (!m_hasValue) |
| 161 | 119 | throw std::exception("Nullable object must have a value"); |
| 162 | 120 | } |
| 163 | 121 | |
| 164 | − template <typename T> | |
| 122 | + template<class T> | |
| 165 | 123 | bool Nullable<T>::HasValue() const { return Value.m_hasValue; } |
| 166 | 124 | |
| 167 | − template <typename T> | |
| 168 | − const T & Nullable<T>::GetValueOrDefault() const | |
| 125 | + template<class T> | |
| 126 | + const T& Nullable<T>::GetValueOrDefault() const | |
| 169 | 127 | { |
| 170 | 128 | return Value.m_value; |
| 171 | 129 | } |
| 172 | 130 | |
| 173 | − template <typename T> | |
| 174 | − const T & Nullable<T>::GetValueOrDefault(const T &def) const | |
| 131 | + template<class T> | |
| 132 | + const T& Nullable<T>::GetValueOrDefault(const T& def) const | |
| 175 | 133 | { |
| 176 | 134 | if (Value.m_hasValue) |
| 177 | 135 | return Value.m_value; |
| 178 | − else | |
| 179 | − return def; | |
| 136 | + | |
| 137 | + return def; | |
| 180 | 138 | } |
| 181 | 139 | |
| 182 | − template <typename T> | |
| 183 | − bool Nullable<T>::TryGetValue(T &value) const | |
| 140 | + template<class T> | |
| 141 | + bool Nullable<T>::TryGetValue(T& value) const | |
| 184 | 142 | { |
| 185 | 143 | value = Value.m_value; |
| 186 | 144 | return Value.m_hasValue; |
| 187 | 145 | } |
| 188 | 146 | |
| 189 | − template <typename T> | |
| 190 | − Nullable<T>::Nullable() { } | |
| 147 | + template<class T> | |
| 148 | + Nullable<T>::Nullable() | |
| 149 | + { | |
| 150 | + } | |
| 191 | 151 | |
| 192 | − template <typename T> | |
| 193 | − Nullable<T>::Nullable(nullptr_t nullpointer) { (void)nullpointer; } | |
| 152 | + template<class T> | |
| 153 | + Nullable<T>::Nullable(nullptr_t nullpointer) | |
| 154 | + { | |
| 155 | + (void)nullpointer; | |
| 156 | + } | |
| 194 | 157 | |
| 195 | − template <typename T> | |
| 196 | − Nullable<T>::Nullable(const T &value) | |
| 197 | − : Value(value) { } | |
| 158 | + template<class T> | |
| 159 | + Nullable<T>::Nullable(const T& value) | |
| 160 | + : Value(value) | |
| 161 | + { | |
| 162 | + } | |
| 198 | 163 | |
| 199 | − template <typename T2> | |
| 164 | + template<class T2> | |
| 200 | 165 | bool operator==(const Nullable<T2> &op1, const Nullable<T2> &op2) |
| 201 | 166 | { |
| 202 | 167 | if (op1.Value.m_hasValue != op2.Value.m_hasValue) |
| @@ -204,11 +169,11 @@ namespace GSF · 1 unmodified line | ||
| 204 | 169 | |
| 205 | 170 | if (op1.Value.m_hasValue) |
| 206 | 171 | return op1.Value.m_value == op2.Value.m_value; |
| 207 | − else | |
| 208 | − return true; | |
| 172 | + | |
| 173 | + return true; | |
| 209 | 174 | } |
| 210 | 175 | |
| 211 | − template <typename T2> | |
| 176 | + template<class T2> | |
| 212 | 177 | bool operator==(const Nullable<T2> &op, const T2 &value) |
| 213 | 178 | { |
| 214 | 179 | if (!op.Value.m_hasValue) |
| @@ -217,7 +182,7 @@ namespace GSF · 2 unmodified lines | ||
| 217 | 182 | return op.Value.m_value == value; |
| 218 | 183 | } |
| 219 | 184 | |
| 220 | − template <typename T2> | |
| 185 | + template<class T2> | |
| 221 | 186 | bool operator==(const T2 &value, const Nullable<T2> &op) |
| 222 | 187 | { |
| 223 | 188 | if (!op.Value.m_hasValue) |
| @@ -226,21 +191,21 @@ namespace GSF · 2 unmodified lines | ||
| 226 | 191 | return op.Value.m_value == value; |
| 227 | 192 | } |
| 228 | 193 | |
| 229 | − template <typename T2> | |
| 194 | + template<class T2> | |
| 230 | 195 | bool operator==(const Nullable<T2> &op, nullptr_t nullpointer) |
| 231 | 196 | { |
| 232 | 197 | (void)nullpointer; |
| 233 | 198 | return !op.Value.m_hasValue; |
| 234 | 199 | } |
| 235 | 200 | |
| 236 | − template <typename T2> | |
| 201 | + template<class T2> | |
| 237 | 202 | bool operator==(nullptr_t nullpointer, const Nullable<T2> &op) |
| 238 | 203 | { |
| 239 | 204 | (void)nullpointer; |
| 240 | 205 | return !op.Value.m_hasValue; |
| 241 | 206 | } |
| 242 | 207 | |
| 243 | − template <typename T2> | |
| 208 | + template<class T2> | |
| 244 | 209 | bool operator!=(const Nullable<T2> &op1, const Nullable<T2> &op2) |
| 245 | 210 | { |
| 246 | 211 | if (op1.Value.m_hasValue != op2.Value.m_hasValue) |
| @@ -248,11 +213,11 @@ namespace GSF · 1 unmodified line | ||
| 248 | 213 | |
| 249 | 214 | if (op1.Value.m_hasValue) |
| 250 | 215 | return op1.Value.m_value != op2.Value.m_value; |
| 251 | − else | |
| 252 | − return false; | |
| 216 | + | |
| 217 | + return false; | |
| 253 | 218 | } |
| 254 | 219 | |
| 255 | − template <typename T2> | |
| 220 | + template<class T2> | |
| 256 | 221 | bool operator!=(const Nullable<T2> &op, const T2 &value) |
| 257 | 222 | { |
| 258 | 223 | if (!op.Value.m_hasValue) |
| @@ -261,7 +226,7 @@ namespace GSF · 2 unmodified lines | ||
| 261 | 226 | return op.Value.m_value != value; |
| 262 | 227 | } |
| 263 | 228 | |
| 264 | − template <typename T2> | |
| 229 | + template<class T2> | |
| 265 | 230 | bool operator!=(const T2 &value, const Nullable<T2> &op) |
| 266 | 231 | { |
| 267 | 232 | if (!op.Value.m_hasValue) |
| @@ -270,38 +235,38 @@ namespace GSF · 2 unmodified lines | ||
| 270 | 235 | return op.Value.m_value != value; |
| 271 | 236 | } |
| 272 | 237 | |
| 273 | − template <typename T2> | |
| 238 | + template<class T2> | |
| 274 | 239 | bool operator!=(const Nullable<T2> &op, nullptr_t nullpointer) |
| 275 | 240 | { |
| 276 | 241 | (void)nullpointer; |
| 277 | 242 | return op.Value.m_hasValue; |
| 278 | 243 | } |
| 279 | 244 | |
| 280 | − template <typename T2> | |
| 245 | + template<class T2> | |
| 281 | 246 | bool operator!=(nullptr_t nullpointer, const Nullable<T2> &op) |
| 282 | 247 | { |
| 283 | 248 | (void)nullpointer; |
| 284 | 249 | return op.Value.m_hasValue; |
| 285 | 250 | } |
| 286 | 251 | |
| 287 | − template <typename T> | |
| 288 | − const Nullable<T> & Nullable<T>::operator=(const Nullable<T> &value) | |
| 252 | + template<class T> // NOLINT | |
| 253 | + const Nullable<T>& Nullable<T>::operator=(const Nullable<T>& value) | |
| 289 | 254 | { |
| 290 | 255 | Value.m_hasValue = value.Value.m_hasValue; |
| 291 | 256 | Value.m_value = value.Value.m_value; |
| 292 | 257 | return *this; |
| 293 | 258 | } |
| 294 | 259 | |
| 295 | − template <typename T> | |
| 296 | − const Nullable<T> & Nullable<T>::operator=(const T &value) | |
| 260 | + template<class T> // NOLINT | |
| 261 | + const Nullable<T>& Nullable<T>::operator=(const T& value) | |
| 297 | 262 | { |
| 298 | 263 | Value.m_hasValue = true; |
| 299 | 264 | Value.m_value = value; |
| 300 | 265 | return *this; |
| 301 | 266 | } |
| 302 | 267 | |
| 303 | − template <typename T> | |
| 304 | − const Nullable<T> & Nullable<T>::operator=(nullptr_t nullpointer) | |
| 268 | + template<class T> // NOLINT | |
| 269 | + const Nullable<T>& Nullable<T>::operator=(nullptr_t nullpointer) | |
| 305 | 270 | { |
| 306 | 271 | (void)nullpointer; |
| 307 | 272 | Value.m_hasValue = false; |
| @@ -309,7 +274,7 @@ namespace GSF · 1 unmodified line | ||
| 309 | 274 | return *this; |
| 310 | 275 | } |
| 311 | 276 | |
| 312 | − template<typename T, typename U> | |
| 277 | + template<class T, class U> | |
| 313 | 278 | Nullable<T> CastAsNullable(const Nullable<U>& source) |
| 314 | 279 | { |
| 315 | 280 | if (source.HasValue()) |
| @@ -318,7 +283,7 @@ namespace GSF · 2 unmodified lines | ||
| 318 | 283 | return nullptr; |
| 319 | 284 | } |
| 320 | 285 | |
| 321 | − template<typename T> | |
| 286 | + template<class T> | |
| 322 | 287 | std::string ToString(const Nullable<T>& value) |
| 323 | 288 | { |
| 324 | 289 | if (value.HasValue()) |
| @@ -367,7 +332,7 @@ namespace GSF · 42 unmodified lines | ||
| 367 | 332 | return {}; |
| 368 | 333 | } |
| 369 | 334 | |
| 370 | − template<typename T> | |
| 335 | + template<class T> | |
| 371 | 336 | static int32_t CompareValues(Nullable<T> leftNullable, Nullable<T> rightNullable) |
| 372 | 337 | { |
| 373 | 338 | const bool leftHasValue = leftNullable.HasValue(); |
| @@ -24,9 +24,8 @@ · 23 unmodified lines | ||
| 24 | 24 | #ifndef __THREAD_SAFE_QUEUE_H |
| 25 | 25 | #define __THREAD_SAFE_QUEUE_H |
| 26 | 26 | |
| 27 | −#include <queue> | |
| 28 | − | |
| 29 | 27 | #include "CommonTypes.h" |
| 28 | +#include <queue> | |
| 30 | 29 | |
| 31 | 30 | namespace GSF |
| 32 | 31 | { |
| @@ -37,8 +36,8 @@ namespace GSF · 4 unmodified lines | ||
| 37 | 36 | // single thread and process in FIFO order. |
| 38 | 37 | // |
| 39 | 38 | // The use of multiple consumers may cause undesired effects. |
| 40 | − template <class T> | |
| 41 | − class ThreadSafeQueue | |
| 39 | + template<class T> | |
| 40 | + class ThreadSafeQueue // NOLINT | |
| 42 | 41 | { |
| 43 | 42 | private: |
| 44 | 43 | Mutex m_mutex; |
| @@ -89,14 +88,14 @@ namespace GSF · 44 unmodified lines | ||
| 89 | 88 | }; |
| 90 | 89 | |
| 91 | 90 | // Releases all threads waiting for data. |
| 92 | − template <class T> | |
| 91 | + template<class T> | |
| 93 | 92 | ThreadSafeQueue<T>::~ThreadSafeQueue() |
| 94 | 93 | { |
| 95 | 94 | Release(); |
| 96 | 95 | } |
| 97 | 96 | |
| 98 | 97 | // Inserts an item into the queue. |
| 99 | − template <class T> | |
| 98 | + template<class T> | |
| 100 | 99 | void ThreadSafeQueue<T>::Enqueue(T item) |
| 101 | 100 | { |
| 102 | 101 | ScopeLock lock(m_mutex); |
| @@ -106,7 +105,7 @@ namespace GSF · 3 unmodified lines | ||
| 106 | 105 | |
| 107 | 106 | // Removes an item from the |
| 108 | 107 | // queue and returns that item. |
| 109 | − template <class T> | |
| 108 | + template<class T> | |
| 110 | 109 | T ThreadSafeQueue<T>::Dequeue() |
| 111 | 110 | { |
| 112 | 111 | ScopeLock lock(m_mutex); |
| @@ -116,7 +115,7 @@ namespace GSF · 3 unmodified lines | ||
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | // Empties the queue. |
| 119 | − template <class T> | |
| 118 | + template<class T> | |
| 120 | 119 | void ThreadSafeQueue<T>::Clear() |
| 121 | 120 | { |
| 122 | 121 | ScopeLock lock(m_mutex); |
| @@ -127,7 +126,7 @@ namespace GSF · 4 unmodified lines | ||
| 127 | 126 | |
| 128 | 127 | // Returns the number of |
| 129 | 128 | // items left in the queue. |
| 130 | − template <class T> | |
| 129 | + template<class T> | |
| 131 | 130 | uint32_t ThreadSafeQueue<T>::Size() |
| 132 | 131 | { |
| 133 | 132 | ScopeLock lock(m_mutex); |
| @@ -137,7 +136,7 @@ namespace GSF · 3 unmodified lines | ||
| 137 | 136 | // Waits for data to be inserted into the queue. |
| 138 | 137 | // If there is already data in the queue, |
| 139 | 138 | // this method will not wait. |
| 140 | − template <class T> | |
| 139 | + template<class T> | |
| 141 | 140 | void ThreadSafeQueue<T>::WaitForData() |
| 142 | 141 | { |
| 143 | 142 | UniqueLock lock(m_mutex); |
| @@ -147,7 +146,7 @@ namespace GSF · 3 unmodified lines | ||
| 147 | 146 | } |
| 148 | 147 | |
| 149 | 148 | // Releases all threads waiting for data. |
| 150 | − template <class T> | |
| 149 | + template<class T> | |
| 151 | 150 | void ThreadSafeQueue<T>::Release() |
| 152 | 151 | { |
| 153 | 152 | ScopeLock lock(m_mutex); |
| @@ -159,7 +158,7 @@ namespace GSF · 5 unmodified lines | ||
| 159 | 158 | // Resets the "release valve" for threads calling WaitForData. |
| 160 | 159 | // This can be called after Release so that the queue can be |
| 161 | 160 | // used again. |
| 162 | − template <class T> | |
| 161 | + template<class T> | |
| 163 | 162 | void ThreadSafeQueue<T>::Reset() |
| 164 | 163 | { |
| 165 | 164 | ScopeLock lock(m_mutex); |
| @@ -2843,7 +2843,7 @@ ValueExpressionPtr ExpressionTree::Or(const ValueExpressionPtr& leftValue, const · 2842 unmodified lines | ||
| 2843 | 2843 | return NewSharedPtr<ValueExpression>(ExpressionValueType::Boolean, left || right); |
| 2844 | 2844 | } |
| 2845 | 2845 | |
| 2846 | −template<typename T> | |
| 2846 | +template<class T> | |
| 2847 | 2847 | T ExpressionTree::Unary(const T& unaryValue, ExpressionUnaryType unaryOperation) |
| 2848 | 2848 | { |
| 2849 | 2849 | switch (unaryOperation) |
| @@ -2859,7 +2859,7 @@ T ExpressionTree::Unary(const T& unaryValue, ExpressionUnaryType unaryOperation) · 9 unmodified lines | ||
| 2859 | 2859 | } |
| 2860 | 2860 | } |
| 2861 | 2861 | |
| 2862 | −template<typename T> | |
| 2862 | +template<class T> | |
| 2863 | 2863 | T ExpressionTree::UnaryFloat(const T& unaryValue, ExpressionUnaryType unaryOperation, ExpressionValueType unaryValueType) |
| 2864 | 2864 | { |
| 2865 | 2865 | switch (unaryOperation) |
| @@ -366,10 +366,10 @@ private: · 365 unmodified lines | ||
| 366 | 366 | ValueExpressionPtr And(const ValueExpressionPtr& leftValue, const ValueExpressionPtr& rightValue) const; |
| 367 | 367 | ValueExpressionPtr Or(const ValueExpressionPtr& leftValue, const ValueExpressionPtr& rightValue) const; |
| 368 | 368 | |
| 369 | − template<typename T> | |
| 369 | + template<class T> | |
| 370 | 370 | static T Unary(const T& unaryValue, ExpressionUnaryType unaryOperation); |
| 371 | 371 | |
| 372 | − template<typename T> | |
| 372 | + template<class T> | |
| 373 | 373 | static T UnaryFloat(const T& unaryValue, ExpressionUnaryType unaryOperation, ExpressionValueType unaryValueType); |
| 374 | 374 | |
| 375 | 375 | static bool UnaryBool(bool unaryValue, ExpressionUnaryType unaryOperation); |
| @@ -21,13 +21,12 @@ · 20 unmodified lines | ||
| 21 | 21 | // |
| 22 | 22 | //****************************************************************************************************** |
| 23 | 23 | |
| 24 | −#include <iostream> | |
| 25 | −#include <string> | |
| 26 | − | |
| 27 | 24 | #include "../Transport/DataPublisher.h" |
| 25 | +#include <iostream> | |
| 28 | 26 | |
| 29 | 27 | using namespace std; |
| 30 | 28 | using namespace GSF; |
| 29 | +using namespace GSF::Data; | |
| 31 | 30 | using namespace GSF::TimeSeries; |
| 32 | 31 | using namespace GSF::TimeSeries::Transport; |
| 33 | 32 | |
| @@ -115,6 +114,9 @@ bool RunPublisher(uint16_t port) · 81 unmodified lines | ||
| 115 | 114 | Publisher->RegisterClientDisconnectedCallback(&DisplayClientDisconnected); |
| 116 | 115 | Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage); |
| 117 | 116 | Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage); |
| 117 | + | |
| 118 | + // Define metadata | |
| 119 | + Publisher->DefineMetadata(DataSet::FromXml("Metadata.xml")); | |
| 118 | 120 | } |
| 119 | 121 | else |
| 120 | 122 | { |
| @@ -1,4 +1,4 @@ | ||
| 1 | −// Auto-generated on Thu Feb 7 16:57:40 2019 | |
| 1 | +// Auto-generated on Fri Feb 8 13:02:59 2019 | |
| 2 | 2 | // EmbedFile.exe ActiveMeasurementsSchema D:\Projects\gsf\Source\Libraries\TimeSeriesPlatformLibrary\Transport\ActiveMeasurementsSchema.xml GSF::TimeSeries::Transport:: |
| 3 | 3 | |
| 4 | 4 | #include "ActiveMeasurementsSchema.h" |
| @@ -206,7 +206,7 @@ const uint8_t GSF::TimeSeries::Transport::ActiveMeasurementsSchema[] = { · 201 unmodified lines | ||
| 206 | 206 | 0x79, 0x70, 0x65, 0x3E, 0x3C, 0x2F, 0x78, 0x73, 0x3A, 0x65, |
| 207 | 207 | 0x6C, 0x65, 0x6D, 0x65, 0x6E, 0x74, 0x3E, 0x3C, 0x2F, 0x78, |
| 208 | 208 | 0x73, 0x3A, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x3E, 0x3C, |
| 209 | − 0x2F, 0x49, 0x61, 0x6F, 0x6E, 0x3E, 0x00 | |
| 209 | + 0x2F, 0x49, 0x61, 0x6F, 0x6E, 0x3E | |
| 210 | 210 | }; |
| 211 | 211 | |
| 212 | 212 | const uint32_t GSF::TimeSeries::Transport::ActiveMeasurementsSchemaLength = sizeof(GSF::TimeSeries::Transport::ActiveMeasurementsSchema); |
| @@ -1,4 +1,4 @@ | ||
| 1 | −// Auto-generated on Thu Feb 7 16:57:40 2019 | |
| 1 | +// Auto-generated on Fri Feb 8 13:02:59 2019 | |
| 2 | 2 | // EmbedFile.exe ActiveMeasurementsSchema D:\Projects\gsf\Source\Libraries\TimeSeriesPlatformLibrary\Transport\ActiveMeasurementsSchema.xml GSF::TimeSeries::Transport:: |
| 3 | 3 | |
| 4 | 4 | #ifndef _ACTIVE_MEASUREMENTS_SCHEMA |
| @@ -646,68 +646,70 @@ DataSetPtr DataPublisher::FilterClientMetadata(const SubscriberConnectionPtr& co · 645 unmodified lines | ||
| 646 | 646 | |
| 647 | 647 | vector<uint8_t> DataPublisher::SerializeSignalIndexCache(const SubscriberConnectionPtr& connection, const SignalIndexCachePtr& signalIndexCache) const |
| 648 | 648 | { |
| 649 | − if (connection == nullptr) | |
| 650 | − return vector<uint8_t>{}; | |
| 649 | + vector<uint8_t> serializationBuffer; | |
| 651 | 650 | |
| 652 | − const uint32_t operationalModes = connection->GetOperationalModes(); | |
| 653 | − const uint32_t compressionModes = operationalModes & OperationalModes::CompressionModeMask; | |
| 654 | − const bool useCommonSerializationFormat = (operationalModes & OperationalModes::UseCommonSerializationFormat) > 0; | |
| 655 | − const bool compressSignalIndexCache = (operationalModes & OperationalModes::CompressSignalIndexCache) > 0; | |
| 651 | + if (connection != nullptr) | |
| 652 | + { | |
| 653 | + const uint32_t operationalModes = connection->GetOperationalModes(); | |
| 654 | + const bool useCommonSerializationFormat = (operationalModes & OperationalModes::UseCommonSerializationFormat) > 0; | |
| 655 | + const bool compressSignalIndexCache = (operationalModes & OperationalModes::CompressSignalIndexCache) > 0; | |
| 656 | + const bool useGZipCompression = (operationalModes & CompressionModes::GZip) > 0; | |
| 656 | 657 | |
| 657 | − if (!useCommonSerializationFormat) | |
| 658 | − throw PublisherException("DataPublisher only supports common serialization format"); | |
| 658 | + if (!useCommonSerializationFormat) | |
| 659 | + throw PublisherException("DataPublisher only supports common serialization format"); | |
| 659 | 660 | |
| 660 | − vector<uint8_t> serializedCache(uint32_t(signalIndexCache->GetBinaryLength() * 0.02)); | |
| 661 | − signalIndexCache->Serialize(connection, serializedCache); | |
| 661 | + serializationBuffer.reserve(uint32_t(signalIndexCache->GetBinaryLength() * 0.02)); | |
| 662 | + signalIndexCache->Serialize(connection, serializationBuffer); | |
| 662 | 663 | |
| 663 | − if (compressSignalIndexCache && (compressionModes & CompressionModes::GZip) > 0) | |
| 664 | − { | |
| 665 | − const MemoryStream metadataStream(serializedCache); | |
| 666 | − StreamBuffer streamBuffer; | |
| 664 | + if (compressSignalIndexCache && useGZipCompression) | |
| 665 | + { | |
| 666 | + const MemoryStream memoryStream(serializationBuffer); | |
| 667 | + StreamBuffer streamBuffer; | |
| 667 | 668 | |
| 668 | − streamBuffer.push(GZipCompressor()); | |
| 669 | − streamBuffer.push(metadataStream); | |
| 669 | + streamBuffer.push(GZipCompressor()); | |
| 670 | + streamBuffer.push(memoryStream); | |
| 670 | 671 | |
| 671 | − vector<uint8_t> compressed; | |
| 672 | − CopyStream(&streamBuffer, compressed); | |
| 673 | − return compressed; | |
| 672 | + vector<uint8_t> compressedBuffer; | |
| 673 | + CopyStream(&streamBuffer, compressedBuffer); | |
| 674 | + return compressedBuffer; | |
| 675 | + } | |
| 674 | 676 | } |
| 675 | 677 | |
| 676 | − return serializedCache; | |
| 678 | + return serializationBuffer; | |
| 677 | 679 | } |
| 678 | 680 | |
| 679 | 681 | vector<uint8_t> DataPublisher::SerializeMetadata(const SubscriberConnectionPtr& connection, const DataSetPtr& metadata) const |
| 680 | 682 | { |
| 681 | − vector<uint8_t> serializedMetadata; | |
| 683 | + vector<uint8_t> serializationBuffer; | |
| 682 | 684 | |
| 683 | 685 | if (connection != nullptr) |
| 684 | 686 | { |
| 685 | 687 | const uint32_t operationalModes = connection->GetOperationalModes(); |
| 686 | − const uint32_t compressionModes = operationalModes & OperationalModes::CompressionModeMask; | |
| 687 | 688 | const bool useCommonSerializationFormat = (operationalModes & OperationalModes::UseCommonSerializationFormat) > 0; |
| 688 | 689 | const bool compressMetadata = (operationalModes & OperationalModes::CompressMetadata) > 0; |
| 690 | + const bool useGZipCompression = (operationalModes & CompressionModes::GZip) > 0; | |
| 689 | 691 | |
| 690 | 692 | if (!useCommonSerializationFormat) |
| 691 | 693 | throw PublisherException("DataPublisher only supports common serialization format"); |
| 692 | 694 | |
| 693 | − metadata->WriteXml(serializedMetadata); | |
| 695 | + metadata->WriteXml(serializationBuffer); | |
| 694 | 696 | |
| 695 | − if (compressMetadata && (compressionModes & CompressionModes::GZip) > 0) | |
| 697 | + if (compressMetadata && useGZipCompression) | |
| 696 | 698 | { |
| 697 | − const MemoryStream metadataStream(serializedMetadata); | |
| 699 | + const MemoryStream memoryStream(serializationBuffer); | |
| 698 | 700 | StreamBuffer streamBuffer; |
| 699 | 701 | |
| 700 | 702 | streamBuffer.push(GZipCompressor()); |
| 701 | − streamBuffer.push(metadataStream); | |
| 703 | + streamBuffer.push(memoryStream); | |
| 702 | 704 | |
| 703 | − vector<uint8_t> compressed; | |
| 704 | − CopyStream(&streamBuffer, compressed); | |
| 705 | + vector<uint8_t> compressionBuffer; | |
| 706 | + CopyStream(&streamBuffer, compressionBuffer); | |
| 705 | 707 | |
| 706 | − return compressed; | |
| 708 | + return compressionBuffer; | |
| 707 | 709 | } |
| 708 | 710 | } |
| 709 | 711 | |
| 710 | − return serializedMetadata; | |
| 712 | + return serializationBuffer; | |
| 711 | 713 | } |
| 712 | 714 | |
| 713 | 715 | bool DataPublisher::SendClientResponse(const SubscriberConnectionPtr& connection, uint8_t responseCode, uint8_t commandCode, const std::string& message) |
| @@ -745,10 +747,7 @@ bool DataPublisher::SendClientResponse(const SubscriberConnectionPtr& connection · 31 unmodified lines | ||
| 745 | 747 | if (data.empty()) |
| 746 | 748 | { |
| 747 | 749 | // Add zero sized data buffer to response packet |
| 748 | − buffer.push_back(0); | |
| 749 | − buffer.push_back(0); | |
| 750 | − buffer.push_back(0); | |
| 751 | − buffer.push_back(0); | |
| 750 | + WriteBytes(buffer, uint32_t(0)); | |
| 752 | 751 | } |
| 753 | 752 | else |
| 754 | 753 | { |
| @@ -1081,7 +1080,7 @@ void DataPublisher::DefineMetadata(const DataSetPtr& metadata) · 326 unmodified lines | ||
| 1081 | 1080 | phasorData[deviceName] = phasorMap; |
| 1082 | 1081 | } |
| 1083 | 1082 | |
| 1084 | − phasorMap->at(row->ValueAsInt32(sourceIndex).GetValueOrDefault()) = phasor; | |
| 1083 | + phasorMap->insert_or_assign(row->ValueAsInt32(sourceIndex).GetValueOrDefault(), phasor); | |
| 1085 | 1084 | } |
| 1086 | 1085 | } |
| 1087 | 1086 | |
| @@ -1147,8 +1146,8 @@ void DataPublisher::DefineMetadata(const DataSetPtr& metadata) · 59 unmodified lines | ||
| 1147 | 1146 | am_row->SetGuidValue(am_signalID, md_row->ValueAsGuid(md_signalID)); |
| 1148 | 1147 | am_row->SetStringValue(am_pointTag, md_row->ValueAsString(md_pointTag)); |
| 1149 | 1148 | am_row->SetStringValue(am_signalReference, md_row->ValueAsString(md_signalReference)); |
| 1150 | − am_row->SetInt32Value(am_internal, md_row->ValueAsInt32(md_internal)); | |
| 1151 | − am_row->SetBooleanValue(am_subscribed, false); | |
| 1149 | + am_row->SetInt32Value(am_internal, md_row->ValueAsBoolean(md_internal).GetValueOrDefault() ? 1 : 0); | |
| 1150 | + am_row->SetInt32Value(am_subscribed, 0); | |
| 1152 | 1151 | am_row->SetStringValue(am_description, md_row->ValueAsString(md_description)); |
| 1153 | 1152 | am_row->SetDoubleValue(am_adder, 0.0); |
| 1154 | 1153 | am_row->SetDoubleValue(am_multiplier, 1.0); |
| @@ -224,6 +224,7 @@ bool SubscriberConnector::GetAutoReconnect() const · 223 unmodified lines | ||
| 224 | 224 | // --- DataSubscriber --- |
| 225 | 225 | |
| 226 | 226 | DataSubscriber::DataSubscriber() : |
| 227 | + m_subscriberID(Empty::Guid), | |
| 227 | 228 | m_compressPayloadData(true), |
| 228 | 229 | m_compressMetadata(true), |
| 229 | 230 | m_compressSignalIndexCache(true), |
| @@ -1,4 +1,4 @@ | ||
| 1 | −// Auto-generated on Thu Feb 7 17:00:15 2019 | |
| 1 | +// Auto-generated on Fri Feb 8 13:02:18 2019 | |
| 2 | 2 | // EmbedFile.exe MetadataSchema D:\Projects\gsf\Source\Libraries\TimeSeriesPlatformLibrary\Transport\MetadataSchema.xml GSF::TimeSeries::Transport:: |
| 3 | 3 | |
| 4 | 4 | #include "MetadataSchema.h" |
| @@ -331,7 +331,7 @@ const uint8_t GSF::TimeSeries::Transport::MetadataSchema[] = { · 326 unmodified lines | ||
| 331 | 331 | 0x65, 0x78, 0x54, 0x79, 0x70, 0x65, 0x3E, 0x3C, 0x2F, 0x78, |
| 332 | 332 | 0x73, 0x3A, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E, 0x74, 0x3E, |
| 333 | 333 | 0x3C, 0x2F, 0x78, 0x73, 0x3A, 0x73, 0x63, 0x68, 0x65, 0x6D, |
| 334 | − 0x61, 0x3E, 0x00 | |
| 334 | + 0x61, 0x3E | |
| 335 | 335 | }; |
| 336 | 336 | |
| 337 | 337 | const uint32_t GSF::TimeSeries::Transport::MetadataSchemaLength = sizeof(GSF::TimeSeries::Transport::MetadataSchema); |
| @@ -1,4 +1,4 @@ | ||
| 1 | −// Auto-generated on Thu Feb 7 17:00:15 2019 | |
| 1 | +// Auto-generated on Fri Feb 8 13:02:18 2019 | |
| 2 | 2 | // EmbedFile.exe MetadataSchema D:\Projects\gsf\Source\Libraries\TimeSeriesPlatformLibrary\Transport\MetadataSchema.xml GSF::TimeSeries::Transport:: |
| 3 | 3 | |
| 4 | 4 | #ifndef _METADATA_SCHEMA |
| @@ -178,7 +178,7 @@ void SignalIndexCache::Parse(const vector<uint8_t>& buffer, Guid& subscriberID) · 177 unmodified lines | ||
| 178 | 178 | const uint32_t referenceCount = EndianConverter::Default.ConvertBigEndian(*referenceCountPtr); |
| 179 | 179 | |
| 180 | 180 | // Set up signalIndexPtr before entering the loop |
| 181 | − const uint16_t * signalIndexPtr = reinterpret_cast<const uint16_t*>(referenceCountPtr + 1); | |
| 181 | + const uint16_t* signalIndexPtr = reinterpret_cast<const uint16_t*>(referenceCountPtr + 1); | |
| 182 | 182 | |
| 183 | 183 | for (uint32_t i = 0; i < referenceCount; ++i) |
| 184 | 184 | { |
| @@ -222,19 +222,12 @@ void SignalIndexCache::Serialize(const SubscriberConnectionPtr& connection, vect · 37 unmodified lines | ||
| 222 | 222 | uint32_t binaryLength = 28; |
| 223 | 223 | |
| 224 | 224 | // Reserve space for binary byte length of cache |
| 225 | − buffer.push_back(0); | |
| 226 | − buffer.push_back(0); | |
| 227 | − buffer.push_back(0); | |
| 228 | − buffer.push_back(0); | |
| 225 | + WriteBytes(buffer, uint32_t(0)); | |
| 229 | 226 | |
| 230 | 227 | // Encode subscriber ID |
| 231 | 228 | Guid subscriberID = connection->GetSubscriberID(); |
| 232 | − | |
| 233 | 229 | SwapGuidEndianness(subscriberID, true); |
| 234 | − uint8_t* bytes = subscriberID.data; | |
| 235 | − | |
| 236 | − for (int32_t i = 0; i < 16; i++) | |
| 237 | − buffer.push_back(bytes[i]); | |
| 230 | + WriteBytes(buffer, subscriberID); | |
| 238 | 231 | |
| 239 | 232 | // Encode number of references |
| 240 | 233 | EndianConverter::WriteBigEndianBytes(buffer, int32_t(m_reference.size())); |
| @@ -248,10 +241,7 @@ void SignalIndexCache::Serialize(const SubscriberConnectionPtr& connection, vect · 7 unmodified lines | ||
| 248 | 241 | |
| 249 | 242 | // Encode signal ID |
| 250 | 243 | SwapGuidEndianness(signalID, true); |
| 251 | − bytes = signalID.data; | |
| 252 | − | |
| 253 | − for (int32_t j = 0; j < 16; j++) | |
| 254 | − buffer.push_back(bytes[j]); | |
| 244 | + WriteBytes(buffer, signalID); | |
| 255 | 245 | |
| 256 | 246 | // Encode source |
| 257 | 247 | vector<uint8_t> sourceBytes = DataPublisher::EncodeClientString(connection, m_sourceList[i]); |
| @@ -36,7 +36,7 @@ namespace Transport · 35 unmodified lines | ||
| 36 | 36 | typedef GSF::SharedPtr<DataPublisher> DataPublisherPtr; |
| 37 | 37 | |
| 38 | 38 | // Represents a subscriber connection to a data publisher |
| 39 | − class SubscriberConnection : public GSF::EnableSharedThisPtr<SubscriberConnection> //NOLINT | |
| 39 | + class SubscriberConnection : public GSF::EnableSharedThisPtr<SubscriberConnection> // NOLINT | |
| 40 | 40 | { |
| 41 | 41 | private: |
| 42 | 42 | const DataPublisherPtr m_parent; |
| @@ -577,35 +577,35 @@ void SubscriberInstance::ReceivedMetadata(const vector<uint8_t>& payload) · 576 unmodified lines | ||
| 577 | 577 | return; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | − vector<uint8_t>* uncompressed; | |
| 580 | + vector<uint8_t>* uncompressesBuffer; | |
| 581 | 581 | |
| 582 | 582 | // Step 1: Decompress meta-data if needed |
| 583 | 583 | if (IsMetadataCompressed()) |
| 584 | 584 | { |
| 585 | 585 | // Perform zlib decompression on buffer |
| 586 | − const MemoryStream payloadStream(payload); | |
| 586 | + const MemoryStream memoryStream(payload); | |
| 587 | 587 | StreamBuffer streamBuffer; |
| 588 | 588 | |
| 589 | 589 | streamBuffer.push(GZipDecompressor()); |
| 590 | − streamBuffer.push(payloadStream); | |
| 590 | + streamBuffer.push(memoryStream); | |
| 591 | 591 | |
| 592 | − uncompressed = new vector<uint8_t>(); | |
| 593 | − CopyStream(&streamBuffer, *uncompressed); | |
| 592 | + uncompressesBuffer = new vector<uint8_t>(); | |
| 593 | + CopyStream(&streamBuffer, *uncompressesBuffer); | |
| 594 | 594 | } |
| 595 | 595 | else |
| 596 | 596 | { |
| 597 | − uncompressed = const_cast<vector<uint8_t>*>(&payload); | |
| 597 | + uncompressesBuffer = const_cast<vector<uint8_t>*>(&payload); | |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | // Step 2: Load string into an XML parser |
| 601 | 601 | xml_document document; |
| 602 | 602 | |
| 603 | − const xml_parse_result result = document.load_buffer_inplace(static_cast<void*>(uncompressed->data()), uncompressed->size()); | |
| 603 | + const xml_parse_result result = document.load_buffer_inplace(static_cast<void*>(uncompressesBuffer->data()), uncompressesBuffer->size()); | |
| 604 | 604 | |
| 605 | 605 | if (result.status != xml_parse_status::status_ok) |
| 606 | 606 | { |
| 607 | 607 | if (IsMetadataCompressed()) |
| 608 | − delete uncompressed; | |
| 608 | + delete uncompressesBuffer; | |
| 609 | 609 | |
| 610 | 610 | stringstream errorMessageStream; |
| 611 | 611 | errorMessageStream << "Failed to parse meta data XML, status code = " << ToHex(result.status); |
| @@ -758,7 +758,7 @@ void SubscriberInstance::ReceivedMetadata(const vector<uint8_t>& payload) · 146 unmodified lines | ||
| 758 | 758 | |
| 759 | 759 | // Release uncompressed buffer |
| 760 | 760 | if (IsMetadataCompressed()) |
| 761 | − delete uncompressed; | |
| 761 | + delete uncompressesBuffer; | |
| 762 | 762 | |
| 763 | 763 | // Notify derived class that meta-data has been parsed and is now available |
| 764 | 764 | ParsedMetadata(); |