ChimeraTK-DeviceAccess  03.18.00
ChimeraTK::OneDRegisterAccessor< UserType > Class Template Reference

Accessor class to read and write registers transparently by using the accessor object like a vector of the type UserType. More...

#include <OneDRegisterAccessor.h>

+ Inheritance diagram for ChimeraTK::OneDRegisterAccessor< UserType >:
+ Collaboration diagram for ChimeraTK::OneDRegisterAccessor< UserType >:

Public Types

using iterator = typename std::vector< UserType >::iterator
 
using const_iterator = typename std::vector< UserType >::const_iterator
 
using reverse_iterator = typename std::vector< UserType >::reverse_iterator
 
using const_reverse_iterator = typename std::vector< UserType >::const_reverse_iterator
 

Public Member Functions

 OneDRegisterAccessor (boost::shared_ptr< NDRegisterAccessor< UserType >> impl)
 Create accessor from pointer to implementation. More...
 
 OneDRegisterAccessor ()
 Placeholder constructer, to allow late initialisation of the accessor, e.g. More...
 
UserType & operator[] (unsigned int element)
 Get or set buffer content by [] operator. More...
 
unsigned int getNElements ()
 Return number of elements/samples in the register. More...
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator crbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
const_reverse_iterator crend () const
 
void swap (std::vector< UserType > &x) noexcept
 Swap content of (cooked) buffer with std::vector. More...
 
OneDRegisterAccessor< UserType > & operator= (const std::vector< UserType > &x)
 Copy content of (cooked) buffer from std::vector. More...
 
 operator const std::vector< UserType > & ()
 Convert content of (cooked) buffer into std::vector. More...
 
UserType * data ()
 Return a direct pointer to the memory buffer storng the elements. More...
 
template<typename COOKED_TYPE >
COOKED_TYPE getAsCooked (unsigned int sample)
 Get the cooked values in case the accessor is a raw accessor (which does not do data conversion). More...
 
template<typename COOKED_TYPE >
void setAsCooked (unsigned int sample, COOKED_TYPE value)
 Set the cooked values in case the accessor is a raw accessor (which does not do data conversion). More...
 
void writeIfDifferent (const std::vector< UserType > &newValue, VersionNumber versionNumber=VersionNumber{nullptr}, DataValidity validity=DataValidity::ok)
 Convenience function to set and write new value if it differes from the current value. More...
 
- Public Member Functions inherited from ChimeraTK::NDRegisterAccessorAbstractor< UserType >
 NDRegisterAccessorAbstractor ()=default
 Create an uninitialised abstractor - just for late initialisation. More...
 
 NDRegisterAccessorAbstractor (const NDRegisterAccessorAbstractor &)=default
 Declare that we want the default copy constructor although we delete the assigmnent operator. More...
 
void replace (const NDRegisterAccessorAbstractor< UserType > &newAccessor)
 Assign a new accessor to this NDRegisterAccessorAbstractor. More...
 
void replace (boost::shared_ptr< NDRegisterAccessor< UserType >> newImpl)
 Alternative signature of replace() with the same functionality, used when a pointer to the implementation has been obtained directly (instead of a NDRegisterAccessorAbstractor). More...
 
const NDRegisterAccessorAbstractoroperator= (const NDRegisterAccessorAbstractor &rightHandSide) const =delete
 Prevent copying by operator=, since it will be confusing (operator= may also be overloaded to access the content of the buffer!) More...
 
boost::shared_ptr< NDRegisterAccessor< UserType > > getImpl ()
 
- Public Member Functions inherited from ChimeraTK::TransferElementAbstractor
 TransferElementAbstractor (boost::shared_ptr< TransferElement > impl)
 Construct from TransferElement implementation. More...
 
 TransferElementAbstractor ()=default
 Create an uninitialised abstractor - just for late initialisation. More...
 
const std::string & getName () const
 Returns the name that identifies the process variable. More...
 
const std::string & getUnit () const
 Returns the engineering unit. More...
 
const std::string & getDescription () const
 Returns the description of this variable/register. More...
 
const std::type_info & getValueType () const
 Returns the std::type_info for the value type of this transfer element. More...
 
AccessModeFlags getAccessModeFlags () const
 Return the AccessModeFlags for this TransferElement. More...
 
void read ()
 Read the data from the device. More...
 
bool readNonBlocking ()
 Read the next value, if available in the input buffer. More...
 
bool readLatest ()
 Read the latest value, discarding any other update since the last read if present. More...
 
ChimeraTK::VersionNumber getVersionNumber () const
 Returns the version number that is associated with the last transfer (i.e. More...
 
bool write (ChimeraTK::VersionNumber versionNumber={})
 Write the data to device. More...
 
bool writeDestructively (ChimeraTK::VersionNumber versionNumber={})
 Just like write(), but allows the implementation to destroy the content of the user buffer in the process. More...
 
bool isReadOnly () const
 Check if transfer element is read only, i.e. More...
 
bool isReadable () const
 Check if transfer element is readable. More...
 
bool isWriteable () const
 Check if transfer element is writeable. More...
 
std::vector< boost::shared_ptr< TransferElement > > getHardwareAccessingElements ()
 Obtain the underlying TransferElements with actual hardware access. More...
 
std::list< boost::shared_ptr< TransferElement > > getInternalElements ()
 Obtain the full list of TransferElements internally used by this TransferElement. More...
 
const boost::shared_ptr< TransferElement > & getHighLevelImplElement ()
 Obtain the highest level implementation TransferElement. More...
 
bool isInitialised () const
 Return if the accessor is properly initialised. More...
 
void replace (const TransferElementAbstractor &newAccessor)
 Assign a new accessor to this TransferElementAbstractor. More...
 
void replace (boost::shared_ptr< TransferElement > newImpl)
 Alternative signature of relace() with the same functionality, used when a pointer to the implementation has been obtained directly (instead of a TransferElementAbstractor). More...
 
void replaceTransferElement (const boost::shared_ptr< TransferElement > &newElement)
 Search for all underlying TransferElements which are considered identical (see mayReplaceOther()) with the given TransferElement. More...
 
void setPersistentDataStorage (boost::shared_ptr< ChimeraTK::PersistentDataStorage > storage)
 Associate a persistent data storage object to be updated on each write operation of this ProcessArray. More...
 
TransferElementID getId () const
 Obtain unique ID for the actual implementation of this TransferElement. More...
 
void setDataValidity (DataValidity valid=DataValidity::ok)
 Set the current DataValidity for this TransferElement. More...
 
DataValidity dataValidity () const
 Return current validity of the data. More...
 
void interrupt ()
 Return from a blocking read immediately and throw boost::thread_interrupted. More...
 

Friends

class TransferGroup
 

Additional Inherited Members

- Protected Member Functions inherited from ChimeraTK::NDRegisterAccessorAbstractor< UserType >
 NDRegisterAccessorAbstractor (boost::shared_ptr< NDRegisterAccessor< UserType >> impl)
 
NDRegisterAccessor< UserType > * get ()
 
const NDRegisterAccessor< UserType > * get () const
 
- Protected Attributes inherited from ChimeraTK::TransferElementAbstractor
boost::shared_ptr< TransferElement_impl
 Untyped pointer to implementation. More...
 

Detailed Description

template<typename UserType>
class ChimeraTK::OneDRegisterAccessor< UserType >

Accessor class to read and write registers transparently by using the accessor object like a vector of the type UserType.

Conversion to and from the UserType will be handled by a data converter matching the register description in the map (if applicable). Obtain the accessor using the Device::getBufferingRegisterAccessor() function.

Note: Transfers between the device and the internal buffer need to be triggered using the read() and write() functions before reading from resp. after writing to the buffer using the operators.

Examples
accessor1D.cpp.

Definition at line 20 of file OneDRegisterAccessor.h.

Member Typedef Documentation

◆ const_iterator

template<typename UserType >
using ChimeraTK::OneDRegisterAccessor< UserType >::const_iterator = typename std::vector<UserType>::const_iterator

Definition at line 55 of file OneDRegisterAccessor.h.

◆ const_reverse_iterator

template<typename UserType >
using ChimeraTK::OneDRegisterAccessor< UserType >::const_reverse_iterator = typename std::vector<UserType>::const_reverse_iterator

Definition at line 57 of file OneDRegisterAccessor.h.

◆ iterator

template<typename UserType >
using ChimeraTK::OneDRegisterAccessor< UserType >::iterator = typename std::vector<UserType>::iterator

Definition at line 54 of file OneDRegisterAccessor.h.

◆ reverse_iterator

template<typename UserType >
using ChimeraTK::OneDRegisterAccessor< UserType >::reverse_iterator = typename std::vector<UserType>::reverse_iterator

Definition at line 56 of file OneDRegisterAccessor.h.

Constructor & Destructor Documentation

◆ OneDRegisterAccessor() [1/2]

template<typename UserType >
ChimeraTK::OneDRegisterAccessor< UserType >::OneDRegisterAccessor ( boost::shared_ptr< NDRegisterAccessor< UserType >>  impl)

Create accessor from pointer to implementation.

Attention
Do not normally use directly. Users should call Device::getOneDRegisterAccessor() to obtain an instance instead.

Definition at line 129 of file OneDRegisterAccessor.h.

◆ OneDRegisterAccessor() [2/2]

template<typename UserType >
ChimeraTK::OneDRegisterAccessor< UserType >::OneDRegisterAccessor

Placeholder constructer, to allow late initialisation of the accessor, e.g.

in the open function.

Attention
Accessors created with this constructors will be dysfunctional, calling any member function will throw an exception (by the boost::shared_ptr)!

Definition at line 143 of file OneDRegisterAccessor.h.

Member Function Documentation

◆ begin() [1/2]

template<typename UserType >
iterator ChimeraTK::OneDRegisterAccessor< UserType >::begin ( )
inline

Definition at line 58 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ begin() [2/2]

template<typename UserType >
const_iterator ChimeraTK::OneDRegisterAccessor< UserType >::begin ( ) const
inline

Definition at line 59 of file OneDRegisterAccessor.h.

◆ cbegin()

template<typename UserType >
const_iterator ChimeraTK::OneDRegisterAccessor< UserType >::cbegin ( ) const
inline

Definition at line 60 of file OneDRegisterAccessor.h.

◆ cend()

template<typename UserType >
const_iterator ChimeraTK::OneDRegisterAccessor< UserType >::cend ( ) const
inline

Definition at line 63 of file OneDRegisterAccessor.h.

◆ crbegin()

template<typename UserType >
const_reverse_iterator ChimeraTK::OneDRegisterAccessor< UserType >::crbegin ( ) const
inline

Definition at line 66 of file OneDRegisterAccessor.h.

◆ crend()

template<typename UserType >
const_reverse_iterator ChimeraTK::OneDRegisterAccessor< UserType >::crend ( ) const
inline

Definition at line 69 of file OneDRegisterAccessor.h.

◆ data()

template<typename UserType >
UserType* ChimeraTK::OneDRegisterAccessor< UserType >::data ( )
inline

Return a direct pointer to the memory buffer storng the elements.

Attention
Note that this pointer will be invalidated during read(), write() and swap(). If this accessor is part of a TransferGroup, any call to one of these functions on any element of the TransferGroup or the TransferGroup itself may invalidate the pointer!

Definition at line 96 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ end() [1/2]

template<typename UserType >
iterator ChimeraTK::OneDRegisterAccessor< UserType >::end ( )
inline

Definition at line 61 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ end() [2/2]

template<typename UserType >
const_iterator ChimeraTK::OneDRegisterAccessor< UserType >::end ( ) const
inline

Definition at line 62 of file OneDRegisterAccessor.h.

◆ getAsCooked()

template<typename UserType >
template<typename COOKED_TYPE >
COOKED_TYPE ChimeraTK::OneDRegisterAccessor< UserType >::getAsCooked ( unsigned int  sample)

Get the cooked values in case the accessor is a raw accessor (which does not do data conversion).

This returns the converted data from the use buffer. It does not do any read or write transfer.

Definition at line 186 of file OneDRegisterAccessor.h.

◆ getNElements()

template<typename UserType >
unsigned int ChimeraTK::OneDRegisterAccessor< UserType >::getNElements ( )
inline

Return number of elements/samples in the register.

Definition at line 51 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ operator const std::vector< UserType > &()

template<typename UserType >
ChimeraTK::OneDRegisterAccessor< UserType >::operator const std::vector< UserType > & ( )
inline

Convert content of (cooked) buffer into std::vector.

Implicit conversion is allowed so one can pass a OneDRegisterAccessor directly when a std::vector is expected.

Definition at line 87 of file OneDRegisterAccessor.h.

+ Here is the call graph for this function:

◆ operator=()

template<typename UserType >
OneDRegisterAccessor< UserType > & ChimeraTK::OneDRegisterAccessor< UserType >::operator= ( const std::vector< UserType > &  x)

Copy content of (cooked) buffer from std::vector.

Definition at line 170 of file OneDRegisterAccessor.h.

◆ operator[]()

template<typename UserType >
UserType& ChimeraTK::OneDRegisterAccessor< UserType >::operator[] ( unsigned int  element)
inline

Get or set buffer content by [] operator.

Attention
No bounds checking is performed, use getNumberOfElements() to obtain the number of elements in the register. Note: Using the iterators is slightly more efficient than using this operator!

Definition at line 46 of file OneDRegisterAccessor.h.

◆ rbegin() [1/2]

template<typename UserType >
reverse_iterator ChimeraTK::OneDRegisterAccessor< UserType >::rbegin ( )
inline

Definition at line 64 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ rbegin() [2/2]

template<typename UserType >
const_reverse_iterator ChimeraTK::OneDRegisterAccessor< UserType >::rbegin ( ) const
inline

Definition at line 65 of file OneDRegisterAccessor.h.

◆ rend() [1/2]

template<typename UserType >
reverse_iterator ChimeraTK::OneDRegisterAccessor< UserType >::rend ( )
inline

Definition at line 67 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ rend() [2/2]

template<typename UserType >
const_reverse_iterator ChimeraTK::OneDRegisterAccessor< UserType >::rend ( ) const
inline

Definition at line 68 of file OneDRegisterAccessor.h.

◆ setAsCooked()

template<typename UserType >
template<typename COOKED_TYPE >
void ChimeraTK::OneDRegisterAccessor< UserType >::setAsCooked ( unsigned int  sample,
COOKED_TYPE  value 
)

Set the cooked values in case the accessor is a raw accessor (which does not do data conversion).

This converts to raw and writes the data to the user buffer. It does not do any read or write transfer.

Definition at line 198 of file OneDRegisterAccessor.h.

◆ swap()

template<typename UserType >
void ChimeraTK::OneDRegisterAccessor< UserType >::swap ( std::vector< UserType > &  x)
noexcept

Swap content of (cooked) buffer with std::vector.

Definition at line 154 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

◆ writeIfDifferent()

template<typename UserType >
void ChimeraTK::OneDRegisterAccessor< UserType >::writeIfDifferent ( const std::vector< UserType > &  newValue,
VersionNumber  versionNumber = VersionNumber{nullptr},
DataValidity  validity = DataValidity::ok 
)

Convenience function to set and write new value if it differes from the current value.

The given version number is only used in case the value differs. If versionNumber == {nullptr}, a new version number is generated only if the write actually takes place.

Definition at line 210 of file OneDRegisterAccessor.h.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ TransferGroup

template<typename UserType >
friend class TransferGroup
friend

Definition at line 120 of file OneDRegisterAccessor.h.


The documentation for this class was generated from the following file: