| Version: 3.2.5

Public Member Functions | List of all members
wxCharTypeBuffer< T > Class Template Reference
Class List by Category » Data Structures

`#include <wx/buffer.h>`

Inheritance diagram for wxCharTypeBuffer< T >:
[legend]

## Detailed Description

### template<typename T>
class wxCharTypeBuffer< T >

wxCharTypeBuffer<T> is a template class for storing characters.

The difference from wxScopedCharTypeBuffer<T> is that this class doesn't have non-owned mode and the data stored in it are valid for as long as the buffer instance exists. Other than that, this class' behaviour is the same as wxScopedCharTypeBuffer<T>'s – in particular, the data are reference-counted and copying the buffer is cheap.

wxScopedCharTypeBuffer<T> buffers can be converted into wxCharTypeBuffer<T>.

Template Parameters

  T | The type of the characters stored in this class.

Since
  2.9.0

##

Library: None; this class implementation is entirely header-based.
Category: Data Structures

## Public Member Functions

| wxCharTypeBuffer (const CharType *str=NULL, size_t len=wxNO_LEN)
| Creates (owned) buffer from str and takes ownership of it. More...
| wxCharTypeBuffer (size_t len)
| Creates (owned) buffer of size len. More...
| wxCharTypeBuffer (const wxCharTypeBuffer &src)
| Copy constructor. More...
| wxCharTypeBuffer (const wxScopedCharTypeBuffer< T > &src)
| Makes a copy of scoped buffer src. More...
wxCharTypeBuffer & | operator= (const CharType *str)
| Assigns str to this buffer and takes ownership of it (i.e. the buffer becomes "owned"). More...
wxCharTypeBuffer & | operator= (const wxCharTypeBuffer &src)
| Assignment operator behaves in the same way as the copy constructor. More...
wxCharTypeBuffer & | operator= (const wxScopedCharTypeBuffer< T > &src)
| Assigns a scoped buffer to this buffer. More...
bool | extend (size_t len)
| Extends the buffer to have size len. More...
bool | shrink (size_t len)
| Shrinks the buffer to have size len and NUL-terminates the string at this length. More...
Public Member Functions inherited from wxScopedCharTypeBuffer< T >
| wxScopedCharTypeBuffer ()
| Default constructor, creates NULL buffer. More...
| wxScopedCharTypeBuffer (const wxScopedCharTypeBuffer &src)
| Copy constructor. More...
wxScopedCharTypeBuffer & | operator= (const wxScopedCharTypeBuffer &src)
| Assignment operator behaves in the same way as the copy constructor. More...
| ~wxScopedCharTypeBuffer ()
| Destructor. More...
CharType * | release () const
| Returns the internal pointer and resets the buffer. More...
void | reset ()
| Resets the buffer to NULL, freeing the data if necessary. More...
CharType * | data ()
| Returns pointer to the stored data. More...
const CharType * | data () const
| Returns const pointer to the stored data. More...
size_t | length () const
| Returns length of the string stored. More...
| operator const CharType * () const
| Implicit conversion to C string. More...
CharType | operator[] (size_t n) const
| Random access to the stored C string. More...

## Additional Inherited Members

Public Types inherited from wxScopedCharTypeBuffer< T >
typedef T | CharType
| Stored characters type. More...
Static Public Member Functions inherited from wxScopedCharTypeBuffer< T >
static const wxScopedCharTypeBuffer | CreateNonOwned (const CharType *str, size_t len=wxNO_LEN)
| Creates non-owned buffer from string data str. More...
static const wxScopedCharTypeBuffer | CreateOwned (CharType *str, size_t len=wxNO_LEN)
| Creates owned buffer from str and takes ownership of it. More...

## Constructor & Destructor Documentation

## ◆ wxCharTypeBuffer() [1/4]

template<typename T >

wxCharTypeBuffer< T >::wxCharTypeBuffer | ( | const CharType * | str = `NULL`,
|  | size_t | len = `wxNO_LEN`
| ) |  |

Creates (owned) buffer from str and takes ownership of it.

Parameters

  str | String data.
  len | If specified, length of the string, otherwise the string is considered to be NUL-terminated.

See also
  wxScopedCharTypeBuffer<T>::CreateOwned()

## ◆ wxCharTypeBuffer() [2/4]

template<typename T >

wxCharTypeBuffer< T >::wxCharTypeBuffer | ( | size_t | len | ) |

Creates (owned) buffer of size len.

See also
  wxScopedCharTypeBuffer<T>::CreateOwned()

## ◆ wxCharTypeBuffer() [3/4]

template<typename T >

wxCharTypeBuffer< T >::wxCharTypeBuffer | ( | const wxCharTypeBuffer< T > & | src | ) |

Copy constructor.

Increases reference count on the data, does not make wxStrdup() copy of the data.

## ◆ wxCharTypeBuffer() [4/4]

template<typename T >

wxCharTypeBuffer< T >::wxCharTypeBuffer | ( | const wxScopedCharTypeBuffer< T > & | src | ) |

Makes a copy of scoped buffer src.

If src is a non-owned buffer, a copy of its data is made using wxStrdup(). If src is an owned buffer, this constructor behaves in the usual way (reference count on buffer data is incremented).

## Member Function Documentation

## ◆ extend()

template<typename T >

bool wxCharTypeBuffer< T >::extend | ( | size_t | len | ) |

Extends the buffer to have size len.

Can only be called on buffers that don't share data with another buffer (i.e. reference count of the data is 1).

See also
  shrink()

## ◆ operator=() [1/3]

template<typename T >

wxCharTypeBuffer& wxCharTypeBuffer< T >::operator= | ( | const CharType * | str | ) |

Assigns str to this buffer and takes ownership of it (i.e. the buffer becomes "owned").

## ◆ operator=() [2/3]

template<typename T >

wxCharTypeBuffer& wxCharTypeBuffer< T >::operator= | ( | const wxCharTypeBuffer< T > & | src | ) |

Assignment operator behaves in the same way as the copy constructor.

## ◆ operator=() [3/3]

template<typename T >

wxCharTypeBuffer& wxCharTypeBuffer< T >::operator= | ( | const wxScopedCharTypeBuffer< T > & | src | ) |

Assigns a scoped buffer to this buffer.

If src is a non-owned buffer, a copy of its data is made using wxStrdup(). If src is an owned buffer, the assignment behaves in the usual way (reference count on buffer data is incremented).

## ◆ shrink()

template<typename T >

bool wxCharTypeBuffer< T >::shrink | ( | size_t | len | ) |

Shrinks the buffer to have size len and NUL-terminates the string at this length.

Can only be called on buffers that don't share data with another buffer (i.e. reference count of the data is 1).

Parameters

  len | Length to shrink to. Must not be larger than current length.

Note
  The string is not reallocated to take less memory.

Since
  2.9.0

See also
  extend()