cbitcoin
 All Data Structures Files Functions Variables Typedefs
src/structures/CBObject/CBObject.h File Reference

The base structure for other structures using OOP-style and reference counting features. More...

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "CBConstants.h"

Go to the source code of this file.

Data Structures

struct  CBObject
 Base structure for all other structures. More...

Typedefs

typedef struct CBObject CBObject
 Base structure for all other structures.

Functions

CBObjectCBNewObject (void)
 Creates a new CBObject.
CBObjectCBGetObject (void *self)
 Gets a CBObject from another object. Use this to avoid casts.
bool CBInitObject (CBObject *self)
 Initialises a CBObject.
void CBFreeObject (void *self)
 Frees a CBObject.
void CBReleaseObject (void *self)
 Releases a CBObject. The reference counter is decremented and if the reference count is returned to 0, the object will be freed. The pointer will be assigned to NULL.
void CBRetainObject (void *self)
 Retains a CBObject. The reference counter is incremented.

Detailed Description

The base structure for other structures using OOP-style and reference counting features.

CBObject is the root structure for all other OOP-type structures in cbitcoin. It provides memory mangement through reference counting. Other structures inherit CBObject through the CBOBjectVT structure and the CBOBject structure itself. The retain, release and free functions are used for memory management.

The rule for memory management is to retain an object before returning it, to retain an object when giving it to another object, and to release an object once the object is no longer needed. When a new object is created it should be retained. Unless required for thread safety, objects don't need to be retained when passed into functions. Whenever an object is created it must be released and objects must be released for each time they are retained. Failure to abide by this properly will cause memory leaks or segmentation faults.

Remember to pass a reference to an object to the release function. Forgeting to do this will break your code.


Typedef Documentation

typedef struct CBObject CBObject

Base structure for all other structures.

See also:
CBObject.h

Function Documentation

void CBFreeObject ( void *  self)

Frees a CBObject.

Parameters:
selfThe CBOBject to free.
CBObject* CBGetObject ( void *  self)

Gets a CBObject from another object. Use this to avoid casts.

Parameters:
selfThe object to obtain the CBObject from.
Returns:
The CBObject.
bool CBInitObject ( CBObject self)

Initialises a CBObject.

Parameters:
selfThe CBObject to initialise
Returns:
This always returns true.
CBObject* CBNewObject ( void  )

Creates a new CBObject.

Returns:
A new CBObject.
void CBReleaseObject ( void *  self)

Releases a CBObject. The reference counter is decremented and if the reference count is returned to 0, the object will be freed. The pointer will be assigned to NULL.

Parameters:
selfThe pointer to the object to release.
void CBRetainObject ( void *  self)

Retains a CBObject. The reference counter is incremented.

Parameters:
selfThe object to retain.