1 // Copyright 2019 The Amber Authors.
2 //
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 #ifndef SRC_DESCRIPTOR_SET_AND_BINDING_PARSER_H_
16 #define SRC_DESCRIPTOR_SET_AND_BINDING_PARSER_H_
17 
18 #include <string>
19 
20 #include "amber/result.h"
21 
22 namespace amber {
23 
24 /// Class for descriptor set and binding parser.
25 class DescriptorSetAndBindingParser {
26  public:
27   DescriptorSetAndBindingParser();
28   ~DescriptorSetAndBindingParser();
29 
30   /// Run the parser against |buffer_id|. The result is success if the parse
31   /// completes correctly. |buffer_id| must be non-empty string. It must
32   /// be a single non-negative integer or two those integers separated by
33   /// ':'. For example, ":0", "1", and "2:3" are valid strings for |buffer_id|,
34   /// but "", "-4", ":-5", ":", "a", and "b:c" are invalid strings for
35   /// |buffer_id|. The |buffer_id| can be prefixed by the name of a pipeline.
36   Result Parse(const std::string& buffer_id);
37 
38   /// Returns true if a pipeline name was specified
HasPipelineName()39   bool HasPipelineName() const { return !pipeline_name_.empty(); }
PipelineName()40   std::string PipelineName() const { return pipeline_name_; }
41 
42   /// Return descriptor set that is the result of Parse().
GetDescriptorSet()43   uint32_t GetDescriptorSet() const { return descriptor_set_; }
44 
45   /// Return binding that is the result of Parse().
GetBinding()46   uint32_t GetBinding() const { return binding_; }
47 
48  private:
49   std::string pipeline_name_;
50   uint32_t descriptor_set_ = 0;
51   uint32_t binding_ = 0;
52 };
53 
54 }  // namespace amber
55 
56 #endif  // SRC_DESCRIPTOR_SET_AND_BINDING_PARSER_H_
57