Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 45ab9a9 | 2017-11-05 19:34:31 -0500 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
Junxiao Shi | 70f95fa | 2016-11-25 03:04:39 +0000 | [diff] [blame] | 24 | #ifndef NDN_UTIL_REGEX_REGEX_BACKREF_MANAGER_HPP |
| 25 | #define NDN_UTIL_REGEX_REGEX_BACKREF_MANAGER_HPP |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 26 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 27 | #include "../../common.hpp" |
| 28 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 29 | #include <vector> |
| 30 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 31 | namespace ndn { |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 32 | |
| 33 | class RegexMatcher; |
| 34 | |
| 35 | class RegexBackrefManager |
| 36 | { |
| 37 | public: |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 38 | size_t |
| 39 | pushRef(const shared_ptr<RegexMatcher>& matcher); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 40 | |
| 41 | void |
Davide Pesavento | 45ab9a9 | 2017-11-05 19:34:31 -0500 | [diff] [blame^] | 42 | popRef() |
| 43 | { |
| 44 | m_backrefs.pop_back(); |
| 45 | } |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 47 | size_t |
Davide Pesavento | 45ab9a9 | 2017-11-05 19:34:31 -0500 | [diff] [blame^] | 48 | size() const |
| 49 | { |
| 50 | return m_backrefs.size(); |
| 51 | } |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 52 | |
Junxiao Shi | 70f95fa | 2016-11-25 03:04:39 +0000 | [diff] [blame] | 53 | shared_ptr<RegexMatcher> |
| 54 | getBackref(size_t i) const; |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 55 | |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 56 | private: |
Junxiao Shi | 70f95fa | 2016-11-25 03:04:39 +0000 | [diff] [blame] | 57 | std::vector<weak_ptr<RegexMatcher>> m_backrefs; |
Yingdi Yu | 5e97420 | 2014-01-29 16:59:06 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
Alexander Afanasyev | b6b21b3 | 2014-04-28 22:38:03 -0700 | [diff] [blame] | 60 | inline size_t |
| 61 | RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher) |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 62 | { |
Davide Pesavento | 45ab9a9 | 2017-11-05 19:34:31 -0500 | [diff] [blame^] | 63 | auto last = m_backrefs.size(); |
| 64 | m_backrefs.emplace_back(matcher); |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 65 | return last; |
| 66 | } |
| 67 | |
Junxiao Shi | 70f95fa | 2016-11-25 03:04:39 +0000 | [diff] [blame] | 68 | inline shared_ptr<RegexMatcher> |
| 69 | RegexBackrefManager::getBackref(size_t i) const |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 70 | { |
Junxiao Shi | 70f95fa | 2016-11-25 03:04:39 +0000 | [diff] [blame] | 71 | auto backref = m_backrefs[i].lock(); |
| 72 | BOOST_ASSERT(backref != nullptr); |
| 73 | return backref; |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Alexander Afanasyev | 36b84cf | 2014-02-17 19:34:18 -0800 | [diff] [blame] | 76 | } // namespace ndn |
| 77 | |
Junxiao Shi | 70f95fa | 2016-11-25 03:04:39 +0000 | [diff] [blame] | 78 | #endif // NDN_UTIL_REGEX_REGEX_BACKREF_MANAGER_HPP |