2 #ifndef GRAMODS_NETWORK_SYNCSDATA
3 #define GRAMODS_NETWORK_SYNCSDATA
5 #include <gmNetwork/SyncData.hh>
6 #include <gmCore/InvalidArgument.hh>
8 BEGIN_NAMESPACE_GMNETWORK;
38 operator TYPE ()
const {
41 std::lock_guard<std::mutex> guard(
const_cast<SyncSData<TYPE>*
>(
this)->lock);
53 std::lock_guard<std::mutex> guard(
const_cast<SyncSData<TYPE>*
>(
this)->lock);
65 std::lock_guard<std::mutex> guard(lock);
68 SyncData::pushValue();
78 void encode(std::vector<char> &d)
override {
79 std::lock_guard<std::mutex> guard(lock);
81 d.resize(1 +
sizeof(TYPE));
83 char * m =
reinterpret_cast<char*
>(&back);
85 for (
size_t idx = 0; idx <
sizeof(TYPE); ++idx) {
94 void decode(std::vector<char> d)
override {
95 std::lock_guard<std::mutex> guard(lock);
97 if (d.size() != 1 +
sizeof(TYPE))
101 char * m =
reinterpret_cast<char*
>(&value);
103 for (
size_t idx = 0; idx <
sizeof(TYPE); ++idx)
113 std::lock_guard<std::mutex> guard(lock);
133 typedef SyncSData<bool> SyncSBool;
134 typedef SyncSData<int32_t> SyncSInt32;
135 typedef SyncSData<uint32_t> SyncSUInt32;
136 typedef SyncSData<int64_t> SyncSInt64;
137 typedef SyncSData<uint64_t> SyncSUInt64;
138 typedef SyncSData<float> SyncSFloat32;
139 typedef SyncSData<double> SyncSFloat64;
141 END_NAMESPACE_GMNETWORK;
Simple synchronizeable data container.
Definition: SyncData.hh:17
Simple, single value synchronizeable data container, without support for pointers or types containing...
Definition: SyncSData.hh:16
void encode(std::vector< char > &d) override
Encodes the back data of the container into the specified vector, using vector indices 1-N and leavin...
Definition: SyncSData.hh:78
TYPE operator*() const
Retrieves the front value of the container.
Definition: SyncSData.hh:50
void decode(std::vector< char > d) override
Decodes the specified vector into the back data of the container, using vector indices 1-N.
Definition: SyncSData.hh:94
SyncSData()
Initializes without specifying value.
Definition: SyncSData.hh:23
SyncSData(TYPE val)
Initializes the SyncSData to the specified value.
Definition: SyncSData.hh:28
void update() override
Copies the back value to the front.
Definition: SyncSData.hh:112
Standard exception for invalid arguments in a call to a function or object.
Definition: InvalidArgument.hh:15