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_ANNOTATION_INTERFACE_IMPL_H
17 #define CPP_ABCKIT_CORE_ANNOTATION_INTERFACE_IMPL_H
18
19 #include "annotation_interface.h"
20 #include "module.h"
21
22 namespace abckit::core {
23
GetFile()24 inline const File *AnnotationInterface::GetFile() const
25 {
26 return GetResource();
27 }
28
EnumerateFields(const std::function<bool (core::AnnotationInterfaceField)> & cb)29 inline bool AnnotationInterface::EnumerateFields(const std::function<bool(core::AnnotationInterfaceField)> &cb) const
30 {
31 Payload<const std::function<bool(core::AnnotationInterfaceField)> &> payload {cb, GetApiConfig(), GetResource()};
32
33 bool isNormalExit = GetApiConfig()->cIapi_->annotationInterfaceEnumerateFields(
34 GetView(), &payload, [](AbckitCoreAnnotationInterfaceField *func, void *data) {
35 const auto &payload =
36 *static_cast<Payload<const std::function<bool(core::AnnotationInterfaceField)> &> *>(data);
37 return payload.data(core::AnnotationInterfaceField(func, payload.config, payload.resource));
38 });
39 CheckError(GetApiConfig());
40 return isNormalExit;
41 }
42
43 // CC-OFFNXT(G.FUD.06) perf critical
GetFields()44 inline std::vector<AnnotationInterfaceField> AnnotationInterface::GetFields() const
45 {
46 std::vector<core::AnnotationInterfaceField> namespaces;
47 Payload<std::vector<core::AnnotationInterfaceField> *> payload {&namespaces, GetApiConfig(), GetResource()};
48
49 GetApiConfig()->cIapi_->annotationInterfaceEnumerateFields(
50 GetView(), &payload, [](AbckitCoreAnnotationInterfaceField *func, void *data) {
51 const auto &payload = *static_cast<Payload<std::vector<core::AnnotationInterfaceField> *> *>(data);
52 payload.data->push_back(core::AnnotationInterfaceField(func, payload.config, payload.resource));
53 return true;
54 });
55
56 CheckError(GetApiConfig());
57
58 return namespaces;
59 }
60
GetModule()61 inline core::Module AnnotationInterface::GetModule() const
62 {
63 auto mod = GetApiConfig()->cIapi_->annotationInterfaceGetModule(GetView());
64 CheckError(GetApiConfig());
65 return Module(mod, GetApiConfig(), GetResource());
66 }
67
GetName()68 inline std::string AnnotationInterface::GetName() const
69 {
70 const ApiConfig *conf = GetApiConfig();
71 AbckitString *abcStr = conf->cIapi_->annotationInterfaceGetName(GetView());
72 CheckError(conf);
73 std::string str = conf->cIapi_->abckitStringToString(abcStr);
74 CheckError(conf);
75 return str;
76 }
77
78 } // namespace abckit::core
79
80 #endif // CPP_ABCKIT_CORE_ANNOTATION_INTERFACE_IMPL_H
81