Boost C++ Libraries

PrevUpHomeNext

Class template basic_string_literal

boost::log::basic_string_literal — String literal wrapper.

Synopsis

// In header: <boost/log/utility/string_literal.hpp>

template<typename CharT, typename TraitsT = std::char_traits< CharT > > 
class basic_string_literal {
public:
  // types
  typedef CharT                                        value_type;            
  typedef TraitsT                                      traits_type;           
  typedef std::size_t                                  size_type;             
  typedef std::ptrdiff_t                               difference_type;       
  typedef const value_type *                           const_pointer;         
  typedef value_type const &                           const_reference;       
  typedef const value_type *                           const_iterator;        
  typedef std::reverse_iterator< const_iterator >      const_reverse_iterator;
  typedef std::basic_string< value_type, traits_type > string_type;             // Corresponding STL string type. 

  // construct/copy/destruct
  basic_string_literal();
  template<typename T, size_type LenV> basic_string_literal(T(&));
  basic_string_literal(basic_string_literal const &);
  basic_string_literal& operator=(this_type const &);
  template<typename T, size_type LenV> basic_string_literal& operator=(T(&));

  // public member functions
  bool operator==(this_type const &) const;
  bool operator==(const_pointer) const;
  bool operator==(string_type const &) const;
  bool operator<(this_type const &) const;
  bool operator<(const_pointer) const;
  bool operator<(string_type const &) const;
  bool operator>(this_type const &) const;
  bool operator>(const_pointer) const;
  bool operator>(string_type const &) const;
  const_reference operator[](size_type) const;
  const_reference at(size_type) const;
  const_pointer c_str() const;
  const_pointer data() const;
  size_type size() const;
  size_type length() const;
  bool empty() const;
  const_iterator begin() const;
  const_iterator end() const;
  const_reverse_iterator rbegin() const;
  const_reverse_iterator rend() const;
  string_type str() const;
  void clear();
  void swap(this_type &);
  this_type & assign(this_type const &);
  template<typename T, size_type LenV> this_type & assign(T(&));
  size_type copy(value_type *, size_type, size_type = 0) const;
  int compare(size_type, size_type, const_pointer, size_type) const;
  int compare(size_type, size_type, const_pointer) const;
  int compare(size_type, size_type, this_type const &) const;
  int compare(const_pointer, size_type) const;
  int compare(const_pointer) const;
  int compare(this_type const &) const;
};

Description

The basic_string_literal is a thin wrapper around a constant string literal. It provides interface similar to STL strings, but because of read-only nature of string literals, lacks ability to modify string contents. However, basic_string_literal objects can be assigned to and cleared.

The main advantage of this class comparing to other string classes is that it doesn't dynamically allocate memory and therefore is fast, thin and exception safe.

basic_string_literal public construct/copy/destruct

  1. basic_string_literal();

    Constructor

    Postconditions:

    empty() == true

  2. template<typename T, size_type LenV> basic_string_literal(T(&) p);

    Constructor from a string literal

    Parameters:
    p

    A zero-terminated constant sequence of characters

    Postconditions:

    *this == p

  3. basic_string_literal(basic_string_literal const & that);

    Copy constructor

    Parameters:
    that

    Source literal to copy string from

    Postconditions:

    *this == that

  4. basic_string_literal& operator=(this_type const & that);

    Assignment operator

    Parameters:
    that

    Source literal to copy string from

    Postconditions:

    *this == that

  5. template<typename T, size_type LenV> basic_string_literal& operator=(T(&) p);

    Assignment from a string literal

    Parameters:
    p

    A zero-terminated constant sequence of characters

    Postconditions:

    *this == p

basic_string_literal public member functions

  1. bool operator==(this_type const & that) const;

    Lexicographical comparison (equality)

    Parameters:
    that

    Comparand

    Returns:

    true if the comparand string equals to this string, false otherwise

  2. bool operator==(const_pointer str) const;

    Lexicographical comparison (equality)

    Parameters:
    str

    Comparand. Must point to a zero-terminated sequence of characters, must not be NULL.

    Returns:

    true if the comparand string equals to this string, false otherwise

  3. bool operator==(string_type const & that) const;

    Lexicographical comparison (equality)

    Parameters:
    that

    Comparand

    Returns:

    true if the comparand string equals to this string, false otherwise

  4. bool operator<(this_type const & that) const;

    Lexicographical comparison (less ordering)

    Parameters:
    that

    Comparand

    Returns:

    true if this string is less than the comparand, false otherwise

  5. bool operator<(const_pointer str) const;

    Lexicographical comparison (less ordering)

    Parameters:
    str

    Comparand. Must point to a zero-terminated sequence of characters, must not be NULL.

    Returns:

    true if this string is less than the comparand, false otherwise

  6. bool operator<(string_type const & that) const;

    Lexicographical comparison (less ordering)

    Parameters:
    that

    Comparand

    Returns:

    true if this string is less than the comparand, false otherwise

  7. bool operator>(this_type const & that) const;

    Lexicographical comparison (greater ordering)

    Parameters:
    that

    Comparand

    Returns:

    true if this string is greater than the comparand, false otherwise

  8. bool operator>(const_pointer str) const;

    Lexicographical comparison (greater ordering)

    Parameters:
    str

    Comparand. Must point to a zero-terminated sequence of characters, must not be NULL.

    Returns:

    true if this string is greater than the comparand, false otherwise

  9. bool operator>(string_type const & that) const;

    Lexicographical comparison (greater ordering)

    Parameters:
    that

    Comparand

    Returns:

    true if this string is greater than the comparand, false otherwise

  10. const_reference operator[](size_type i) const;

    Subscript operator

    Parameters:
    i

    Requested character index

    Requires:

    i < size()

    Returns:

    Constant reference to the requested character

  11. const_reference at(size_type i) const;

    Checked subscript

    Throws: An std::exception-based exception if index i is out of string boundaries

    Parameters:
    i

    Requested character index

    Returns:

    Constant reference to the requested character

  12. const_pointer c_str() const;

    Returns:

    Pointer to the beginning of the literal

  13. const_pointer data() const;

    Returns:

    Pointer to the beginning of the literal

  14. size_type size() const;

    Returns:

    Length of the literal

  15. size_type length() const;

    Returns:

    Length of the literal

  16. bool empty() const;

    Returns:

    true if the literal is an empty string, false otherwise

  17. const_iterator begin() const;

    Returns:

    Iterator that points to the first character of the literal

  18. const_iterator end() const;

    Returns:

    Iterator that points after the last character of the literal

  19. const_reverse_iterator rbegin() const;

    Returns:

    Reverse iterator that points to the last character of the literal

  20. const_reverse_iterator rend() const;

    Returns:

    Reverse iterator that points before the first character of the literal

  21. string_type str() const;

    Returns:

    STL string constructed from the literal

  22. void clear();

    The method clears the literal

    Postconditions:

    empty() == true

  23. void swap(this_type & that);

    The method swaps two literals

  24. this_type & assign(this_type const & that);

    Assignment from another literal

    Parameters:
    that

    Source literal to copy string from

    Postconditions:

    *this == that

  25. template<typename T, size_type LenV> this_type & assign(T(&) p);

    Assignment from another literal

    Parameters:
    p

    A zero-terminated constant sequence of characters

    Postconditions:

    *this == p

  26. size_type copy(value_type * str, size_type n, size_type pos = 0) const;

    The method copies the literal or its portion to an external buffer

    Throws: An std::exception-based exception if pos is out of range.

    Parameters:
    n

    Maximum number of characters to copy

    pos

    Starting position to start copying from

    str

    Pointer to the external buffer beginning. Must not be NULL. The buffer must have enough capacity to accommodate the requested number of characters.

    Requires:

    pos <= size()

    Returns:

    Number of characters copied

  27. int compare(size_type pos, size_type n, const_pointer str, size_type len) const;

    Lexicographically compares the argument string to a part of this string

    Throws: An std::exception-based exception if pos is out of range.

    Parameters:
    len

    Number of characters in the sequence str.

    n

    Length of the substring of this string to perform comparison to

    pos

    Starting position within this string to perform comparison to

    str

    Comparand. Must point to a sequence of characters, must not be NULL.

    Requires:

    pos <= size()

    Returns:

    Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand.

  28. int compare(size_type pos, size_type n, const_pointer str) const;

    Lexicographically compares the argument string to a part of this string

    Throws: An std::exception-based exception if pos is out of range.

    Parameters:
    n

    Length of the substring of this string to perform comparison to

    pos

    Starting position within this string to perform comparison to

    str

    Comparand. Must point to a zero-terminated sequence of characters, must not be NULL.

    Requires:

    pos <= size()

    Returns:

    Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand.

  29. int compare(size_type pos, size_type n, this_type const & that) const;

    Lexicographically compares the argument string literal to a part of this string

    Throws: An std::exception-based exception if pos is out of range.

    Parameters:
    n

    Length of the substring of this string to perform comparison to

    pos

    Starting position within this string to perform comparison to

    that

    Comparand

    Requires:

    pos <= size()

    Returns:

    Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand.

  30. int compare(const_pointer str, size_type len) const;

    Lexicographically compares the argument string to this string

    Parameters:
    len

    Number of characters in the sequence str.

    str

    Comparand. Must point to a sequence of characters, must not be NULL.

    Returns:

    Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand.

  31. int compare(const_pointer str) const;

    Lexicographically compares the argument string to this string

    Parameters:
    str

    Comparand. Must point to a zero-terminated sequence of characters, must not be NULL.

    Returns:

    Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand.

  32. int compare(this_type const & that) const;

    Lexicographically compares the argument string to this string

    Parameters:
    that

    Comparand

    Returns:

    Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand.


PrevUpHomeNext