efl::eina::stringshare Struct Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Class Hierarchy
- Data Fields

Public Types | Public Member Functions
efl::eina::stringshare Struct Reference
Eina C++ » Data Types » Stringshare

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...
stringshare & | operator= (stringshare const &other)
| Replace the current shared string. More...
stringshare & | operator= (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

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

Default constructor.

Creates a new object holding an shared empty string.

See also
  stringshare(const char* str)

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>-terminated | string 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)

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

  str | Shared 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)

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

  i | Iterator to the initial position of the string (inclusive).
  j | Iterator 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().

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

  i | Iterator to the initial position of the string (inclusive).
  j | Iterator to the final position of the string (exclusive).

Note
  The ending position (pointed by `j`) is not considered.

See also
  stringshare(const char* str)

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().

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

Copy constructor.

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

Parameters

  other | Another `eina::stringshare`.

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

See also
  stringshare(const char* str)

## Member Function Documentation

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

Replace the current shared string.

Parameters

  other | Another `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.

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

Replace the current shared string.

Parameters

  c_string | `NULL`-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)

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.

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.

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.

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.

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.

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.

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.

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.

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().

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.

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

Check if the string has no characters.

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

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

Get the character at the given position.

Parameters

  i | Position 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.

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

Get the character at the given position.

Parameters

  i | Position 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`.

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.

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.

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==().