A class that provides shared ownership of a string.
More...
#include <rcpp_shared_primitive.hpp>
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.
◆ 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
-
| val | The string value to be stored in the shared pointer. |
◆ SharedString() [3/4]
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
-
◆ SharedString() [4/4]
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
-
| other | The temporary SharedString object to move from. After this call, other will no longer own the resource. |
◆ 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]
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
-
- Returns
- A reference to the current object (
*this) to allow for chained assignments.
◆ operator=() [2/3]
Overloaded assignment operator for a string value.
Assigns a new string value to the underlying shared string, modifying the object in place.
- Parameters
-
| other | The string value to assign. |
- Returns
- A reference to the current object (
*this) to allow for chained assignments.
◆ operator=() [3/3]
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
-
- 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
-
| val | The string value to set. |
◆ operator<<
Overloads the stream insertion operator (<<) for SharedString.
Provides a way to print the string value of a SharedString object to an output stream.
- Parameters
-
| os | The output stream to write to. |
| sp | The 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: