Skip to content

Commit

Permalink
liblossy version 0.3.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robertu94 committed Jul 18, 2019
1 parent f1e594e commit 7022fa2
Show file tree
Hide file tree
Showing 7 changed files with 595 additions and 253 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(liblossy VERSION "0.2.0" LANGUAGES CXX C)
project(liblossy VERSION "0.3.0" LANGUAGES CXX C)

enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -84,6 +84,7 @@ if(BUILD_DOCS)
set(DOXYGEN_GENERATE_MAN YES)
set(DOXYGEN_EXTRACT_LOCAL_METHODS YES)
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_MACRO_EXPANSION YES)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
doxygen_add_docs(
docs
Expand Down
124 changes: 57 additions & 67 deletions include/lossy_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ extern "C" {
* \brief A single option value for a compressor
*/


#ifndef LOSSY_OPTION
/**
* hearder guard
*/
#define LOSSY_OPTION
#include "lossy_options.h"

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

/**
* creates an empty lossy_option
* \returns a new option structure with dtype lossy_option_unset
*/
struct lossy_option* lossy_option_new();
/**
* frees the memory associated with a returned option
* \param[in] options the option to free
Expand All @@ -32,78 +42,58 @@ void lossy_option_free(struct lossy_option* options);
enum lossy_option_type lossy_option_get_type(struct lossy_option const* option);

/**
* Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
* \param[in] option the option to retrieve a value from
* \returns the value contained in the option
*/
int lossy_option_get_integer(struct lossy_option const* option);
/**
* Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
* \param[in] option the option to retrieve a value from
* \returns the value contained in the option
* defines a getter and setter prototype for a lossy option type
*
* \param[in] name the name to append to the function
* \param[in] type the type return or accept in the function
*
*/
unsigned int lossy_option_get_uinteger(struct lossy_option const* option);
/**
* Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
* \param[in] option the option to retrieve a value from
* \returns the value contained in the option
*/
float lossy_option_get_float(struct lossy_option const* option);
/**
* Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
* \param[in] option the option to retrieve a value from
* \returns the value contained in the option
*/
double lossy_option_get_double(struct lossy_option const* option);
/**
* Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
* \param[in] option the option to retrieve a value from
* \returns non-owning pointer to the value contained in the option
*/
const char* lossy_option_get_string(struct lossy_option const* option);
/**
* Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior
* \param[in] option the option to retrieve a value from
* \returns non-owning pointer to the value contained in the option
*/
void* lossy_option_get_userptr(struct lossy_option const* option);
#define lossy_option_define_type(name, type) \
/**
Creates a new lossy_option containing the specified value
\param[in] value the value to use to create the object \
\returns a pointer to a new lossy option set to value passed in\
*/ \
struct lossy_option* lossy_option_new_##name(type value); \
/**
Gets the value stored in the lossy_option. Calling this with the improper dtype has undefined behavior \
\param[in] option the option to retrieve a value from \
\returns the value contained in the option \
*/ \
type lossy_option_get_##name(struct lossy_option const* option); \
/**
Sets the option to an integer value \
\param[in] option the option to set \
\param[in] value the value to set \
*/ \
void lossy_option_set_##name(struct lossy_option* option, type value);

lossy_option_define_type(uinteger, unsigned int)
lossy_option_define_type(integer, int)
lossy_option_define_type(float, float)
lossy_option_define_type(double, double)
lossy_option_define_type(string, const char*)
lossy_option_define_type(userptr, void*)

#undef lossy_option_define_type

/**
* Sets the option to an integer value
* \param[in] option the option to set
* \param[in] value the value to set
*/
void lossy_option_set_uinteger(struct lossy_option* option, unsigned int value);
/**
* Sets the option to an integer value
* \param[in] option the option to set
* \param[in] value the value to set
*/
void lossy_option_set_integer(struct lossy_option* option, int value);
/**
* Sets the option to an double value
* \param[in] option the option to set
* \param[in] value the value to set
*/
void lossy_option_set_float(struct lossy_option* option, float value);
/**
* Sets the option to an double value
* \param[in] option the option to set
* \param[in] value the value to set
*/
void lossy_option_set_double(struct lossy_option* option, double value);
/**
* Sets the option to an c-string value
* \param[in] option the option to set
* \param[in] value the value to set
* \param[in] option the option to convert
* \param[in] type the type to convert to
* \returns a new option value of the type specified if possible, otherwise returns NULL.
* \see lossy_option_convert behaves as if this function was called if with safety=lossy_conversion_implicit
*/
void lossy_option_set_string(struct lossy_option* option, const char* value);
struct lossy_option* lossy_option_convert_implicit(struct lossy_option const* option, enum lossy_option_type type);
/**
* Sets the option to an non-owning void* value
* \param[in] option the option to set
* \param[in] value the value to set
* converts between one type and another
* \param[in] option the option to convert
* \param[in] type the type to convert to
* \param[in] safety how safe to make perform a conversion
* \returns a new option value of the type specified if possible, otherwise returns NULL.
*/
void lossy_option_set_userptr(struct lossy_option* option, void* value);
struct lossy_option* lossy_option_convert(struct lossy_option const* option, enum lossy_option_type type, enum lossy_conversion_safety safety);

#endif

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 7022fa2

Please sign in to comment.