CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pathspec_pattern.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_PATHSPEC_PATHSPEC_PATTERN_H_
6 #define CVMFS_PATHSPEC_PATHSPEC_PATTERN_H_
7 
8 #include <string>
9 #include <vector>
10 
37  private:
38  class SubPattern {
39  public:
41  virtual ~SubPattern() {}
42  virtual SubPattern* Clone() const = 0;
43  virtual bool IsEmpty() const { return false; }
44 
45  virtual bool Compare(const SubPattern *other) const = 0;
46 
47  virtual bool IsPlaintext() const { return false; }
48  virtual bool IsWildcard() const { return false; }
49  virtual bool IsPlaceholder() const { return false; }
50 
51  virtual std::string
52  GenerateRegularExpression(const bool is_relaxed) const = 0;
53  virtual std::string GenerateGlobString() const = 0;
54  };
55 
57  public:
59  SubPattern* Clone() const { return new PlaintextSubPattern(*this); }
60  bool Compare(const SubPattern *other) const;
61 
62  void AddChar(const char chr);
63  bool IsEmpty() const { return chars_.empty(); }
64  bool IsPlaintext() const { return true; }
65 
66  std::string GenerateRegularExpression(const bool is_relaxed) const;
67  std::string GenerateGlobString() const;
68 
69  protected:
71  chars_(other.chars_) {}
73  bool IsSpecialRegexCharacter(const char chr) const;
74 
75  private:
76  std::string chars_;
77  };
78 
79  class WildcardSubPattern : public SubPattern {
80  public:
81  SubPattern* Clone() const { return new WildcardSubPattern(); }
82  bool Compare(const SubPattern *other) const;
83  std::string GenerateRegularExpression(const bool is_relaxed) const;
84  std::string GenerateGlobString() const;
85  bool IsWildcard() const { return true; }
86  };
87 
89  public:
90  SubPattern* Clone() const { return new PlaceholderSubPattern(); }
91  bool Compare(const SubPattern *other) const;
92  std::string GenerateRegularExpression(const bool is_relaxed) const;
93  std::string GenerateGlobString() const;
94  bool IsPlaceholder() const { return true; }
95  };
96 
97  private:
98  typedef std::vector<SubPattern*> SubPatterns;
99 
100  public:
101  PathspecElementPattern(const std::string::const_iterator begin,
102  const std::string::const_iterator &end);
105  // TODO(rmeusel): C++11 - move constructor!
107 
108  std::string GenerateRegularExpression(const bool is_relaxed = false) const;
109  std::string GenerateGlobString() const;
110 
111  bool IsValid() const { return valid_; }
112 
113  bool operator== (const PathspecElementPattern &other) const;
114  bool operator!= (const PathspecElementPattern &other) const {
115  return !(*this == other);
116  }
117 
118  protected:
119  void Parse(const std::string::const_iterator &begin,
120  const std::string::const_iterator &end);
121  SubPattern* ParsePlaintext(const std::string::const_iterator &end,
122  std::string::const_iterator *i);
123  SubPattern* ParseSpecialChar(const std::string::const_iterator &end,
124  std::string::const_iterator *i);
125 
126  private:
127  bool valid_;
129 };
130 
131 #endif // CVMFS_PATHSPEC_PATHSPEC_PATTERN_H_
PathspecElementPattern(const std::string::const_iterator begin, const std::string::const_iterator &end)
PlaintextSubPattern(const PlaintextSubPattern &other)
bool Compare(const SubPattern *other) const
virtual std::string GenerateRegularExpression(const bool is_relaxed) const =0
void Parse(const std::string::const_iterator &begin, const std::string::const_iterator &end)
bool IsSpecialRegexCharacter(const char chr) const
virtual bool IsPlaceholder() const
std::string GenerateRegularExpression(const bool is_relaxed) const
std::vector< SubPattern * > SubPatterns
virtual std::string GenerateGlobString() const =0
bool operator==(const PathspecElementPattern &other) const
SubPattern * ParsePlaintext(const std::string::const_iterator &end, std::string::const_iterator *i)
std::string GenerateGlobString() const
bool Compare(const SubPattern *other) const
PathspecElementPattern & operator=(const PathspecElementPattern &other)
std::string GenerateRegularExpression(const bool is_relaxed=false) const
virtual bool Compare(const SubPattern *other) const =0
std::string GenerateRegularExpression(const bool is_relaxed) const
PlaintextSubPattern & operator=(const PlaintextSubPattern &other)
std::string GenerateRegularExpression(const bool is_relaxed) const
bool operator!=(const PathspecElementPattern &other) const
virtual SubPattern * Clone() const =0
bool Compare(const SubPattern *other) const
SubPattern * ParseSpecialChar(const std::string::const_iterator &end, std::string::const_iterator *i)