• 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_VALUE_H
17 #define CPP_ABCKIT_VALUE_H
18 
19 #include "./base_classes.h"
20 
21 namespace abckit {
22 
23 /**
24  * @brief Value
25  */
26 class Value : public ViewInResource<AbckitValue *, const File *> {
27     /// @brief abckit::File
28     friend class abckit::File;
29     /// @brief abckit::core::Annotation
30     friend class core::Annotation;
31     /// @brief abckit::core::Annotation
32     friend class core::AnnotationElement;
33     /// @brief abckit::core::AnnotationInterfaceField
34     friend class core::AnnotationInterfaceField;
35     /// @brief abckit::arkts::Annotation
36     friend class arkts::Annotation;
37     /// @brief abckit::DefaultHash<Value>
38     friend class abckit::DefaultHash<Value>;
39     /// @brief arkts::AnnotationInterface
40     friend class arkts::AnnotationInterface;
41 
42 public:
43     /**
44      * @brief Construct a new Value object
45      * @param other
46      */
47     Value(const Value &other) = default;
48 
49     /**
50      * @brief Constructor
51      * @param other
52      * @return Value&
53      */
54     Value &operator=(const Value &other) = default;
55 
56     /**
57      * @brief Construct a new Value object
58      * @param other
59      */
60     Value(Value &&other) = default;
61 
62     /**
63      * @brief Constructor
64      * @param other
65      * @return Value&
66      */
67     Value &operator=(Value &&other) = default;
68 
69     /**
70      * @brief Destroy the Value object
71      */
72     ~Value() override = default;
73 
74     /**
75      * @brief Returns boolean value that value holds.
76      * @return Boolean value that is stored in the value.
77      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if value is NULL.
78      * @note Set `ABCKIT_STATUS_TODO` error if value type id differs from `ABCKIT_TYPE_ID_U1`.
79      */
80     bool GetU1() const;
81 
82     /**
83      * @brief Returns double value that value holds.
84      * @return Double value that is stored in the value.
85      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if value is NULL.
86      * @note Set `ABCKIT_STATUS_TODO` error if value type id differs from `ABCKIT_TYPE_ID_F64`.
87      */
88     double GetDouble() const;
89 
90     /**
91      * @brief Returns binary file that the Value is a part of.
92      * @return Pointer to the file that contains value.
93      */
94     const File *GetFile() const;
95 
96     /**
97      * @brief Returns type that value has.
98      * @return Pointer to the `AbckitType` that corresponds to provided value.
99      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if value is NULL.
100      */
101     Type GetType() const;
102 
103     /**
104      * @brief Returns literal array that value holds.
105      * @return Pointer to the `AbckitLiteralArray`.
106      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if value is NULL.
107      * @note Set `ABCKIT_STATUS_TODO` error if value type id differs from `ABCKIT_TYPE_ID_LITERALARRAY`.
108      */
109     abckit::LiteralArray GetLiteralArray() const;
110 
111     /**
112      * @brief Returns string that value holds.
113      * @return `std::string`.
114      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if value is NULL.
115      * @note Set `ABCKIT_STATUS_TODO` error if value type id differs from `ABCKIT_TYPE_ID_LITERALARRAY`.
116      */
117     std::string GetString() const;
118 
119 protected:
120     /**
121      * @brief Get the Api Config object
122      * @return const ApiConfig*
123      */
GetApiConfig()124     const ApiConfig *GetApiConfig() const override
125     {
126         return conf_;
127     }
128 
129 private:
Value(AbckitValue * val,const ApiConfig * conf,const File * file)130     explicit Value(AbckitValue *val, const ApiConfig *conf, const File *file) : ViewInResource(val), conf_(conf)
131     {
132         SetResource(file);
133     };
134     const ApiConfig *conf_;
135 };
136 
137 }  // namespace abckit
138 
139 #endif  // CPP_ABCKIT_VALUE_H
140