1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef CPP_ABCKIT_CORE_NAMESPACE_IMPL_H
17 #define CPP_ABCKIT_CORE_NAMESPACE_IMPL_H
18
19 #include "namespace.h"
20 #include "function.h"
21 #include "class.h"
22
23 namespace abckit::core {
24
25 // CC-OFFNXT(G.FUD.06) perf critical
EnumerateNamespaces(const std::function<bool (core::Namespace)> & cb)26 inline bool Namespace::EnumerateNamespaces(const std::function<bool(core::Namespace)> &cb) const
27 {
28 Payload<const std::function<bool(core::Namespace)> &> payload {cb, GetApiConfig(), GetResource()};
29
30 bool isNormalExit = GetApiConfig()->cIapi_->namespaceEnumerateNamespaces(
31 GetView(), &payload, [](AbckitCoreNamespace *ns, void *data) {
32 const auto &payload = *static_cast<Payload<const std::function<bool(core::Namespace)> &> *>(data);
33 return payload.data(core::Namespace(ns, payload.config, payload.resource));
34 });
35 CheckError(GetApiConfig());
36 return isNormalExit;
37 }
38
39 // CC-OFFNXT(G.FUD.06) perf critical
EnumerateClasses(const std::function<bool (core::Class)> & cb)40 inline bool Namespace::EnumerateClasses(const std::function<bool(core::Class)> &cb) const
41 {
42 Payload<const std::function<bool(core::Class)> &> payload {cb, GetApiConfig(), GetResource()};
43
44 bool isNormalExit =
45 GetApiConfig()->cIapi_->namespaceEnumerateClasses(GetView(), &payload, [](AbckitCoreClass *ns, void *data) {
46 const auto &payload = *static_cast<Payload<const std::function<bool(core::Class)> &> *>(data);
47 return payload.data(core::Class(ns, payload.config, payload.resource));
48 });
49 CheckError(GetApiConfig());
50 return isNormalExit;
51 }
52
53 // CC-OFFNXT(G.FUD.06) perf critical
EnumerateTopLevelFunctions(const std::function<bool (core::Function)> & cb)54 inline bool Namespace::EnumerateTopLevelFunctions(const std::function<bool(core::Function)> &cb) const
55 {
56 Payload<const std::function<bool(core::Function)> &> payload {cb, GetApiConfig(), GetResource()};
57
58 bool isNormalExit = GetApiConfig()->cIapi_->namespaceEnumerateTopLevelFunctions(
59 GetView(), &payload, [](AbckitCoreFunction *func, void *data) {
60 const auto &payload = *static_cast<Payload<const std::function<bool(core::Function)> &> *>(data);
61 return payload.data(core::Function(func, payload.config, payload.resource));
62 });
63 CheckError(GetApiConfig());
64 return isNormalExit;
65 }
66
67 } // namespace abckit::core
68
69 #endif // CPP_ABCKIT_CORE_NAMESPACE_IMPL_H
70