blob: aa00605b5a1c862913aac55801172a670c6fc1ad [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
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -08008#ifndef NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
9#define NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
10
11#include "../../common.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080012
13#include "regex-matcher.hpp"
14
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080015namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080016
17class RegexBackrefMatcher : public RegexMatcher
18{
19public:
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080020 RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070021
Yingdi Yu5e974202014-01-29 16:59:06 -080022 virtual ~RegexBackrefMatcher(){}
23
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070024 void
Yingdi Yu5e974202014-01-29 16:59:06 -080025 lateCompile()
26 {
27 compile();
28 }
29
30protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070031 virtual void
Yingdi Yu5e974202014-01-29 16:59:06 -080032 compile();
Yingdi Yu5e974202014-01-29 16:59:06 -080033};
34
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080035} // namespace ndn
Yingdi Yu5e974202014-01-29 16:59:06 -080036
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080037#include "regex-pattern-list-matcher.hpp"
38
39namespace ndn {
40
41inline RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager)
42 : RegexMatcher (expr, EXPR_BACKREF, backRefManager)
43{
44 // compile();
45}
46
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047inline void
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080048RegexBackrefMatcher::compile()
49{
50 int lastIndex = m_expr.size() - 1;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070051 if ('(' == m_expr[0] && ')' == m_expr[lastIndex]){
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080052 // m_backRefManager->pushRef(this);
53
54 shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1), m_backrefManager));
55 m_matcherList.push_back(matcher);
56 }
57 else
58 throw RegexMatcher::Error(std::string("Error: RegexBackrefMatcher.Compile(): ")
59 + " Unrecognoized format " + m_expr);
60}
61
62
63} // namespace ndn
64
65#endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP