ae2f_docs
Loading...
Searching...
No Matches
Cmp.h
Go to the documentation of this file.
1/**
2 * @file Cmp.h
3 * @author ae2f
4 * @brief
5 * @date 2025-02-01
6 *
7 * @copyright Copyright (c) 2025
8 *
9 */
10
11#ifndef ae2f_Cmp_h
12#define ae2f_Cmp_h
13
14
15typedef int
16/**
17 * @typedef ae2f_CmpFunRet_t
18 * @brief
19 * A predefined returning data type for @ref ae2f_fpCmp_t.
20 * @see ae2f_CmpFunRet_EQUAL
21 * @see ae2f_CmpFunRet_RISLESSER
22 * @see ae2f_CmpFunRet_LISLESSER
23 */
24ae2f_CmpFunRet_t;
25
26typedef ae2f_CmpFunRet_t
27/**
28 * @typedef ae2f_fpCmp_t
29 * @brief
30 * It is an api for following approximate pseudo code.
31 * ```c
32 * const void *l, *r;
33 * return *l - *r;
34 * ```
35 * @see ae2f_CmpFunRet_t
36 */
37(*ae2f_fpCmp_t)(const void* l, const void* r);
38
39/**
40 * @brief they are same
41 * @see ae2f_CmpFunRet_t
42 */
43#define ae2f_CmpFunRet_EQUAL 0
44
45/**
46 * @brief right is lesser
47 * @see ae2f_CmpFunRet_t
48 */
49#define ae2f_CmpFunRet_RISLESSER 1
50
51/**
52 * @brief left is lesser
53 * @see ae2f_CmpFunRet_t
54 */
55#define ae2f_CmpFunRet_LISLESSER -1
56
57/**
58 * @warning
59 * Two parameters must be comparable with operator.
60 * @return
61 * One bigger.
62 */
63#define ae2f_CmpGetGt(a, b) ((a) > (b) ? (a) : (b))
64
65/**
66 * @warning
67 * Two parameters must be comparable with operator.
68 * @return
69 * One smaller.
70 */
71#define ae2f_CmpGetLs(a, b) ((a) < (b) ? (a) : (b))
72
73/**
74 * @return
75 * The absolute different of two.
76 */
77#define ae2f_CmpDiff(a, b) (ae2f_CmpGetGt(a, b) - ae2f_CmpGetLs(a, b))
78
79/**
80 * @brief
81 * Gets the member from the pointer.
82 * Given nullptr, the return will be alter.
83 * @param ptr The pointer for getting member.
84 * @param member The valid member's name. [from the structure]
85 * @param alter The alternative value when given nullptr.
86 */
87#define ae2f_CmpGetMem(ptr, member, alter) ((ptr) ? ((ptr)->member) : (alter))
88
89/**
90 * @brief
91 * Returns ptr's self.
92 * Given nullptr, the return will be alt.
93 * @param ptr Self Referring
94 * @param alt The alternative value.
95 */
96#define ae2f_CmpGetSelf(ptr, alt) ((ptr) ? (ptr) : (alt))
97#endif /** !defined(ae2f_Macro_Compare_h) */
#define ae2f_CmpGetGt(a, b)
Definition Cmp.h:63
#define ae2f_CmpGetLs(a, b)
Definition Cmp.h:71
#define ae2f_constexprmethod
Definition Constexpr.h:56
#define ae2f_WhenCXX(a)
Appears when the current language is C.
Definition Cxx.h:44
#define ae2f_is_cxx
Definition Cxx.h:48
#define ae2f_WhenC(a)
Appears when the current language is C++.
Definition Cxx.h:38
#define ae2f_NONE
Definition Guide.h:11
#define ae2f_stdcc_v
Standard C++ version. .
Definition LangVer.h:34
#define __ae2f_stdcheck_CC(v)
Definition LangVer.h:50
#define ae2f_PackCount
Definition Num.auto.h:6