Public Types | Public Member Functions
efl::eina::stringshare Struct Reference

Stringshare class. More...

Public Types

typedef char value_type
 
typedef value_type & reference
 
typedef value_type const & const_reference
 
typedef value_type * pointer
 
typedef value_type const * const_pointer
 
typedef const_pointer const_iterator
 
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
 
typedef std::ptrdiff_t difference_type
 
typedef std::size_t size_type
 

Public Member Functions

 stringshare ()
 Default constructor. More...
 
 stringshare (const char *str)
 Share an instance of the given string wrapped by the newly created stringshare object. More...
 
 stringshare (const char *str, steal_stringshare_ref_t)
 Create an eina::stringshare that steal the ownership of the given shared string. More...
 
template<typename InputIterator >
 stringshare (InputIterator i, InputIterator j, typename eina::enable_if<!eina::is_integral< InputIterator >::value &&!eina::is_contiguous_iterator< InputIterator >::value >::type *=0)
 Share the string between the iterator. More...
 
template<typename ContiguousMemoryIterator >
 stringshare (ContiguousMemoryIterator i, ContiguousMemoryIterator j, typename eina::enable_if< eina::is_contiguous_iterator< ContiguousMemoryIterator >::value >::type *=0)
 Share the string between the iterator. More...
 
 ~stringshare ()
 Destructor. More...
 
 stringshare (stringshare const &other)
 Copy constructor. More...
 
stringshareoperator= (stringshare const &other)
 Replace the current shared string. More...
 
stringshareoperator= (const char *c_string)
 Replace the current shared string. More...
 
const_iterator begin () const
 Get a constant iterator pointing to the first character of the string. More...
 
const_iterator end () const
 Get a constant iterator to the position following the last character of the string. More...
 
const_reverse_iterator rbegin () const
 Get a constant reverse iterator pointing to the reverse begin of the string. More...
 
const_reverse_iterator rend () const
 Get a constant reverse iterator pointing to the reverse end of the string. More...
 
const_iterator cbegin () const
 Get a constant iterator pointing to the first character of the string. More...
 
const_iterator cend () const
 Get a constant iterator to the position following the last character of the string. More...
 
const_reverse_iterator crbegin () const
 Get a constant reverse iterator pointing to the reverse begin of the string. More...
 
const_reverse_iterator crend () const
 Get a constant reverse iterator pointing to the reverse end of the string. More...
 
size_type size () const
 Get the size of the string. More...
 
size_type length () const
 Alias to size() const.
 
size_type max_size () const
 Get the maximum number of characters a string can hold. More...
 
bool empty () const
 Check if the string has no characters. More...
 
const_reference operator[] (size_type i) const
 Get the character at the given position. More...
 
const_reference at (size_type i) const
 Get the character at the given position. More...
 
const_reference back () const
 Get the last character of the string. More...
 
const_reference front () const
 Get the first character of the string. More...
 
void swap (stringshare &other)
 Swap shared strings with other eina::stringshare.
 
const char * c_str () const
 Get the c-like shared string currently associated with the object. More...
 
const char * data () const
 Alias to c_str() const.
 

Detailed Description

Stringshare class.

It provides an OOP interface to the Eina_Stringshare functions, and automatically take care of sharing the string upon construction and deleting it upon destruction using the RAII programming idiom.

It also provides additional member functions to facilitate the access to the string content, much like a STL string.

Constructor & Destructor Documentation

◆ stringshare() [1/6]

efl::eina::stringshare::stringshare ( )
inline

Default constructor.

Creates a new object holding an shared empty string.

See also
stringshare(const char* str)

◆ stringshare() [2/6]

efl::eina::stringshare::stringshare ( const char *  str)
inline

Share an instance of the given string wrapped by the newly created stringshare object.

Parameters
<tt>NULL</tt>-terminatedstring to be shared.

This constructor creates an eina::stringshare object that shares the given string and wraps the shared pointer, providing an OOP interface to the string content. If the string is already shared this constructor simple increment its reference counter and wraps the shared pointer.

See also
stringshare(const char* str, steal_stringshare_ref_t)

◆ stringshare() [3/6]

efl::eina::stringshare::stringshare ( const char *  str,
steal_stringshare_ref_t   
)
inline

Create an eina::stringshare that steal the ownership of the given shared string.

Parameters
strShared string whose ownership should be stolen.

This constructor creates an eina::stringshare object that steals the ownership of the given shared string. At destruction time, the reference counter for the shared string will be decremented.

The second parameter is an empty object of a specific type that should be supplied to explicitly inform that this is the intended constructor; and to differentiate this from stringshare(const char* str).

Warning
str should be a string that was previously shared (most likely by an call to the native eina_stringshare_add function). If the string is not shared, upon destruction time bad things will happen, likely a segmentation fault.
See also
stringshare(const char* str)

◆ stringshare() [4/6]

template<typename InputIterator >
efl::eina::stringshare::stringshare ( InputIterator  i,
InputIterator  j,
typename eina::enable_if<!eina::is_integral< InputIterator >::value &&!eina::is_contiguous_iterator< InputIterator >::value >::type *  = 0 
)
inline

Share the string between the iterator.

Parameters
iIterator to the initial position of the string (inclusive).
jIterator to the final position of the string (exclusive).
Note
The ending position (pointed by j) is not considered.
See also
stringshare(const char* str)

References eina_stringshare_add().

◆ stringshare() [5/6]

template<typename ContiguousMemoryIterator >
efl::eina::stringshare::stringshare ( ContiguousMemoryIterator  i,
ContiguousMemoryIterator  j,
typename eina::enable_if< eina::is_contiguous_iterator< ContiguousMemoryIterator >::value >::type *  = 0 
)
inline

Share the string between the iterator.

Parameters
iIterator to the initial position of the string (inclusive).
jIterator to the final position of the string (exclusive).
Note
The ending position (pointed by j) is not considered.
See also
stringshare(const char* str)

◆ ~stringshare()

efl::eina::stringshare::~stringshare ( )
inline

Destructor.

Delete the shared string.

Decreases the reference counter associated with the shared string. If the reference counter reaches 0, the memory associated with the string is freed.

References eina_stringshare_del().

◆ stringshare() [6/6]

efl::eina::stringshare::stringshare ( stringshare const &  other)
inline

Copy constructor.

Creates a new eina::stringshare associated with the same shared string.

Parameters
otherAnother eina::stringshare.

This constructor increments the reference counter to the shared string associated with other.

See also
stringshare(const char* str)

Member Function Documentation

◆ operator=() [1/2]

stringshare& efl::eina::stringshare::operator= ( stringshare const &  other)
inline

Replace the current shared string.

Parameters
otherAnother eina::stringshare.

This operator replaces the current shared string by the string shared by other. The reference counter of the older shared string is decremented (the string is released if needed) and the reference counter of the given shared string is incremented.

◆ operator=() [2/2]

stringshare& efl::eina::stringshare::operator= ( const char *  c_string)
inline

Replace the current shared string.

Parameters
c_stringNULL-terminated string.

This operator replaces the shared string currently associated with this object by a shared instance of c_string.

See also
stringshare(const char* str)

◆ begin()

const_iterator efl::eina::stringshare::begin ( ) const
inline

Get a constant iterator pointing to the first character of the string.

Returns
Constant iterator to the initial position of the string.

This member function returns a constant iterator pointing to the first character of the string. If the string is empty the iterator is equal to the one returned by end() const.

Referenced by cbegin(), and rend().

◆ end()

const_iterator efl::eina::stringshare::end ( ) const
inline

Get a constant iterator to the position following the last character of the string.

Returns
Constant iterator to the final position of the string.

This member function returns an constant iterator to the position following the last character in the string. If the string is empty the iterator is equal to the one returned by begin().

Note
Note that attempting to access this position causes undefined behavior.

References size().

Referenced by cend(), and rbegin().

◆ rbegin()

const_reverse_iterator efl::eina::stringshare::rbegin ( ) const
inline

Get a constant reverse iterator pointing to the reverse begin of the string.

Returns
Constant reverse iterator pointing to the reverse begin of the string.

This member function returns a constant reverse iterator pointing to the last character of the string. If the string is empty the returned reverse iterator is the same as the one returned by rend() const.

References end().

Referenced by crbegin().

◆ rend()

const_reverse_iterator efl::eina::stringshare::rend ( ) const
inline

Get a constant reverse iterator pointing to the reverse end of the string.

Returns
Constant reverse iterator pointing to the reverse end of the string.

This member function returns a constant reverse iterator pointing to the position before the first character of the string. If the string is empty the returned iterator is the same as the one returned by rbegin() const.

Note
Note that attempting to access this position causes undefined behavior.

References begin().

Referenced by crend().

◆ cbegin()

const_iterator efl::eina::stringshare::cbegin ( ) const
inline

Get a constant iterator pointing to the first character of the string.

Returns
Constant iterator to the initial position of the string.

This member function works just like begin() const. But it is granted to always return a constant iterator.

References begin().

◆ cend()

const_iterator efl::eina::stringshare::cend ( ) const
inline

Get a constant iterator to the position following the last character of the string.

Returns
Constant iterator to the final position of the string.

This member function works just like end() const. But it is granted to always return a constant iterator.

References end().

◆ crbegin()

const_reverse_iterator efl::eina::stringshare::crbegin ( ) const
inline

Get a constant reverse iterator pointing to the reverse begin of the string.

Returns
Constant reverse iterator pointing to the reverse begin of the string.

This member function works just like rbegin() const. But it is granted to always return a constant reverse iterator.

References rbegin().

◆ crend()

const_reverse_iterator efl::eina::stringshare::crend ( ) const
inline

Get a constant reverse iterator pointing to the reverse end of the string.

Returns
Constant reverse iterator pointing to the reverse end of the string.

This member function works just like rend() const. But it is granted to always return a constant reverse iterator.

References rend().

◆ size()

size_type efl::eina::stringshare::size ( ) const
inline

Get the size of the string.

Returns
Number of characters in the string.

References eina_stringshare_strlen().

Referenced by at(), back(), end(), and length().

◆ max_size()

size_type efl::eina::stringshare::max_size ( ) const
inline

Get the maximum number of characters a string can hold.

Returns
Maximum number of characters a string can hold.

◆ empty()

bool efl::eina::stringshare::empty ( ) const
inline

Check if the string has no characters.

Returns
true if the string has no characters, false otherwise.

◆ operator[]()

const_reference efl::eina::stringshare::operator[] ( size_type  i) const
inline

Get the character at the given position.

Parameters
iPosition of the character in the string.
Returns
Constant reference to the character at the given position.
Note
Do not check if the given position exceeds the string size.

◆ at()

const_reference efl::eina::stringshare::at ( size_type  i) const
inline

Get the character at the given position.

Parameters
iPosition of the character in the string.
Returns
Constant reference to the character at the given position.
Exceptions
<tt>std::out_of_range</tt>if the given position exceeds the string size.

This member function returns a constant reference to the character at the position i. If i exceeds the string size this function will throw a std::out_of_range.

References size().

◆ back()

const_reference efl::eina::stringshare::back ( ) const
inline

Get the last character of the string.

Returns
Constant reference to the last character of the string.

References size().

◆ front()

const_reference efl::eina::stringshare::front ( ) const
inline

Get the first character of the string.

Returns
Constant reference to the first character of the string.

◆ c_str()

const char* efl::eina::stringshare::c_str ( ) const
inline

Get the c-like shared string currently associated with the object.

Returns
Pointer to the shared string.
Note
The pointer returned may be invalidated by calls to non-const member functions.

Referenced by efl::eina::operator==().