audio: change default preference order of AO drivers
[mplayer.git] / m_struct.h
blob79c7c24f2f5a3f87ff4131815dd6cc42dd86d582
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_M_STRUCT_H
20 #define MPLAYER_M_STRUCT_H
22 #include "bstr.h"
24 /// \defgroup OptionsStruct Options struct
25 /// \ingroup Options
26 /// An API to manipulate structs using m_option.
27 ///@{
29 /// \file m_struct.h
31 struct m_option;
33 /// Struct definition
34 typedef struct m_struct_st {
35 /// For error messages and debugging
36 const char* name;
37 /// size of the whole struct
38 unsigned int size;
39 /// Pointer to a struct filled with the default settings
40 const void* defaults;
41 /// Field list.
42 /** The p field of the \ref m_option struct must contain the offset
43 * of the member in the struct (use M_ST_OFF macro for this).
45 const struct m_option* fields;
46 } m_struct_t;
49 // From glib.h (modified ;-)
51 /// Get the offset of a struct field.
52 /** \param struct_type Struct type.
53 * \param member Name of the field.
54 * \return The offset of the field in bytes.
56 #define M_ST_OFF(struct_type, member) \
57 ((void*) &((struct_type*) 0)->member)
59 /// Get a pointer to a struct field.
60 /** \param struct_p Pointer to the struct.
61 * \param struct_offset Offset of the field in the struct.
62 * \return Pointer to the struct field.
64 #define M_ST_MB_P(struct_p, struct_offset) \
65 ((void *)((char *)(struct_p) + (unsigned long)(struct_offset)))
67 /// Access a struct field at a given offset.
68 /** \param member_type Type of the field.
69 * \param struct_p Pointer to the struct.
70 * \param struct_offset Offset of the field in the struct.
71 * \return The struct field at the given offset.
73 #define M_ST_MB(member_type, struct_p, struct_offset) \
74 (*(member_type*) M_ST_MB_P ((struct_p), (struct_offset)))
78 /// Allocate the struct and set it to the defaults.
79 /** \param st Struct definition.
80 * \return The newly allocated object set to default.
82 void*
83 m_struct_alloc(const m_struct_t* st);
85 /// Set a field of the struct.
86 /** \param st Struct definition.
87 * \param obj Pointer to the struct to set.
88 * \param field Name of the field to set.
89 * \param param New value of the field.
90 * \return 0 on error, 1 on success.
92 int m_struct_set(const m_struct_t *st, void *obj, const char *field,
93 struct bstr param);
95 /// Reset a field (or all if field == NULL) to defaults.
96 /** \param st Struct definition.
97 * \param obj Pointer to the struct to set.
98 * \param field Name of the field to reset, if NULL all fields are reseted.
100 void
101 m_struct_reset(const m_struct_t* st, void* obj, const char* field);
103 /// Create a copy of an existing struct.
104 /** \param st Struct definition.
105 * \param obj Pointer to the struct to copy.
106 * \return Newly allocated copy of obj.
108 void*
109 m_struct_copy(const m_struct_t* st, void* obj);
111 /// Free an allocated struct.
112 /** \param st Struct definition.
113 * \param obj Pointer to the struct to copy.
115 void
116 m_struct_free(const m_struct_t* st, void* obj);
118 /// Get a field description.
119 /** \param st Struct definition.
120 * \param f Name of the field.
121 * \return The \ref m_option struct describing the field or NULL if not found.
123 const struct m_option*
124 m_struct_get_field(const m_struct_t* st,const char* f);
126 ///@}
128 #endif /* MPLAYER_M_STRUCT_H */