VirtualBox

source: vbox/trunk/include/iprt/expreval.h@ 93170

最後變更 在這個檔案從93170是 93170,由 vboxsync 提交於 3 年 前

iprt/RTExprEval: Early code for a 'simple' expression evaluator a la /bin/expr and such. bugref:9781

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette