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 LOADER_PIPELINE_LAYOUT_LOADER_H
17 #define LOADER_PIPELINE_LAYOUT_LOADER_H
18
19 #include <base/containers/string.h>
20 #include <core/namespace.h>
21 #include <render/device/pipeline_layout_desc.h>
22 #include <render/namespace.h>
23
24 CORE_BEGIN_NAMESPACE()
25 class IFileManager;
26 CORE_END_NAMESPACE()
RENDER_BEGIN_NAMESPACE()27 RENDER_BEGIN_NAMESPACE()
28
29 /** Pipeline layout loader.
30 * A class that can be used to load pipeline layout from json structure.
31 */
32 class PipelineLayoutLoader final {
33 public:
34 /** Describes result of the parsing operation. */
35 struct LoadResult {
36 LoadResult() = default;
37 explicit LoadResult(BASE_NS::string_view error) : success(false), error(error) {}
38
39 /** Indicates, whether the parsing operation is successful. */
40 bool success { true };
41
42 /** In case of parsing error, contains the description of the error. */
43 BASE_NS::string error;
44 };
45
46 /** Retrieve uri of the pipeline layout.
47 * @return String view to uri of the pipeline layout.
48 */
49 BASE_NS::string_view GetUri() const;
50
51 /** Retrieve pipeline layout.
52 * @return A pipeline layout, as defined in the json file.
53 */
54 const PipelineLayout& GetPipelineLayout() const;
55
56 /** Loads pipeline layout from json string.
57 * @param jsonString A string containing valid json as content.
58 * @return A structure containing result for the parsing operation.
59 */
60 LoadResult Load(BASE_NS::string_view jsonString);
61
62 /** Loads pipeline layout from given uri, using file manager.
63 * @param fileManager A file manager to access the file in given uri.
64 * @param uri Uri to json file.
65 * @return A structure containing result for the parsing operation.
66 */
67 LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri);
68
69 private:
70 PipelineLayout pipelineLayout_;
71 BASE_NS::string uri_;
72 };
73 RENDER_END_NAMESPACE()
74
75 #endif // LOADER_PIPELINE_LAYOUT_LOADER_H
76