MPD
tag.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_TAG_H
21 #define MPD_TAG_H
22 
23 #include "gcc.h"
24 
25 #include <stdint.h>
26 #include <stddef.h>
27 #include <stdbool.h>
28 #include <string.h>
29 
33 enum tag_type {
48 
53 
55 };
56 
61 extern const char *tag_item_names[];
62 
68 struct tag_item {
70  enum tag_type type;
71 
75  char value[sizeof(long)];
76 } mpd_packed;
77 
82 struct tag {
89  int time;
90 
92  struct tag_item **items;
93 
95  unsigned num_items;
96 };
97 
102 enum tag_type
103 tag_name_parse(const char *name);
104 
111 enum tag_type
112 tag_name_parse_i(const char *name);
113 
117 struct tag *tag_new(void);
118 
122 void tag_lib_init(void);
123 
127 void tag_clear_items_by_type(struct tag *tag, enum tag_type type);
128 
132 void tag_free(struct tag *tag);
133 
141 void tag_begin_add(struct tag *tag);
142 
146 void tag_end_add(struct tag *tag);
147 
156 void tag_add_item_n(struct tag *tag, enum tag_type type,
157  const char *value, size_t len);
158 
166 static inline void
167 tag_add_item(struct tag *tag, enum tag_type type, const char *value)
168 {
169  tag_add_item_n(tag, type, value, strlen(value));
170 }
171 
175 struct tag *tag_dup(const struct tag *tag);
176 
183 struct tag *
184 tag_merge(const struct tag *base, const struct tag *add);
185 
192 struct tag *
193 tag_merge_replace(struct tag *base, struct tag *add);
194 
199 static inline bool
200 tag_is_empty(const struct tag *tag)
201 {
202  return tag->num_items == 0;
203 }
204 
208 static inline bool
209 tag_is_defined(const struct tag *tag)
210 {
211  return !tag_is_empty(tag) || tag->time >= 0;
212 }
213 
218 const char *
219 tag_get_value(const struct tag *tag, enum tag_type type);
220 
225 bool tag_has_type(const struct tag *tag, enum tag_type type);
226 
231 bool tag_equal(const struct tag *tag1, const struct tag *tag2);
232 
233 #endif