• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ARKTS_ANNOTATION_IMPL_H
17 #define CPP_ABCKIT_ARKTS_ANNOTATION_IMPL_H
18 
19 #include "annotation.h"
20 #include "annotation_element.h"
21 #include "../value.h"
22 #include "../core/annotation_element.h"
23 
24 // NOLINTBEGIN(performance-unnecessary-value-param)
25 namespace abckit::arkts {
26 
TargetCast()27 inline AbckitArktsAnnotation *Annotation::TargetCast() const
28 {
29     auto ret = GetApiConfig()->cArktsIapi_->coreAnnotationToArktsAnnotation(GetView());
30     CheckError(GetApiConfig());
31     return ret;
32 }
33 
Annotation(const core::Annotation & coreOther)34 inline Annotation::Annotation(const core::Annotation &coreOther) : core::Annotation(coreOther), targetChecker_(this) {}
35 
AddElement(const abckit::Value & val,std::string_view name)36 inline arkts::Annotation Annotation::AddElement(const abckit::Value &val, std::string_view name) const
37 {
38     struct AbckitArktsAnnotationElementCreateParams params {
39         name.data(), val.GetView()
40     };
41     GetApiConfig()->cArktsMapi_->annotationAddAnnotationElement(TargetCast(), &params);
42     CheckError(GetApiConfig());
43     return *this;
44 }
45 
AddAndGetElementImpl(AbckitArktsAnnotationElementCreateParams * params)46 inline AbckitCoreAnnotationElement *Annotation::AddAndGetElementImpl(
47     AbckitArktsAnnotationElementCreateParams *params) const
48 {
49     AbckitArktsAnnotationElement *arktsAnni =
50         GetApiConfig()->cArktsMapi_->annotationAddAnnotationElement(TargetCast(), params);
51     CheckError(GetApiConfig());
52     AbckitCoreAnnotationElement *coreAnni =
53         GetApiConfig()->cArktsIapi_->arktsAnnotationElementToCoreAnnotationElement(arktsAnni);
54     CheckError(GetApiConfig());
55     return coreAnni;
56 }
57 
AddAndGetElement(const abckit::Value & val,std::string_view name)58 inline arkts::AnnotationElement Annotation::AddAndGetElement(const abckit::Value &val, std::string_view name) const
59 {
60     struct AbckitArktsAnnotationElementCreateParams params {
61         name.data(), val.GetView()
62     };
63     auto *coreAnni = AddAndGetElementImpl(&params);
64     core::AnnotationElement element(coreAnni, GetApiConfig(), GetResource());
65     return arkts::AnnotationElement(element);
66 }
67 
AddAnnotationElement(std::string_view name,Value value)68 inline AnnotationElement Annotation::AddAnnotationElement(std::string_view name, Value value) const
69 {
70     struct AbckitArktsAnnotationElementCreateParams params {
71         name.data(), value.GetView()
72     };
73 
74     auto arktsAnnoElem = GetApiConfig()->cArktsMapi_->annotationAddAnnotationElement(TargetCast(), &params);
75     CheckError(GetApiConfig());
76     auto coreAnnoElenm = GetApiConfig()->cArktsIapi_->arktsAnnotationElementToCoreAnnotationElement(arktsAnnoElem);
77     CheckError(GetApiConfig());
78     return AnnotationElement(core::AnnotationElement(coreAnnoElenm, GetApiConfig(), GetResource()));
79 }
80 
RemoveAnnotationElement(AnnotationElement elem)81 inline Annotation Annotation::RemoveAnnotationElement(AnnotationElement elem) const
82 {
83     GetApiConfig()->cArktsMapi_->annotationRemoveAnnotationElement(TargetCast(), elem.TargetCast());
84     CheckError(GetApiConfig());
85     return *this;
86 }
87 
88 }  // namespace abckit::arkts
89 // NOLINTEND(performance-unnecessary-value-param)
90 
91 #endif  // CPP_ABCKIT_ARKTS_ANNOTATION_IMPL_H
92