1 // Copyright (C) 2019 Google LLC
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 ICING_RESULT_PROJECTION_TREE_H_
16 #define ICING_RESULT_PROJECTION_TREE_H_
17 
18 #include <string_view>
19 #include <vector>
20 
21 #include "icing/text_classifier/lib3/utils/base/statusor.h"
22 #include "icing/proto/search.pb.h"
23 
24 namespace icing {
25 namespace lib {
26 
27 class ProjectionTree {
28  public:
29   static constexpr std::string_view kSchemaTypeWildcard = "*";
30 
31   struct Node {
nameNode32     explicit Node(std::string_view name = "") : name(name) {}
33 
34     std::string_view name;
35     std::vector<Node> children;
36   };
37 
38   explicit ProjectionTree(const TypePropertyMask& type_field_mask);
39 
root()40   const Node& root() const { return root_; }
41 
42  private:
43   // Add a child node with property_name to current_children and returns a
44   // pointer to the child node.
45   Node* AddChildNode(std::string_view property_name,
46                      std::vector<Node>* current_children);
47 
48   Node root_;
49 };
50 
51 }  // namespace lib
52 }  // namespace icing
53 
54 #endif  // ICING_RESULT_PROJECTION_TREE_H_
55