blob: ba465ac44e5588e459e0b6ed44a7b8d1e9bd2797 [file] [log] [blame]
Yingdi Yu5e974202014-01-29 16:59:06 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8
9#ifndef NDN_REGEX_MATCHER_H
10#define NDN_REGEX_MATCHER_H
11
12#include <string>
13#include "../../name.hpp"
14#include "regex-backref-manager.hpp"
15
16namespace ndn
17{
18class RegexMatcher;
19
20class RegexMatcher
21{
22public:
23 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
24
25 enum RegexExprType{
26 EXPR_TOP,
27
28 EXPR_PATTERNLIST,
29
30 EXPR_REPEAT_PATTERN,
31
32 EXPR_BACKREF,
33 EXPR_COMPONENT_SET,
34 EXPR_COMPONENT,
35
36 EXPR_PSEUDO
37 };
38
39 RegexMatcher(const std::string& expr,
40 const RegexExprType& type,
41 ptr_lib::shared_ptr<RegexBackrefManager> backrefManager = ptr_lib::shared_ptr<RegexBackrefManager>());
42
43 virtual
44 ~RegexMatcher();
45
46 virtual bool
47 match(const Name& name, const int& offset, const int& len);
48
49 /**
50 * @brief get the matched name components
51 * @returns the matched name components
52 */
53 const std::vector<Name::Component>&
54 getMatchResult() const
55 { return m_matchResult; }
56
57 const std::string&
58 getExpr() const
59 { return m_expr; }
60
61protected:
62 /**
63 * @brief Compile the regular expression to generate the more matchers when necessary
64 * @returns true if compiling succeeds
65 */
66 virtual void
67 compile() = 0;
68
69private:
70 bool
71 recursiveMatch(const int& mId, const Name& name, const int& offset, const int& len);
72
73
74protected:
75 const std::string m_expr;
76 const RegexExprType m_type;
77 ptr_lib::shared_ptr<RegexBackrefManager> m_backrefManager;
78 std::vector<ptr_lib::shared_ptr<RegexMatcher> > m_matcherList;
79 std::vector<Name::Component> m_matchResult;
80
81};
82}//ndn
83
84
85#endif