blob: ceb1337d463dbc40486810bd5258d6cf18362238 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yu5e974202014-01-29 16:59:06 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu5e974202014-01-29 16:59:06 -080022 */
23
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080024#ifndef NDN_UTIL_REGEX_BACKREF_MANAGER_HPP
25#define NDN_UTIL_REGEX_BACKREF_MANAGER_HPP
Yingdi Yu5e974202014-01-29 16:59:06 -080026
Yingdi Yu5e974202014-01-29 16:59:06 -080027#include "../../common.hpp"
28
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070029#include <vector>
30
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080031namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080032
33class RegexMatcher;
34
35class RegexBackrefManager
36{
37public:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070038 RegexBackrefManager()
39 {
40 }
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070041
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070042 virtual
43 ~RegexBackrefManager();
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070044
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070045 size_t
46 pushRef(const shared_ptr<RegexMatcher>& matcher);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070047
48 void
Yingdi Yu5e974202014-01-29 16:59:06 -080049 popRef();
50
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070051 size_t
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080052 size();
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070053
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070054 const shared_ptr<RegexMatcher>&
55 getBackref(size_t backrefNo);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070056
Yingdi Yu5e974202014-01-29 16:59:06 -080057private:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070058 std::vector<shared_ptr<RegexMatcher> > m_backrefs;
Yingdi Yu5e974202014-01-29 16:59:06 -080059};
60
Yingdi Yu5e974202014-01-29 16:59:06 -080061
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070062inline
63RegexBackrefManager::~RegexBackrefManager()
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080064{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070065 m_backrefs.clear();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080066}
67
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070068inline size_t
69RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080070{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070071 size_t last = m_backrefs.size();
72 m_backrefs.push_back(matcher);
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080073
74 return last;
75}
76
77inline void
78RegexBackrefManager::popRef()
79{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070080 m_backrefs.pop_back();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080081}
82
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070083inline size_t
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080084RegexBackrefManager::size()
85{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070086 return m_backrefs.size();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080087}
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070088
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070089inline const shared_ptr<RegexMatcher>&
90RegexBackrefManager::getBackref(size_t backrefNo)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080091{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070092 return m_backrefs[backrefNo];
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080093}
94
95
96} // namespace ndn
97
98#endif // NDN_UTIL_REGEX_BACKREF_MANAGER_HPP