Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringView Class Reference

Detailed Description

StringView is a reference to a part of a string, consisting of only a char pointer and a length.

It does not have ownership of the substring and is used mainly for temporary objects.

Definition at line 31 of file string_view.hpp.

#include <string_view.hpp>

Public Types

using iterator = const char *
 

Public Member Functions

 StringView ()=default
 Default constructor for a StringView. Doesn't do anything. More...
 
 StringView (const char *data, size_t size) noexcept
 Creates a new StringView, given a const char* and the size. More...
 
 StringView (const std::string::const_iterator &data, size_t size) noexcept
 Creates a new StringView, given a const iterator to a std::string and the size. More...
 
 StringView (const std::string::const_iterator &begin, const std::string::const_iterator &end) noexcept
 Creates a new reference StringView, given two const iterators to a std::string. More...
 
 StringView (const std::string &str) noexcept
 Construct a StringView to the whole std::string. More...
 
iterator begin () const noexcept
 Returns a pointer to the beginning of the data. More...
 
const char * data () const noexcept
 Returns a pointer to the start of the data. More...
 
iterator end () const noexcept
 Returns a pointer beyond the end of the data. More...
 
bool operator!= (const StringView &other) const noexcept
 Inequality operator to compare a StringView with another StringView. More...
 
bool operator!= (const std::string &other) const noexcept
 Inequality operator to compare a StringView with an std::string. More...
 
bool operator== (const StringView &other) const noexcept
 Equality operator to compare a StringView with another StringView. More...
 
bool operator== (const std::string &other) const noexcept
 Equality operator to compare a StringView with an std::string. More...
 
size_t size () const noexcept
 Returns the size of this StringView. More...
 
std::string ToString () const
 Returns the data of this StringView as an std::string. More...
 

Private Attributes

const char * data_ = nullptr
 pointer to character data More...
 
size_t size_ = 0
 size of data More...
 

Friends

std::ostream & operator<< (std::ostream &os, const StringView &sv)
 make StringView ostreamable More...
 

Member Typedef Documentation

using iterator = const char*

Definition at line 34 of file string_view.hpp.

Constructor & Destructor Documentation

StringView ( )
default

Default constructor for a StringView. Doesn't do anything.

StringView ( const char *  data,
size_t  size 
)
inlinenoexcept

Creates a new StringView, given a const char* and the size.

Parameters
datapointer to start of data
sizesize of data in bytes.
Returns
new StringView object.

Definition at line 46 of file string_view.hpp.

StringView ( const std::string::const_iterator &  data,
size_t  size 
)
inlinenoexcept

Creates a new StringView, given a const iterator to a std::string and the size.

Parameters
dataiterator to start of data
sizesize of data in character.
Returns
new StringView object.

Definition at line 57 of file string_view.hpp.

StringView ( const std::string::const_iterator &  begin,
const std::string::const_iterator &  end 
)
inlinenoexcept

Creates a new reference StringView, given two const iterators to a std::string.

Parameters
beginiterator to start of data
enditerator to the end of data.
Returns
new StringView object.

Definition at line 68 of file string_view.hpp.

StringView ( const std::string &  str)
inlineexplicitnoexcept

Construct a StringView to the whole std::string.

Definition at line 73 of file string_view.hpp.

Member Function Documentation

iterator begin ( ) const
inlinenoexcept

Returns a pointer to the beginning of the data.

Definition at line 82 of file string_view.hpp.

References StringView::data_.

Referenced by hash< thrill::common::StringView >::operator()().

const char* data ( ) const
inlinenoexcept

Returns a pointer to the start of the data.

Definition at line 77 of file string_view.hpp.

References StringView::data_.

iterator end ( ) const
inlinenoexcept

Returns a pointer beyond the end of the data.

Definition at line 87 of file string_view.hpp.

References StringView::data_, and StringView::size_.

Referenced by hash< thrill::common::StringView >::operator()().

bool operator!= ( const StringView other) const
inlinenoexcept

Inequality operator to compare a StringView with another StringView.

Definition at line 103 of file string_view.hpp.

References StringView::operator==().

bool operator!= ( const std::string &  other) const
inlinenoexcept

Inequality operator to compare a StringView with an std::string.

Definition at line 114 of file string_view.hpp.

References StringView::operator==().

bool operator== ( const StringView other) const
inlinenoexcept

Equality operator to compare a StringView with another StringView.

Definition at line 97 of file string_view.hpp.

References StringView::data_, and StringView::size_.

Referenced by StringView::operator!=().

bool operator== ( const std::string &  other) const
inlinenoexcept

Equality operator to compare a StringView with an std::string.

Definition at line 108 of file string_view.hpp.

References StringView::data_, and StringView::size_.

size_t size ( ) const
inlinenoexcept

Returns the size of this StringView.

Definition at line 92 of file string_view.hpp.

References StringView::size_.

Referenced by examples::word_count::HashWordCountExample(), main(), and examples::word_count::WordCount().

std::string ToString ( ) const
inline

Returns the data of this StringView as an std::string.

Definition at line 124 of file string_view.hpp.

References StringView::data_, and StringView::size_.

Referenced by examples::word_count::HashWordCountExample(), main(), WordCount(), and examples::word_count::WordCount().

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const StringView sv 
)
friend

make StringView ostreamable

Definition at line 119 of file string_view.hpp.

Member Data Documentation

const char* data_ = nullptr
private

pointer to character data

Definition at line 132 of file string_view.hpp.

Referenced by StringView::begin(), StringView::data(), StringView::end(), StringView::operator==(), and StringView::ToString().

size_t size_ = 0
private

size of data

Definition at line 134 of file string_view.hpp.

Referenced by StringView::end(), StringView::operator==(), StringView::size(), and StringView::ToString().


The documentation for this class was generated from the following file: