blob: 9ca95ea1b577d45e0b4de02e98a5eebc31515c0f [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_BACKREF_MANAGER_HPP
16#define NDN_UTIL_REGEX_BACKREF_MANAGER_HPP
Yingdi Yu5e974202014-01-29 16:59:06 -080017
Yingdi Yu5e974202014-01-29 16:59:06 -080018#include "../../common.hpp"
19
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080020namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080021
22class RegexMatcher;
23
24class RegexBackrefManager
25{
26public:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070027 RegexBackrefManager()
28 {
29 }
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070031 virtual
32 ~RegexBackrefManager();
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070033
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070034 size_t
35 pushRef(const shared_ptr<RegexMatcher>& matcher);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070036
37 void
Yingdi Yu5e974202014-01-29 16:59:06 -080038 popRef();
39
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070040 size_t
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080041 size();
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070042
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070043 const shared_ptr<RegexMatcher>&
44 getBackref(size_t backrefNo);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070045
Yingdi Yu5e974202014-01-29 16:59:06 -080046private:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070047 std::vector<shared_ptr<RegexMatcher> > m_backrefs;
Yingdi Yu5e974202014-01-29 16:59:06 -080048};
49
Yingdi Yu5e974202014-01-29 16:59:06 -080050
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070051inline
52RegexBackrefManager::~RegexBackrefManager()
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080053{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070054 m_backrefs.clear();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080055}
56
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070057inline size_t
58RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080059{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070060 size_t last = m_backrefs.size();
61 m_backrefs.push_back(matcher);
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080062
63 return last;
64}
65
66inline void
67RegexBackrefManager::popRef()
68{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070069 m_backrefs.pop_back();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080070}
71
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070072inline size_t
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080073RegexBackrefManager::size()
74{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070075 return m_backrefs.size();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080076}
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070077
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070078inline const shared_ptr<RegexMatcher>&
79RegexBackrefManager::getBackref(size_t backrefNo)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080080{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070081 return m_backrefs[backrefNo];
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080082}
83
84
85} // namespace ndn
86
87#endif // NDN_UTIL_REGEX_BACKREF_MANAGER_HPP