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_IMPL_H
17 #define CPP_ABCKIT_LITERAL_ARRAY_IMPL_H
18
19 #include "literal_array.h"
20 #include "literal.h"
21 #include <functional>
22 #include <memory>
23 #include <string_view>
24 #include <vector>
25
26 namespace abckit {
27
EnumerateElements(const std::function<bool (Literal)> & cb)28 inline bool LiteralArray::EnumerateElements(const std::function<bool(Literal)> &cb) const
29 {
30 Payload<const std::function<bool(Literal)> &> payload {cb, GetApiConfig(), GetResource()};
31
32 auto isNormalExit = GetApiConfig()->cIapi_->literalArrayEnumerateElements(
33 GetView(), &payload, [](AbckitFile *, AbckitLiteral *lit, void *data) {
34 const auto &payload = *static_cast<Payload<const std::function<bool(Literal)> &> *>(data);
35 return payload.data(Literal(lit, payload.config, payload.resource));
36 });
37 CheckError(GetApiConfig());
38 return isNormalExit;
39 }
40
41 } // namespace abckit
42
43 #endif // CPP_ABCKIT_LITERAL_ARRAY_IMPL_H
44