glibmm: Glib::ByteArray Class Reference

glibmm 2.89.1

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Glib::ByteArray Class Referencefinal

ByteArray - Arrays of bytes. More...

`#include <glibmm/bytearray.h>`

## Public Types
using | SlotCompare = sigc::slot<int(const guint8*, const guint8*)>
| A Slot type to compare two elements in the array.

## Public Member Functions
void | reference () const
| Increment the reference count for this object.
void | unreference () const
| Decrement the reference count for this object.
GByteArray * | gobj ()
| Provides access to the underlying C instance.
const GByteArray * | gobj () const
| Provides access to the underlying C instance.
GByteArray * | gobj_copy () const
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
| ByteArray ()=delete
| ByteArray (const ByteArray &)=delete
ByteArray & | operator= (const ByteArray &)=delete
Glib::RefPtr< ByteArray > | append (const guint8 * data, guint len)
| Adds the given bytes to the end of the ByteArray.
Glib::RefPtr< ByteArray > | prepend (const guint8 * data, guint len)
| Adds the given data to the start of the ByteArray.
guint | size () const
| Gets the size of the byte array.
guint8 * | get_data ()
| Gets the data of the byte array.
const guint8 * | get_data () const
| Gets the data of the byte array.
Glib::RefPtr< ByteArray > | remove_index (guint index)
| Removes the byte at the given index from a ByteArray.
Glib::RefPtr< ByteArray > | remove_index_fast (guint index)
| Removes the byte at the given index from a ByteArray.
Glib::RefPtr< ByteArray > | remove_range (guint index, guint length)
| Removes the given number of bytes starting at the given index from a ByteArray.
void | sort (const SlotCompare & slot)
| Like glib_byte_array_sort(), but the comparison function takes an extra user data argument.
Glib::RefPtr< ByteArray > | set_size (guint length)
| Sets the size of the ByteArray, expanding it if necessary.

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< ByteArray > | create ()
| Creates a new ByteArray with a reference count of 1.

## Protected Member Functions
void | operator delete (void *, std::size_t)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Glib::ByteArray > | wrap (GByteArray * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

ByteArray - Arrays of bytes.

ByteArray is a mutable array of bytes, to provide arrays of bytes which grow automatically as elements are added.

To create a new ByteArray use create(). To add elements to a ByteArray, use append(), and prepend().

To set the size of a ByteArray, use set_size().

Since glibmm 2.36

## Member Typedef Documentation

## ◆ SlotCompare

using Glib::ByteArray::SlotCompare = sigc::slot<int(const guint8*, const guint8*)>

A Slot type to compare two elements in the array.

The slot should return -1 if the first value is less than the second, 0 if they are equal and 1 if the first value is greater than the second.

Slot Prototype:

`int compare(const guint8* first, const guint8* second);`

## Constructor & Destructor Documentation

## ◆ ByteArray() [1/2]

Glib::ByteArray::ByteArray | ( |  | ) |
| delete

## ◆ ByteArray() [2/2]

Glib::ByteArray::ByteArray | ( | const ByteArray & |  | ) |
| delete

## Member Function Documentation

## ◆ append()

Glib::RefPtr< ByteArray > Glib::ByteArray::append | ( | const guint8 * | data,
|  | guint | len )

Adds the given bytes to the end of the ByteArray.

The array will grow in size automatically if necessary.

Parameters

  data | The byte data to be added.
  len | The number of bytes to add.

Returns
  The ByteArray.

## ◆ create()

Glib::RefPtr< ByteArray > Glib::ByteArray::create | ( |  | ) |
| static

Creates a new ByteArray with a reference count of 1.

Returns
  The new ByteArray.

## ◆ get_data() [1/2]

guint8 * Glib::ByteArray::get_data | ( |  | ) |

Gets the data of the byte array.

Returns
  The data.

Since glibmm 2.36

## ◆ get_data() [2/2]

const guint8 * Glib::ByteArray::get_data | ( |  | ) | const

Gets the data of the byte array.

Returns
  The data.

Since glibmm 2.36

## ◆ get_type()

GType Glib::ByteArray::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GByteArray * Glib::ByteArray::gobj | ( |  | ) |

Provides access to the underlying C instance.

## ◆ gobj() [2/2]

const GByteArray * Glib::ByteArray::gobj | ( |  | ) | const

Provides access to the underlying C instance.

## ◆ gobj_copy()

GByteArray * Glib::ByteArray::gobj_copy | ( |  | ) | const

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ operator delete()

void Glib::ByteArray::operator delete | ( | void * | ,
|  | std::size_t | )
| protected

## ◆ operator=()

ByteArray & Glib::ByteArray::operator= | ( | const ByteArray & |  | ) |
| delete

## ◆ prepend()

Glib::RefPtr< ByteArray > Glib::ByteArray::prepend | ( | const guint8 * | data,
|  | guint | len )

Adds the given data to the start of the ByteArray.

The array will grow in size automatically if necessary.

Parameters

  data | The byte data to be added.
  len | The number of bytes to add.

Returns
  The ByteArray.

## ◆ reference()

void Glib::ByteArray::reference | ( |  | ) | const

Increment the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

## ◆ remove_index()

Glib::RefPtr< ByteArray > Glib::ByteArray::remove_index | ( | guint | index | ) |

Removes the byte at the given index from a ByteArray.

The following bytes are moved down one place.

Parameters

  index | The index of the byte to remove.

Returns
  The ByteArray.

## ◆ remove_index_fast()

Glib::RefPtr< ByteArray > Glib::ByteArray::remove_index_fast | ( | guint | index | ) |

Removes the byte at the given index from a ByteArray.

The last element in the array is used to fill in the space, so this function does not preserve the order of the ByteArray. But it is faster than glib_byte_array_remove_index().

Parameters

  index | The index of the byte to remove.

Returns
  The ByteArray.

## ◆ remove_range()

Glib::RefPtr< ByteArray > Glib::ByteArray::remove_range | ( | guint | index,
|  | guint | length )

Removes the given number of bytes starting at the given index from a ByteArray.

The following elements are moved to close the gap.

Since glibmm 2.4

Parameters

  index | The index of the first byte to remove.
  length | The number of bytes to remove.

Returns
  The ByteArray.

## ◆ set_size()

Glib::RefPtr< ByteArray > Glib::ByteArray::set_size | ( | guint | length | ) |

Sets the size of the ByteArray, expanding it if necessary.

Parameters

  length | The new size of the ByteArray.

Returns
  The ByteArray.

## ◆ size()

guint Glib::ByteArray::size | ( |  | ) | const

Gets the size of the byte array.

Returns
  The size.

Since glibmm 2.36

## ◆ sort()

void Glib::ByteArray::sort | ( | const SlotCompare & | slot | ) |

Like glib_byte_array_sort(), but the comparison function takes an extra user data argument.

Parameters

  slot | The comparison function.

## ◆ unreference()

void Glib::ByteArray::unreference | ( |  | ) | const

Decrement the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Glib::ByteArray > wrap | ( | GByteArray * | object,
|  | bool | take_copy = false )
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.