Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * 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 Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 15 | #ifndef NDN_UTIL_REGEX_BACKREF_MANAGER_HPP |
| 16 | #define NDN_UTIL_REGEX_BACKREF_MANAGER_HPP |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 17 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 18 | #include "../../common.hpp" |
| 19 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 22 | namespace ndn { |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 23 | |
| 24 | class RegexMatcher; |
| 25 | |
| 26 | class RegexBackrefManager |
| 27 | { |
| 28 | public: |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 29 | RegexBackrefManager() |
| 30 | { |
| 31 | } |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 33 | virtual |
| 34 | ~RegexBackrefManager(); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 36 | size_t |
| 37 | pushRef(const shared_ptr<RegexMatcher>& matcher); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 38 | |
| 39 | void |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 40 | popRef(); |
| 41 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 42 | size_t |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 43 | size(); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 45 | const shared_ptr<RegexMatcher>& |
| 46 | getBackref(size_t backrefNo); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 47 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 48 | private: |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 49 | std::vector<shared_ptr<RegexMatcher> > m_backrefs; |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 53 | inline |
| 54 | RegexBackrefManager::~RegexBackrefManager() |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 55 | { |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 56 | m_backrefs.clear(); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 59 | inline size_t |
| 60 | RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher) |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 61 | { |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 62 | size_t last = m_backrefs.size(); |
| 63 | m_backrefs.push_back(matcher); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 64 | |
| 65 | return last; |
| 66 | } |
| 67 | |
| 68 | inline void |
| 69 | RegexBackrefManager::popRef() |
| 70 | { |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 71 | m_backrefs.pop_back(); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 74 | inline size_t |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 75 | RegexBackrefManager::size() |
| 76 | { |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 77 | return m_backrefs.size(); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 78 | } |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 80 | inline const shared_ptr<RegexMatcher>& |
| 81 | RegexBackrefManager::getBackref(size_t backrefNo) |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 82 | { |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 83 | return m_backrefs[backrefNo]; |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
| 87 | } // namespace ndn |
| 88 | |
| 89 | #endif // NDN_UTIL_REGEX_BACKREF_MANAGER_HPP |