• 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_LITERAL_H
17 #define CPP_ABCKIT_LITERAL_H
18 
19 #include <string>
20 #include "base_classes.h"
21 #include "core/function.h"
22 #include "literal_array.h"
23 
24 namespace abckit {
25 
26 /**
27  * @brief Literal
28  */
29 class Literal : public ViewInResource<AbckitLiteral *, const File *> {
30     /// @brief abckit::File
31     friend class abckit::File;
32     /// @brief abckit::LiteralArray
33     friend class abckit::LiteralArray;
34     /// @brief abckit::DefaultHash<Literal>
35     friend class abckit::DefaultHash<Literal>;
36 
37 public:
38     /**
39      * @brief Construct a new Literal object
40      * @param other
41      */
42     Literal(const Literal &other) = default;
43 
44     /**
45      * @brief Constructor
46      * @param other
47      * @return Literal&
48      */
49     Literal &operator=(const Literal &other) = default;
50 
51     /**
52      * @brief Construct a new Literal object
53      * @param other
54      */
55     Literal(Literal &&other) = default;
56 
57     /**
58      * @brief Constructor
59      * @param other
60      * @return Literal&
61      */
62     Literal &operator=(Literal &&other) = default;
63 
64     /**
65      * @brief Destroy the Literal object
66      */
67     ~Literal() override = default;
68 
69     /**
70      * @brief Get the Literal Array object
71      * @return abckit::LiteralArray
72      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
73      */
74     abckit::LiteralArray GetLiteralArray() const;
75 
76     /**
77      * @brief Returns binary file that the LiteralArray is a part of.
78      * @return pointer to File.
79      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
80      */
GetFile()81     const File *GetFile() const
82     {
83         return GetResource();
84     };
85 
86     /**
87      * @brief Returns boolean value for Literal.
88      * @return Boolean value of the Literal.
89      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
90      */
91     bool GetBool() const;
92 
93     /**
94      * @brief Returns byte value for Literal.
95      * @return Byte value of the Literal.
96      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
97      */
98     uint8_t GetU8() const;
99 
100     /**
101      * @brief Returns short value for Literal.
102      * @return Short value of the Literal.
103      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
104      */
105     uint16_t GetU16() const;
106 
107     /**
108      * @brief Returns integer value for Literal.
109      * @return Short value of the Literal.
110      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
111      */
112     uint32_t GetU32() const;
113 
114     /**
115      * @brief Returns long value for Literal.
116      * @return Short value of the Literal.
117      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
118      */
119     uint64_t GetU64() const;
120 
121     /**
122      * @brief Returns method affiliate value for the Literal.
123      * @return uint16_t containing method affiliate оffset that is stored in the Literal.
124      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
125      */
126     uint16_t GetMethodAffiliate() const;
127 
128     /**
129      * @brief Returns float value that is stored in Literal.
130      * @return float value for Literal.
131      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
132      */
133     float GetFloat() const;
134 
135     /**
136      * @brief Returns double value that is stored in Literal.
137      * @return float value for Literal.
138      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
139      */
140     double GetDouble() const;
141 
142     /**
143      * @brief Returns string value for Literal.
144      * @return std::string that holds the string value of the Literal.
145      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
146      */
147     std::string GetString() const;
148 
149     /**
150      * @brief Returns method descriptor that is stored in Literal.
151      * @return std::string that holds the string value of the Literal.
152      * @note Allocates
153      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
154      */
155     std::string GetMethod() const;
156 
157     /**
158      * @brief Returns type tag that the Literal has.
159      * @return Tag of the Literal.
160      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
161      */
162     enum AbckitLiteralTag GetTag() const;
163 
164 protected:
165     /**
166      * @brief Get the Api Config object
167      * @return const ApiConfig*
168      */
GetApiConfig()169     const ApiConfig *GetApiConfig() const override
170     {
171         return conf_;
172     }
173 
174 private:
Literal(AbckitLiteral * lit,const ApiConfig * conf,const File * file)175     Literal(AbckitLiteral *lit, const ApiConfig *conf, const File *file) : ViewInResource(lit), conf_(conf)
176     {
177         SetResource(file);
178     };
179     const ApiConfig *conf_;
180 };
181 
182 }  // namespace abckit
183 
184 #endif  // CPP_ABCKIT_LITERAL_H
185