Browse Source

Macros for clish_view_t

Serj Kalichev 6 years ago
parent
commit
ebea57dc68
3 changed files with 33 additions and 110 deletions
  1. 2 2
      clish/shell/shell_startup.c
  2. 13 26
      clish/view.h
  3. 18 82
      clish/view/view.c

+ 2 - 2
clish/shell/shell_startup.c

@@ -222,7 +222,7 @@ int clish_shell_prepare(clish_shell_t *this)
 		}
 
 		/* Iterate the NAMESPACEs */
-		nspace_tree = clish_view__get_nspace_tree(view);
+		nspace_tree = clish_view__get_nspaces(view);
 		nspace_iter = lub_list__get_head(nspace_tree);
 		while(nspace_iter) {
 			clish_view_t *ref_view;
@@ -264,7 +264,7 @@ int clish_shell_prepare(clish_shell_t *this)
 		}
 
 		/* Iterate the COMMANDs */
-		cmd_tree = clish_view__get_command_tree(view);
+		cmd_tree = clish_view__get_tree(view);
 		cmd = lub_bintree_findfirst(cmd_tree);
 		for (lub_bintree_iterator_init(&cmd_iter, cmd_tree, cmd);
 			cmd; cmd = lub_bintree_iterator_next(&cmd_iter)) {

+ 13 - 26
clish/view.h

@@ -29,22 +29,10 @@ typedef enum {
 #include "clish/nspace.h"
 #include "clish/var.h"
 
-/*=====================================
- * VIEW INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
 clish_view_t *clish_view_new(const char *name, const char *prompt);
 int clish_view_bt_compare(const void *clientnode, const void *clientkey);
 void clish_view_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
 size_t clish_view_bt_offset(void);
-
-/*-----------------
- * methods
- *----------------- */
-lub_bintree_t * clish_view__get_command_tree(clish_view_t *instance);
-lub_list_t * clish_view__get_nspace_tree(clish_view_t *instance);
 void clish_view_delete(clish_view_t * instance);
 clish_command_t *clish_view_new_command(clish_view_t * instance,
 	const char *name, const char *text);
@@ -60,22 +48,21 @@ clish_command_t *clish_view_resolve_prefix(clish_view_t * instance,
 void clish_view_dump(clish_view_t * instance);
 void clish_view_insert_nspace(clish_view_t * instance, clish_nspace_t * nspace);
 void clish_view_clean_proxy(clish_view_t * instance);
-
-/*-----------------
- * attributes
- *----------------- */
-const char *clish_view__get_name(const clish_view_t * instance);
-void clish_view__set_prompt(clish_view_t * instance, const char *prompt);
-char *clish_view__get_prompt(const clish_view_t *instance);
-void clish_view__set_depth(clish_view_t * instance, unsigned depth);
-unsigned clish_view__get_depth(const clish_view_t * instance);
-void clish_view__set_restore(clish_view_t * instance,
-	clish_view_restore_e restore);
-clish_view_restore_e clish_view__get_restore(const clish_view_t * instance);
 int clish_view_insert_hotkey(const clish_view_t *instance, const char *key, const char *cmd);
 const char *clish_view_find_hotkey(const clish_view_t *instance, int code);
-void clish_view__set_access(clish_view_t *instance, const char *access);
-char *clish_view__get_access(const clish_view_t *instance);
+
+_CLISH_GET(view, lub_list_t *, nspaces);
+_CLISH_GET_STR(view, name);
+_CLISH_SET_STR_ONCE(view, prompt);
+_CLISH_GET_STR(view, prompt);
+_CLISH_SET_STR(view, access);
+_CLISH_GET_STR(view, access);
+_CLISH_SET(view, unsigned int, depth);
+_CLISH_GET(view, unsigned int, depth);
+_CLISH_SET(view, clish_view_restore_e, restore);
+_CLISH_GET(view, clish_view_restore_e, restore);
+
+lub_bintree_t * clish_view__get_tree(clish_view_t *instance);
 
 #endif				/* _clish_view_h */
 /** @} clish_view */

+ 18 - 82
clish/view/view.c

@@ -14,9 +14,7 @@
 #include <string.h>
 #include <stdio.h>
 
-/*---------------------------------------------------------
- * PRIVATE META FUNCTIONS
- *--------------------------------------------------------- */
+/*-------------------------------------------------------- */
 int clish_view_bt_compare(const void *clientnode, const void *clientkey)
 {
 	const clish_view_t *this = clientnode;
@@ -34,9 +32,7 @@ void clish_view_bt_getkey(const void *clientnode, lub_bintree_key_t * key)
 	strcpy((char *)key, this->name);
 }
 
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
+/*-------------------------------------------------------- */
 static void clish_view_init(clish_view_t * this, const char *name, const char *prompt)
 {
 	/* set up defaults */
@@ -102,9 +98,7 @@ static void clish_view_fini(clish_view_t * this)
 	lub_string_free(this->access);
 }
 
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
+/*-------------------------------------------------------- */
 size_t clish_view_bt_offset(void)
 {
 	return offsetof(clish_view_t, bt_node);
@@ -120,9 +114,7 @@ clish_view_t *clish_view_new(const char *name, const char *prompt)
 	return this;
 }
 
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
+/*-------------------------------------------------------- */
 void clish_view_delete(clish_view_t * this)
 {
 	clish_view_fini(this);
@@ -332,64 +324,6 @@ void clish_view_clean_proxy(clish_view_t * this)
 	}
 }
 
-/*---------------------------------------------------------
- * PUBLIC ATTRIBUTES
- *--------------------------------------------------------- */
-lub_bintree_t * clish_view__get_command_tree(clish_view_t *this)
-{
-	return &this->tree;
-}
-
-/*--------------------------------------------------------- */
-lub_list_t * clish_view__get_nspace_tree(clish_view_t *this)
-{
-	return this->nspaces;
-}
-
-/*--------------------------------------------------------- */
-const char *clish_view__get_name(const clish_view_t * this)
-{
-	return this->name;
-}
-
-/*--------------------------------------------------------- */
-void clish_view__set_prompt(clish_view_t * this, const char *prompt)
-{
-	assert(!this->prompt);
-	this->prompt = lub_string_dup(prompt);
-}
-
-/*--------------------------------------------------------- */
-char *clish_view__get_prompt(const clish_view_t *this)
-{
-	return this->prompt;
-}
-
-/*--------------------------------------------------------- */
-void clish_view__set_depth(clish_view_t * this, unsigned depth)
-{
-	this->depth = depth;
-}
-
-/*--------------------------------------------------------- */
-unsigned clish_view__get_depth(const clish_view_t * this)
-{
-	return this->depth;
-}
-
-/*--------------------------------------------------------- */
-void clish_view__set_restore(clish_view_t * this,
-	clish_view_restore_e restore)
-{
-	this->restore = restore;
-}
-
-/*--------------------------------------------------------- */
-clish_view_restore_e clish_view__get_restore(const clish_view_t * this)
-{
-	return this->restore;
-}
-
 /*--------------------------------------------------------- */
 int clish_view_insert_hotkey(const clish_view_t *this, const char *key, const char *cmd)
 {
@@ -402,18 +336,20 @@ const char *clish_view_find_hotkey(const clish_view_t *this, int code)
 	return clish_hotkeyv_cmd_by_code(this->hotkeys, code);
 }
 
-/*--------------------------------------------------------- */
-void clish_view__set_access(clish_view_t *this, const char *access)
-{
-	if (this->access)
-		lub_string_free(this->access);
-	this->access = lub_string_dup(access);
-}
+CLISH_GET(view, lub_list_t *, nspaces);
+CLISH_GET_STR(view, name);
+CLISH_SET_STR_ONCE(view, prompt);
+CLISH_GET_STR(view, prompt);
+CLISH_SET_STR(view, access);
+CLISH_GET_STR(view, access);
+CLISH_SET(view, unsigned int, depth);
+CLISH_GET(view, unsigned int, depth);
+CLISH_SET(view, clish_view_restore_e, restore);
+CLISH_GET(view, clish_view_restore_e, restore);
 
-/*--------------------------------------------------------- */
-char *clish_view__get_access(const clish_view_t *this)
+/*-------------------------------------------------------- */
+lub_bintree_t * clish_view__get_tree(clish_view_t *inst)
 {
-	return this->access;
+	assert(inst);
+	return &inst->tree;
 }
-
-/*--------------------------------------------------------- */