Browse Source

Macros for clish_config_t

Serj Kalichev 1 year ago
parent
commit
f666e51841
2 changed files with 37 additions and 139 deletions
  1. 18 28
      clish/config.h
  2. 19 111
      clish/config/config.c

+ 18 - 28
clish/config.h

@@ -4,6 +4,7 @@
 #ifndef _clish_config_h
 #define _clish_config_h
 
+#include "clish/macros.h"
 #include "lub/types.h"
 
 typedef struct clish_config_s clish_config_t;
@@ -16,37 +17,26 @@ typedef enum {
 	CLISH_CONFIG_DUMP
 } clish_config_op_e;
 
-/*=====================================
- * COMMAND INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
 clish_config_t *clish_config_new(void);
-/*-----------------
- * methods
- *----------------- */
+
 void clish_config_delete(clish_config_t *instance);
 void clish_config_dump(const clish_config_t *instance);
 
-/*-----------------
- * attributes
- *----------------- */
-void clish_config__set_op(clish_config_t *instance, clish_config_op_e op);
-clish_config_op_e clish_config__get_op(const clish_config_t *instance);
-void clish_config__set_priority(clish_config_t *instance, unsigned short priority);
-unsigned short clish_config__get_priority(const clish_config_t *instance);
-void clish_config__set_pattern(clish_config_t *instance, const char *pattern);
-char *clish_config__get_pattern(const clish_config_t *instance);
-void clish_config__set_file(clish_config_t *instance, const char *file);
-char *clish_config__get_file(const clish_config_t *instance);
-void clish_config__set_splitter(clish_config_t *instance, bool_t splitter);
-bool_t clish_config__get_splitter(const clish_config_t *instance);
-void clish_config__set_seq(clish_config_t *instance, const char *seq_num);
-const char *clish_config__get_seq(const clish_config_t *instance);
-bool_t clish_config__get_unique(const clish_config_t *instance);
-void clish_config__set_unique(clish_config_t *instance, bool_t unique);
-void clish_config__set_depth(clish_config_t *instance, const char *depth);
-const char *clish_config__get_depth(const clish_config_t *instance);
+_CLISH_SET(config, clish_config_op_e, op);
+_CLISH_GET(config, clish_config_op_e, op);
+_CLISH_SET(config, unsigned short, priority);
+_CLISH_GET(config, unsigned short, priority);
+_CLISH_SET(config, bool_t, splitter);
+_CLISH_GET(config, bool_t, splitter);
+_CLISH_SET(config, bool_t, unique);
+_CLISH_GET(config, bool_t, unique);
+_CLISH_SET_STR_ONCE(config, pattern);
+_CLISH_GET_STR(config, pattern);
+_CLISH_SET_STR_ONCE(config, file);
+_CLISH_GET_STR(config, file);
+_CLISH_SET_STR_ONCE(config, seq);
+_CLISH_GET_STR(config, seq);
+_CLISH_SET_STR_ONCE(config, depth);
+_CLISH_GET_STR(config, depth);
 
 #endif				/* _clish_config_h */

+ 19 - 111
clish/config/config.c

@@ -13,10 +13,7 @@
 #include "lub/string.h"
 #include "private.h"
 
-
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 static void clish_config_init(clish_config_t *this)
 {
 	this->op = CLISH_CONFIG_NONE;
@@ -38,9 +35,7 @@ static void clish_config_fini(clish_config_t *this)
 	lub_string_free(this->depth);
 }
 
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 clish_config_t *clish_config_new(void)
 {
 	clish_config_t *this = malloc(sizeof(clish_config_t));
@@ -51,113 +46,26 @@ clish_config_t *clish_config_new(void)
 	return this;
 }
 
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 void clish_config_delete(clish_config_t *this)
 {
 	clish_config_fini(this);
 	free(this);
 }
 
-/*---------------------------------------------------------
- * PUBLIC ATTRIBUTES
- *--------------------------------------------------------- */
-void clish_config__set_op(clish_config_t *this, clish_config_op_e op)
-{
-	this->op = op;
-}
-
-/*--------------------------------------------------------- */
-clish_config_op_e clish_config__get_op(const clish_config_t *this)
-{
-	return this->op;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_priority(clish_config_t *this, unsigned short priority)
-{
-	this->priority = priority;
-}
-
-/*--------------------------------------------------------- */
-unsigned short clish_config__get_priority(const clish_config_t *this)
-{
-	return this->priority;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_pattern(clish_config_t *this, const char *pattern)
-{
-	assert(!this->pattern);
-	this->pattern = lub_string_dup(pattern);
-}
-
-/*--------------------------------------------------------- */
-char *clish_config__get_pattern(const clish_config_t *this)
-{
-	return this->pattern;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_file(clish_config_t *this, const char *file)
-{
-	assert(!this->file);
-	this->file = lub_string_dup(file);
-}
-
-/*--------------------------------------------------------- */
-char *clish_config__get_file(const clish_config_t *this)
-{
-	return this->file;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_config__get_splitter(const clish_config_t *this)
-{
-	return this->splitter;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_splitter(clish_config_t *this, bool_t splitter)
-{
-	this->splitter = splitter;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_seq(clish_config_t *this, const char *seq)
-{
-	assert(!this->seq);
-	this->seq = lub_string_dup(seq);
-}
-
-/*--------------------------------------------------------- */
-const char *clish_config__get_seq(const clish_config_t *this)
-{
-	return this->seq;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_config__get_unique(const clish_config_t *this)
-{
-	return this->unique;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_unique(clish_config_t *this, bool_t unique)
-{
-	this->unique = unique;
-}
-
-/*--------------------------------------------------------- */
-void clish_config__set_depth(clish_config_t *this, const char *depth)
-{
-	assert(!this->depth);
-	this->depth = lub_string_dup(depth);
-}
-
-/*--------------------------------------------------------- */
-const char *clish_config__get_depth(const clish_config_t *this)
-{
-	return this->depth;
-}
+CLISH_SET(config, clish_config_op_e, op);
+CLISH_GET(config, clish_config_op_e, op);
+CLISH_SET(config, unsigned short, priority);
+CLISH_GET(config, unsigned short, priority);
+CLISH_SET(config, bool_t, splitter);
+CLISH_GET(config, bool_t, splitter);
+CLISH_SET(config, bool_t, unique);
+CLISH_GET(config, bool_t, unique);
+CLISH_SET_STR_ONCE(config, pattern);
+CLISH_GET_STR(config, pattern);
+CLISH_SET_STR_ONCE(config, file);
+CLISH_GET_STR(config, file);
+CLISH_SET_STR_ONCE(config, seq);
+CLISH_GET_STR(config, seq);
+CLISH_SET_STR_ONCE(config, depth);
+CLISH_GET_STR(config, depth);