lots of old and new edits
[kugel-rb.git] / apps / tagdb / artist.h
blobc74159493653b626ee2a713f1f8f27a6ec3e3006
1 #ifndef __ARTIST_H__
2 #define __ARTIST_H__
4 #include "config.h"
5 #include <stdio.h>
6 #include <stdint.h>
8 struct artist_entry {
9 char* name; // artist name
10 uint32_t *album; // album-pointers
11 struct artist_size {
12 uint32_t name_len; // length of this field (must be mulitple of 4)
13 uint32_t album_count; // number of album pointers
14 } size;
15 unsigned char flag; // flags
18 struct artist_entry* new_artist_entry(const uint32_t name_len, const uint32_t album_count);
19 /* Creates a new artist_entry with the specified sizes
20 * Returns a pointer to the structure on success,
21 * NULL on failure
24 int artist_entry_destruct(struct artist_entry *e);
25 /* Destructs the given artist_entry and free()'s it's memory
26 * returns ERR_NONE on success (can't fail)
29 int artist_entry_resize(struct artist_entry *e, const uint32_t name_len, const uint32_t album_count);
30 /* Change the size of the entry
31 * returns ERR_NONE on succes
32 * ERR_MALLOC on malloc() failure
35 int artist_entry_serialize(FILE *fd, const struct artist_entry *e);
36 /* Serializes the entry in the file at the current position
37 * returns ERR_NONE on success
38 * ERR_FILE on fwrite() failure
41 int artist_entry_unserialize(struct artist_entry* *e, FILE *fd);
42 /* Unserializes an entry from file into a new structure
43 * The address of the structure is saved into *e
44 * returns ERR_NONE on success
45 * ERR_MALLOC on malloc() failure
46 * ERR_FILE on fread() failure
49 int artist_entry_write(FILE *fd, const struct artist_entry *e, const struct artist_size *s);
50 /* Writes the entry to file in the final form
51 * returns ERR_NONE on success
52 * ERR_FILE on fwrite() failure
55 inline int artist_entry_compare(const struct artist_entry *a, const struct artist_entry *b);
56 /* Compares 2 entries
57 * When a < b it returns <0
58 * a = b 0
59 * a > b >0
62 struct artist_size* new_artist_size();
63 /* Creates a new size structure
64 * returns a pointer to the structure on success,
65 * NULL on failure
68 inline uint32_t artist_size_get_length(const struct artist_size *size);
69 /* Calculates the length of the entry when written by artist_entry_write()
70 * returns the length on success (can't fail)
73 inline int artist_size_max(struct artist_size *s, const struct artist_entry *e);
74 /* Updates the artist_size structure to contain the maximal lengths of either
75 * the original entry in s, or the entry e
76 * returns ERR_NONE on success (can't fail)
79 int artist_size_destruct(struct artist_size *s);
80 /* destructs the artist_size structure
81 * returns ERR_NONE on success (can't fail)
85 int artist_entry_add_album_mem(struct artist_entry *e, struct artist_size *s, const uint32_t album);
86 /* Adds the album to the array
87 * returns ERR_NONE on success
88 * ERR_MALLOC on malloc() failure
91 int artist_entry_add_album_file(FILE *fd, struct artist_entry *e, struct artist_size *s, const uint32_t album);
92 /* Adds the album to the serialized entry in the file
93 * When this fails, the entry is invalidated and the function returns
94 * ERR_NO_INPLACE_UPDATE
95 * returns ERR_NONE on success
96 * ERR_NO_INPLACE_UPDATE (see above)
97 * ERR_FILE on fread()/fwrite() error
100 #endif