Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 8 | #ifndef NDN_UTIL_REGEX_BACKREF_MANAGER_HPP |
| 9 | #define NDN_UTIL_REGEX_BACKREF_MANAGER_HPP |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 10 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 11 | #include "../../common.hpp" |
| 12 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 13 | namespace ndn { |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 14 | |
| 15 | class RegexMatcher; |
| 16 | |
| 17 | class RegexBackrefManager |
| 18 | { |
| 19 | public: |
| 20 | RegexBackrefManager(){} |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 21 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 22 | virtual ~RegexBackrefManager(); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 23 | |
| 24 | int |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 25 | pushRef(shared_ptr<RegexMatcher> matcher); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 26 | |
| 27 | void |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 28 | popRef(); |
| 29 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 30 | size_t |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 31 | size(); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 32 | |
| 33 | shared_ptr<RegexMatcher> |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 34 | getBackRef(int i); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 35 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 36 | private: |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 37 | std::vector<shared_ptr<RegexMatcher> > m_backRefs; |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 41 | inline RegexBackrefManager::~RegexBackrefManager() |
| 42 | { |
| 43 | m_backRefs.clear(); |
| 44 | } |
| 45 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 46 | inline int |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 47 | RegexBackrefManager::pushRef(shared_ptr<RegexMatcher> matcher) |
| 48 | { |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 49 | size_t last = m_backRefs.size(); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 50 | m_backRefs.push_back(matcher); |
| 51 | |
| 52 | return last; |
| 53 | } |
| 54 | |
| 55 | inline void |
| 56 | RegexBackrefManager::popRef() |
| 57 | { |
| 58 | m_backRefs.pop_back(); |
| 59 | } |
| 60 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 61 | inline size_t |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 62 | RegexBackrefManager::size() |
| 63 | { |
| 64 | return m_backRefs.size(); |
| 65 | } |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 66 | |
| 67 | inline shared_ptr<RegexMatcher> |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 68 | RegexBackrefManager::getBackRef(int i) |
| 69 | { |
| 70 | return m_backRefs[i]; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | } // namespace ndn |
| 75 | |
| 76 | #endif // NDN_UTIL_REGEX_BACKREF_MANAGER_HPP |