49 boost::shared_ptr<DoocsBackend> backend,
const std::string& path,
const std::string& registerPathName,
50 size_t numberOfWords,
size_t wordOffsetInRegister, AccessModeFlags flags)
52 backend, path, registerPathName, numberOfWords, wordOffsetInRegister, flags) {
61 catch(ChimeraTK::runtime_error&) {
141 switch(this->dst.type()) {
143 return this->dst.get_bool();
148 return this->dst.get_short(index);
152 return this->dst.get_ushort(index);
157 return this->dst.get_int(index);
161 return this->dst.get_uint(index);
165 return this->dst.get_long(index);
169 return this->dst.get_ulong(index);
175 return this->dst.get_float(index);
180 return this->dst.get_double(index);
196 if(!hasNewData)
return;
199 if(this->dst.type() == DATA_NULL) {
203 std::fill(this->accessChannel(0).begin(), this->accessChannel(0).end(), UserType());
208 if(
size_t(this->dst.length()) < this->nElements + this->elementOffset) {
209 throw ChimeraTK::runtime_error(
"DoocsBackend: Unexpected array length found in remote property " +
210 this->ea.show_adr() +
": " + std::to_string(this->dst.length()) +
" is shorter than the expected " +
211 std::to_string(this->nElements + this->elementOffset));
215 auto copyFromSourcePointer = [&](
const auto* sourcePointer) {
216 using SourceType = std::remove_const_t<std::remove_reference_t<
decltype(*sourcePointer)>>;
217 assert(sourcePointer);
219 sourcePointer += this->elementOffset;
220 if constexpr(std::is_same<UserType, SourceType>::value) {
222 memcpy(this->buffer_2D[0].data(), sourcePointer, this->nElements *
sizeof(SourceType));
225 std::transform(sourcePointer, sourcePointer + this->nElements, this->buffer_2D[0].begin(),
226 [](
const SourceType& v) {
return ChimeraTK::numericToUserType<UserType>(v); });
231 switch(this->dst.type()) {
234 copyFromSourcePointer(this->dst.get_float_array());
237 case DATA_A_DOUBLE: {
238 copyFromSourcePointer(this->dst.get_double_array());
242 copyFromSourcePointer(this->dst.get_int_array());
246 copyFromSourcePointer(this->dst.get_long_array());
251 copyFromSourcePointer(this->dst.get_short_array());
256 callForDoocsType(this->dst, [&](
auto t) {
257 using T =
decltype(t);
258 for(
size_t i = 0; i < this->nElements; i++) {
259 this->buffer_2D[0][i] = ChimeraTK::numericToUserType<UserType>(dataGet<T>(i + this->elementOffset));
282 if(this->isPartial) {
283 this->doReadTransferSynchronously();
284 this->src = this->dst;
286 if(
size_t(this->src.length()) < this->nElements + this->elementOffset) {
287 this->src.length(this->nElements + this->elementOffset);
292 auto copyToTargetPointer = [&](
auto* targetPointer) {
293 using TargetType = std::remove_reference_t<
decltype(*targetPointer)>;
294 assert(targetPointer);
296 targetPointer += this->elementOffset;
297 if constexpr(std::is_same<UserType, TargetType>::value) {
299 memcpy(targetPointer, this->buffer_2D[0].data(), this->nElements *
sizeof(TargetType));
302 std::transform(this->buffer_2D[0].begin(), this->buffer_2D[0].end(), targetPointer,
303 [](UserType v) {
return ChimeraTK::userTypeToNumeric<TargetType>(v); });
308 switch(this->src.type()) {
311 copyToTargetPointer(this->src.get_float_array());
314 case DATA_A_DOUBLE: {
315 copyToTargetPointer(this->src.get_double_array());
319 copyToTargetPointer(this->src.get_int_array());
323 copyToTargetPointer(this->src.get_long_array());
328 copyToTargetPointer(this->src.get_short_array());
333 callForDoocsType(this->src, [&](
auto t) {
334 using T =
decltype(t);
335 if(this->src.array_length() == 0) {
337 this->src.set(ChimeraTK::userTypeToNumeric<T>(this->buffer_2D[0][0]));
340 for(
size_t i = 0; i < this->nElements; i++) {
341 this->src.set(ChimeraTK::userTypeToNumeric<T>(this->buffer_2D[0][i]),
int(i + this->elementOffset));