@@ -5,7 +5,12 @@ extern "C" {
5
5
* \brief A single option value for a compressor
6
6
*/
7
7
8
-
8
+ #ifndef LOSSY_OPTION
9
+ /**
10
+ * hearder guard
11
+ */
12
+ #define LOSSY_OPTION
13
+ #include "lossy_options.h"
9
14
10
15
/** possible types contained in a lossy_option, more types may be added in the future */
11
16
enum lossy_option_type {
@@ -18,6 +23,11 @@ enum lossy_option_type {
18
23
/** option is a option that is not set */ lossy_option_unset = 6
19
24
};
20
25
26
+ /**
27
+ * creates an empty lossy_option
28
+ * \returns a new option structure with dtype lossy_option_unset
29
+ */
30
+ struct lossy_option * lossy_option_new ();
21
31
/**
22
32
* frees the memory associated with a returned option
23
33
* \param[in] options the option to free
@@ -32,78 +42,58 @@ void lossy_option_free(struct lossy_option* options);
32
42
enum lossy_option_type lossy_option_get_type (struct lossy_option const * option );
33
43
34
44
/**
35
- * Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
36
- * \param[in] option the option to retrieve a value from
37
- * \returns the value contained in the option
38
- */
39
- int lossy_option_get_integer (struct lossy_option const * option );
40
- /**
41
- * Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
42
- * \param[in] option the option to retrieve a value from
43
- * \returns the value contained in the option
45
+ * defines a getter and setter prototype for a lossy option type
46
+ *
47
+ * \param[in] name the name to append to the function
48
+ * \param[in] type the type return or accept in the function
49
+ *
44
50
*/
45
- unsigned int lossy_option_get_uinteger (struct lossy_option const * option );
46
- /**
47
- * Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
48
- * \param[in] option the option to retrieve a value from
49
- * \returns the value contained in the option
50
- */
51
- float lossy_option_get_float (struct lossy_option const * option );
52
- /**
53
- * Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
54
- * \param[in] option the option to retrieve a value from
55
- * \returns the value contained in the option
56
- */
57
- double lossy_option_get_double (struct lossy_option const * option );
58
- /**
59
- * Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
60
- * \param[in] option the option to retrieve a value from
61
- * \returns non-owning pointer to the value contained in the option
62
- */
63
- const char * lossy_option_get_string (struct lossy_option const * option );
64
- /**
65
- * Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
66
- * \param[in] option the option to retrieve a value from
67
- * \returns non-owning pointer to the value contained in the option
68
- */
69
- void * lossy_option_get_userptr (struct lossy_option const * option );
51
+ #define lossy_option_define_type (name , type ) \
52
+ /**
53
+ Creates a new lossy_option containing the specified value
54
+ \param[in] value the value to use to create the object \
55
+ \returns a pointer to a new lossy option set to value passed in\
56
+ */ \
57
+ struct lossy_option* lossy_option_new_##name(type value); \
58
+ /**
59
+ Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior \
60
+ \param[in] option the option to retrieve a value from \
61
+ \returns the value contained in the option \
62
+ */ \
63
+ type lossy_option_get_ ##name (struct lossy_option const* option); \
64
+ /**
65
+ Sets the option to an integer value \
66
+ \param[in] option the option to set \
67
+ \param[in] value the value to set \
68
+ */ \
69
+ void lossy_option_set_ ##name (struct lossy_option* option, type value);
70
+
71
+ lossy_option_define_type (uinteger , unsigned int )
72
+ lossy_option_define_type (integer , int )
73
+ lossy_option_define_type (float , float )
74
+ lossy_option_define_type (double , double )
75
+ lossy_option_define_type (string , const char * )
76
+ lossy_option_define_type (userptr , void * )
77
+
78
+ #undef lossy_option_define_type
70
79
71
80
/**
72
- * Sets the option to an integer value
73
- * \param[in] option the option to set
74
- * \param[in] value the value to set
75
- */
76
- void lossy_option_set_uinteger (struct lossy_option * option , unsigned int value );
77
- /**
78
- * Sets the option to an integer value
79
- * \param[in] option the option to set
80
- * \param[in] value the value to set
81
- */
82
- void lossy_option_set_integer (struct lossy_option * option , int value );
83
- /**
84
- * Sets the option to an double value
85
- * \param[in] option the option to set
86
- * \param[in] value the value to set
87
- */
88
- void lossy_option_set_float (struct lossy_option * option , float value );
89
- /**
90
- * Sets the option to an double value
91
- * \param[in] option the option to set
92
- * \param[in] value the value to set
93
- */
94
- void lossy_option_set_double (struct lossy_option * option , double value );
95
- /**
96
- * Sets the option to an c-string value
97
- * \param[in] option the option to set
98
- * \param[in] value the value to set
81
+ * \param[in] option the option to convert
82
+ * \param[in] type the type to convert to
83
+ * \returns a new option value of the type specified if possible, otherwise returns NULL.
84
+ * \see lossy_option_convert behaves as if this function was called if with safety=lossy_conversion_implicit
99
85
*/
100
- void lossy_option_set_string (struct lossy_option * option , const char * value );
86
+ struct lossy_option * lossy_option_convert_implicit (struct lossy_option const * option , enum lossy_option_type type );
101
87
/**
102
- * Sets the option to an non-owning void* value
103
- * \param[in] option the option to set
104
- * \param[in] value the value to set
88
+ * converts between one type and another
89
+ * \param[in] option the option to convert
90
+ * \param[in] type the type to convert to
91
+ * \param[in] safety how safe to make perform a conversion
92
+ * \returns a new option value of the type specified if possible, otherwise returns NULL.
105
93
*/
106
- void lossy_option_set_userptr (struct lossy_option * option , void * value );
94
+ struct lossy_option * lossy_option_convert (struct lossy_option const * option , enum lossy_option_type type , enum lossy_conversion_safety safety );
95
+
96
+ #endif
107
97
108
98
#ifdef __cplusplus
109
99
}
0 commit comments