blob: 6ca7258a9a5eab73e36c5ab65e0726d5c53540a1 [file] [log] [blame]
Yingdi Yu5e974202014-01-29 16:59:06 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu5e974202014-01-29 16:59:06 -080013 */
14
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080015#ifndef NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
16#define NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
17
18#include "../../common.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080019
20#include "regex-matcher.hpp"
21
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080022namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080023
24class RegexBackrefMatcher : public RegexMatcher
25{
26public:
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080027 RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070028
Yingdi Yu5e974202014-01-29 16:59:06 -080029 virtual ~RegexBackrefMatcher(){}
30
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070031 void
Yingdi Yu5e974202014-01-29 16:59:06 -080032 lateCompile()
33 {
34 compile();
35 }
36
37protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038 virtual void
Yingdi Yu5e974202014-01-29 16:59:06 -080039 compile();
Yingdi Yu5e974202014-01-29 16:59:06 -080040};
41
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080042} // namespace ndn
Yingdi Yu5e974202014-01-29 16:59:06 -080043
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080044#include "regex-pattern-list-matcher.hpp"
45
46namespace ndn {
47
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070048inline RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr,
49 shared_ptr<RegexBackrefManager> backRefManager)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080050 : RegexMatcher (expr, EXPR_BACKREF, backRefManager)
51{
52 // compile();
53}
54
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070055inline void
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080056RegexBackrefMatcher::compile()
57{
58 int lastIndex = m_expr.size() - 1;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070059 if ('(' == m_expr[0] && ')' == m_expr[lastIndex]){
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080060 // m_backRefManager->pushRef(this);
61
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070062 shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1),
63 m_backrefManager));
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080064 m_matcherList.push_back(matcher);
65 }
66 else
67 throw RegexMatcher::Error(std::string("Error: RegexBackrefMatcher.Compile(): ")
68 + " Unrecognoized format " + m_expr);
69}
70
71
72} // namespace ndn
73
74#endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP