gui: macos: use float for rate
[vlc.git] / src / input / info.h
blobc76903a9db635fa227020747242be91ca8a708aa
1 /*****************************************************************************
2 * info.h
3 *****************************************************************************
4 * Copyright (C) 2010 Laurent Aimar
6 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifndef LIBVLC_INPUT_INFO_H
24 #define LIBVLC_INPUT_INFO_H 1
26 #include "vlc_input_item.h"
28 static inline info_t *info_New(const char *name)
30 info_t *info = malloc(sizeof(*info));
31 if (!info)
32 return NULL;
34 info->psz_name = strdup(name);
35 info->psz_value = NULL;
36 return info;
39 static inline void info_Delete(info_t *i)
41 free(i->psz_name);
42 free(i->psz_value);
43 free(i);
46 static inline info_category_t *info_category_New(const char *name)
48 info_category_t *cat = malloc(sizeof(*cat));
49 if (!cat)
50 return NULL;
51 cat->psz_name = strdup(name);
52 vlc_list_init(&cat->infos);
53 return cat;
56 static inline info_t *info_category_FindInfo(const info_category_t *cat,
57 const char *name)
59 info_t *info;
61 info_foreach(info, &cat->infos)
62 if (!strcmp(info->psz_name, name))
63 return info;
64 return NULL;
67 static inline void info_category_ReplaceInfo(info_category_t *cat,
68 info_t *info)
70 info_t *old = info_category_FindInfo(cat, info->psz_name);
71 if (old) {
72 vlc_list_remove(&old->node);
73 info_Delete(old);
75 vlc_list_append(&info->node, &cat->infos);
78 static inline info_t *info_category_VaAddInfo(info_category_t *cat,
79 const char *name,
80 const char *format, va_list args)
82 info_t *info = info_category_FindInfo(cat, name);
83 if (!info) {
84 info = info_New(name);
85 if (!info)
86 return NULL;
87 vlc_list_append(&info->node, &cat->infos);
88 } else
89 free(info->psz_value);
90 if (vasprintf(&info->psz_value, format, args) == -1)
91 info->psz_value = NULL;
92 return info;
95 static inline info_t *info_category_AddInfo(info_category_t *cat,
96 const char *name,
97 const char *format, ...)
99 va_list args;
101 va_start(args, format);
102 info_t *info = info_category_VaAddInfo(cat, name, format, args);
103 va_end(args);
105 return info;
108 static inline int info_category_DeleteInfo(info_category_t *cat, const char *name)
110 info_t *info = info_category_FindInfo(cat, name);
111 if (info != NULL) {
112 vlc_list_remove(&info->node);
113 info_Delete(info);
114 return VLC_SUCCESS;
116 return VLC_EGENERIC;
119 static inline void info_category_Delete(info_category_t *cat)
121 info_t *info;
123 while ((info = vlc_list_first_entry_or_null(&cat->infos, info_t, node))) {
124 vlc_list_remove(&info->node);
125 info_Delete(info);
127 free(cat->psz_name);
128 free(cat);
131 #endif