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

A class that provides shared ownership of a string. More...

#include <rcpp_shared_primitive.hpp>

Public Member Functions

 SharedString ()
 Constructs a new SharedString object with a default, empty value.
 
 SharedString (std::string val)
 Constructs a new SharedString object from a string value.
 
 SharedString (const SharedString &other)
 Copy constructs a new SharedString object.
 
SharedStringoperator= (const SharedString &other)
 Overloaded copy assignment operator.
 
SharedStringoperator= (const std::string &other)
 Overloaded assignment operator for a string value.
 
 SharedString (SharedString &&other) noexcept
 Constructs a new SharedString object by moving resources.
 
SharedStringoperator= (SharedString &&other) noexcept
 Overloaded move assignment operator.
 
std::string get () const
 Retrieves the string value managed by the object.
 
void set (std::string val)
 Sets the string value of the object.
 
 operator std::string ()
 User-defined conversion to std::string.
 
std::string operator* () const
 Overloads the dereference operator (*).
 
std::string * operator-> ()
 Overloads the member access operator (->).
 
const std::string * operator-> () const
 Overloads the member access operator (->) for const objects.
 

Friends

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

Detailed Description

A class that provides shared ownership of a string.

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

Constructor & Destructor Documentation

◆ SharedString() [1/4]

SharedString::SharedString ( )
inline

Constructs a new SharedString object with a default, empty value.

Initializes the object's internal shared pointer to manage a new string that is initially empty.

◆ SharedString() [2/4]

SharedString::SharedString ( std::string  val)
inline

Constructs a new SharedString object from a string value.

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

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

◆ SharedString() [3/4]

SharedString::SharedString ( const SharedString other)
inline

Copy constructs a new SharedString object.

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

Parameters
otherThe existing SharedString object to copy from.

◆ SharedString() [4/4]

SharedString::SharedString ( SharedString &&  other)
inlinenoexcept

Constructs a new SharedString object by moving resources.

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

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

Member Function Documentation

◆ get()

std::string SharedString::get ( ) const
inline

Retrieves the string value managed by the object.

This is a getter function that returns a copy of the string value. The function is const and can be called on a constant instance of the class without modifying its state.

Returns
The string value managed by the shared pointer.

◆ operator std::string()

SharedString::operator std::string ( )
inline

User-defined conversion to std::string.

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

Returns
The string value held by the object.

◆ operator*()

std::string SharedString::operator* ( ) const
inline

Overloads the dereference operator (*).

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

Returns
The string value held by the object.

◆ operator->() [1/2]

std::string * SharedString::operator-> ( )
inline

Overloads the member access operator (->).

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

Returns
A raw pointer (std::string*) to the string managed by the shared pointer.

◆ operator->() [2/2]

const std::string * SharedString::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 string. The const return type prevents modification of the string 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 string managed by the shared pointer.

◆ operator=() [1/3]

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

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

◆ operator=() [2/3]

SharedString & SharedString::operator= ( const std::string &  other)
inline

Overloaded assignment operator for a string value.

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

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

◆ operator=() [3/3]

SharedString & SharedString::operator= ( SharedString &&  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 SharedString object to move from.
Returns
A reference to the current object (*this).

◆ set()

void SharedString::set ( std::string  val)
inline

Sets the string value of the object.

Assigns a new string value to the underlying shared string.

Parameters
valThe string value to set.

Friends And Related Symbol Documentation

◆ operator<<

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

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

Provides a way to print the string value of a SharedString object to an output stream.

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