## BtPersistence

BtPersistence — object persistence interface

## Functions

void | bt_persistence_collect_hashtable_entries ()
BtPersistence * | bt_persistence_load ()
gboolean | bt_persistence_load_hashtable ()
xmlNodePtr | bt_persistence_save ()
gboolean | bt_persistence_save_hashtable ()
gboolean | bt_persistence_save_list ()

## Types and Values

| BtPersistence
struct | BtPersistenceInterface

## Object Hierarchy

        GInterface
        ╰── BtPersistence

## Known Implementations

BtPersistence is implemented by BtMachine, BtPattern, BtProcessorMachine, BtSequence, BtSetup, BtSinkMachine, BtSong, BtSongInfo, BtSourceMachine, BtWave, BtWavelevel, BtWavetable and BtWire.

## Includes

    #include <libbtcore/core.h>

## Description

Classes can implement this interface to store their data as xml and restore them from xml. They should call the interface methods on their children objects (which also implement the interface) to serialize/ deserialize a whole object hierarchy.

## Functions

### bt_persistence_collect_hashtable_entries ()

    void
    bt_persistence_collect_hashtable_entries
                                   (gpointer const key,
                                    gpointer const value,
                                    gpointer const user_data);

Gather GHashTable entries in a list. Should be used with `g_hash_table_foreach()`.

#### Parameters

key | hashtable key |
value | hashtable value |
user_data | GList **list |

### bt_persistence_load ()

    BtPersistence *
    bt_persistence_load (const GType type,
                         const BtPersistence * const self,
                         xmlNodePtr node,
                         GError **err,
                         ...);

Deserializes the given object from the `node` . If `self` is `NULL` and a `type` is given it constructs a new object.

#### Parameters

type | a GObject type |
self | a deserialiable object |
node | the xml node |
err | a GError for deserialisation errors |
... | extra parameters NULL terminated name/value pairs. |

#### Returns

the deserialized object or `NULL`.

[transfer none]

### bt_persistence_load_hashtable ()

    gboolean
    bt_persistence_load_hashtable (GHashTable *hashtable,
                                   xmlNodePtr node);

Iterates over the xml-node and deserializes elements into the hashtable.

#### Parameters

hashtable | a GHashTable. | [element-type utf8 utf8]
node | the list xml node |

#### Returns

`TRUE` if all elements have been deserialized.

### bt_persistence_save ()

    xmlNodePtr
    bt_persistence_save (const BtPersistence * const self,
                         xmlNodePtr const parent_node);

Serializes the given object into `node` .

#### Parameters

self | a serialiable object |
parent_node | the parent xml node |

#### Returns

the new node if the object has been serialized, else `NULL`.

### bt_persistence_save_hashtable ()

    gboolean
    bt_persistence_save_hashtable (GHashTable *hashtable,
                                   xmlNodePtr const node);

Iterates over a hashtable with strings and serializes them.

#### Parameters

hashtable | a GHashTable with strings. | [element-type utf8 utf8]
node | the list xml node |

#### Returns

`TRUE` if all elements have been serialized.

### bt_persistence_save_list ()

    gboolean
    bt_persistence_save_list (const GList *list,
                              xmlNodePtr const node);

Iterates over a list of objects, which must implement the BtPersistence interface and calls `bt_persistence_save()` on each item.

#### Parameters

list | a GList `doc` ; the xml-document. | [element-type BuzztraxCore.Persistence]
node | the list xml node |

#### Returns

`TRUE` if all elements have been serialized.

## Types and Values

### BtPersistence

    typedef struct _BtPersistence BtPersistence;

Opaque interface handle.

### struct BtPersistenceInterface

    struct BtPersistenceInterface {
      /* virtual methods */
      xmlNodePtr (*save)(const BtPersistence * const self, xmlNodePtr const node);
      BtPersistence* (*load)(const GType type, const BtPersistence * const self, xmlNodePtr node, GError **err, va_list var_args);
    };

BtPersistence interface

#### Members

`save` () | virtual method to serialize an object to an xml node |
`load` () | virtual method to deserialze an object from an xml node |