DOCS/xml/README: improve
[mplayer/glamo.git] / m_struct.h
blobbcf09dc86fc2771cac2a7f70fd0d03c7ddd95c75
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 /// \defgroup OptionsStruct Options struct
23 /// \ingroup Options
24 /// An API to manipulate structs using m_option.
25 ///@{
27 /// \file m_struct.h
29 struct m_option;
31 /// Struct definition
32 typedef struct m_struct_st {
33 /// For error messages and debugging
34 const char* name;
35 /// size of the whole struct
36 unsigned int size;
37 /// Pointer to a struct filled with the default settings
38 const void* defaults;
39 /// Field list.
40 /** The p field of the \ref m_option struct must contain the offset
41 * of the member in the struct (use M_ST_OFF macro for this).
43 const struct m_option* fields;
44 } m_struct_t;
47 // From glib.h (modified ;-)
49 /// Get the offset of a struct field.
50 /** \param struct_type Struct type.
51 * \param member Name of the field.
52 * \return The offset of the field in bytes.
54 #define M_ST_OFF(struct_type, member) \
55 ((void*) &((struct_type*) 0)->member)
57 /// Get a pointer to a struct field.
58 /** \param struct_p Pointer to the struct.
59 * \param struct_offset Offset of the field in the struct.
60 * \return Pointer to the struct field.
62 #define M_ST_MB_P(struct_p, struct_offset) \
63 ((void *)((char *)(struct_p) + (unsigned long)(struct_offset)))
65 /// Access a struct field at a given offset.
66 /** \param member_type Type of the field.
67 * \param struct_p Pointer to the struct.
68 * \param struct_offset Offset of the field in the struct.
69 * \return The struct field at the given offset.
71 #define M_ST_MB(member_type, struct_p, struct_offset) \
72 (*(member_type*) M_ST_MB_P ((struct_p), (struct_offset)))
76 /// Allocate the struct and set it to the defaults.
77 /** \param st Struct definition.
78 * \return The newly allocated object set to default.
80 void*
81 m_struct_alloc(const m_struct_t* st);
83 /// Set a field of the struct.
84 /** \param st Struct definition.
85 * \param obj Pointer to the struct to set.
86 * \param field Name of the field to set.
87 * \param param New value of the field.
88 * \return 0 on error, 1 on success.
90 int
91 m_struct_set(const m_struct_t* st, void* obj, const char* field, const char* param);
93 /// Reset a field (or all if field == NULL) to defaults.
94 /** \param st Struct definition.
95 * \param obj Pointer to the struct to set.
96 * \param field Name of the field to reset, if NULL all fields are reseted.
98 void
99 m_struct_reset(const m_struct_t* st, void* obj, const char* field);
101 /// Create a copy of an existing struct.
102 /** \param st Struct definition.
103 * \param obj Pointer to the struct to copy.
104 * \return Newly allocated copy of obj.
106 void*
107 m_struct_copy(const m_struct_t* st, void* obj);
109 /// Free an allocated struct.
110 /** \param st Struct definition.
111 * \param obj Pointer to the struct to copy.
113 void
114 m_struct_free(const m_struct_t* st, void* obj);
116 /// Get a field description.
117 /** \param st Struct definition.
118 * \param f Name of the field.
119 * \return The \ref m_option struct describing the field or NULL if not found.
121 const struct m_option*
122 m_struct_get_field(const m_struct_t* st,const char* f);
124 ///@}
126 #endif /* MPLAYER_M_STRUCT_H */