FIMS  v0.8.0
Loading...
Searching...
No Matches
SharedBoolean Class Reference

A class that provides shared ownership of a boolean value. More...

#include <rcpp_shared_primitive.hpp>

Public Member Functions

 SharedBoolean ()
 Constructs a new SharedBoolean object with a default value.
 
 SharedBoolean (bool val)
 Constructs a new SharedBoolean object from a boolean value.
 
 SharedBoolean (const SharedBoolean &other)
 Copy constructs a new SharedBoolean object.
 
SharedBooleanoperator= (const SharedBoolean &other)
 Overloaded copy assignment operator.
 
SharedBooleanoperator= (const bool &other)
 Overloaded assignment operator for a boolean value.
 
 SharedBoolean (SharedBoolean &&other) noexcept
 Constructs a new SharedBoolean object by moving resources.
 
SharedBooleanoperator= (SharedBoolean &&other) noexcept
 Overloaded move assignment operator.
 
bool get () const
 Retrieves the boolean value managed by the object.
 
void set (bool val)
 Sets the boolean value of the object.
 
 operator bool ()
 User-defined conversion to bool.
 
bool operator* () const
 Overloads the dereference operator (*).
 
booloperator-> ()
 Overloads the member access operator (->).
 
const booloperator-> () const
 Overloads the member access operator (->) for const objects.
 
bool operator== (const SharedBoolean &other) const
 Overloads the equality operator (==).
 
bool operator!= (const SharedBoolean &other) const
 Overloads the inequality operator (!=).
 
bool operator< (const SharedBoolean &other) const
 Overloads the less-than operator (<).
 
bool operator<= (const SharedBoolean &other) const
 Overloads the less-than-or-equal-to operator (<=).
 
bool operator> (const SharedBoolean &other) const
 Overloads the greater-than operator (>).
 
bool operator>= (const SharedBoolean &other) const
 Overloads the greater-than-or-equal-to operator (>=).
 
bool operator== (const bool &other) const
 Overloads the equality operator (==) for a boolean value.
 
bool operator!= (const bool &other) const
 Overloads the inequality operator (!=) for a boolean value.
 
bool operator< (const bool &other) const
 Overloads the less-than operator (<) for a boolean value.
 
bool operator<= (const bool &other) const
 Overloads the less-than-or-equal-to operator (<=) for a boolean.
 
bool operator> (const bool &other) const
 Overloads the greater-than operator (>) for a boolean value.
 
bool operator>= (const bool &other) const
 Overloads the greater-than-or-equal-to operator (>=) for a boolean.
 

Friends

std::ostream & operator<< (std::ostream &os, const SharedBoolean &sp)
 Overloads the stream insertion operator (<<) for SharedBoolean.
 

Detailed Description

A class that provides shared ownership of a boolean value.

This class wraps a std::shared_ptr to provide a reference-counted boolean value. When a SharedBoolean object is copied, it shares the same underlying boolean with the original object. The boolean's memory is automatically deallocated when the last SharedBoolean object pointing to it is destroyed.

Constructor & Destructor Documentation

◆ SharedBoolean() [1/4]

SharedBoolean::SharedBoolean ( )
inline

Constructs a new SharedBoolean object with a default value.

Initializes the object's internal shared pointer to manage a new boolean with a default value of false.

◆ SharedBoolean() [2/4]

SharedBoolean::SharedBoolean ( bool  val)
inline

Constructs a new SharedBoolean object from a boolean value.

Initializes the object's internal shared pointer to manage a new boolean with the value provided by the val parameter.

Parameters
valThe boolean value to be stored in the shared pointer.

◆ SharedBoolean() [3/4]

SharedBoolean::SharedBoolean ( const SharedBoolean other)
inline

Copy constructs a new SharedBoolean object.

Initializes the object by creating a new shared pointer that shares ownership of the boolean managed by another SharedBoolean object.

Parameters
otherThe existing SharedBoolean object to copy from.

◆ SharedBoolean() [4/4]

SharedBoolean::SharedBoolean ( SharedBoolean &&  other)
inlinenoexcept

Constructs a new SharedBoolean object by moving resources.

Transfers ownership of the shared boolean from other to the new object. This is a non-throwing operation that is more efficient than a copy.

Parameters
otherThe temporary SharedBoolean object to move from. After this call, other will no longer own the resource.

Member Function Documentation

◆ get()

bool SharedBoolean::get ( ) const
inline

Retrieves the boolean value managed by the object.

This is a getter function that returns a copy of the boolean value. Since the function is const, it can be safely called on a constant instance of the class without modifying its state.

Returns
The boolean value managed by the shared pointer.

◆ operator bool()

SharedBoolean::operator bool ( )
inline

User-defined conversion to bool.

This conversion operator allows the object to be implicitly converted to a bool. The returned value is the boolean managed by the object's internal shared pointer.

Returns
The boolean value held by the object.

◆ operator!=() [1/2]

bool SharedBoolean::operator!= ( const bool other) const
inline

Overloads the inequality operator (!=) for a boolean value.

Compares the boolean value of the current object with a bool for inequality. This is a non-mutating operation.

Parameters
otherThe boolean value to compare against.
Returns
true if the values are not equal, false otherwise.

◆ operator!=() [2/2]

bool SharedBoolean::operator!= ( const SharedBoolean other) const
inline

Overloads the inequality operator (!=).

Compares the boolean value of the current object with the boolean value of other for inequality. This is a non-mutating operation.

Parameters
otherThe SharedBoolean object to compare against.
Returns
true if the values are not equal, false otherwise.

◆ operator*()

bool SharedBoolean::operator* ( ) const
inline

Overloads the dereference operator (*).

Provides direct access to the boolean value managed by the internal shared pointer. This function is const and provides a read-only view of the data.

Returns
The boolean value held by the object.

◆ operator->() [1/2]

bool * SharedBoolean::operator-> ( )
inline

Overloads the member access operator (->).

This function provides a way to access the underlying boolean value by returning a raw pointer to it. It returns the result of the std::shared_ptr::get() method.

Returns
A raw pointer (bool*) to the boolean managed by the shared pointer.

◆ operator->() [2/2]

const bool * SharedBoolean::operator-> ( ) const
inline

Overloads the member access operator (->) for const objects.

This function provides a way to get a read-only raw pointer to the underlying boolean. The const return type prevents modification of the boolean value through this pointer. The function itself is also const, ensuring it can be called on const instances of the class.

Returns
A const raw pointer to the boolean managed by the shared pointer.

◆ operator<() [1/2]

bool SharedBoolean::operator< ( const bool other) const
inline

Overloads the less-than operator (<) for a boolean value.

Compares the boolean value of the current object with a bool. This is a non-mutating operation.

Parameters
otherThe boolean value to compare against.
Returns
true if the current object's value is less than other, false otherwise.

◆ operator<() [2/2]

bool SharedBoolean::operator< ( const SharedBoolean other) const
inline

Overloads the less-than operator (<).

Compares the boolean value of the current object with the boolean value of other. This is a non-mutating operation.

Parameters
otherThe SharedBoolean object to compare against.
Returns
true if the current object's value is less than other's value, false otherwise.

◆ operator<=() [1/2]

bool SharedBoolean::operator<= ( const bool other) const
inline

Overloads the less-than-or-equal-to operator (<=) for a boolean.

Compares the boolean value of the current object with a bool. This is a non-mutating operation.

Parameters
otherThe boolean value to compare against.
Returns
true if the current object's value is less than or equal to other, false otherwise.

◆ operator<=() [2/2]

bool SharedBoolean::operator<= ( const SharedBoolean other) const
inline

Overloads the less-than-or-equal-to operator (<=).

Compares the boolean value of the current object with the boolean value of other. This is a non-mutating operation.

Parameters
otherThe SharedBoolean object to compare against.
Returns
true if the current object's value is less than or equal to other's value, false otherwise.

◆ operator=() [1/3]

SharedBoolean & SharedBoolean::operator= ( const bool other)
inline

Overloaded assignment operator for a boolean value.

Assigns a new boolean value to the underlying shared boolean, modifying the object in place.

Parameters
otherThe boolean value to assign.
Returns
A reference to the current object (*this) to allow for chained assignments.

◆ operator=() [2/3]

SharedBoolean & SharedBoolean::operator= ( const SharedBoolean other)
inline

Overloaded copy assignment operator.

Assigns the shared state of other to the current object. If the objects are not the same, the current object will release its old resource and share ownership of the boolean value managed by other.

Parameters
otherThe SharedBoolean object to assign from.
Returns
A reference to the current object (*this) to allow for chained assignments.

◆ operator=() [3/3]

SharedBoolean & SharedBoolean::operator= ( SharedBoolean &&  other)
inlinenoexcept

Overloaded move assignment operator.

Moves the shared state from other to the current object, releasing any resources the current object might have held. This is a non-throwing and more efficient operation than a copy assignment.

Parameters
otherThe temporary SharedBoolean object to move from.
Returns
A reference to the current object (*this).

◆ operator==() [1/2]

bool SharedBoolean::operator== ( const bool other) const
inline

Overloads the equality operator (==) for a boolean value.

Compares the boolean value of the current object with a bool for equality. This is a non-mutating operation.

Parameters
otherThe boolean value to compare against.
Returns
true if the values are equal, false otherwise.

◆ operator==() [2/2]

bool SharedBoolean::operator== ( const SharedBoolean other) const
inline

Overloads the equality operator (==).

Compares the boolean value of the current object with the boolean value of other for equality. This is a non-mutating operation.

Parameters
otherThe SharedBoolean object to compare against.
Returns
true if the values are equal, false otherwise.

◆ operator>() [1/2]

bool SharedBoolean::operator> ( const bool other) const
inline

Overloads the greater-than operator (>) for a boolean value.

Compares the boolean value of the current object with a bool. This is a non-mutating operation.

Parameters
otherThe boolean value to compare against.
Returns
true if the current object's value is greater than other, false otherwise.

◆ operator>() [2/2]

bool SharedBoolean::operator> ( const SharedBoolean other) const
inline

Overloads the greater-than operator (>).

Compares the boolean value of the current object with the boolean value of other. This is a non-mutating operation.

Parameters
otherThe SharedBoolean object to compare against.
Returns
true if the current object's value is greater than other's value, false otherwise.

◆ operator>=() [1/2]

bool SharedBoolean::operator>= ( const bool other) const
inline

Overloads the greater-than-or-equal-to operator (>=) for a boolean.

Compares the boolean value of the current object with a bool. This is a non-mutating operation.

Parameters
otherThe boolean value to compare against.
Returns
true if the current object's value is greater than or equal to other, false otherwise.

◆ operator>=() [2/2]

bool SharedBoolean::operator>= ( const SharedBoolean other) const
inline

Overloads the greater-than-or-equal-to operator (>=).

Compares the boolean value of the current object with the boolean value of other. This is a non-mutating operation.

Parameters
otherThe SharedBoolean object to compare against.
Returns
true if the current object's value is greater than or equal to other's value, false otherwise.

◆ set()

void SharedBoolean::set ( bool  val)
inline

Sets the boolean value of the object.

Assigns a new boolean value to the underlying shared boolean.

Parameters
valThe boolean value to set.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const SharedBoolean sp 
)
friend

Overloads the stream insertion operator (<<) for SharedBoolean.

Provides a way to print the boolean value of a SharedBoolean object to an output stream.

Parameters
osThe output stream to write to.
spThe SharedBoolean object to print.
Returns
A reference to the output stream, allowing for chained insertions.

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