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

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

#include <rcpp_shared_primitive.hpp>

Public Member Functions

 SharedReal ()
 Constructs a new SharedReal object with a default value.
 
 SharedReal (int val)
 Constructs a new SharedReal object from an integer value.
 
 SharedReal (const SharedReal &other)
 Copy constructs a new SharedReal object.
 
SharedRealoperator= (const SharedReal &other)
 Overloaded copy assignment operator.
 
SharedRealoperator= (const int &other)
 Overloaded assignment operator for an integer value.
 
 SharedReal (SharedReal &&other) noexcept
 Constructs a new SharedReal object by moving resources.
 
SharedRealoperator= (SharedReal &&other) noexcept
 Overloaded move assignment operator.
 
int get () const
 Retrieves the integer value managed by the object.
 
void set (int val)
 Sets the integer value of the object.
 
 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.
 
SharedRealoperator++ ()
 Overloads the prefix increment operator (++).
 
SharedReal operator++ (int)
 Overloads the postfix increment operator.
 
SharedRealoperator-- ()
 Overloads the prefix decrement operator (--).
 
SharedReal operator-- (int)
 Overloads the postfix decrement operator.
 
SharedReal operator+ (const SharedReal &other) const
 Overloads the binary addition operator (+).
 
SharedReal operator- (const SharedReal &other) const
 Overloads the binary subtraction operator (-).
 
SharedReal operator* (const SharedReal &other) const
 Overloads the binary multiplication operator (*).
 
SharedReal operator/ (const SharedReal &other) const
 Overloads the binary division operator (/).
 
SharedReal operator+ (const int &other) const
 Overloads the binary addition operator (+) for an integer.
 
SharedReal operator- (const int &other) const
 Overloads the binary subtraction operator (-) for an integer.
 
SharedReal operator* (const int &other) const
 Overloads the binary multiplication operator (*) for an integer.
 
SharedReal operator/ (const int &other) const
 Overloads the binary division operator (/) for an integer.
 
SharedRealoperator+= (const SharedReal &other)
 Overloads the compound assignment operator (+=).
 
SharedRealoperator-= (const SharedReal &other)
 Overloads the compound assignment operator (-=).
 
SharedRealoperator*= (const SharedReal &other)
 Overloads the compound assignment operator (*=).
 
SharedRealoperator/= (const SharedReal &other)
 Overloads the compound assignment operator (/=).
 
SharedRealoperator+= (const int &other)
 Overloads the compound assignment operator (+=) for an integer.
 
SharedRealoperator-= (const int &other)
 Overloads the compound assignment operator (-=) for an integer.
 
SharedRealoperator*= (const int &other)
 Overloads the compound assignment operator (*=) for an integer.
 
SharedRealoperator/= (const int &other)
 Overloads the compound assignment operator (/=) for an integer.
 
bool operator== (const SharedReal &other) const
 Overloads the equality operator (==).
 
bool operator!= (const SharedReal &other) const
 Overloads the inequality operator (!=).
 
bool operator< (const SharedReal &other) const
 Overloads the less-than operator (<).
 
bool operator<= (const SharedReal &other) const
 Overloads the less-than-or-equal-to operator (<=).
 
bool operator> (const SharedReal &other) const
 Overloads the greater-than operator (>).
 
bool operator>= (const SharedReal &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.
 
bool operator< (const int &other) const
 Overloads the less-than operator (<) for an integer.
 
bool operator<= (const int &other) const
 Overloads the less-than-or-equal-to operator (<=) for an integer.
 
bool operator> (const int &other) const
 Overloads the greater-than operator (>) for an integer.
 
bool operator>= (const int &other) const
 Overloads the greater-than-or-equal-to operator (>=) for an integer.
 

Friends

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

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 SharedReal object is copied, it shares the same underlying integer with the original object. The integer's memory is automatically deallocated when the last SharedReal object pointing to it is destroyed.

Constructor & Destructor Documentation

◆ SharedReal() [1/4]

SharedReal::SharedReal ( )
inline

Constructs a new SharedReal object with a default value.

Initializes the object's internal shared pointer to manage a new integer with a value of zero.

◆ SharedReal() [2/4]

SharedReal::SharedReal ( int  val)
inline

Constructs a new SharedReal object from an integer value.

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

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

◆ SharedReal() [3/4]

SharedReal::SharedReal ( const SharedReal other)
inline

Copy constructs a new SharedReal object.

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

Parameters
otherThe existing SharedReal object to copy from.

◆ SharedReal() [4/4]

SharedReal::SharedReal ( SharedReal &&  other)
inlinenoexcept

Constructs a new SharedReal 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 and is also known as a move constructor.

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

Member Function Documentation

◆ get()

int SharedReal::get ( ) const
inline

Retrieves the integer value managed by the object.

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

Returns
The integer value managed by the shared pointer.

◆ operator int()

SharedReal::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 SharedReal::operator!= ( const int other) const
inline

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

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 SharedReal::operator!= ( const SharedReal 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 SharedReal object to compare against.
Returns
true if the values are not equal, false otherwise.

◆ operator*() [1/3]

int SharedReal::operator* ( ) const
inline

Overloads the dereference operator (*).

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

Returns
The integer value held by the object.

◆ operator*() [2/3]

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

Overloads the binary multiplication operator (*) for an integer.

Multiplies the current object's value by an integer. This operation does not modify the current object; it returns a new SharedReal object containing the product.

Parameters
otherThe integer value to multiply the current object by.
Returns
A new SharedReal object containing the product.

◆ operator*() [3/3]

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

Overloads the binary multiplication operator (*).

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

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

◆ operator*=() [1/2]

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

Overloads the compound assignment operator (*=) for an integer.

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]

SharedReal & SharedReal::operator*= ( const SharedReal 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 SharedReal object to multiply by.
Returns
A reference to the current object (*this) after the multiplication.

◆ operator+() [1/2]

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

Overloads the binary addition operator (+) for an integer.

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

Parameters
otherThe integer value to add to the current object.
Returns
A new SharedReal object containing the sum.

◆ operator+() [2/2]

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

Overloads the binary addition operator (+).

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

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

◆ operator++() [1/2]

SharedReal & SharedReal::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]

SharedReal SharedReal::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]

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

Overloads the compound assignment operator (+=) for an integer.

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]

SharedReal & SharedReal::operator+= ( const SharedReal 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 SharedReal object to add.
Returns
A reference to the current object (*this) after the addition.

◆ operator-() [1/2]

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

Overloads the binary subtraction operator (-) for an integer.

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

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

◆ operator-() [2/2]

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

Overloads the binary subtraction operator (-).

Subtracts the integer value of other from the current object's value. This operation does not modify either object; it returns a new SharedReal object containing the result.

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

◆ operator--() [1/2]

SharedReal & SharedReal::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]

SharedReal SharedReal::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]

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

Overloads the compound assignment operator (-=) for an integer.

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]

SharedReal & SharedReal::operator-= ( const SharedReal 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 SharedReal object to subtract.
Returns
A reference to the current object (*this) after the subtraction.

◆ operator->() [1/2]

int * SharedReal::operator-> ( )
inline

Overloads the member access operator (->).

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

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

◆ operator->() [2/2]

const int * SharedReal::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]

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

Overloads the binary division operator (/) for an integer.

Divides the current object's value by an integer. This operation does not modify the current object; it returns a new SharedReal object containing the quotient.

Parameters
otherThe integer value to divide the current object by.
Returns
A new SharedReal object containing the quotient.

◆ operator/() [2/2]

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

Overloads the binary division operator (/).

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

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

◆ operator/=() [1/2]

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

Overloads the compound assignment operator (/=) for an integer.

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]

SharedReal & SharedReal::operator/= ( const SharedReal 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 SharedReal object to divide by.
Returns
A reference to the current object (*this) after the division.

◆ operator<() [1/2]

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

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

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 SharedReal::operator< ( const SharedReal 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 SharedReal object to compare against.
Returns
true if the current object's value is less than other's value, false otherwise.

◆ operator<=() [1/2]

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

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

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 SharedReal::operator<= ( const SharedReal 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 SharedReal 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]

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

Overloaded assignment operator for an integer value.

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

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

◆ operator=() [2/3]

SharedReal & SharedReal::operator= ( const SharedReal 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 integer value managed by other.

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

◆ operator=() [3/3]

SharedReal & SharedReal::operator= ( SharedReal &&  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 and is also known as a move assignment operator.

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

◆ operator==() [1/2]

bool SharedReal::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 SharedReal::operator== ( const SharedReal 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 SharedReal object to compare against.
Returns
true if the values are equal, false otherwise.

◆ operator>() [1/2]

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

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

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 SharedReal::operator> ( const SharedReal 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 SharedReal object to compare against.
Returns
true if the current object's value is greater than other's value, false otherwise.

◆ operator>=() [1/2]

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

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

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 SharedReal::operator>= ( const SharedReal 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 SharedReal 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 SharedReal::set ( int  val)
inline

Sets the integer value of the object.

Assigns a new integer value to the underlying shared integer.

Parameters
valThe integer value to set.

Friends And Related Symbol Documentation

◆ operator<<

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

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

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

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