DQCsim
Public Member Functions | Static Public Member Functions | List of all members
dqcsim::wrap::ArbCmdQueue Class Reference

Class wrapper for queues (lists) of ArbCmds. More...

Inheritance diagram for dqcsim::wrap::ArbCmdQueue:
dqcsim::wrap::Cmd dqcsim::wrap::Arb dqcsim::wrap::Handle

Public Member Functions

 ArbCmdQueue (HandleIndex handle) noexcept
 Wraps the given ArbCmdQueue handle. More...
 
 ArbCmdQueue ()
 Constructs an empty ArbCmd queue object. More...
 
void push (ArbCmd &&cmd)
 Pushes an ArbCmd into the queue by moving. More...
 
void push (const Cmd &cmd)
 Pushes an ArbCmd into the queue by copying. More...
 
ArbCmdQueue && with (ArbCmd &&cmd)
 Pushes an ArbCmd into the queue by moving (builder pattern). More...
 
ArbCmdQueue && with (const Cmd &cmd)
 Pushes an ArbCmd into the queue by copying (builder pattern). More...
 
void next ()
 Pops the first ArbCmd from the queue, allowing the next one to be accessed. More...
 
size_t size () const
 Returns the number of ArbCmds in the queue. More...
 
std::vector< ArbCmddrain_into_vector ()
 Drains the queue into a vector of ArbCmds. More...
 
std::vector< ArbCmdcopy_into_vector ()
 Copies the queue into a vector of ArbCmds. More...
 
 ArbCmdQueue (ArbCmdQueue &src)
 Copy-constructs a queue of ArbCmds. More...
 
ArbCmdQueueoperator= (ArbCmdQueue &src)
 Copy-assigns a queue of ArbCmds. More...
 
 ArbCmdQueue (ArbCmdQueue &&)=default
 Default move constructor.
 
ArbCmdQueueoperator= (ArbCmdQueue &&)=default
 Default move assignment.
 
- Public Member Functions inherited from dqcsim::wrap::Cmd
 Cmd (HandleIndex handle) noexcept
 Wraps the given cmd handle. More...
 
std::string get_iface () const
 Returns the interface identifier of this command. More...
 
bool is_iface (const std::string &iface) const
 Returns whether this command has the given interface identifier. More...
 
std::string get_oper () const
 Returns the operation identifier of this command. More...
 
bool is_oper (const std::string &oper) const
 Returns whether this command has the given operation identifier. More...
 
- Public Member Functions inherited from dqcsim::wrap::Arb
 Arb (HandleIndex handle) noexcept
 Wraps the given arb handle. More...
 
std::string get_arb_json_string () const
 Returns the current arbitrary JSON data as a serialized JSON string. More...
 
void set_arb_json_string (const std::string &json)
 Sets the arbitrary JSON data to the given serialized JSON string. More...
 
std::string get_arb_cbor_string () const
 Returns the current arbitrary JSON data as a serialized CBOR string. More...
 
void set_arb_cbor_string (const std::string &cbor)
 Sets the arbitrary JSON data to the given serialized CBOR string. More...
 
template<class JSON >
JSON get_arb_json () const
 Returns the current arbitrary JSON data as a JSON object from nlohmann::json. More...
 
template<class JSON >
void set_arb_json (const JSON &json)
 Sets the arbitrary JSON data to the given JSON object from nlohmann::json. More...
 
std::string get_arb_arg_string (ssize_t index) const
 Returns the arbitrary argument at the given index as a (binary) string. More...
 
template<typename T >
get_arb_arg_as (ssize_t index) const
 Returns the arbitrary argument at the given index as the given type. More...
 
template<typename T >
void set_arb_arg_strings (const T &strings)
 Sets the arbitrary argument list to the given iterable of std::strings. More...
 
void set_arb_arg_string (ssize_t index, const std::string &data)
 Sets the arbitrary argument at the given index to a (binary) string. More...
 
template<typename T >
void set_arb_arg (ssize_t index, const T &data)
 Sets the arbitrary argument at the given index to a value of type T. More...
 
void push_arb_arg_string (const std::string &data)
 Pushes a (binary) string to the back of the arbitrary argument list. More...
 
template<typename T >
void push_arb_arg (const T &data)
 Pushes a value of type T to the back of the arbitrary argument list. More...
 
std::string pop_arb_arg_string ()
 Pops from the back of the arbitrary argument list as a (binary) string. More...
 
template<typename T >
pop_arb_arg_as () const
 Pops from the back of the arbitrary argument list as a value of type T. More...
 
void insert_arb_arg_string (ssize_t index, const std::string &data)
 Inserts an arbitrary argument at the given index using a (binary) string. More...
 
template<typename T >
void insert_arb_arg (ssize_t index, const T &data)
 Inserts an arbitrary argument at the given index using a value of type T. More...
 
void remove_arb_arg (ssize_t index)
 Removes the arbitrary argument at the given index. More...
 
size_t get_arb_arg_count () const
 Returns the number of arbitrary arguments. More...
 
void clear_arb_args ()
 Clears the arbitrary argument list. More...
 
void set_arb (const Arb &src)
 Assigns all arb data from the given arb to this one. More...
 
- Public Member Functions inherited from dqcsim::wrap::Handle
 Handle () noexcept
 Constructs an empty wrapper. More...
 
 Handle (HandleIndex handle) noexcept
 Wraps the given raw handle. More...
 
virtual ~Handle () noexcept
 Delete the handle and its wrapper.
 
void free ()
 Explicitly delete the handle, allowing errors to be caught. More...
 
bool is_valid () const noexcept
 Returns whether this wrapper (still) contains a valid handle. More...
 
HandleIndex get_handle () const noexcept
 Returns the raw handle without relinquishing ownership. More...
 
HandleIndex take_handle () noexcept
 Returns the raw handle and relinquishes ownership. More...
 
 Handle (const Handle &)=delete
 
void operator= (const Handle &)=delete
 
 Handle (Handle &&src)
 Move constructor; simply moves ownership of the handle from the source object to the constructed object. More...
 
Handleoperator= (Handle &&src)
 Move constructor; simply moves ownership of the handle from the source object to the assignment target. More...
 
std::string dump () const
 Returns a string containing a debug dump of the handle. More...
 
HandleType type () const
 Returns the type of this handle. More...
 

Static Public Member Functions

template<class T >
static ArbCmdQueue from_iter (T &&cmds)
 Constructs an ArbCmd queue object from an iterable of ArbCmds by moving. More...
 
template<class T >
static ArbCmdQueue from_iter (const T &cmds)
 Constructs an ArbCmd queue object from an iterable of ArbCmds by copying. More...
 

Additional Inherited Members

- Protected Attributes inherited from dqcsim::wrap::Handle
HandleIndex handle
 The wrapped handle.
 

Detailed Description

Class wrapper for queues (lists) of ArbCmds.

To construct an ArbCmd queue iteratively, create a new queue using the default constructor and push ArbCmds into it using push(). For instance:

.push(ArbCmd("dummy", "foo").with_arg_string("bar"))
.push(ArbCmd("dummy", "baz").with_arg<int>(42));

To iterate over an existing ArbCmd queue (destructively!) in the most efficient way, you can use the following code:

for (; queue.size() > 0; queue.next()) {
// queue can be used as the current cmd/arb without any copies now
}

You can also drain it into a std::vector of ArbCmds (drain_into_vector), or, if you must, copy it into one (copy_into_vector).

Definition at line 2652 of file dqcsim.

Constructor & Destructor Documentation

◆ ArbCmdQueue() [1/3]

dqcsim::wrap::ArbCmdQueue::ArbCmdQueue ( HandleIndex  handle)
inlinenoexcept

Wraps the given ArbCmdQueue handle.

Note
This constructor does not verify that the handle is actually valid.
Parameters
handleThe raw handle to wrap.

Definition at line 2663 of file dqcsim.

◆ ArbCmdQueue() [2/3]

dqcsim::wrap::ArbCmdQueue::ArbCmdQueue ( )
inline

Constructs an empty ArbCmd queue object.

Exceptions
std::runtime_errorWhen constructing the handle fails for some reason.

Definition at line 2672 of file dqcsim.

◆ ArbCmdQueue() [3/3]

dqcsim::wrap::ArbCmdQueue::ArbCmdQueue ( ArbCmdQueue src)
inline

Copy-constructs a queue of ArbCmds.

Note
This requires destructive iteration of the source object, so it isn't not const; if an exception occurs, the state of the source object may be changed.
Parameters
srcThe queue to copy from.
Exceptions
std::runtime_errorWhen the source handle is invalid or construction of the new object fails.

Definition at line 2824 of file dqcsim.

Member Function Documentation

◆ push() [1/2]

void dqcsim::wrap::ArbCmdQueue::push ( ArbCmd &&  cmd)
inline

Pushes an ArbCmd into the queue by moving.

Parameters
cmdThe ArbCmd to push. Consumed by this function.
Exceptions
std::runtime_errorWhen either handle is invalid.

Definition at line 2681 of file dqcsim.

◆ push() [2/2]

void dqcsim::wrap::ArbCmdQueue::push ( const Cmd cmd)
inline

Pushes an ArbCmd into the queue by copying.

Parameters
cmdThe ArbCmd to push.
Exceptions
std::runtime_errorWhen either handle is invalid, or copying cmd fails.

Definition at line 2692 of file dqcsim.

◆ from_iter() [1/2]

template<class T >
static ArbCmdQueue dqcsim::wrap::ArbCmdQueue::from_iter ( T &&  cmds)
inlinestatic

Constructs an ArbCmd queue object from an iterable of ArbCmds by moving.

Parameters
cmdsThe iterable of ArbCmd&s to push. Consumed by this function.
Returns
The constructed ArbCmdQueue.
Exceptions
std::runtime_errorWhen any of the handles are invalid, or construction of the queue handle fails.

Definition at line 2707 of file dqcsim.

◆ from_iter() [2/2]

template<class T >
static ArbCmdQueue dqcsim::wrap::ArbCmdQueue::from_iter ( const T &  cmds)
inlinestatic

Constructs an ArbCmd queue object from an iterable of ArbCmds by copying.

Parameters
cmdsThe iterable of const ArbCmd&s to push.
Returns
The constructed ArbCmdQueue.
Exceptions
std::runtime_errorWhen any of the handles are invalid, copying those handles fails, or construction of the queue handle fails.

Definition at line 2725 of file dqcsim.

◆ with() [1/2]

ArbCmdQueue&& dqcsim::wrap::ArbCmdQueue::with ( ArbCmd &&  cmd)
inline

Pushes an ArbCmd into the queue by moving (builder pattern).

Parameters
cmdThe ArbCmd to push. Consumed by this function.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen either handle is invalid.

Definition at line 2740 of file dqcsim.

◆ with() [2/2]

ArbCmdQueue&& dqcsim::wrap::ArbCmdQueue::with ( const Cmd cmd)
inline

Pushes an ArbCmd into the queue by copying (builder pattern).

Parameters
cmdThe ArbCmd to push.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen either handle is invalid or the copy fails.

Definition at line 2753 of file dqcsim.

◆ next()

void dqcsim::wrap::ArbCmdQueue::next ( )
inline

Pops the first ArbCmd from the queue, allowing the next one to be accessed.

Exceptions
std::runtime_errorWhen the handle is invalid, or the queue is empty.

Definition at line 2765 of file dqcsim.

◆ size()

size_t dqcsim::wrap::ArbCmdQueue::size ( ) const
inline

Returns the number of ArbCmds in the queue.

Returns
The number of ArbCmds in the queue.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 2775 of file dqcsim.

◆ drain_into_vector()

std::vector<ArbCmd> dqcsim::wrap::ArbCmdQueue::drain_into_vector ( )
inline

Drains the queue into a vector of ArbCmds.

This is less performant than iterating over the queue manually, because it requires copies.

Returns
A std::vector<ArbCmd> representation of the queue.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 2786 of file dqcsim.

◆ copy_into_vector()

std::vector<ArbCmd> dqcsim::wrap::ArbCmdQueue::copy_into_vector ( )
inline

Copies the queue into a vector of ArbCmds.

This is less performant than iterating over the queue manually or using drain_into_vector(), because it requires (additional) copies.

Note
This function is not const, because exceptions during the copy operation can change its value, and the underlying handle is changed. However, under normal conditions, the contents appear to be unchanged.
Returns
A std::vector<ArbCmd> representation of the queue.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 2806 of file dqcsim.

◆ operator=()

ArbCmdQueue& dqcsim::wrap::ArbCmdQueue::operator= ( ArbCmdQueue src)
inline

Copy-assigns a queue of ArbCmds.

Note
This requires destructive iteration of the source object, so it isn't not const; if an exception occurs, the state of the source object may be changed.
Parameters
srcThe queue to copy from.
Exceptions
std::runtime_errorWhen the source handle is invalid, freeing any existing handle in the destination fails, or construction of the new object fails.

Definition at line 2840 of file dqcsim.


The documentation for this class was generated from the following file:
dqcsim::wrap::ArbCmdQueue::ArbCmdQueue
ArbCmdQueue()
Constructs an empty ArbCmd queue object.
Definition: dqcsim:2672