10 #include <boost/make_shared.hpp>
33 assert(
_lock.owns_lock());
37 std::unique_lock<std::recursive_mutex>
_lock;
46 if(numberOfBits == 0) {
50 return (
static_cast<uint64_t
>(-(numberOfBits != 0)) &
51 (
static_cast<uint64_t
>(-1) >> ((
sizeof(uint64_t) * CHAR_BIT) - numberOfBits)));
56 template<
typename UserType,
typename TargetType>
63 uint64_t shift, uint64_t numberOfBits, uint64_t dataInterpretationFractionalBits,
64 uint64_t dataInterpretationIsSigned)
68 if(_target->getNumberOfChannels() > 1 || _target->getNumberOfSamples() > 1) {
73 auto& map = boost::fusion::at_key<TargetType>(backend->sharedAccessorMap.table);
78 auto it = map.find(key);
80 _lock = {it->second.mutex, &(it->second.useCount)};
95 _target->preRead(type);
101 auto unlock = cppext::finally([
this] { this->
_lock.
unlock(); });
102 _target->postRead(type, hasNewData);
103 if(!hasNewData)
return;
105 if constexpr(std::is_same_v<uint64_t, TargetType>) {
106 auto validity = _target->dataValidity();
107 uint64_t v{_target->accessData(0)};
120 this->_versionNumber = std::max(this->_versionNumber, _target->getVersionNumber());
121 this->_dataValidity = validity;
152 _target->accessData(0) |= (value <<
_shift);
155 _target->setDataValidity(this->_dataValidity);
162 auto unlock = cppext::finally([
this] { this->
_lock.
unlock(); });
169 auto casted = boost::dynamic_pointer_cast<BitRangeAccessPluginDecorator<UserType, TargetType>>(newElement);
175 if(casted && casted.get() !=
this && casted->_target == _target) {
177 casted->_writeable =
false;
204 const LNMBackendRegisterInfo& info,
size_t pluginIndex,
const std::map<std::string, std::string>& parameters)
207 const auto& shift = parameters.at(
"shift");
211 auto [suffix, ec]{std::from_chars(shift.data(), shift.data() + shift.size(),
_shift)};
212 if(ec != std::errc()) {
214 R
"(: Unparseable parameter "shift".)");
217 catch(std::out_of_range&) {
219 R
"(: Missing parameter "shift".)");
223 const auto& numberOfBits = parameters.at(
"numberOfBits");
226 auto [suffix, ec]{std::from_chars(numberOfBits.data(), numberOfBits.data() + numberOfBits.size(),
_numberOfBits)};
227 if(ec != std::errc()) {
229 R
"(: Unparseable parameter "numberOfBits".)");
232 catch(std::out_of_range&) {
234 R
"(: Unparseable parameter "numberOfBits".)");
237 if(
const auto it = parameters.find(
"fractionalBits"); it != parameters.end()) {
242 if(ec != std::errc()) {
244 R
"(: Unparseable parameter "fractionalBits".)");
248 if(
const auto it = parameters.find(
"signed"); it != parameters.end()) {
249 std::stringstream ss(it->second);
268 template<
typename UserType,
typename TargetType>
272 if constexpr(std::is_integral<TargetType>::value) {
273 return boost::make_shared<BitRangeAccessPluginDecorator<UserType, TargetType>>(backend, target, params.
_name,