libiio  1.0
Library for interfacing with IIO devices
iiopp Namespace Reference

Public C++ API. More...

Namespaces

 impl
 Namespace of implementation details.
 

Data Structures

class  Attr
 C++ wrapper for the Attributes C-API. More...
 
class  Block
 C++ wrapper for the Block C-API. More...
 
class  Buffer
 C++ wrapper for the Buffer C-API. More...
 
class  Channel
 C++ wrapper for the Channel C-API. More...
 
class  ChannelsMask
 C++ wrapper for iio_channels_mask. More...
 
class  Context
 C++ wrapper for the Context C-API. More...
 
class  cstr
 Non-owning immutable null terminated string. More...
 
class  Device
 C++ wrapper for the Device C-API. More...
 
class  error
 Thrown to report errors. More...
 
struct  Event
 Event object. More...
 
class  EventStream
 C++ wrapper for iio_event_stream. More...
 
class  Ptr
 Special unique pointer for instances that must be destroyed. More...
 
class  Scan
 C++ wrapper for the Scan C-API. More...
 
class  Stream
 C++ wrapper for the Stream C-API. More...
 

Typedefs

typedef optional< cstroptstr
 Optional string, used for C-functions that return nullptr for "no value".
 
typedef Ptr< ChannelsMask, iio_channels_mask, iio_channels_mask_destroy > ChannelsMaskPtr
 
typedef Ptr< Block, iio_block, iio_block_destroy > BlockPtr
 
typedef Ptr< Stream, iio_stream, iio_stream_destroy > StreamPtr
 
typedef Ptr< EventStream, iio_event_stream, iio_event_stream_destroy > EventStreamPtr
 
typedef Ptr< Buffer, iio_buffer, iio_buffer_destroy > BufferPtr
 
typedef Ptr< cstr, void, free > CstrPtr
 
typedef Ptr< Context, iio_context, iio_context_destroy > ContextPtr
 
typedef Ptr< Scan, struct iio_scan, iio_scan_destroy > ScanPtr
 

Functions

ChannelsMaskPtr create_channels_mask (unsigned int nb_channels)
 
ContextPtr create_context (iio_context_params *params, const char *uri)
 C++ wrapper for iio_create_context.
 
ScanPtr scan (struct iio_context_params const *params, char const *backends)
 
double value (Channel ch)
 Reads the value of a channel by using "input" or "raw" attribute and applying "scale" and "offset" if available. More...
 

Detailed Description

Public C++ API.

This is a C++ wrapper for iio.h

It requires C++17 or C++11 with Boost (for boost::optional).

It provides:

  • Classes that model the major types, providing member functions for easy usage.
  • Error handling (errors are checked and turned into exceptions).
  • Simplified resource management via smart pointers.
  • Functions that may return NULL for "no string" or "no object" are explicit by returning an std::optional.
  • Iterators and array subscription operator for idiomatic access to sequences.
  • Implicit conversion to the wrapped C-types, so C++ instances can easily be passed to the C-API. Arguments C++-API take the raw C-types.
Warning
All objects live in the iiopp::Context that created them. When a context gets destroyed, all its child objects die as well. All wrapper classes have weak reference semantic and become invalid when the context gets destroyed (or their referenced instance get destroyed by other means).

In consequence all types are cheap to copy (at the cost of assigning a pointer). Copies refer to the same underlying object.

Types with Ptr at the end act like unique pointers: Their destructor destroys the object they refer to and they are not copyable (but movable).

See iiopp-enum.cpp for an example.

Function Documentation

◆ value()

double iiopp::value ( Channel  ch)
inline

Reads the value of a channel by using "input" or "raw" attribute and applying "scale" and "offset" if available.

See also
get_channel_value in the example iio-monitor.c
Examples:
iiopp-enum.cpp.
Here is the caller graph for this function: