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

A class that provides shared ownership of an integer value. More...

#include <rcpp_shared_primitive.hpp>

Public Member Functions

 SharedInt ()
 Construct a new SharedInt object.
 
 SharedInt (int val)
 Constructs a new SharedInt object.
 
 SharedInt (const SharedInt &other)
 Copy constructs a new SharedInt object.
 
SharedIntoperator= (const SharedInt &other)
 Overloaded assignment operator for copying a SharedInt object.
 
SharedIntoperator= (const int &other)
 Overloaded assignment operator for an integer value.
 
 SharedInt (SharedInt &&other) noexcept
 Constructs a new SharedInt object by moving resources.
 
SharedIntoperator= (SharedInt &&other) noexcept
 Overloaded move assignment operator.
 
int get () const
 Retrieve the value of the integer.
 
void set (int val)
 Change the value of the integer.
 
 operator int ()
 User-defined conversion to int.
 
int operator* () const
 Overloads the dereference operator.
 
intoperator-> ()
 Overloads the member access operator (->).
 
const intoperator-> () const
 Overloads the member access operator (->) for const objects.
 
SharedIntoperator++ ()
 Overloads the prefix increment operator (++).
 
SharedInt operator++ (int)
 Overloads the postfix increment operator (++).
 
SharedIntoperator-- ()
 Overloads the prefix decrement operator (--).
 
SharedInt operator-- (int)
 Overloads the postfix decrement operator.
 
SharedInt operator+ (const SharedInt &other) const
 Overloads the binary addition operator (+).
 
SharedInt operator- (const SharedInt &other) const
 Overloads the binary subtraction operator (-).
 
SharedInt operator* (const SharedInt &other) const
 Overloads the binary multiplication operator (*).
 
SharedInt operator/ (const SharedInt &other) const
 Overloads the binary division operator (/).
 
SharedInt operator+ (const int &other) const
 Overloads the binary addition operator for an integer value.
 
SharedInt operator- (const int &other) const
 Overloads the binary subtraction operator for an integer value.
 
SharedInt operator* (const int &other) const
 Overloads the binary multiplication operator for an integer value.
 
SharedInt operator/ (const int &other) const
 Overloads the binary division operator for an integer value.
 
SharedIntoperator+= (const SharedInt &other)
 Overloads the compound assignment operator (+=).
 
SharedIntoperator-= (const SharedInt &other)
 Overloads the compound assignment operator (-=).
 
SharedIntoperator*= (const SharedInt &other)
 Overloads the compound assignment operator (*=).
 
SharedIntoperator/= (const SharedInt &other)
 Overloads the compound assignment operator (/=).
 
SharedIntoperator+= (const int &other)
 Overloads the compound assignment operator (+=) for a shared integer value.
 
SharedIntoperator-= (const int &other)
 Overloads the compound assignment operator (-=) for a shared integer value.
 
SharedIntoperator*= (const int &other)
 Overloads the compound assignment operator (*=) for a shared integer value.
 
SharedIntoperator/= (const int &other)
 Overloads the compound assignment operator (/=) for a shared integer value.
 
bool operator== (const SharedInt &other) const
 Overloads the equality operator (==).
 
bool operator!= (const SharedInt &other) const
 Overloads the inequality operator (!=).
 
bool operator< (const SharedInt &other) const
 Overloads the less-than operator (<).
 
bool operator<= (const SharedInt &other) const
 Overloads the less-than-or-equal-to operator (<=).
 
bool operator> (const SharedInt &other) const
 Overloads the greater-than operator (>).
 
bool operator>= (const SharedInt &other) const
 Overloads the greater-than-or-equal-to operator (>=).
 
bool operator== (const int &other) const
 Overloads the equality operator (==) for an integer value.
 
bool operator!= (const int &other) const
 Overloads the inequality operator (!=) for an integer value.
 
bool operator< (const int &other) const
 Overloads the less-than operator (<) for an integer value.
 
bool operator<= (const int &other) const
 Overloads the less-than-or-equal-to operator (<=) for an integer value.
 
bool operator> (const int &other) const
 Overloads the greater-than operator (>) for an integer value.
 
bool operator>= (const int &other) const
 Overloads the greater-than-or-equal-to operator (>=) for an integer value.
 

Friends

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

Detailed Description

A class that provides shared ownership of an integer value.

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

Constructor & Destructor Documentation

◆ SharedInt() [1/3]

SharedInt::SharedInt ( int  val)
inline

Constructs a new SharedInt object.

Initializes the object by creating a std::shared_ptr to an integer with the provided value.

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

◆ SharedInt() [2/3]

SharedInt::SharedInt ( const SharedInt other)
inline

Copy constructs a new SharedInt object.

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

Parameters
otherThe existing SharedInt object to copy from.

◆ SharedInt() [3/3]

SharedInt::SharedInt ( SharedInt &&  other)
inlinenoexcept

Constructs a new SharedInt object by moving resources.

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

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

Member Function Documentation

◆ get()

int SharedInt::get ( ) const
inline

Retrieve the value of the integer.

Returns
int

◆ operator int()

SharedInt::operator int ( )
inline

User-defined conversion to int.

This conversion operator allows the object to be implicitly converted to an int. The returned value is the integer managed by the object's internal shared pointer, which is retrieved by calling get().

Returns
The integer value held by the object.

◆ operator!=() [1/2]

bool SharedInt::operator!= ( const int other) const
inline

Overloads the inequality operator (!=) for an integer value.

Compares the integer value of the current object with an int for inequality. This is a non-mutating operation.

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

◆ operator!=() [2/2]

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

Overloads the inequality operator (!=).

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

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

◆ operator*() [1/3]

int SharedInt::operator* ( ) const
inline

Overloads the dereference operator.

Provides a convenient way to access the integer value held by the shared pointer. This function is const, meaning it provides read-only access and does not modify the object's state.

Returns
The integer value managed by the shared pointer.

◆ operator*() [2/3]

SharedInt SharedInt::operator* ( const int other) const
inline

Overloads the binary multiplication operator for an integer value.

Multiplies the integer value of the current object by the integer value of other. This operation does not modify the current object; it returns a new SharedInt object containing the product.

Parameters
otherThe integer value to multiply the current object by.
Returns
A new SharedInt object containing the product of the two values.

◆ operator*() [3/3]

SharedInt SharedInt::operator* ( const SharedInt other) const
inline

Overloads the binary multiplication operator (*).

Multiplies the integer value of the current object by the integer value of the other object. This operation does not modify either object; it returns a new SharedInt object containing the product.

Parameters
otherThe SharedInt object to multiply the current object by.
Returns
A new SharedInt object containing the product of the two values.

◆ operator*=() [1/2]

SharedInt & SharedInt::operator*= ( const int other)
inline

Overloads the compound assignment operator (*=) for a shared integer value.

Multiplies the integer value of the current object by the integer value of other, modifying the object in place.

Parameters
otherThe integer value to multiply the current object by.
Returns
A reference to the current object (*this) after the multiplication.

◆ operator*=() [2/2]

SharedInt & SharedInt::operator*= ( const SharedInt other)
inline

Overloads the compound assignment operator (*=).

Multiplies the integer value of the current object by the value of other, modifying the object in place.

Parameters
otherThe SharedInt object to multiply by.
Returns
A reference to the current object (*this) after the multiplication.

◆ operator+() [1/2]

SharedInt SharedInt::operator+ ( const int other) const
inline

Overloads the binary addition operator for an integer value.

Adds an integer value to the integer value of the current object. This operation does not modify the current object; it returns a new SharedInt object containing the sum.

Parameters
otherThe integer value to add to the current object.
Returns
A new SharedInt object containing the sum of the two values.

◆ operator+() [2/2]

SharedInt SharedInt::operator+ ( const SharedInt other) const
inline

Overloads the binary addition operator (+).

Adds the integer value of the current object to the integer value of the other object. This operation does not modify either object; it returns a new SharedInt object containing the sum.

Parameters
otherThe SharedInt object to add to the current object.
Returns
A new SharedInt object containing the sum of the two values.

◆ operator++() [1/2]

SharedInt & SharedInt::operator++ ( )
inline

Overloads the prefix increment operator (++).

Increments the integer value managed by the shared pointer. As a prefix operator, it increments the value before returning the result.

Returns
A reference to the current object (*this) after the increment has occurred.

◆ operator++() [2/2]

SharedInt SharedInt::operator++ ( int  )
inline

Overloads the postfix increment operator (++).

This is a postfix operation. It first creates a copy of the object's current state, then increments the underlying integer value, and finally returns the temporary copy, which holds the original value. A dummy parameter used by the compiler to distinguish this operator from the prefix version.

Returns
A copy of the object's state before the increment occurred.

◆ operator+=() [1/2]

SharedInt & SharedInt::operator+= ( const int other)
inline

Overloads the compound assignment operator (+=) for a shared integer value.

Adds an integer value to the current object's value, modifying the object in place.

Parameters
otherThe integer value to add to the current object.
Returns
A reference to the current object (*this) after the addition.

◆ operator+=() [2/2]

SharedInt & SharedInt::operator+= ( const SharedInt other)
inline

Overloads the compound assignment operator (+=).

Adds the integer value of other to the current object's value, modifying the object in place.

Parameters
otherThe SharedInt object to add.
Returns
A reference to the current object (*this) after the addition.

◆ operator-() [1/2]

SharedInt SharedInt::operator- ( const int other) const
inline

Overloads the binary subtraction operator for an integer value.

Subtracts an integer value from the integer value of the current object. This operation does not modify the current object; it returns a new SharedInt object containing the result.

Parameters
otherThe integer value to subtract from the current object.
Returns
A new SharedInt object containing the result of the subtraction.

◆ operator-() [2/2]

SharedInt SharedInt::operator- ( const SharedInt other) const
inline

Overloads the binary subtraction operator (-).

Subtracts the integer value of the current object to the integer value of the other object. This operation does not modify either object; it returns a new SharedInt object containing the difference.

Parameters
otherThe SharedInt object to subtract from the current object.
Returns
A new SharedInt object containing the difference of the two values.

◆ operator--() [1/2]

SharedInt & SharedInt::operator-- ( )
inline

Overloads the prefix decrement operator (--).

Decrements the integer value managed by the shared pointer. As a prefix operator, it decrements the value before returning the result.

Returns
A reference to the current object (*this) after the decrement has occurred.

◆ operator--() [2/2]

SharedInt SharedInt::operator-- ( int  )
inline

Overloads the postfix decrement operator.

This is a postfix operation. It first creates a copy of the object's current state, then decrements the underlying integer value, and finally returns the temporary copy, which holds the original value. A dummy parameter used by the compiler to distinguish this operator from the prefix version.

Returns
A copy of the object's state before the decrement occurred.

◆ operator-=() [1/2]

SharedInt & SharedInt::operator-= ( const int other)
inline

Overloads the compound assignment operator (-=) for a shared integer value.

Subtracts an integer value from the current object's value, modifying the object in place.

Parameters
otherThe integer value to subtract from the current object.
Returns
A reference to the current object (*this) after the subtraction.

◆ operator-=() [2/2]

SharedInt & SharedInt::operator-= ( const SharedInt other)
inline

Overloads the compound assignment operator (-=).

Subtracts the integer value of other from the current object's value, modifying the object in place.

Parameters
otherThe SharedInt object to subtract.
Returns
A reference to the current object (*this) after the subtraction.

◆ operator->() [1/2]

int * SharedInt::operator-> ( )
inline

Overloads the member access operator (->).

Provides a way to access the integer value by returning a raw pointer to it. This function returns the result of std::shared_ptr::get().

Returns
A raw pointer (int*) to the integer managed by the shared pointer.

◆ operator->() [2/2]

const int * SharedInt::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 integer. The const return type prevents modification of the integer 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 integer managed by the shared pointer.

◆ operator/() [1/2]

SharedInt SharedInt::operator/ ( const int other) const
inline

Overloads the binary division operator for an integer value.

Divides the integer value of the current object by the integer value of other. This operation does not modify the current object; it returns a new SharedInt object containing the quotient.

Parameters
otherThe integer value to divide the current object by.
Returns
A new SharedInt object containing the quotient of the two values.

◆ operator/() [2/2]

SharedInt SharedInt::operator/ ( const SharedInt other) const
inline

Overloads the binary division operator (/).

Divides the integer value of the current object by the integer value of the other object. This operation does not modify either object; it returns a new SharedInt object containing the result of the division.

Parameters
otherThe SharedInt object to divide the current object by.
Returns
A new SharedInt object containing the quotient of the two values.

◆ operator/=() [1/2]

SharedInt & SharedInt::operator/= ( const int other)
inline

Overloads the compound assignment operator (/=) for a shared integer value.

Divides the integer value of the current object by the integer value of other, modifying the object in place.

Parameters
otherThe integer value to divide the current object by.
Returns
A reference to the current object (*this) after the division.

◆ operator/=() [2/2]

SharedInt & SharedInt::operator/= ( const SharedInt other)
inline

Overloads the compound assignment operator (/=).

Divides the integer value of the current object by the value of other, modifying the object in place.

Parameters
otherThe SharedInt object to divide by.
Returns
A reference to the current object (*this) after the division.

◆ operator<() [1/2]

bool SharedInt::operator< ( const int other) const
inline

Overloads the less-than operator (<) for an integer value.

Compares the integer value of the current object with an int. This is a non-mutating operation.

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

◆ operator<() [2/2]

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

Overloads the less-than operator (<).

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

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

◆ operator<=() [1/2]

bool SharedInt::operator<= ( const int other) const
inline

Overloads the less-than-or-equal-to operator (<=) for an integer value.

Compares the integer value of the current object with an int. This is a non-mutating operation.

Parameters
otherThe integer 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 SharedInt::operator<= ( const SharedInt other) const
inline

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

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

Parameters
otherThe SharedInt 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]

SharedInt & SharedInt::operator= ( const int other)
inline

Overloaded assignment operator for an integer value.

Assigns a new integer value to the underlying shared integer. This operation modifies the shared state of the object.

Parameters
otherThe integer value to assign.
Returns
A reference to the current object (*this).

◆ operator=() [2/3]

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

Overloaded assignment operator for copying a SharedInt object.

Assigns the shared state of other to the current object. If the object is not self-assigned, it will share ownership of the same integer value.

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

◆ operator=() [3/3]

SharedInt & SharedInt::operator= ( SharedInt &&  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 more efficient than a copy operation.

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

◆ operator==() [1/2]

bool SharedInt::operator== ( const int other) const
inline

Overloads the equality operator (==) for an integer value.

Compares the integer value of the current object with an int for equality. This is a non-mutating operation.

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

◆ operator==() [2/2]

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

Overloads the equality operator (==).

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

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

◆ operator>() [1/2]

bool SharedInt::operator> ( const int other) const
inline

Overloads the greater-than operator (>) for an integer value.

Compares the integer value of the current object with an int. This is a non-mutating operation.

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

◆ operator>() [2/2]

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

Overloads the greater-than operator (>).

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

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

◆ operator>=() [1/2]

bool SharedInt::operator>= ( const int other) const
inline

Overloads the greater-than-or-equal-to operator (>=) for an integer value.

Compares the integer value of the current object with an int. This is a non-mutating operation.

Parameters
otherThe integer 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 SharedInt::operator>= ( const SharedInt other) const
inline

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

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

Parameters
otherThe SharedInt 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 SharedInt::set ( int  val)
inline

Change the value of the integer.

Parameters
valAn integer value to set.

Friends And Related Symbol Documentation

◆ operator<<

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

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

Provides a way to print the integer value of a SharedInt object to an output stream.

Parameters
osThe output stream to write to.
spThe SharedInt 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: