• 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_ARRAY_H
17 #define CPP_ABCKIT_LITERAL_ARRAY_H
18 
19 #include "base_classes.h"
20 #include "config.h"
21 #include "value.h"
22 #include "literal.h"
23 #include <functional>
24 
25 namespace abckit {
26 
27 /**
28  * @brief LiteralArray
29  */
30 class LiteralArray : public ViewInResource<AbckitLiteralArray *, const File *> {
31     /// @brief abckit::File
32     friend class abckit::File;
33     /// @brief abckit::Literal
34     friend class abckit::Literal;
35     /// @brief abckit::Instruction
36     friend class abckit::Instruction;
37     /// @brief abckit::DefaultHash<LiteralArray>
38     friend class abckit::DefaultHash<LiteralArray>;
39     /// @brief abckit::DynamicIsa
40     friend class abckit::DynamicIsa;
41     /// @brief abckit::Value
42     friend class abckit::Value;
43 
44 public:
45     /**
46      * @brief Construct a new Literal Array object
47      * @param other
48      */
49     LiteralArray(const LiteralArray &other) = default;
50 
51     /**
52      * @brief Constructor
53      * @param other
54      * @return LiteralArray&
55      */
56     LiteralArray &operator=(const LiteralArray &other) = default;
57 
58     /**
59      * @brief Construct a new Literal Array object
60      * @param other
61      */
62     LiteralArray(LiteralArray &&other) = default;
63 
64     /**
65      * @brief Constructor
66      * @param other
67      * @return LiteralArray&
68      */
69     LiteralArray &operator=(LiteralArray &&other) = default;
70 
71     /**
72      * @brief Destroy the Literal Array object
73      *
74      */
75     ~LiteralArray() override = default;
76 
77     /**
78      * @brief Enumerates elements of the literal array, invoking callback `cb` for each of it's
79      * elements.
80      * @return `false` if was early exited. Otherwise - `true`.
81      * @param [ in ] cb - Callback that will be invoked. Should return `false` on early exit and `true` when iterations
82      * should continue.
83      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
84      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if 'cb' is false.
85      */
86     bool EnumerateElements(const std::function<bool(Literal)> &cb) const;
87 
88 protected:
89     /**
90      * @brief Get the Api Config object
91      * @return const ApiConfig*
92      */
GetApiConfig()93     const ApiConfig *GetApiConfig() const override
94     {
95         return conf_;
96     }
97 
98 private:
LiteralArray(AbckitLiteralArray * lita,const ApiConfig * conf,const File * file)99     LiteralArray(AbckitLiteralArray *lita, const ApiConfig *conf, const File *file) : ViewInResource(lita), conf_(conf)
100     {
101         SetResource(file);
102     };
103     const ApiConfig *conf_;
104 };
105 
106 }  // namespace abckit
107 
108 #endif  // CPP_ABCKIT_LITERAL_ARRAY_H
109