Browse Source

Macros for clish_nspace_t

Serj Kalichev 5 years ago
parent
commit
494850e947
3 changed files with 50 additions and 154 deletions
  1. 0 1
      clish/hotkey.h
  2. 23 40
      clish/nspace.h
  3. 27 113
      clish/nspace/nspace.c

+ 0 - 1
clish/hotkey.h

@@ -14,4 +14,3 @@ clish_hotkeyv_t *clish_hotkeyv_new(void);
 void clish_hotkeyv_delete(clish_hotkeyv_t *instance);
 
 #endif				/* _clish_hotkey_h */
-/** @} clish_hotkey */

+ 23 - 40
clish/nspace.h

@@ -1,17 +1,9 @@
 /*
  * nspace.h
+ * Namespace instances are assocated with a view to make view's commands available
+ * within current view.
  */
-/**
-\ingroup clish
-\defgroup clish_nspace nspace
-@{
 
-\brief This class represents an instance of a namespace type.
-
-Namespace instances are assocated with a view to make view's commands available
-within current view.
-
-*/
 #ifndef _clish_nspace_h
 #define _clish_nspace_h
 
@@ -26,18 +18,11 @@ typedef enum {
 
 #include <regex.h>
 
+#include "clish/macros.h"
 #include "clish/view.h"
 
-/*=====================================
- * NSPACE INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
 clish_nspace_t *clish_nspace_new(const char *view_name);
-/*-----------------
- * methods
- *----------------- */
+
 void clish_nspace_delete(clish_nspace_t * instance);
 const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t *
 	instance, const char *iter_cmd, const char *line,
@@ -47,28 +32,26 @@ void clish_nspace_dump(const clish_nspace_t * instance);
 clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * instance,
 	const char * name, const char * help);
 void clish_nspace_clean_proxy(clish_nspace_t * instance);
-/*-----------------
- * attributes
- *----------------- */
-void clish_nspace__set_view(clish_nspace_t *instance, clish_view_t *view);
-clish_view_t *clish_nspace__get_view(const clish_nspace_t * instance);
-void clish_nspace__set_view_name(clish_nspace_t *instance, const char *view_name);
-const char * clish_nspace__get_view_name(const clish_nspace_t *instance);
-const char *clish_nspace__get_prefix(const clish_nspace_t * instance);
-const regex_t *clish_nspace__get_prefix_regex(const clish_nspace_t * instance);
-bool_t clish_nspace__get_help(const clish_nspace_t * instance);
-bool_t clish_nspace__get_completion(const clish_nspace_t * instance);
-bool_t clish_nspace__get_context_help(const clish_nspace_t * instance);
-bool_t clish_nspace__get_inherit(const clish_nspace_t * instance);
+
+_CLISH_SET(nspace, bool_t, help);
+_CLISH_GET(nspace, bool_t, help);
+_CLISH_SET(nspace, bool_t, completion);
+_CLISH_GET(nspace, bool_t, completion);
+_CLISH_SET(nspace, bool_t, context_help);
+_CLISH_GET(nspace, bool_t, context_help);
+_CLISH_SET(nspace, bool_t, inherit);
+_CLISH_GET(nspace, bool_t, inherit);
+_CLISH_SET(nspace, clish_view_t *, view);
+_CLISH_GET(nspace, clish_view_t *, view);
+_CLISH_SET_STR(nspace, view_name);
+_CLISH_GET_STR(nspace, view_name);
+_CLISH_SET_STR(nspace, access);
+_CLISH_GET_STR(nspace, access);
+_CLISH_SET_STR_ONCE(nspace, prefix);
+_CLISH_GET_STR(nspace, prefix);
+_CLISH_GET(nspace, const regex_t *, prefix_regex);
+
 bool_t clish_nspace__get_visibility(const clish_nspace_t * instance,
 	clish_nspace_visibility_e field);
-void clish_nspace__set_prefix(clish_nspace_t * instance, const char *prefix);
-void clish_nspace__set_help(clish_nspace_t * instance, bool_t help);
-void clish_nspace__set_completion(clish_nspace_t * instance, bool_t help);
-void clish_nspace__set_context_help(clish_nspace_t * instance, bool_t help);
-void clish_nspace__set_inherit(clish_nspace_t * instance, bool_t inherit);
-void clish_nspace__set_access(clish_nspace_t *instance, const char *access);
-char *clish_nspace__get_access(const clish_nspace_t *instance);
 
 #endif				/* _clish_nspace_h */
-/** @} clish_nspace */

+ 27 - 113
clish/nspace/nspace.c

@@ -14,9 +14,7 @@
 #include <regex.h>
 #include <ctype.h>
 
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 static void clish_nspace_init(clish_nspace_t *this,  const char *view_name)
 {
 	this->view_name = NULL;
@@ -131,9 +129,7 @@ static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
 	return cmd;
 }
 
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 clish_nspace_t *clish_nspace_new(const char *view_name)
 {
 	clish_nspace_t *this = malloc(sizeof(clish_nspace_t));
@@ -143,9 +139,7 @@ clish_nspace_t *clish_nspace_new(const char *view_name)
 	return this;
 }
 
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 void clish_nspace_delete(clish_nspace_t *this)
 {
 	clish_nspace_fini(this);
@@ -280,105 +274,41 @@ void clish_nspace_clean_proxy(clish_nspace_t * this)
 	}
 }
 
-/*---------------------------------------------------------
- * PUBLIC ATTRIBUTES
- *--------------------------------------------------------- */
-clish_view_t *clish_nspace__get_view(const clish_nspace_t *this)
-{
-	return this->view;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_view(clish_nspace_t *this, clish_view_t *view)
-{
-	this->view = view;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_view_name(clish_nspace_t *this, const char *view_name)
-{
-	if (this->view_name)
-		lub_string_free(this->view_name);
-	this->view_name = lub_string_dup(view_name);
-}
-
-/*--------------------------------------------------------- */
-const char * clish_nspace__get_view_name(const clish_nspace_t *this)
-{
-	return this->view_name;
-}
+CLISH_SET(nspace, bool_t, help);
+CLISH_GET(nspace, bool_t, help);
+CLISH_SET(nspace, bool_t, completion);
+CLISH_GET(nspace, bool_t, completion);
+CLISH_SET(nspace, bool_t, context_help);
+CLISH_GET(nspace, bool_t, context_help);
+CLISH_SET(nspace, bool_t, inherit);
+CLISH_GET(nspace, bool_t, inherit);
+CLISH_SET(nspace, clish_view_t *, view);
+CLISH_GET(nspace, clish_view_t *, view);
+CLISH_SET_STR(nspace, view_name);
+CLISH_GET_STR(nspace, view_name);
+CLISH_SET_STR(nspace, access);
+CLISH_GET_STR(nspace, access);
+CLISH_GET_STR(nspace, prefix);
 
 /*--------------------------------------------------------- */
-void clish_nspace__set_prefix(clish_nspace_t * this, const char *prefix)
+_CLISH_SET_STR_ONCE(nspace, prefix)
 {
 	int res = 0;
 
-	assert(!this->prefix);
-	res = regcomp(&this->prefix_regex, prefix, REG_EXTENDED | REG_ICASE);
+	assert(inst);
+	assert(!inst->prefix);
+	res = regcomp(&inst->prefix_regex, val, REG_EXTENDED | REG_ICASE);
 	assert(!res);
-	this->prefix = lub_string_dup(prefix);
-}
-
-/*--------------------------------------------------------- */
-const char *clish_nspace__get_prefix(const clish_nspace_t * this)
-{
-	return this->prefix;
+	inst->prefix = lub_string_dup(val);
 }
 
 /*--------------------------------------------------------- */
-const regex_t *clish_nspace__get_prefix_regex(const clish_nspace_t * this)
+_CLISH_GET(nspace, const regex_t *, prefix_regex)
 {
-	if (!this->prefix)
+	assert(inst);
+	if (!inst->prefix)
 		return NULL;
-	return &this->prefix_regex;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_help(clish_nspace_t * this, bool_t help)
-{
-	this->help = help;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_nspace__get_help(const clish_nspace_t * this)
-{
-	return this->help;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_completion(clish_nspace_t * this, bool_t completion)
-{
-	this->completion = completion;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_nspace__get_completion(const clish_nspace_t * this)
-{
-	return this->completion;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_context_help(clish_nspace_t * this, bool_t context_help)
-{
-	this->context_help = context_help;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_nspace__get_context_help(const clish_nspace_t * this)
-{
-	return this->context_help;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_inherit(clish_nspace_t * this, bool_t inherit)
-{
-	this->inherit = inherit;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_nspace__get_inherit(const clish_nspace_t * this)
-{
-	return this->inherit;
+	return &inst->prefix_regex;
 }
 
 /*--------------------------------------------------------- */
@@ -403,19 +333,3 @@ bool_t clish_nspace__get_visibility(const clish_nspace_t * instance,
 
 	return result;
 }
-
-/*--------------------------------------------------------- */
-void clish_nspace__set_access(clish_nspace_t *this, const char *access)
-{
-	if (this->access)
-		lub_string_free(this->access);
-	this->access = lub_string_dup(access);
-}
-
-/*--------------------------------------------------------- */
-char *clish_nspace__get_access(const clish_nspace_t *this)
-{
-	return this->access;
-}
-
-/*--------------------------------------------------------- */