rogue
Loading...
Searching...
No Matches
Variable.cpp
Go to the documentation of this file.
1
17#include "rogue/Directives.h"
18
20
21#include <sys/time.h>
22
23#include <cmath>
24#include <cstdio>
25#include <cstring>
26#include <iomanip>
27#include <iostream>
28#include <memory>
29#include <sstream>
30#include <string>
31#include <vector>
32
33#include "rogue/GeneralError.h"
34#include "rogue/GilRelease.h"
35#include "rogue/ScopedGil.h"
38
40
41#ifndef NO_PYTHON
42 #include <boost/python.hpp>
43namespace bp = boost::python;
44#endif
45
47rim::VariablePtr rim::Variable::create(std::string name,
48 std::string mode,
49 double minimum,
50 double maximum,
51 uint64_t offset,
52 std::vector<uint32_t> bitOffset,
53 std::vector<uint32_t> bitSize,
54 bool overlapEn,
55 bool verify,
56 bool bulkOpEn,
57 bool updateNotify,
58 uint32_t modelId,
59 bool byteReverse,
60 bool bitReverse,
61 uint32_t binPoint,
62 uint32_t numValues,
63 uint32_t valueBits,
64 uint32_t valueStride,
65 uint32_t retryCount) {
66 rim::VariablePtr v = std::make_shared<rim::Variable>(name,
67 mode,
68 minimum,
69 maximum,
70 offset,
71 bitOffset,
72 bitSize,
74 verify,
76 updateNotify,
77 modelId,
78 byteReverse,
79 bitReverse,
80 binPoint,
85 return (v);
86}
87
88// Setup class for use in python
89void rim::Variable::setup_python() {
90#ifndef NO_PYTHON
91 bp::class_<rim::VariableWrap, rim::VariableWrapPtr, boost::noncopyable>("Variable",
92 bp::init<std::string,
93 std::string,
94 bp::object,
95 bp::object,
96 uint64_t,
97 bp::object,
98 bp::object,
99 bool,
100 bool,
101 bool,
102 bool,
103 bp::object,
104 bp::object,
105 uint32_t>())
106 .def("_varBytes", &rim::Variable::varBytes)
107 .def("_offset", &rim::Variable::offset)
108 .def("_shiftOffsetDown", &rim::Variable::shiftOffsetDown)
109 .def("_updatePath", &rim::Variable::updatePath)
110 .def("_overlapEn", &rim::Variable::overlapEn)
111 .def("_verifyEn", &rim::Variable::verifyEn)
112 .def("_bitOffset", &rim::VariableWrap::bitOffset)
113 .def("_bitSize", &rim::VariableWrap::bitSize)
114 .def("_get", &rim::VariableWrap::get)
115 .def("_set", &rim::VariableWrap::set)
116 .def("_rateTest", &rim::VariableWrap::rateTest)
117 .def("_queueUpdate", &rim::Variable::queueUpdate, &rim::VariableWrap::defQueueUpdate)
118 .def("_setLogLevel", &rim::Variable::setLogLevel)
119 .def("_getDumpValue", &rim::Variable::getDumpValue)
120 .def("_numValues", &rim::Variable::numValues)
121 .def("_valueBits", &rim::Variable::valueBits)
122 .def("_valueStride", &rim::Variable::valueStride)
123 .def("_retryCount", &rim::Variable::retryCount);
124#endif
125}
126
127// Create a Hub device with a given offset
128rim::Variable::Variable(std::string name,
129 std::string mode,
130 double minimum,
131 double maximum,
132 uint64_t offset,
133 std::vector<uint32_t> bitOffset,
134 std::vector<uint32_t> bitSize,
135 bool overlapEn,
136 bool verifyEn,
137 bool bulkOpEn,
138 bool updateNotify,
139 uint32_t modelId,
140 bool byteReverse,
141 bool bitReverse,
142 uint32_t binPoint,
143 uint32_t numValues,
144 uint32_t valueBits,
145 uint32_t valueStride,
146 uint32_t retryCount) {
147 uint32_t x;
148 uint32_t bl;
149
150 name_ = name;
151 path_ = name;
152 mode_ = mode;
153 modelId_ = modelId;
154 offset_ = offset;
155 bitOffset_ = bitOffset;
156 bitSize_ = bitSize;
157 overlapEn_ = overlapEn;
158 verifyEn_ = verifyEn;
159 byteReverse_ = byteReverse;
160 bitReverse_ = bitReverse;
161 bulkOpEn_ = bulkOpEn;
162 updateNotify_ = updateNotify;
163 minValue_ = minimum;
164 maxValue_ = maximum;
165 binPoint_ = binPoint;
166 numValues_ = numValues;
167 valueBits_ = valueBits;
168 valueStride_ = valueStride;
169 retryCount_ = retryCount;
170
171 // Not a list variable
172 if (numValues_ == 0) {
173 // Compute bit total
174 bitTotal_ = bitSize_[0];
175 for (x = 1; x < bitSize_.size(); x++) bitTotal_ += bitSize_[x];
176
177 // Compute rounded up byte size
178 byteSize_ = static_cast<int>(std::ceil(static_cast<float>(bitTotal_) / 8.0));
179
180 lowTranByte_ = reinterpret_cast<uint32_t*>(malloc(sizeof(uint32_t)));
181 highTranByte_ = reinterpret_cast<uint32_t*>(malloc(sizeof(uint32_t)));
182
183 // Init remaining fields
184 valueBytes_ = byteSize_;
185 valueBits_ = bitTotal_;
186 valueStride_ = bitTotal_;
187
188 // List variables
189 } else {
190 // Compute bit total
191 bitTotal_ = bitSize_[0];
192
193 // Compute rounded up byte size
194 byteSize_ = static_cast<int>(std::ceil(static_cast<float>(bitTotal_) / 8.0));
195
196 // Compute total bit range of accessed bits
197 valueBytes_ = static_cast<uint32_t>(std::ceil(static_cast<float>(valueBits_) / 8.0));
198
199 // High and low byte tracking
200 lowTranByte_ = reinterpret_cast<uint32_t*>(malloc(numValues_ * sizeof(uint32_t)));
201 highTranByte_ = reinterpret_cast<uint32_t*>(malloc(numValues_ * sizeof(uint32_t)));
202 }
203
204 // Byte array for fast copies
205 fastByte_ = NULL;
206
207 // Determine if fast byte copies can be utilized
208 // Bit offset vector must have one entry, the offset must be byte aligned and the total number of bits must be byte
209 // aligned
210 if ((bitOffset_.size() == 1) && (bitOffset_[0] % 8 == 0) && (bitSize_[0] % 8 == 0)) {
211 // Standard variable
212 if (numValues_ == 0) {
213 fastByte_ = reinterpret_cast<uint32_t*>(malloc(sizeof(uint32_t)));
214
215 // List variable
216 } else if ((valueBits_ % 8) == 0 && (valueStride_ % 8) == 0) {
217 fastByte_ = reinterpret_cast<uint32_t*>(malloc(numValues_ * sizeof(uint32_t)));
218 }
219 }
220 stale_ = false;
221
222 // Call aligning function to init values
223 shiftOffsetDown(0, 1);
224
225 // Custom data is NULL for now
226 customData_ = NULL;
227
228 // Set default C++ pointers
229 setByteArray_ = NULL;
230 getByteArray_ = NULL;
231 setUInt_ = NULL;
232 getUInt_ = NULL;
233 setInt_ = NULL;
234 getInt_ = NULL;
235 setBool_ = NULL;
236 getBool_ = NULL;
237 setString_ = NULL;
238 getString_ = NULL;
239 setFloat_ = NULL;
240 getFloat_ = NULL;
241 setDouble_ = NULL;
242 getDouble_ = NULL;
243 setFixed_ = NULL;
244 getFixed_ = NULL;
245
246 // Define set function
247 switch (modelId_) {
248 case rim::PyFunc:
249 break;
250
251 case rim::Bytes:
252 setByteArray_ = &rim::Block::setByteArray;
253 break;
254
255 case rim::UInt:
256 if (valueBits_ > 64)
257 setByteArray_ = &rim::Block::setByteArray;
258 else
259 setUInt_ = &rim::Block::setUInt;
260 break;
261
262 case rim::Int:
263 if (valueBits_ > 64)
264 setByteArray_ = &rim::Block::setByteArray;
265 else
266 setInt_ = &rim::Block::setInt;
267 break;
268
269 case rim::Bool:
270 setBool_ = &rim::Block::setBool;
271 break;
272
273 case rim::String:
274 setString_ = &rim::Block::setString;
275 break;
276
277 case rim::Float:
278 setFloat_ = &rim::Block::setFloat;
279 break;
280
281 case rim::Double:
282 setDouble_ = &rim::Block::setDouble;
283 break;
284
285 case rim::Fixed:
286 setFixed_ = &rim::Block::setFixed;
287 break;
288
289 default:
290 break;
291 }
292
293 // Define get function, C++
294 switch (modelId_) {
295 case rim::PyFunc:
296 break;
297
298 case rim::Bytes:
299 getByteArray_ = &rim::Block::getByteArray;
300 break;
301
302 case rim::UInt:
303 if (valueBits_ > 64)
304 getByteArray_ = &rim::Block::getByteArray;
305 else
306 getUInt_ = &rim::Block::getUInt;
307 break;
308
309 case rim::Int:
310 if (valueBits_ > 64)
311 getByteArray_ = &rim::Block::getByteArray;
312 else
313 getInt_ = &rim::Block::getInt;
314 break;
315
316 case rim::Bool:
317 getBool_ = &rim::Block::getBool;
318 break;
319
320 case rim::String:
321 getString_ = &rim::Block::getString;
322 break;
323
324 case rim::Float:
325 getFloat_ = &rim::Block::getFloat;
326 break;
327
328 case rim::Double:
329 getDouble_ = &rim::Block::getDouble;
330 break;
331
332 case rim::Fixed:
333 getFixed_ = &rim::Block::getFixed;
334 break;
335
336 default:
337 break;
338 }
339
340#ifndef NO_PYTHON
341
342 // Define set function, python
343 switch (modelId_) {
344 case rim::PyFunc:
345 setFuncPy_ = &rim::Block::setPyFunc;
346 break;
347
348 case rim::Bytes:
349 setFuncPy_ = &rim::Block::setByteArrayPy;
350 break;
351
352 case rim::UInt:
353 if (valueBits_ > 64)
354 setFuncPy_ = &rim::Block::setPyFunc;
355 else
356 setFuncPy_ = &rim::Block::setUIntPy;
357 break;
358
359 case rim::Int:
360 if (valueBits_ > 64)
361 setFuncPy_ = &rim::Block::setPyFunc;
362 else
363 setFuncPy_ = &rim::Block::setIntPy;
364 break;
365
366 case rim::Bool:
367 setFuncPy_ = &rim::Block::setBoolPy;
368 break;
369
370 case rim::String:
371 setFuncPy_ = &rim::Block::setStringPy;
372 break;
373
374 case rim::Float:
375 setFuncPy_ = &rim::Block::setFloatPy;
376 break;
377
378 case rim::Double:
379 setFuncPy_ = &rim::Block::setDoublePy;
380 break;
381
382 case rim::Fixed:
383 setFuncPy_ = &rim::Block::setFixedPy;
384 break;
385
386 default:
387 getFuncPy_ = NULL;
388 break;
389 }
390
391 // Define get function, python
392 switch (modelId_) {
393 case rim::PyFunc:
394 getFuncPy_ = &rim::Block::getPyFunc;
395 break;
396
397 case rim::Bytes:
398 getFuncPy_ = &rim::Block::getByteArrayPy;
399 break;
400
401 case rim::UInt:
402 if (valueBits_ > 64)
403 getFuncPy_ = &rim::Block::getPyFunc;
404 else
405 getFuncPy_ = &rim::Block::getUIntPy;
406 break;
407
408 case rim::Int:
409 if (valueBits_ > 64)
410 getFuncPy_ = &rim::Block::getPyFunc;
411 else
412 getFuncPy_ = &rim::Block::getIntPy;
413 break;
414
415 case rim::Bool:
416 getFuncPy_ = &rim::Block::getBoolPy;
417 break;
418
419 case rim::String:
420 getFuncPy_ = &rim::Block::getStringPy;
421 break;
422
423 case rim::Float:
424 getFuncPy_ = &rim::Block::getFloatPy;
425 break;
426
427 case rim::Double:
428 getFuncPy_ = &rim::Block::getDoublePy;
429 break;
430
431 case rim::Fixed:
432 getFuncPy_ = &rim::Block::getFixedPy;
433 break;
434
435 default:
436 getFuncPy_ = NULL;
437 break;
438 }
439
440#endif
441}
442
443// Destroy the variable
444rim::Variable::~Variable() {
445 if (lowTranByte_ != NULL) free(lowTranByte_);
446 if (highTranByte_ != NULL) free(highTranByte_);
447 if (fastByte_ != NULL) free(fastByte_);
448}
449
450// Shift offset down
451void rim::Variable::shiftOffsetDown(uint32_t shift, uint32_t minSize) {
452 uint32_t x;
453
454 if (shift != 0) {
455 offset_ -= shift;
456 for (x = 0; x < bitOffset_.size(); x++) bitOffset_[x] += shift * 8;
457 }
458
459 // Standard variable
460 if (numValues_ == 0) {
461 // Compute total bit range of accessed bytes
462 varBytes_ = static_cast<int>(std::ceil(
463 static_cast<float>(bitOffset_[bitOffset_.size() - 1] + bitSize_[bitSize_.size() - 1]) /
464 (static_cast<float>(minSize) * 8.0))) *
465 minSize;
466
467 // Compute the lowest byte, aligned to min access
468 lowTranByte_[0] =
469 static_cast<int>(std::floor(static_cast<float>(bitOffset_[0]) / (static_cast<float>(minSize) * 8.0))) *
470 minSize;
471
472 // Compute the highest byte, aligned to min access
473 highTranByte_[0] = varBytes_ - 1;
474 staleHighByte_ = highTranByte_[0];
475
476 // List variable
477 } else {
478 for (x = 0; x < numValues_; x++) {
479 lowTranByte_[x] =
480 static_cast<uint32_t>(std::floor(
481 (static_cast<float>(bitOffset_[0]) + static_cast<float>(x) * static_cast<float>(valueStride_)) /
482 (static_cast<float>(minSize) * 8.0))) *
483 minSize;
484 highTranByte_[x] = static_cast<uint32_t>(
485 std::ceil((static_cast<float>(bitOffset_[0]) +
486 static_cast<float>(x) * static_cast<float>(valueStride_) + valueBits_) /
487 (static_cast<float>(minSize) * 8.0))) *
488 minSize -
489 1;
490 }
491
492 // Compute total bit range of accessed bytes
493 varBytes_ = highTranByte_[numValues_ - 1] + 1;
494 staleHighByte_ = highTranByte_[numValues_ - 1];
495 }
496
497 // Adjust fast copy locations
498 if (fastByte_ != NULL) {
499 if (numValues_ == 0) {
500 fastByte_[0] = bitOffset_[0] / 8;
501
502 // List variable
503 } else {
504 for (x = 0; x < numValues_; x++) fastByte_[x] = (bitOffset_[0] + (valueStride_ * x)) / 8;
505 }
506 }
507
508 staleLowByte_ = lowTranByte_[0];
509}
510
511void rim::Variable::updatePath(std::string path) {
512 path_ = path;
513}
514
516double rim::Variable::minimum() {
517 return minValue_;
518}
519
521double rim::Variable::maximum() {
522 return maxValue_;
523}
524
526uint32_t rim::Variable::varBytes() {
527 return varBytes_;
528}
529
531uint64_t rim::Variable::offset() {
532 return offset_;
533}
534
536bool rim::Variable::verifyEn() {
537 return verifyEn_;
538}
539
541bool rim::Variable::overlapEn() {
542 return overlapEn_;
543}
544
546bool rim::Variable::bulkOpEn() {
547 return bulkOpEn_;
548}
549
550#ifndef NO_PYTHON
551// Create a Variable
552rim::VariableWrap::VariableWrap(std::string name,
553 std::string mode,
554 bp::object minimum,
555 bp::object maximum,
556 uint64_t offset,
557 bp::object bitOffset,
558 bp::object bitSize,
559 bool overlapEn,
560 bool verify,
561 bool bulkOpEn,
562 bool updateNotify,
563 bp::object model,
564 bp::object listData,
565 uint32_t retryCount)
566
567 : rim::Variable(name,
568 mode,
569 py_object_convert<double>(minimum),
570 py_object_convert<double>(maximum),
571 offset,
572 py_list_to_std_vector<uint32_t>(bitOffset),
573 py_list_to_std_vector<uint32_t>(bitSize),
574 overlapEn,
575 verify,
576 bulkOpEn,
577 updateNotify,
578 bp::extract<uint32_t>(model.attr("modelId")),
579 bp::extract<bool>(model.attr("isBigEndian")),
580 bp::extract<bool>(model.attr("bitReverse")),
581 bp::extract<uint32_t>(model.attr("binPoint")),
582 bp::extract<uint32_t>(listData.attr("numValues")),
583 bp::extract<uint32_t>(listData.attr("valueBits")),
584 bp::extract<uint32_t>(listData.attr("valueStride")),
585 retryCount) {
586 model_ = model;
587}
588
590void rim::VariableWrap::set(bp::object& value, int32_t index) {
591 if (setFuncPy_ == NULL || block_->blockPyTrans()) return;
592 (block_->*setFuncPy_)(value, this, index);
593}
594
596bp::object rim::VariableWrap::get(int32_t index) {
597 if (getFuncPy_ == NULL) {
598 bp::handle<> handle(bp::borrowed(Py_None));
599 return bp::object(handle);
600 }
601 return (block_->*getFuncPy_)(this, index);
602}
603
604// Set data using python function
605bp::object rim::VariableWrap::toBytes(bp::object& value) {
606 return model_.attr("toBytes")(value);
607}
608
609// Get data using python function
610bp::object rim::VariableWrap::fromBytes(bp::object& value) {
611 return model_.attr("fromBytes")(value);
612}
613
614void rim::VariableWrap::defQueueUpdate() {
615 rim::Variable::queueUpdate();
616}
617
618// Queue update
619void rim::VariableWrap::queueUpdate() {
621
622 if (bp::override pb = this->get_override("_queueUpdate")) {
623 try {
624 pb();
625 return;
626 } catch (...) {
627 PyErr_Print();
628 }
629 }
630}
631
632bp::object rim::VariableWrap::bitOffset() {
633 return std_vector_to_py_list<uint32_t>(bitOffset_);
634}
635
636bp::object rim::VariableWrap::bitSize() {
637 return std_vector_to_py_list<uint32_t>(bitSize_);
638}
639
640#endif // ! NO_PYTHON
641
642void rim::Variable::queueUpdate() {}
643
644void rim::Variable::rateTest() {
645 uint64_t x;
646
647 struct timeval stime;
648 struct timeval etime;
649 struct timeval dtime;
650
651 uint64_t count = 1000000;
652 double durr;
653 double rate;
654 uint32_t ret;
655
656 gettimeofday(&stime, NULL);
657 for (x = 0; x < count; ++x) {
658 ret = getUInt();
659 }
660 gettimeofday(&etime, NULL);
661
662 timersub(&etime, &stime, &dtime);
663 durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
664 rate = count / durr;
665
666 printf("\nVariable c++ get: Read %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
667
668 gettimeofday(&stime, NULL);
669 for (x = 0; x < count; ++x) {
670 setUInt(x);
671 }
672 gettimeofday(&etime, NULL);
673
674 timersub(&etime, &stime, &dtime);
675 durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
676 rate = count / durr;
677
678 printf("\nVariable c++ set: Wrote %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
679}
680
681void rim::Variable::setLogLevel(uint32_t level) {
682 if (block_) block_->setLogLevel(level);
683}
684
685void rim::Variable::read() {
686 block_->read(this);
687}
688
690std::string rim::Variable::getDumpValue(bool read) {
691 std::stringstream ret;
692 uint32_t x;
693 int32_t index;
694
695 uint8_t byteData[valueBytes_];
696
697 memset(byteData, 0, valueBytes_);
698
699 if (read) block_->read(this);
700
701 ret << path_ << " =";
702
703 if (numValues_ == 0)
704 index = -1;
705 else
706 index = 0;
707
708 while (index < static_cast<int32_t>(numValues_)) {
709 ret << " ";
710
711 switch (modelId_) {
712 case rim::Bytes:
713 (block_->*getByteArray_)(byteData, this, index);
714 ret << "0x";
715 for (x = 0; x < valueBytes_; x++)
716 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
717 break;
718
719 case rim::UInt:
720 if (valueBits_ > 64) {
721 (block_->*getByteArray_)(byteData, this, index);
722 ret << "0x";
723 for (x = 0; x < valueBytes_; x++)
724 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
725 } else {
726 ret << (block_->*getUInt_)(this, index);
727 }
728 break;
729
730 case rim::Int:
731 if (valueBits_ > 64) {
732 (block_->*getByteArray_)(byteData, this, index);
733 ret << "0x";
734 for (x = 0; x < valueBytes_; x++)
735 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
736 } else {
737 ret << (block_->*getInt_)(this, index);
738 }
739 break;
740
741 case rim::Bool:
742 ret << (block_->*getBool_)(this, index);
743 break;
744
745 case rim::String:
746 ret << (block_->*getString_)(this, index);
747 break;
748
749 case rim::Float:
750 ret << (block_->*getFloat_)(this, index);
751 break;
752
753 case rim::Double:
754 ret << (block_->*getDouble_)(this, index);
755 break;
756
757 case rim::Fixed:
758 ret << (block_->*getFixed_)(this, index);
759 break;
760
761 default:
762 ret << "UNDEFINED";
763 break;
764 }
765 index++;
766 }
767
768 ret << "\n";
769 return ret.str();
770}
771
773// C++ Byte Array
775
776void rim::Variable::setByteArray(uint8_t* value, int32_t index) {
777 if (setByteArray_ == NULL)
778 throw(rogue::GeneralError::create("Variable::setByteArray", "Wrong set type for variable %s", path_.c_str()));
779
780 (block_->*setByteArray_)(value, this, index);
781 block_->write(this, index);
782}
783
784void rim::Variable::getByteArray(uint8_t* value, int32_t index) {
785 if (getByteArray_ == NULL)
786 throw(rogue::GeneralError::create("Variable::getByteArray", "Wrong get type for variable %s", path_.c_str()));
787
788 block_->read(this, index);
789 (block_->*getByteArray_)(value, this, index);
790}
791
793// C++ Uint
795
796void rim::Variable::setUInt(uint64_t& value, int32_t index) {
797 if (setUInt_ == NULL)
798 throw(rogue::GeneralError::create("Variable::setUInt", "Wrong set type for variable %s", path_.c_str()));
799
800 (block_->*setUInt_)(value, this, index);
801 block_->write(this, index);
802}
803
804uint64_t rim::Variable::getUInt(int32_t index) {
805 if (getUInt_ == NULL)
806 throw(rogue::GeneralError::create("Variable::getUInt", "Wrong get type for variable %s", path_.c_str()));
807
808 block_->read(this, index);
809 return (block_->*getUInt_)(this, index);
810}
811
813// C++ int
815
816void rim::Variable::setInt(int64_t& value, int32_t index) {
817 if (setInt_ == NULL)
818 throw(rogue::GeneralError::create("Variable::setInt", "Wrong set type for variable %s", path_.c_str()));
819
820 (block_->*setInt_)(value, this, index);
821 block_->write(this, index);
822}
823
824int64_t rim::Variable::getInt(int32_t index) {
825 if (getInt_ == NULL)
826 throw(rogue::GeneralError::create("Variable::getInt", "Wrong get type for variable %s", path_.c_str()));
827
828 block_->read(this, index);
829 return (block_->*getInt_)(this, index);
830}
831
833// C++ bool
835
836void rim::Variable::setBool(bool& value, int32_t index) {
837 if (setBool_ == NULL)
838 throw(rogue::GeneralError::create("Variable::setBool", "Wrong set type for variable %s", path_.c_str()));
839
840 (block_->*setBool_)(value, this, index);
841 block_->write(this, index);
842}
843
844bool rim::Variable::getBool(int32_t index) {
845 if (getBool_ == NULL)
846 throw(rogue::GeneralError::create("Variable::getBool", "Wrong get type for variable %s", path_.c_str()));
847
848 block_->read(this, index);
849 return (block_->*getBool_)(this, index);
850}
851
853// C++ String
855
856void rim::Variable::setString(const std::string& value, int32_t index) {
857 if (setString_ == NULL)
858 throw(rogue::GeneralError::create("Variable::setString", "Wrong set type for variable %s", path_.c_str()));
859
860 (block_->*setString_)(value, this, index);
861 block_->write(this, index);
862}
863
864std::string rim::Variable::getString(int32_t index) {
865 if (getString_ == NULL)
866 throw(rogue::GeneralError::create("Variable::getString", "Wrong get type for variable %s", path_.c_str()));
867
868 block_->read(this, index);
869 return (block_->*getString_)(this, index);
870}
871
872void rim::Variable::getValue(std::string& valueRet, int32_t index) {
873 if (getString_ == NULL) {
874 throw(rogue::GeneralError::create("Variable::getValue", "Wrong get type for variable %s", path_.c_str()));
875 } else {
876 block_->read(this, index);
877 block_->getValue(this, valueRet, index);
878 }
879}
880
882// C++ Float
884
885void rim::Variable::setFloat(float& value, int32_t index) {
886 if (setFloat_ == NULL)
887 throw(rogue::GeneralError::create("Variable::setFloat", "Wrong set type for variable %s", path_.c_str()));
888
889 (block_->*setFloat_)(value, this, index);
890 block_->write(this, index);
891}
892
893float rim::Variable::getFloat(int32_t index) {
894 if (getFloat_ == NULL)
895 throw(rogue::GeneralError::create("Variable::getFloat", "Wrong get type for variable %s", path_.c_str()));
896
897 block_->read(this, index);
898 return (block_->*getFloat_)(this, index);
899}
900
902// C++ double
904
905void rim::Variable::setDouble(double& value, int32_t index) {
906 if (setDouble_ == NULL)
907 throw(rogue::GeneralError::create("Variable::setDouble", "Wrong set type for variable %s", path_.c_str()));
908
909 (block_->*setDouble_)(value, this, index);
910 block_->write(this, index);
911}
912
913double rim::Variable::getDouble(int32_t index) {
914 if (getDouble_ == NULL)
915 throw(rogue::GeneralError::create("Variable::getDouble", "Wrong get type for variable %s", path_.c_str()));
916
917 block_->read(this, index);
918 return (block_->*getDouble_)(this, index);
919}
920
922// C++ fixed point
924
925void rim::Variable::setFixed(double& value, int32_t index) {
926 if (setFixed_ == NULL)
927 throw(rogue::GeneralError::create("Variable::setFixed", "Wrong set type for variable %s", path_.c_str()));
928
929 (block_->*setFixed_)(value, this, index);
930 block_->write(this, index);
931}
932
933double rim::Variable::getFixed(int32_t index) {
934 if (getFixed_ == NULL)
935 throw(rogue::GeneralError::create("Variable::getFixed", "Wrong get type for variable %s", path_.c_str()));
936
937 block_->read(this, index);
938 return (block_->*getFixed_)(this, index);
939}
static GeneralError create(std::string src, const char *fmt,...)
Creates a formatted error instance.
RAII helper that acquires the Python GIL for a scope.
Definition ScopedGil.h:35
Memory variable descriptor and typed accessor facade.
Definition Variable.h:62
uint32_t retryCount()
Returns retry count.
Definition Variable.h:478
uint64_t offset()
Returns variable byte offset.
Definition Variable.cpp:531
uint32_t modelId() const
Returns model ID of the variable.
Definition Variable.h:399
const std::string & mode() const
Returns variable mode string.
Definition Variable.h:427
bool bulkOpEn()
Returns bulk-operation enable flag.
Definition Variable.cpp:546
double maximum()
Returns maximum value.
Definition Variable.cpp:521
double minimum()
Returns minimum value.
Definition Variable.cpp:516
bool overlapEn()
Returns overlap-enable flag.
Definition Variable.cpp:541
uint32_t valueBits()
Returns number of bits per value.
Definition Variable.h:463
uint32_t numValues()
Returns number of values.
Definition Variable.h:458
uint32_t valueStride()
Returns byte stride per value.
Definition Variable.h:473
const std::string & name() const
Returns variable name.
Definition Variable.h:414
static const uint8_t Fixed
Block access type for fixed-point numeric data.
Definition Constants.h:134
T py_object_convert(const boost::python::object &obj)
Definition Block.h:59
static const uint8_t Double
Block access type for double-precision (double) data.
Definition Constants.h:127
static const uint8_t Bytes
Block access type for raw byte data.
Definition Constants.h:85
static const uint8_t UInt
Block access type for unsigned integer data.
Definition Constants.h:92
static const uint8_t String
Block access type for string data.
Definition Constants.h:113
static const uint8_t PyFunc
Block access type for Python callback functions.
Definition Constants.h:78
static const uint8_t Bool
Block access type for boolean data.
Definition Constants.h:106
std::vector< T > py_list_to_std_vector(const boost::python::object &iterable)
Definition Block.h:42
static const uint8_t Float
Block access type for floating-point (float) data.
Definition Constants.h:120
std::shared_ptr< rogue::interfaces::memory::Variable > VariablePtr
Definition Variable.h:43
static const uint8_t Int
Block access type for signed integer data.
Definition Constants.h:99