1 | /* $Id: expreval.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Expression Evaluator.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_expreval_h
|
---|
38 | #define IPRT_INCLUDED_expreval_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/types.h>
|
---|
44 |
|
---|
45 | RT_C_DECLS_BEGIN
|
---|
46 |
|
---|
47 | /** @defgroup grp_rt_expr_eval RTExprEval - Expression Evaluator
|
---|
48 | * @{ */
|
---|
49 |
|
---|
50 | /** Handle to an expression evaluator. */
|
---|
51 | typedef struct RTEXPREVALINT *RTEXPREVAL;
|
---|
52 | /** Pointer to an expression evaluator handle. */
|
---|
53 | typedef RTEXPREVAL *PRTEXPREVAL;
|
---|
54 | /** NIL expression evaluator handle. */
|
---|
55 | #define NIL_RTEXPREVAL ((RTEXPREVAL)~(uintptr_t)0)
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Variable getter (supplied by user).
|
---|
59 | *
|
---|
60 | * @returns IPRT status code.
|
---|
61 | * @retval VERR_NOT_FOUND if the variable does not exist.
|
---|
62 | */
|
---|
63 | typedef DECLCALLBACKTYPE(int, FNRTEXPREVALQUERYVARIABLE,(const char *pchName, size_t cchName, void *pvUser, char **ppszValue));
|
---|
64 | /** Pointer to a variable getter. */
|
---|
65 | typedef FNRTEXPREVALQUERYVARIABLE *PFNRTEXPREVALQUERYVARIABLE;
|
---|
66 |
|
---|
67 | /** @name Expression evaluator flags.
|
---|
68 | * @sa RTExprEvalCreate
|
---|
69 | * @{ */
|
---|
70 | /** Default to hexadecimal instead of decimal numbers. */
|
---|
71 | #define RTEXPREVAL_F_DEFAULT_BASE_16 RT_BIT_64(0)
|
---|
72 | /** Enables C-ish octal style, i.e. 0777 be read as 0x1ff (in hex). */
|
---|
73 | #define RTEXPREVAL_F_C_OCTAL RT_BIT_64(1)
|
---|
74 | /** Enables the 'exists' operator that can be used to check if a path exists.
|
---|
75 | * @sa RTPathExists */
|
---|
76 | #define RTEXPREVAL_F_EXISTS_OP RT_BIT_64(2)
|
---|
77 | /** Valid mask. */
|
---|
78 | #define RTEXPREVAL_F_VALID_MASK UINT64_MAX(3)
|
---|
79 | /** @} */
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Creates an expression evaluator.
|
---|
83 | *
|
---|
84 | * @returns IPRT status code.
|
---|
85 | * @param phEval Where to return the handle to the evaluator.
|
---|
86 | * @param fFlags RTEXPREVAL_F_XXX.
|
---|
87 | * @param pszName The evaluator name (for logging).
|
---|
88 | * @param pvUser User argument for callbacks.
|
---|
89 | * @param pfnQueryVariable Callback for querying variables. Optional.
|
---|
90 | */
|
---|
91 | RTDECL(int) RTExprEvalCreate(PRTEXPREVAL phEval, uint64_t fFlags, const char *pszName,
|
---|
92 | void *pvUser, PFNRTEXPREVALQUERYVARIABLE pfnQueryVariable);
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Retains a reference to the evaluator.
|
---|
96 | *
|
---|
97 | * @returns New reference count, UINT32_MAX if @a hEval is not valid.
|
---|
98 | * @param hEval Handle to the evaluator.
|
---|
99 | */
|
---|
100 | RTDECL(uint32_t) RTExprEvalRetain(RTEXPREVAL hEval);
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Releases a reference to the evaluator.
|
---|
104 | *
|
---|
105 | * @returns New reference count, UINT32_MAX if @a hEval is not valid. (The
|
---|
106 | * evaluator was destroyed when 0 is returned.)
|
---|
107 | * @param hEval Handle to the evaluator.
|
---|
108 | */
|
---|
109 | RTDECL(uint32_t) RTExprEvalRelease(RTEXPREVAL hEval);
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Evaluates the given if expression to a boolean result.
|
---|
113 | *
|
---|
114 | * @returns IPRT status code
|
---|
115 | * @param hEval Handle to the evaluator.
|
---|
116 | * @param pch The expression string. Does not need to be zero
|
---|
117 | * terminated.
|
---|
118 | * @param cch The length of the expression. Pass RTSTR_MAX if not
|
---|
119 | * known.
|
---|
120 | * @param pfResult Where to return the result.
|
---|
121 | * @param pErrInfo Where to return additional error info.
|
---|
122 | */
|
---|
123 | RTDECL(int) RTExprEvalToBool(RTEXPREVAL hEval, const char *pch, size_t cch, bool *pfResult, PRTERRINFO pErrInfo);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Evaluates the given if expression to an integer (signed 64-bit) result.
|
---|
127 | *
|
---|
128 | * @returns IPRT status code
|
---|
129 | * @param hEval Handle to the evaluator.
|
---|
130 | * @param pch The expression string. Does not need to be zero
|
---|
131 | * terminated.
|
---|
132 | * @param cch The length of the expression. Pass RTSTR_MAX if not
|
---|
133 | * known.
|
---|
134 | * @param piResult Where to return the result.
|
---|
135 | * @param pErrInfo Where to return additional error info.
|
---|
136 | */
|
---|
137 | RTDECL(int) RTExprEvalToInteger(RTEXPREVAL hEval, const char *pch, size_t cch, int64_t *piResult, PRTERRINFO pErrInfo);
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Evaluates the given if expression to a string result.
|
---|
141 | *
|
---|
142 | * @returns IPRT status code
|
---|
143 | * @param hEval Handle to the evaluator.
|
---|
144 | * @param pch The expression string. Does not need to be zero
|
---|
145 | * terminated.
|
---|
146 | * @param cch The length of the expression. Pass RTSTR_MAX if not
|
---|
147 | * known.
|
---|
148 | * @param ppszResult Where to return the result. This must be freed using
|
---|
149 | * RTStrFree.
|
---|
150 | * @param pErrInfo Where to return additional error info.
|
---|
151 | */
|
---|
152 | RTDECL(int) RTExprEvalToString(RTEXPREVAL hEval, const char *pch, size_t cch, char **ppszResult, PRTERRINFO pErrInfo);
|
---|
153 |
|
---|
154 | /** @} */
|
---|
155 |
|
---|
156 | RT_C_DECLS_END
|
---|
157 |
|
---|
158 | #endif /* !IPRT_INCLUDED_expreval_h */
|
---|
159 |
|
---|