Explorar el Código

Macros for clish_ptype_t

Serj Kalichev hace 6 años
padre
commit
15e1798054
Se han modificado 3 ficheros con 22 adiciones y 86 borrados
  1. 2 5
      clish/macros.h
  2. 11 32
      clish/ptype.h
  3. 9 49
      clish/ptype/ptype.c

+ 2 - 5
clish/macros.h

@@ -31,7 +31,7 @@
 #define CLISH_SET_ONCE(obj, type, name) \
 	_CLISH_SET_ONCE(obj, type, name) { \
 		assert(inst); \
-		assert(NULL == inst->name); \
+		assert(!inst->name); \
 		inst->name = val; \
 	}
 #define _CLISH_SET_STR(obj, name) \
@@ -47,11 +47,8 @@
 #define CLISH_SET_STR_ONCE(obj, name) \
 	_CLISH_SET_STR_ONCE(obj, name) { \
 		assert(inst); \
-		assert(NULL == inst->name); \
+		assert(!inst->name); \
 		inst->name = lub_string_dup(val); \
 	}
 
-
-
-
 #endif // _clish_macros_h

+ 11 - 32
clish/ptype.h

@@ -1,16 +1,7 @@
 /*
  * ptype.h
+ * Types are a syntatical template which parameters reference.
  */
-  /**
-\ingroup clish
-\defgroup clish_ptype ptype
-@{
-
-\brief This class represents a parameter type.
-
-Types are a syntatical template which parameters reference.
-
-*/
 
 #ifndef _clish_ptype_h
 #define _clish_ptype_h
@@ -18,17 +9,12 @@ Types are a syntatical template which parameters reference.
 typedef struct clish_ptype_s clish_ptype_t;
 
 #include "lub/types.h"
+#include "clish/macros.h"
 #include "lub/bintree.h"
 #include "lub/argv.h"
 
 #include <stddef.h>
 
-/*=====================================
- * PTYPE INTERFACE
- *===================================== */
-/*-----------------
- * public types
- *----------------- */
 /**
  * The means by which the pattern is interpreted and 
  * validated.
@@ -72,9 +58,6 @@ typedef enum {
 	CLISH_PTYPE_TOLOWER
 } clish_ptype_preprocess_e;
 
-/*-----------------
- * meta functions
- *----------------- */
 int clish_ptype_bt_compare(const void *clientnode, const void *clientkey);
 void clish_ptype_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
 size_t clish_ptype_bt_offset(void);
@@ -87,9 +70,7 @@ clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char
 clish_ptype_t *clish_ptype_new(const char *name, const char *text,
 	const char *pattern, clish_ptype_method_e method,
 	clish_ptype_preprocess_e preprocess);
-/*-----------------
- * methods
- *----------------- */
+
 void clish_ptype_delete(clish_ptype_t * instance);
 /**
  * This is the validation method for the specified type.
@@ -117,16 +98,14 @@ char *clish_ptype_translate(const clish_ptype_t * instance, const char *text);
 void clish_ptype_word_generator(clish_ptype_t * instance,
 	lub_argv_t *matches, const char *text);
 void clish_ptype_dump(clish_ptype_t * instance);
-/*-----------------
- * attributes
- *----------------- */
-const char *clish_ptype__get_name(const clish_ptype_t * instance);
-const char *clish_ptype__get_text(const clish_ptype_t * instance);
-const char *clish_ptype__get_range(const clish_ptype_t * instance);
-void clish_ptype__set_preprocess(clish_ptype_t * instance,
-	clish_ptype_preprocess_e preprocess);
+
+_CLISH_GET_STR(ptype, name);
+_CLISH_SET_STR_ONCE(ptype, text);
+_CLISH_GET_STR(ptype, text);
+_CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
+_CLISH_GET_STR(ptype, range);
+
 void clish_ptype__set_pattern(clish_ptype_t * instance,
 	const char *pattern, clish_ptype_method_e method);
-void clish_ptype__set_text(clish_ptype_t * instance, const char *text);
+
 #endif	/* _clish_ptype_h */
-/** @} clish_ptype */

+ 9 - 49
clish/ptype/ptype.c

@@ -13,9 +13,7 @@
 #include <limits.h>
 #include <stdio.h>
 
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 static char *clish_ptype_select__get_name(const clish_ptype_t * this,
 	unsigned index)
 {
@@ -102,9 +100,7 @@ static void clish_ptype__set_range(clish_ptype_t * this)
 	}
 }
 
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 int clish_ptype_bt_compare(const void *clientnode, const void *clientkey)
 {
 	const clish_ptype_t *this = clientnode;
@@ -196,10 +192,6 @@ clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char *name)
 	return result;
 }
 
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
-
 /*--------------------------------------------------------- */
 void clish_ptype_word_generator(clish_ptype_t * this,
 	lub_argv_t *matches, const char *text)
@@ -458,22 +450,15 @@ void clish_ptype_delete(clish_ptype_t * this)
 	free(this);
 }
 
-/*--------------------------------------------------------- */
-const char *clish_ptype__get_name(const clish_ptype_t * this)
-{
-	return (const char *)this->name;
-}
-
-/*--------------------------------------------------------- */
-const char *clish_ptype__get_text(const clish_ptype_t * this)
-{
-	return (const char *)this->text;
-}
+CLISH_GET_STR(ptype, name);
+CLISH_SET_STR_ONCE(ptype, text);
+CLISH_GET_STR(ptype, text);
+CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
+CLISH_GET_STR(ptype, range);
 
 /*--------------------------------------------------------- */
-void
-clish_ptype__set_pattern(clish_ptype_t * this,
-			 const char *pattern, clish_ptype_method_e method)
+void clish_ptype__set_pattern(clish_ptype_t * this,
+	const char *pattern, clish_ptype_method_e method)
 {
 	assert(NULL == this->pattern);
 	this->method = method;
@@ -527,28 +512,3 @@ clish_ptype__set_pattern(clish_ptype_t * this,
 	/* now set up the range details */
 	clish_ptype__set_range(this);
 }
-
-/*--------------------------------------------------------- */
-void clish_ptype__set_text(clish_ptype_t * this, const char *text)
-{
-	assert(!this->text);
-	this->text = lub_string_dup(text);
-
-}
-
-/*--------------------------------------------------------- */
-void
-clish_ptype__set_preprocess(clish_ptype_t * this,
-	clish_ptype_preprocess_e preprocess)
-{
-	assert(!this->preprocess);
-	this->preprocess = preprocess;
-}
-
-/*--------------------------------------------------------- */
-const char *clish_ptype__get_range(const clish_ptype_t * this)
-{
-	return (const char *)this->range;
-}
-
-/*--------------------------------------------------------- */