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

Class representation of the measurement result for a single qubit. More...

Inheritance diagram for dqcsim::wrap::Measurement:
dqcsim::wrap::Arb dqcsim::wrap::Handle

Public Member Functions

 Measurement (HandleIndex handle) noexcept
 Wraps the given measurement handle. More...
 
 Measurement (const QubitRef &qubit, MeasurementValue value)
 Constructs a measurement object. More...
 
 Measurement (const Measurement &src)
 Copy-constructs a Measurement object. More...
 
void operator= (const Measurement &src)
 Copy assignment operator for Measurement objects. More...
 
 Measurement (Measurement &&handle)=default
 Default move constructor.
 
Measurementoperator= (Measurement &&)=default
 Default move assignment.
 
MeasurementValue get_value () const
 Returns the measurement value. More...
 
void set_value (MeasurementValue value)
 Sets the measurement value. More...
 
QubitRef get_qubit () const
 Returns the qubit reference associated with this measurement. More...
 
void set_qubit (QubitRef qubit)
 Sets the qubit reference associated with this measurement. More...
 
Measurementwith_json_string (const std::string &json)
 Sets the arbitrary JSON data to the given serialized JSON string (builder pattern). More...
 
Measurementwith_cbor_string (const std::string &cbor)
 Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern). More...
 
template<class JSON >
Measurementwith_json (const JSON &json)
 Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern). More...
 
Measurementwith_arg_string (const std::string &data)
 Pushes a (binary) string to the back of the arbitrary argument list (builder pattern). More...
 
template<typename T >
Measurementwith_arg (const T &data)
 Pushes a value of type T to the back of the arbitrary argument list (builder pattern). 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...
 

Additional Inherited Members

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

Detailed Description

Class representation of the measurement result for a single qubit.

Measurement objects carry the following information:

You can construct the arbitrary data part of a measurement object with the builder pattern, for instance:

Measurement(1_q, MeasurementValue::One)
.with_json_string("{\"hello\": \"world\"}")
.with_arg<int>(33)
.with_arg_string("I'm a string!");

Definition at line 5592 of file dqcsim.

Constructor & Destructor Documentation

◆ Measurement() [1/3]

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

Wraps the given measurement handle.

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

Definition at line 5603 of file dqcsim.

◆ Measurement() [2/3]

dqcsim::wrap::Measurement::Measurement ( const QubitRef qubit,
MeasurementValue  value 
)
inline

Constructs a measurement object.

Parameters
qubitThe qubit reference that this measurement belongs to.
valueThe measurement value.
Exceptions
std::runtime_errorWhen construction of the new handle failed for some reason.

Definition at line 5614 of file dqcsim.

◆ Measurement() [3/3]

dqcsim::wrap::Measurement::Measurement ( const Measurement src)
inline

Copy-constructs a Measurement object.

Parameters
srcThe measurement object to copy from.
Exceptions
std::runtime_errorWhen the source handle is invalid or construction of the new handle failed for some reason.

Definition at line 5626 of file dqcsim.

Member Function Documentation

◆ operator=()

void dqcsim::wrap::Measurement::operator= ( const Measurement src)
inline

Copy assignment operator for Measurement objects.

Parameters
srcThe measurement object to copy from.
Exceptions
std::runtime_errorWhen the source handle is invalid or construction of the new handle failed for some reason.

Definition at line 5639 of file dqcsim.

◆ get_value()

MeasurementValue dqcsim::wrap::Measurement::get_value ( ) const
inline

Returns the measurement value.

Returns
The measurement value.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5661 of file dqcsim.

◆ set_value()

void dqcsim::wrap::Measurement::set_value ( MeasurementValue  value)
inline

Sets the measurement value.

Parameters
valueThe new measurement value.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5671 of file dqcsim.

◆ get_qubit()

QubitRef dqcsim::wrap::Measurement::get_qubit ( ) const
inline

Returns the qubit reference associated with this measurement.

Returns
The qubit reference associated with this measurement.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5681 of file dqcsim.

◆ set_qubit()

void dqcsim::wrap::Measurement::set_qubit ( QubitRef  qubit)
inline

Sets the qubit reference associated with this measurement.

Parameters
qubitThe new qubit reference.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5691 of file dqcsim.

◆ with_json_string()

Measurement& dqcsim::wrap::Measurement::with_json_string ( const std::string &  json)
inline

Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).

Parameters
jsonA string representation of a JSON dictionary object to assign.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen the string representation is invalid, or when the current handle is invalid.

Definition at line 5710 of file dqcsim.

◆ with_cbor_string()

Measurement& dqcsim::wrap::Measurement::with_cbor_string ( const std::string &  cbor)
inline

Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).

Parameters
cborA JSON object represented as a CBOR binary string.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen the CBOR string is invalid, or when the current handle is invalid.

Definition at line 5724 of file dqcsim.

◆ with_json()

template<class JSON >
Measurement& dqcsim::wrap::Measurement::with_json ( const JSON &  json)
inline

Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).

Since that is a header-only library that isn't usually installed system-wide and be using a specific version in your project already, you need to specify the nlohmann::json type as a generic to this function.

Parameters
jsonThe C++ JSON object representation of the object to set.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5741 of file dqcsim.

◆ with_arg_string()

Measurement& dqcsim::wrap::Measurement::with_arg_string ( const std::string &  data)
inline

Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).

Parameters
dataThe data for the new argument, represented as a (binary) string.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5755 of file dqcsim.

◆ with_arg()

template<typename T >
Measurement& dqcsim::wrap::Measurement::with_arg ( const T &  data)
inline

Pushes a value of type T to the back of the arbitrary argument list (builder pattern).

Warning
Type T must be a primitive value (like an int) or a struct thereof, without pointers or any other "complicated" constructs. DQCsim just copies the bytes over. It is up to you to ensure that that's what you want to happen; unfortunately C++11 does not provide a way to statically ensure that this is the case.
Parameters
dataThe data for the new argument, represented as some C object.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen the current handle is invalid.

Definition at line 5775 of file dqcsim.


The documentation for this class was generated from the following file:
dqcsim::wrap::Measurement::Measurement
Measurement(HandleIndex handle) noexcept
Wraps the given measurement handle.
Definition: dqcsim:5603
dqcsim::wrap::Measurement::with_arg_string
Measurement & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:5755