Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Static Public Member Functions

bslstl::StringRefImp< CHAR_TYPE > Class Template Reference

#include <bslstl_stringref.h>

Inheritance diagram for bslstl::StringRefImp< CHAR_TYPE >:
bslstl::StringRefData< CHAR_TYPE >

List of all members.

Public Types

typedef const CHAR_TYPE value_type
typedef const CHAR_TYPE & reference
typedef const CHAR_TYPE & const_reference
typedef const CHAR_TYPE * iterator
typedef const CHAR_TYPE * const_iterator
typedef bsl::reverse_iterator
< const_iterator
const_reverse_iterator
typedef std::ptrdiff_t difference_type
typedef std::size_t size_type

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (StringRefImp, bsl::is_trivially_copyable)
 StringRefImp ()
template<class INT_TYPE >
 StringRefImp (const CHAR_TYPE *data, INT_TYPE length, typename bsl::enable_if< bsl::is_integral< INT_TYPE >::value, bslmf::Nil >::type=bslmf::Nil())
 StringRefImp (const CHAR_TYPE *data, size_type length)
 StringRefImp (const_iterator begin, const_iterator end)
 StringRefImp (const CHAR_TYPE *data)
 StringRefImp (const bsl::basic_string_view< CHAR_TYPE > &str)
 StringRefImp (const std::basic_string< CHAR_TYPE > &str)
 StringRefImp (const bsl::basic_string< CHAR_TYPE > &str)
 StringRefImp (const StringRefImp &original, size_type startIndex, size_type numCharacters)
StringRefImpoperator= (const StringRefImp &rhs)
template<class INT_TYPE >
void assign (const CHAR_TYPE *data, INT_TYPE length, typename bsl::enable_if< bsl::is_integral< INT_TYPE >::value, bslmf::Nil >::type=bslmf::Nil())
void assign (const CHAR_TYPE *data, size_type length)
void assign (const_iterator begin, const_iterator end)
void assign (const CHAR_TYPE *data)
void assign (const bsl::basic_string< CHAR_TYPE > &str)
void assign (const StringRefImp< CHAR_TYPE > &stringRef)
void reset ()
const_reference operator[] (size_type index) const
 operator std::basic_string< CHAR_TYPE > () const
const_iterator begin () const
const_iterator end () const
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
const CHAR_TYPE * data () const
bool empty () const
bool isEmpty () const
size_type length () const
size_type size () const
int compare (const StringRefImp &other) const
 BSLMF_NESTED_TRAIT_DECLARATION (StringRefData, bsl::is_trivially_copyable)

Static Public Member Functions

static std::size_t cStringLength (const CHAR_TYPE *data)

Detailed Description

template<class CHAR_TYPE>
class bslstl::StringRefImp< CHAR_TYPE >

This class provides a reference-semantic-like (see below) mechanism that allows const std::string values, which are represented externally as either an std::string or null-terminated c-style string (or parts thereof), to be treated both uniformly and efficiently when passed as an argument to a function in which the string's length will be needed. The interface of this class provides a subset of accessor methods found on std::string (but none of the manipulators) -- all of which apply to the referenced string. But, because only non-modifiable access is afforded to the referenced string value, each of the manipulators on this type -- assignment in particular -- apply to this string-reference object itself (as if it had pointer semantics). Hence, this class has a hybrid of reference- and pointer-semantics.

This class:

For terminology see bsldoc_glossary.

See Component bslstl_stringref


Member Typedef Documentation

template<class CHAR_TYPE>
typedef const CHAR_TYPE bslstl::StringRefImp< CHAR_TYPE >::value_type
template<class CHAR_TYPE>
typedef const CHAR_TYPE& bslstl::StringRefImp< CHAR_TYPE >::reference
template<class CHAR_TYPE>
typedef const CHAR_TYPE& bslstl::StringRefImp< CHAR_TYPE >::const_reference
template<class CHAR_TYPE>
typedef const CHAR_TYPE* bslstl::StringRefImp< CHAR_TYPE >::iterator
template<class CHAR_TYPE>
typedef const CHAR_TYPE* bslstl::StringRefImp< CHAR_TYPE >::const_iterator
template<class CHAR_TYPE>
typedef bsl::reverse_iterator<const_iterator> bslstl::StringRefImp< CHAR_TYPE >::const_reverse_iterator
template<class CHAR_TYPE>
typedef std::ptrdiff_t bslstl::StringRefImp< CHAR_TYPE >::difference_type
template<class CHAR_TYPE>
typedef std::size_t bslstl::StringRefImp< CHAR_TYPE >::size_type

Constructor & Destructor Documentation

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp (  ) 

Create an object representing an empty std::string value that is independent of any external representation and with the following attribute values:

          begin() == end()
          isEmpty() == true
template<class CHAR_TYPE>
template<class INT_TYPE >
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const CHAR_TYPE *  data,
INT_TYPE  length,
typename bsl::enable_if< bsl::is_integral< INT_TYPE >::value, bslmf::Nil >::type  = bslmf::Nil() 
)
template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const CHAR_TYPE *  data,
size_type  length 
)

Create a string-reference object having a valid std::string value, whose external representation begins at the specified data address and extends for the specified length. The external representation must remain valid as long as it is bound to this string reference. Passing 0 has the same effect as default construction. The behavior is undefined unless 0 <= length and, if 0 == data, then 0 == length. Note that, like an std::string, the data need not be null-terminated and may contain embedded null characters. Note that the template and non-template versions combine to allow various integral and enumeration types to be used for length while preventing (char *, 0) initializer arguments from matching the two-iterator constructor below.

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const_iterator  begin,
const_iterator  end 
)

Create a string-reference object having a valid std::string value, whose external representation begins at the specified begin iterator and extends up to, but not including, the specified end iterator. The external representation must remain valid as long as it is bound to this string reference. The behavior is undefined unless begin <= end. Note that, like an std::string, the string need not be null-terminated and may contain embedded null characters.

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const CHAR_TYPE *  data  ) 

IMPLICIT: Create a string-reference object having a valid std::string value, whose external representation begins at the specified data address and extends for std::char_traits<CHAR_TYPE>length(data) characters. The external representation must remain valid as long as it is bound to this string reference. The behavior is undefined unless data is null-terminated.

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const bsl::basic_string_view< CHAR_TYPE > &  str  ) 

IMPLICIT:

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const std::basic_string< CHAR_TYPE > &  str  ) 

IMPLICIT:

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const bsl::basic_string< CHAR_TYPE > &  str  ) 

IMPLICIT: Create a string-reference object having a valid std::string value, whose external representation is defined by the specified str object. The external representation must remain valid as long as it is bound to this string reference.

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::StringRefImp ( const StringRefImp< CHAR_TYPE > &  original,
size_type  startIndex,
size_type  numCharacters 
)

Create a string-reference object having a valid std::string value, whose external representation begins at the specified startIndex in the specified original string reference, and extends either the specified numCharacters or until the end of the original string reference, whichever comes first. The external representation must remain valid as long as it is bound to this string reference. The behavior is undefined unless startIndex <= original.length(). Note that if startIndex is original.length() an empty string reference is returned.


Member Function Documentation

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( StringRefImp< CHAR_TYPE >  ,
bsl::is_trivially_copyable   
)
template<class CHAR_TYPE>
StringRefImp& bslstl::StringRefImp< CHAR_TYPE >::operator= ( const StringRefImp< CHAR_TYPE > &  rhs  ) 

Modify this string reference to refer to the same string as the specified rhs string reference and return a reference providing modifiable access to this object. The assigned object is guaranteed to have values of attributes begin and end equal to the rhs object's attributes.

template<class CHAR_TYPE>
template<class INT_TYPE >
void bslstl::StringRefImp< CHAR_TYPE >::assign ( const CHAR_TYPE *  data,
INT_TYPE  length,
typename bsl::enable_if< bsl::is_integral< INT_TYPE >::value, bslmf::Nil >::type  = bslmf::Nil() 
)
template<class CHAR_TYPE>
void bslstl::StringRefImp< CHAR_TYPE >::assign ( const CHAR_TYPE *  data,
size_type  length 
)

Bind this string reference to the string at the specified data address and extending for the specified length characters. The string indicated by data and length must remain valid as long as it is bound to this object. The behavior is undefined unless 0 <= length or 0 == data && 0 == length. Note that the string need not be null-terminated and may contain embedded null characters. Note that the template and non-template versions combine to allow various integral and enumeration types to be used for length while preventing (char *, 0) initializer arguments from matching the two-iterator overload of assign below.

template<class CHAR_TYPE>
void bslstl::StringRefImp< CHAR_TYPE >::assign ( const_iterator  begin,
const_iterator  end 
)

Bind this string reference to the string at the specified begin iterator, extending up to, but not including, the character at the specified end iterator. The string indicated by begin and end must remain valid as long as it is bound to this object. The behavior is undefined unless begin <= end. Note that the string need not be null-terminated and may contain embedded null characters.

template<class CHAR_TYPE>
void bslstl::StringRefImp< CHAR_TYPE >::assign ( const CHAR_TYPE *  data  ) 

Bind this string reference to the string at the specified data address and extending for std::char_traits<CHAR_TYPE>length(data) characters. The string at the data address must remain valid as long as it is bound to this string reference. The behavior is undefined unless data is null-terminated.

template<class CHAR_TYPE>
void bslstl::StringRefImp< CHAR_TYPE >::assign ( const bsl::basic_string< CHAR_TYPE > &  str  ) 

Bind this string reference to the specified str string. The string indicated by str must remain valid as long as it is bound to this object.

template<class CHAR_TYPE>
void bslstl::StringRefImp< CHAR_TYPE >::assign ( const StringRefImp< CHAR_TYPE > &  stringRef  ) 

Modify this string reference to refer to the same string as the specified stringRef. Note, that the string bound to stringRef must remain valid as long as it is bound to this object.

template<class CHAR_TYPE>
void bslstl::StringRefImp< CHAR_TYPE >::reset (  ) 

Reset this string reference to the default-constructed state having an empty std::string value and the following attribute values:

          begin() == end()
          isEmpty() == true
template<class CHAR_TYPE>
const_reference bslstl::StringRefImp< CHAR_TYPE >::operator[] ( size_type  index  )  const

Return a reference providing a non-modifiable access to the character at the specified index in the string bound to this reference. This reference remains valid as long as the string currently bound to this object remains valid. The behavior is undefined unless 0 <= index < length().

template<class CHAR_TYPE>
bslstl::StringRefImp< CHAR_TYPE >::operator std::basic_string< CHAR_TYPE > (  )  const

Return an std::basic_string (synonymous with std::basic_string) having the value of the string bound to this string reference.

template<class CHAR_TYPE>
const_iterator bslstl::StringRefImp< CHAR_TYPE >::begin (  )  const

Return an STL-compatible iterator to the first character of the string bound to this string reference or end() if the string reference is empty. The iterator remains valid as long as this object is valid and is bound to the same string.

template<class CHAR_TYPE>
const_iterator bslstl::StringRefImp< CHAR_TYPE >::end (  )  const

Return an STL-compatible iterator one-past-the-last character of the string bound to this string reference or begin() if the string reference is empty. The iterator remains valid as long as this object is valid and is bound to the same string.

template<class CHAR_TYPE>
const_reverse_iterator bslstl::StringRefImp< CHAR_TYPE >::rbegin (  )  const

Return an STL-compatible reverse iterator to the last character of the string bound to this string reference or rend() if the string reference is empty. The iterator remains valid as long as this object is valid and is bound to the same string.

template<class CHAR_TYPE>
const_reverse_iterator bslstl::StringRefImp< CHAR_TYPE >::rend (  )  const

Return an STL-compatible reverse iterator to the prior-to-the-beginning character of the string bound to this string reference or rbegin() if the string reference is empty. The iterator remains valid as long as this object is valid and is bound to the same string.

template<class CHAR_TYPE>
const CHAR_TYPE* bslstl::StringRefImp< CHAR_TYPE >::data (  )  const

Return the address of the first character of the string bound to this string reference such that [data() .. data()+length()) is a valid half-open range of characters. Note that the range of characters might not be null-terminated and may contain embedded null characters.

template<class CHAR_TYPE>
bool bslstl::StringRefImp< CHAR_TYPE >::empty (  )  const

Return true if this object represents an empty string value, and false otherwise. This object represents an empty string value if begin() == end(). Note that this method is functionally identical with the isEmpty method and allows developers to avoid distracting syntax differences when StringRef appears in juxtaposition with string, which defines empty but not isEmpty.

template<class CHAR_TYPE>
bool bslstl::StringRefImp< CHAR_TYPE >::isEmpty (  )  const

Return true if this object represents an empty string value, and false otherwise. This object represents an empty string value if begin() == end().

template<class CHAR_TYPE>
size_type bslstl::StringRefImp< CHAR_TYPE >::length (  )  const

Return the length of the string referred to by this object. Note that this call is equivalent to end() - begin().

template<class CHAR_TYPE>
size_type bslstl::StringRefImp< CHAR_TYPE >::size (  )  const

Return the number of characters in the string referred to by this object. Note that this call is equivalent to end() - begin().

template<class CHAR_TYPE>
int bslstl::StringRefImp< CHAR_TYPE >::compare ( const StringRefImp< CHAR_TYPE > &  other  )  const

Compare this and the specified other string objects using a lexicographical comparison and return a negative value if this string is less than other string, a positive value if this string is greater than other string, and 0 if this string is equal to other string.

template<class CHAR_TYPE >
std::size_t bslstl::StringRefData< CHAR_TYPE >::cStringLength ( const CHAR_TYPE *  data  )  [inline, static, inherited]

Return the number of CHAR_TYPE characters in the specified null-terminated data string, up to but not including the terminal null value.

References BSLS_ASSERT_SAFE.

template<class CHAR_TYPE>
bslstl::StringRefData< CHAR_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( StringRefData< CHAR_TYPE >  ,
bsl::is_trivially_copyable   
) [inherited]

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