2 #ifndef GRAMODS_NETWORK_SYNCMDATA
3 #define GRAMODS_NETWORK_SYNCMDATA
5 #include <gmNetwork/SyncData.hh>
6 #include <gmCore/InvalidArgument.hh>
8 BEGIN_NAMESPACE_GMNETWORK;
31 SyncMData(std::vector<TYPE> val) { back = front = val; }
41 operator std::vector<TYPE> ()
const {
42 std::vector<TYPE> retval;
44 std::lock_guard<std::mutex> guard(
const_cast<SyncMData<TYPE>*
>(
this)->lock);
53 TYPE operator[] (
size_t idx)
const {
56 std::lock_guard<std::mutex> guard(
const_cast<SyncMData<TYPE>*
>(
this)->lock);
68 std::lock_guard<std::mutex> guard(lock);
71 SyncData::pushValue();
81 void encode(std::vector<char> &d)
override {
82 std::lock_guard<std::mutex> guard(lock);
84 d.resize(1 + back.size() *
sizeof(TYPE));
86 char * m =
reinterpret_cast<char*
>(&back[0]);
88 for (
size_t idx = 0; idx < back.size() *
sizeof(TYPE); ++idx) {
97 void decode(std::vector<char> d)
override {
98 std::lock_guard<std::mutex> guard(lock);
100 if ((d.size() - 1)%
sizeof(TYPE) != 0)
103 size_t vector_size = (d.size() - 1)/
sizeof(TYPE);
105 std::vector<TYPE> value;
106 value.resize(vector_size);
107 char * m =
reinterpret_cast<char*
>(&value[0]);
109 for (
size_t idx = 0; idx < vector_size *
sizeof(TYPE); ++idx)
112 back = std::move(value);
119 std::lock_guard<std::mutex> guard(lock);
128 std::vector<TYPE> front;
133 std::vector<TYPE> back;
139 typedef SyncMData<char> SyncMBool;
140 typedef SyncMData<int32_t> SyncMInt32;
141 typedef SyncMData<int64_t> SyncMInt64;
142 typedef SyncMData<float> SyncMFloat32;
143 typedef SyncMData<double> SyncMFloat64;
145 END_NAMESPACE_GMNETWORK;
Simple synchronizeable data container.
Definition: SyncData.hh:17
Simple, multi value (vector) synchronizeable data container, without support for pointers or types co...
Definition: SyncMData.hh:19
SyncMData(std::vector< TYPE > val)
Initializes the SyncMData to the specified value.
Definition: SyncMData.hh:31
SyncMData()
Initializes the SyncMData to an empty list.
Definition: SyncMData.hh:26
void decode(std::vector< char > d) override
Decodes the specified vector into the back data of the container, using vector indices 1-N.
Definition: SyncMData.hh:97
void update() override
Copies the back value to the front.
Definition: SyncMData.hh:118
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: SyncMData.hh:81
Standard exception for invalid arguments in a call to a function or object.
Definition: InvalidArgument.hh:15