Qt 4.8
Public Functions | Public Variables | Private Types | Private Functions | Friends | List of all members
QStringBuilder< A, B > Class Template Reference

The QStringBuilder class is a template class that provides a facility to build up QStrings from smaller chunks. More...

#include <qstringbuilder.h>

Public Functions

 operator ConvertTo () const
 
 QStringBuilder (const A &a_, const B &b_)
 Constructs a QStringBuilder from a and b. More...
 
int size () const
 
QByteArray toLatin1 () const
 Returns a Latin-1 representation of the string as a QByteArray. More...
 

Public Variables

const Aa
 
const B & b
 

Private Types

typedef QConcatenable< QStringBuilder< A, B > > Concatenable
 
typedef Concatenable::ConvertTo ConvertTo
 

Private Functions

template<typename T >
convertTo () const
 

Friends

class QByteArray
 
class QString
 

Detailed Description

template<typename A, typename B>
class QStringBuilder< A, B >

The QStringBuilder class is a template class that provides a facility to build up QStrings from smaller chunks.

Warning
This function is not part of the public interface.
Note
This class or function is reentrant.
Since
4.6

To build a QString by multiple concatenations, QString::operator+() is typically used. This causes n - 1 reallocations when building a string from n chunks.

QStringBuilder uses expression templates to collect the individual chunks, compute the total size, allocate the required amount of memory for the final QString object, and copy the chunks into the allocated memory.

The QStringBuilder class is not to be used explicitly in user code. Instances of the class are created as return values of the operator%() function, acting on objects of type QString, QLatin1String, QLatin1Literal, QStringRef, QChar, QCharRef, QLatin1Char, and char.

Concatenating strings with operator%() generally yields better performance then using QString::operator+() on the same chunks if there are three or more of them, and performs equally well in other cases.

See also
QLatin1Literal, QString

Definition at line 112 of file qstringbuilder.h.

Typedefs

◆ Concatenable

template<typename A, typename B>
typedef QConcatenable<QStringBuilder<A, B> > QStringBuilder< A, B >::Concatenable
private

Definition at line 136 of file qstringbuilder.h.

◆ ConvertTo

template<typename A, typename B>
typedef Concatenable::ConvertTo QStringBuilder< A, B >::ConvertTo
private

Definition at line 137 of file qstringbuilder.h.

Constructors and Destructors

◆ QStringBuilder()

template<typename A, typename B>
QStringBuilder< A, B >::QStringBuilder ( const A a_,
const B &  b_ 
)
inline

Constructs a QStringBuilder from a and b.

Definition at line 115 of file qstringbuilder.h.

115 : a(a_), b(b_) {}

Functions

◆ convertTo()

template<typename A, typename B>
template<typename T >
T QStringBuilder< A, B >::convertTo ( ) const
inlineprivate

Definition at line 119 of file qstringbuilder.h.

120  {
121  const uint len = QConcatenable< QStringBuilder<A, B> >::size(*this);
122  T s(len, Qt::Uninitialized);
123 
124  typename T::iterator d = s.data();
125  typename T::const_iterator const start = d;
126  QConcatenable< QStringBuilder<A, B> >::appendTo(*this, d);
127 
128  if (!QConcatenable< QStringBuilder<A, B> >::ExactSize && int(len) != d - start) {
129  // this resize is necessary since we allocate a bit too much
130  // when dealing with variable sized 8-bit encodings
131  s.resize(d - start);
132  }
133  return s;
134  }
double d
Definition: qnumeric_p.h:62
The QStringBuilder class is a template class that provides a facility to build up QStrings from small...
unsigned int uint
Definition: qglobal.h:996
int size() const

◆ operator ConvertTo()

template<typename A, typename B>
QStringBuilder< A, B >::operator ConvertTo ( ) const
inline

Definition at line 139 of file qstringbuilder.h.

139 { return convertTo<ConvertTo>(); }

◆ size()

template<typename A, typename B>
int QStringBuilder< A, B >::size ( ) const
inline

Definition at line 142 of file qstringbuilder.h.

142 { return Concatenable::size(*this); }

◆ toLatin1()

template<typename A, typename B>
QByteArray QStringBuilder< A, B >::toLatin1 ( ) const
inline

Returns a Latin-1 representation of the string as a QByteArray.

The returned byte array is undefined if the string contains non-Latin1 characters.

Definition at line 141 of file qstringbuilder.h.

Referenced by QStringBuilder< A, B >::toLatin1().

141 { return convertTo<QString>().toLatin1(); }
QByteArray toLatin1() const
Returns a Latin-1 representation of the string as a QByteArray.

Friends and Related Functions

◆ QByteArray

template<typename A, typename B>
friend class QByteArray
friend

Definition at line 117 of file qstringbuilder.h.

◆ QString

template<typename A, typename B>
friend class QString
friend

Definition at line 118 of file qstringbuilder.h.

Properties

◆ a

template<typename A, typename B>
const A& QStringBuilder< A, B >::a

◆ b

template<typename A, typename B>
const B& QStringBuilder< A, B >::b

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