Skip to content

Commit 7022fa2

Browse files
committed
liblossy version 0.3.0
Major Changes - Added functions to work with lossy_option structures with different types. Added similar convenience functions to lossy_options. - Casting functions allow three levels of casting implicit, explicit, and special function casting. Minor Changes - Refactored type generic code to macros. Macros were used instead of templates to preserve a C-compatible interface.
1 parent f1e594e commit 7022fa2

File tree

7 files changed

+595
-253
lines changed

7 files changed

+595
-253
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
2-
project(liblossy VERSION "0.2.0" LANGUAGES CXX C)
2+
project(liblossy VERSION "0.3.0" LANGUAGES CXX C)
33

44
enable_testing()
55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -84,6 +84,7 @@ if(BUILD_DOCS)
8484
set(DOXYGEN_GENERATE_MAN YES)
8585
set(DOXYGEN_EXTRACT_LOCAL_METHODS YES)
8686
set(DOXYGEN_EXTRACT_STATIC YES)
87+
set(DOXYGEN_MACRO_EXPANSION YES)
8788
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
8889
doxygen_add_docs(
8990
docs

include/lossy_option.h

Lines changed: 57 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ extern "C" {
55
* \brief A single option value for a compressor
66
*/
77

8-
8+
#ifndef LOSSY_OPTION
9+
/**
10+
* hearder guard
11+
*/
12+
#define LOSSY_OPTION
13+
#include "lossy_options.h"
914

1015
/** possible types contained in a lossy_option, more types may be added in the future */
1116
enum lossy_option_type {
@@ -18,6 +23,11 @@ enum lossy_option_type {
1823
/** option is a option that is not set */lossy_option_unset=6
1924
};
2025

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();
2131
/**
2232
* frees the memory associated with a returned option
2333
* \param[in] options the option to free
@@ -32,78 +42,58 @@ void lossy_option_free(struct lossy_option* options);
3242
enum lossy_option_type lossy_option_get_type(struct lossy_option const* option);
3343

3444
/**
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+
*
4450
*/
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
7079

7180
/**
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
9985
*/
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);
10187
/**
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.
10593
*/
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
10797

10898
#ifdef __cplusplus
10999
}

0 commit comments

Comments
 (0)