[asterisk-commits] eliel: branch group/data_api_gsoc2009 r205767 - in /team/group/data_api_gsoc2...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 10 09:23:39 CDT 2009


Author: eliel
Date: Fri Jul 10 09:23:35 2009
New Revision: 205767

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205767
Log:
Avoid needing to specify the type of argument we are comparing.

Modified:
    team/group/data_api_gsoc2009/include/asterisk/data.h
    team/group/data_api_gsoc2009/main/data.c

Modified: team/group/data_api_gsoc2009/include/asterisk/data.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/include/asterisk/data.h?view=diff&rev=205767&r1=205766&r2=205767
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Fri Jul 10 09:23:35 2009
@@ -187,6 +187,17 @@
 int __ast_data_unregister(const char *path, const char *registrar);
 #define ast_data_unregister(path) __ast_data_unregister(path, __FILE__)
 
+#define ast_data_search_cmp(_root, _name, _value) ({					\
+	int __ret = 0;									\
+	if (__builtin_types_compatible_p(typeof(_value), int))				\
+		__ret  = ast_data_search_cmp_sint(_root, _name, (void *) _value);	\
+	else if (__builtin_types_compatible_p(typeof(_value), char[]))			\
+		__ret = ast_data_search_cmp_string(_root, _name, (void *) _value);	\
+	else										\
+		abort();								\
+	__ret;										\
+})
+
 /*!
  * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
  *        current string value.
@@ -198,7 +209,7 @@
  * \param[in] value The value to compare.
  * \returns The strcmp return value.
  */
-int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, const char *value);
+int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, void *value);
 
 /*!
  * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
@@ -211,7 +222,7 @@
  * \param[in] value The value to compare.
  * \returns The strcmp return value.
  */
-int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, int value);
+int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, void *value);
 
 /*!
  * \brief Retrieve a subtree from the asterisk data API.

Modified: team/group/data_api_gsoc2009/main/data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/data.c?view=diff&rev=205767&r1=205766&r2=205767
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Fri Jul 10 09:23:35 2009
@@ -922,7 +922,7 @@
 	return data_search_get_node(child, savepath);
 }
 
-int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, const char *value)
+int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, void *value)
 {
 	struct ast_data_search *child;
 	enum data_search_comparison cmp_type;
@@ -933,7 +933,7 @@
 		return 0;
 	}
 
-	ret = strcmp(value, child->value);
+	ret = strcmp((const char *) value, child->value);
 	cmp_type = child->cmp_type;
 
 	ao2_ref(child, -1);
@@ -941,7 +941,7 @@
 	return data_search_comparison_result(ret, cmp_type);
 }
 
-int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, int value)
+int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, void *value)
 {
 	struct ast_data_search *child;
 	int node_value;
@@ -957,7 +957,7 @@
 
 	ao2_ref(child, -1);
 
-	return data_search_comparison_result(node_value - value, cmp_type);
+	return data_search_comparison_result(node_value - (int)value, cmp_type);
 }
 
 /*!




More information about the asterisk-commits mailing list