Squash  0.7.0
options.h
1 /* Copyright (c) 2013-2015 The Squash Authors
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  * Evan Nemerson <evan@nemerson.com>
25  */
26 
27 #ifndef SQUASH_OPTIONS_H
28 #define SQUASH_OPTIONS_H
29 
30 #if !defined (SQUASH_H_INSIDE) && !defined (SQUASH_COMPILATION)
31 #error "Only <squash/squash.h> can be included directly."
32 #endif
33 
34 #include <stdarg.h>
35 
36 SQUASH_BEGIN_DECLS
37 
38 typedef struct _SquashOptionInfoEnumStringMap SquashOptionInfoEnumStringMap;
39 typedef struct _SquashOptionInfoEnumString SquashOptionInfoEnumString;
40 typedef struct _SquashOptionInfoEnumInt SquashOptionInfoEnumInt;
41 typedef struct _SquashOptionInfoRangeInt SquashOptionInfoRangeInt;
42 typedef struct _SquashOptionInfoRangeSize SquashOptionInfoRangeSize;
43 typedef struct _SquashOptionInfo SquashOptionInfo;
44 typedef union _SquashOptionValue SquashOptionValue;
45 
47  SquashObject base_object;
48 
49  SquashCodec* codec;
50 
51  SquashOptionValue* values;
52 };
53 
54 typedef enum {
55  SQUASH_OPTION_TYPE_NONE = 0,
56  SQUASH_OPTION_TYPE_BOOL = 1,
57  SQUASH_OPTION_TYPE_STRING = 2,
58  SQUASH_OPTION_TYPE_INT = 3,
59  SQUASH_OPTION_TYPE_SIZE = 4,
60 
61  SQUASH_OPTION_TYPE_ENUM_STRING = (16 | SQUASH_OPTION_TYPE_STRING),
62  SQUASH_OPTION_TYPE_ENUM_INT = (16 | SQUASH_OPTION_TYPE_INT),
63 
64  SQUASH_OPTION_TYPE_RANGE_INT = (32 | SQUASH_OPTION_TYPE_INT),
65  SQUASH_OPTION_TYPE_RANGE_SIZE = (32 | SQUASH_OPTION_TYPE_SIZE),
66 } SquashOptionType;
67 
69  const char* name;
70  int value;
71 };
72 
74  const SquashOptionInfoEnumStringMap* values;
75 };
76 
78  size_t values_length;
79  const int* values;
80 };
81 
83  int min;
84  int max;
85  int modulus;
86  bool allow_zero;
87 };
88 
90  size_t min;
91  size_t max;
92  size_t modulus;
93  bool allow_zero;
94 };
95 
97  char* string_value;
98  int int_value;
99  bool bool_value;
100  size_t size_value;
101 };
102 
104  const char* name;
105  SquashOptionType type;
106  union {
107  struct _SquashOptionInfoEnumString enum_string;
108  struct _SquashOptionInfoEnumInt enum_int;
109  struct _SquashOptionInfoRangeInt range_int;
110  struct _SquashOptionInfoRangeSize range_size;
111  } info;
112  SquashOptionValue default_value;
113 };
114 
115 SQUASH_API SquashOptions* squash_options_new (SquashCodec* codec, ...);
116 SQUASH_API SquashOptions* squash_options_newv (SquashCodec* codec, va_list options);
117 SQUASH_API SquashOptions* squash_options_newa (SquashCodec* codec, const char* const* keys, const char* const* values);
118 
119 SQUASH_API const char* squash_options_get_string (SquashOptions* options, const char* key);
120 SQUASH_API bool squash_options_get_bool (SquashOptions* options, const char* key);
121 SQUASH_API int squash_options_get_int (SquashOptions* options, const char* key);
122 SQUASH_API size_t squash_options_get_size (SquashOptions* options, const char* key);
123 
124 SQUASH_API SquashStatus squash_options_parse (SquashOptions* options, ...);
125 SQUASH_API SquashStatus squash_options_parsev (SquashOptions* options, va_list options_list);
126 SQUASH_API SquashStatus squash_options_parsea (SquashOptions* options, const char* const* keys, const char* const* values);
127 
128 SQUASH_API SquashStatus squash_options_parse_option (SquashOptions* options, const char* key, const char* value);
129 
130 SQUASH_API void squash_options_init (void* options, SquashCodec* codec, SquashDestroyNotify destroy_notify);
131 SQUASH_API void squash_options_destroy (void* options);
132 
133 SQUASH_END_DECLS
134 
135 #endif /* SQUASH_OPTIONS_H */
size_t min
minimum value for this option
Definition: options.h:90
SQUASH_API void squash_options_init(void *options, SquashCodec *codec, SquashDestroyNotify destroy_notify)
Initialize a new SquashOptions instance.
Definition: options.c:607
int max
maximum value for this option
Definition: options.h:84
SQUASH_API SquashStatus squash_options_parse(SquashOptions *options,...)
Parse a variadic list of options.
Definition: options.c:514
SQUASH_API int squash_options_get_int(SquashOptions *options, const char *key)
Definition: options.c:246
char * string_value
the value as a string
Definition: options.h:97
union _SquashOptionInfo::@1 info
detailed information about the value
SQUASH_API SquashStatus squash_options_parsev(SquashOptions *options, va_list options_list)
Parse a va_list of options.
Definition: options.c:486
SQUASH_API SquashStatus squash_options_parsea(SquashOptions *options, const char *const *keys, const char *const *values)
Parse an array of options.
Definition: options.c:458
int min
minimum value for this option
Definition: options.h:83
A value.
Definition: options.h:96
SQUASH_API SquashOptions * squash_options_new(SquashCodec *codec,...)
Create a new group of options.
Definition: options.c:533
SquashOptionType type
type of the option
Definition: options.h:105
void(* SquashDestroyNotify)(void *data)
Callback to be invoked when information data is no longer needed.
Definition: object.h:43
bool allow_zero
whether to allow zero as a value
Definition: options.h:93
size_t size_value
the value as a size
Definition: options.h:100
SQUASH_API const char * squash_options_get_string(SquashOptions *options, const char *key)
Definition: options.c:186
const char * name
a string representing the option value
Definition: options.h:69
SQUASH_API SquashStatus squash_options_parse_option(SquashOptions *options, const char *key, const char *value)
Parse a single option.
Definition: options.c:311
SQUASH_API SquashOptions * squash_options_newv(SquashCodec *codec, va_list options)
Create a new group of options from a variadic list.
Definition: options.c:560
SQUASH_API bool squash_options_get_bool(SquashOptions *options, const char *key)
Definition: options.c:217
SquashOptionValue default_value
value to use if none is provided by the user
Definition: options.h:112
size_t max
maximum value for this option
Definition: options.h:91
int value
an integer representing the option value
Definition: options.h:70
size_t values_length
number of integer values understood for this option
Definition: options.h:78
const SquashOptionInfoEnumStringMap * values
a NULL terminated list of string and integer pairs
Definition: options.h:74
size_t modulus
modulus of acceptable values, or 0 to accept all
Definition: options.h:92
A list of strings which are mapped to integer values.
Definition: options.h:73
SQUASH_API SquashOptions * squash_options_newa(SquashCodec *codec, const char *const *keys, const char *const *values)
Create a new group of options from key and value arrays.
Definition: options.c:582
SquashStatus
Status codes.
Definition: status.h:36
Information about options which can be passed to a codec.
Definition: options.h:103
int int_value
the value as an integer
Definition: options.h:98
bool bool_value
the value as a boolean
Definition: options.h:99
SquashCodec * codec
Codec.
Definition: options.h:49
int modulus
modulus of acceptable values, or 0 to accept all
Definition: options.h:85
bool allow_zero
whether to allow zero as a value
Definition: options.h:86
SQUASH_API void squash_options_destroy(void *options)
Destroy a SquashOptions instance.
Definition: options.c:661
A set of compression/decompression options.
Definition: options.h:46
const char * name
name of the option
Definition: options.h:104
A list of potential integer values.
Definition: options.h:77
const int * values
array of integer values understood for this option
Definition: options.h:79
An item in a map of strings to integer values.
Definition: options.h:68
A range of potential size values.
Definition: options.h:89
SQUASH_API size_t squash_options_get_size(SquashOptions *options, const char *key)
Definition: options.c:277
SquashObject base_object
Base object.
Definition: options.h:47
A range of potential integer values.
Definition: options.h:82
SquashOptionValue * values
NULL-terminated array of option values.
Definition: options.h:51