• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 Google Inc. All rights reserved
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 FIND_H_
16 #define FIND_H_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_set>
21 #include <vector>
22 
23 #include "string_piece.h"
24 
25 using namespace std;
26 
27 class FindCond;
28 
29 enum struct FindCommandType {
30   FIND,
31   FINDLEAVES,
32   LS,
33 };
34 
35 struct FindCommand {
36   FindCommand();
37   ~FindCommand();
38 
39   bool Parse(const string& cmd);
40 
41   FindCommandType type;
42   string chdir;
43   string testdir;
44   vector<StringPiece> finddirs;
45   bool follows_symlinks;
46   unique_ptr<FindCond> print_cond;
47   unique_ptr<FindCond> prune_cond;
48   int depth;
49   int mindepth;
50   bool redirect_to_devnull;
51 
52   unique_ptr<unordered_set<string>> read_dirs;
53 
54  private:
55   FindCommand(const FindCommand&) = delete;
56   void operator=(FindCommand) = delete;
57 };
58 
59 class FindEmulator {
60  public:
61   virtual ~FindEmulator() = default;
62 
63   virtual bool HandleFind(const string& cmd, const FindCommand& fc,
64                           string* out) = 0;
65 
66   static FindEmulator* Get();
67 
68  protected:
69   FindEmulator() = default;
70 };
71 
72 void InitFindEmulator();
73 
74 #endif  // FIND_H_
75