glibmm 2.88.0

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

A simple refcounted data type representing an immutable byte sequence from an unspecified origin. More...

`#include <glibmm/bytes.h>`

## Public Member Functions
void | reference () const
| Increment the reference count for this object.
void | unreference () const
| Decrement the reference count for this object.
GBytes * | gobj ()
| Provides access to the underlying C instance.
const GBytes * | gobj () const
| Provides access to the underlying C instance.
GBytes * | gobj_copy () const
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
| Bytes ()=delete
| Bytes (const Bytes &)=delete
Bytes & | operator= (const Bytes &)=delete
gconstpointer | get_data (gsize &size) const
| Get the byte data in the Glib::Bytes.
gsize | get_size () const
| Get the size of the byte data in the Glib::Bytes.

## Static Public Member Functions
static Glib::RefPtr< Glib::Bytes > | create (gconstpointer data, gsize size)
static guint | hash (gconstpointer bytes)
| Creates an integer hash code for the byte data in the Glib::Bytes.
static bool | equal (gconstpointer bytes1, gconstpointer bytes2)
| Compares the two Glib::Bytes values being pointed to and returns `true` if they are equal.
static gint | compare (gconstpointer bytes1, gconstpointer bytes2)
| Compares the two Glib::Bytes values.

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

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

## Detailed Description

A simple refcounted data type representing an immutable byte sequence from an unspecified origin.

The purpose of the Bytes class is to keep the memory region that it holds alive for as long as anyone holds a reference to the bytes. When the last reference count is dropped, the memory is released. Multiple unrelated callers can use byte data in the Bytes object without coordinating their activities, resting assured that the byte data will not change or move while they hold a reference.

A Bytes object can come from many different origins that may have different procedures for freeing the memory region. Examples are memory from g_malloc(), from memory slices, from a GMappedFile or memory from other allocators.

Since glibmm 2.34:

## Constructor & Destructor Documentation

## ◆ Bytes() [1/2]

Glib::Bytes::Bytes | ( |  | ) |
| delete

## ◆ Bytes() [2/2]

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

## Member Function Documentation

## ◆ compare()

static gint Glib::Bytes::compare | ( | gconstpointer | bytes1,
|  | gconstpointer | bytes2
| ) |  |
| static

Compares the two Glib::Bytes values.

This function can be used to sort `Bytes` instances in lexicographical order.

If bytes1 and bytes2 have different length but the shorter one is a prefix of the longer one then the shorter one is considered to be less than the longer one. Otherwise the first byte where both differ is used for comparison. If bytes1 has a smaller value at that position it is considered less, otherwise greater than bytes2.

Since glibmm 2.32:

Parameters

  bytes1 | A pointer to a Glib::Bytes.
  bytes2 | A pointer to a Glib::Bytes to compare with bytes1.

Returns
  A negative value if bytes1 is less than bytes2, a positive value if bytes1 is greater than bytes2, and zero if bytes1 is equal to bytes2.

## ◆ create()

static Glib::RefPtr< Glib::Bytes > Glib::Bytes::create | ( | gconstpointer | data,
|  | gsize | size
| ) |  |
| static

## ◆ equal()

static bool Glib::Bytes::equal | ( | gconstpointer | bytes1,
|  | gconstpointer | bytes2
| ) |  |
| static

Compares the two Glib::Bytes values being pointed to and returns `true` if they are equal.

This function can be passed to glib_hash_table_new() as the key_equal_func parameter, when using non-`nullptr` `Bytes` pointers as keys in a Glib::HashTable.

Since glibmm 2.32:

Parameters

  bytes1 | A pointer to a Glib::Bytes.
  bytes2 | A pointer to a Glib::Bytes to compare with bytes1.

Returns
  `true` if the two keys match.

## ◆ get_data()

gconstpointer Glib::Bytes::get_data | ( | gsize & | size | ) | const

Get the byte data in the Glib::Bytes.

This data should not be modified.

This function will always return the same pointer for a given `Bytes`.

`nullptr` may be returned if size is 0. This is not guaranteed, as the `Bytes` may represent an empty string with data non-`nullptr` and size as 0. `nullptr` will not be returned if size is non-zero.

Since glibmm 2.32:

Parameters

  size | Location to return size of byte data.

Returns
  A pointer to the byte data.

## ◆ get_size()

gsize Glib::Bytes::get_size | ( |  | ) | const

Get the size of the byte data in the Glib::Bytes.

This function will always return the same value for a given `Bytes`.

Since glibmm 2.32:

Returns
  The size.

## ◆ gobj() [1/2]

GBytes * Glib::Bytes::gobj | ( |  | ) |

Provides access to the underlying C instance.

## ◆ gobj() [2/2]

const GBytes * Glib::Bytes::gobj | ( |  | ) | const

Provides access to the underlying C instance.

## ◆ gobj_copy()

GBytes * Glib::Bytes::gobj_copy | ( |  | ) | const

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

## ◆ hash()

static guint Glib::Bytes::hash | ( | gconstpointer | bytes | ) |
| static

Creates an integer hash code for the byte data in the Glib::Bytes.

This function can be passed to glib_hash_table_new() as the key_hash_func parameter, when using non-`nullptr` `Bytes` pointers as keys in a Glib::HashTable.

Since glibmm 2.32:

Parameters

  bytes | A pointer to a Glib::Bytes key.

Returns
  A hash value corresponding to the key.

## ◆ operator delete()

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

## ◆ operator=()

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

## ◆ reference()

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

Increment the reference count for this object.

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

## ◆ unreference()

void Glib::Bytes::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::Bytes > wrap | ( | GBytes * | 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.