Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
9efcaf5e
Commit
9efcaf5e
authored
7 years ago
by
Jenkins2
Committed by
Gerrit Code Review
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge "astobj2: Create case-insensitive variants of container function macros."
parents
f77ca954
b32d6d5e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/asterisk/astobj2.h
+66
-38
66 additions, 38 deletions
include/asterisk/astobj2.h
with
66 additions
and
38 deletions
include/asterisk/astobj2.h
+
66
−
38
View file @
9efcaf5e
...
@@ -1985,14 +1985,16 @@ void ao2_iterator_cleanup(struct ao2_iterator *iter);
...
@@ -1985,14 +1985,16 @@ void ao2_iterator_cleanup(struct ao2_iterator *iter);
int
ao2_iterator_count
(
struct
ao2_iterator
*
iter
);
int
ao2_iterator_count
(
struct
ao2_iterator
*
iter
);
/*!
/*!
* \brief Creates a hash function for a structure
string
field.
* \brief Creates a hash function for a structure field.
* \param stype The structure type
* \param stype The structure type
* \param field The string field in the structure to hash
* \param field The string field in the structure to hash
* \param hash_fn Function which hashes the field
*
*
* AO2_STRING_FIELD_HASH_CB(mystruct, myfield) will produce a function
* AO2_FIELD_HASH_FN(mystruct, myfield, ast_str_hash) will
* named mystruct_hash_fn which hashes mystruct->myfield.
* produce a function named mystruct_hash_fn which hashes
* mystruct->myfield with ast_str_hash.
*/
*/
#define AO2_
STRING_
FIELD_HASH_FN(stype, field) \
#define AO2_FIELD_HASH_FN(stype, field
, hash_fn
) \
static int stype ## _hash_fn(const void *obj, const int flags) \
static int stype ## _hash_fn(const void *obj, const int flags) \
{ \
{ \
const struct stype *object = obj; \
const struct stype *object = obj; \
...
@@ -2008,19 +2010,33 @@ static int stype ## _hash_fn(const void *obj, const int flags) \
...
@@ -2008,19 +2010,33 @@ static int stype ## _hash_fn(const void *obj, const int flags) \
ast_assert(0); \
ast_assert(0); \
return 0; \
return 0; \
} \
} \
return
ast_str_
hash(key); \
return hash
_fn
(key); \
}
}
#define AO2_FIELD_TRANSFORM_CMP_FN(cmp) ((cmp) ? 0 : CMP_MATCH)
#define AO2_FIELD_TRANSFORM_SORT_FN(cmp) (cmp)
/*!
/*!
* \internal
*
* \brief Creates a compare function for a structure string field.
* \brief Creates a compare function for a structure string field.
* \param stype The structure type
* \param stype The structure type
* \param fn_suffix Function name suffix
* \param field The string field in the structure to compare
* \param field The string field in the structure to compare
* \param key_cmp Key comparison function like strcmp
* \param partial_key_cmp Partial key comparison function like strncmp
* \param transform A macro that takes the cmp result as an argument
* and transforms it to a return value.
*
*
* AO2_STRING_FIELD_CMP_FN(mystruct, myfield) will produce a function
* Do not use this macro directly, instead use macro's starting with
* named mystruct_cmp_fn which compares mystruct->myfield.
* AST_STRING_FIELD.
*
* \warning The macro is an internal implementation detail, the API
* may change at any time.
*/
*/
#define AO2_
STRING_
FIELD_CMP_FN(stype, f
ield
) \
#define AO2_FIELD_CMP_FN(stype, f
n_suffix, field, key_cmp, partial_key_cmp, transform, argconst
) \
static int stype ##
_cmp_fn(
void *obj, void *arg, int flags) \
static int stype ##
fn_suffix(argconst
void *obj,
argconst
void *arg, int flags) \
{ \
{ \
const struct stype *object_left = obj, *object_right = arg; \
const struct stype *object_left = obj, *object_right = arg; \
const char *right_key = arg; \
const char *right_key = arg; \
...
@@ -2029,21 +2045,50 @@ static int stype ## _cmp_fn(void *obj, void *arg, int flags) \
...
@@ -2029,21 +2045,50 @@ static int stype ## _cmp_fn(void *obj, void *arg, int flags) \
case OBJ_SEARCH_OBJECT: \
case OBJ_SEARCH_OBJECT: \
right_key = object_right->field; \
right_key = object_right->field; \
case OBJ_SEARCH_KEY: \
case OBJ_SEARCH_KEY: \
cmp =
str
cmp(object_left->field, right_key); \
cmp =
key_
cmp(object_left->field, right_key); \
break; \
break; \
case OBJ_SEARCH_PARTIAL_KEY: \
case OBJ_SEARCH_PARTIAL_KEY: \
cmp =
strn
cmp(object_left->field, right_key, strlen(right_key)); \
cmp =
partial_key_
cmp(object_left->field, right_key, strlen(right_key)); \
break; \
break; \
default: \
default: \
cmp = 0; \
cmp = 0; \
break; \
break; \
} \
} \
if (cmp) { \
return transform(cmp); \
return 0; \
} \
return CMP_MATCH; \
}
}
/*!
* \brief Creates a hash function for a structure string field.
* \param stype The structure type
* \param field The string field in the structure to hash
*
* AO2_STRING_FIELD_HASH_FN(mystruct, myfield) will produce a function
* named mystruct_hash_fn which hashes mystruct->myfield.
*
* AO2_STRING_FIELD_HASH_FN(mystruct, myfield) would do the same except
* it uses the hash function which ignores case.
*/
#define AO2_STRING_FIELD_HASH_FN(stype, field) \
AO2_FIELD_HASH_FN(stype, field, ast_str_hash)
#define AO2_STRING_FIELD_CASE_HASH_FN(stype, field) \
AO2_FIELD_HASH_FN(stype, field, ast_str_case_hash)
/*!
* \brief Creates a compare function for a structure string field.
* \param stype The structure type
* \param field The string field in the structure to compare
*
* AO2_STRING_FIELD_CMP_FN(mystruct, myfield) will produce a function
* named mystruct_cmp_fn which compares mystruct->myfield.
*
* AO2_STRING_FIELD_CASE_CMP_FN(mystruct, myfield) would do the same
* except it performs case insensitive comparisons.
*/
#define AO2_STRING_FIELD_CMP_FN(stype, field) \
AO2_FIELD_CMP_FN(stype, _cmp_fn, field, strcmp, strncmp, AO2_FIELD_TRANSFORM_CMP_FN,)
#define AO2_STRING_FIELD_CASE_CMP_FN(stype, field) \
AO2_FIELD_CMP_FN(stype, _cmp_fn, field, strcasecmp, strncasecmp, AO2_FIELD_TRANSFORM_CMP_FN,)
/*!
/*!
* \brief Creates a sort function for a structure string field.
* \brief Creates a sort function for a structure string field.
* \param stype The structure type
* \param stype The structure type
...
@@ -2051,30 +2096,13 @@ static int stype ## _cmp_fn(void *obj, void *arg, int flags) \
...
@@ -2051,30 +2096,13 @@ static int stype ## _cmp_fn(void *obj, void *arg, int flags) \
*
*
* AO2_STRING_FIELD_SORT_FN(mystruct, myfield) will produce a function
* AO2_STRING_FIELD_SORT_FN(mystruct, myfield) will produce a function
* named mystruct_sort_fn which compares mystruct->myfield.
* named mystruct_sort_fn which compares mystruct->myfield.
*
* AO2_STRING_FIELD_CASE_SORT_FN(mystruct, myfield) would do the same
* except it performs case insensitive comparisons.
*/
*/
#define AO2_STRING_FIELD_SORT_FN(stype, field) \
#define AO2_STRING_FIELD_SORT_FN(stype, field) \
static int stype ## _sort_fn(const void *obj, const void *arg, int flags) \
AO2_FIELD_CMP_FN(stype, _sort_fn, field, strcmp, strncmp, AO2_FIELD_TRANSFORM_SORT_FN, const)
{ \
#define AO2_STRING_FIELD_CASE_SORT_FN(stype, field) \
const struct stype *object_left = obj; \
AO2_FIELD_CMP_FN(stype, _sort_fn, field, strcasecmp, strncasecmp, AO2_FIELD_TRANSFORM_SORT_FN, const)
const struct stype *object_right = arg; \
const char *right_key = arg; \
int cmp; \
\
switch (flags & OBJ_SEARCH_MASK) { \
case OBJ_SEARCH_OBJECT: \
right_key = object_right->field; \
/* Fall through */
\
case OBJ_SEARCH_KEY: \
cmp = strcmp(object_left->field, right_key); \
break; \
case OBJ_SEARCH_PARTIAL_KEY: \
cmp = strncmp(object_left->field, right_key, strlen(right_key)); \
break; \
default: \
cmp = 0; \
break; \
} \
return cmp; \
}
#endif
/* _ASTERISK_ASTOBJ2_H */
#endif
/* _ASTERISK_ASTOBJ2_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment