blob: a87640c37f5bcceb83d48afd7636d0f03acba053 [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 Afanasyev258ec2b2014-05-14 16:15:37 -070020#include <vector>
21
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080022namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080023
24class RegexMatcher;
25
26class RegexBackrefManager
27{
28public:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070029 RegexBackrefManager()
30 {
31 }
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070032
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070033 virtual
34 ~RegexBackrefManager();
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070035
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070036 size_t
37 pushRef(const shared_ptr<RegexMatcher>& matcher);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070038
39 void
Yingdi Yu5e974202014-01-29 16:59:06 -080040 popRef();
41
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070042 size_t
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080043 size();
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070044
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070045 const shared_ptr<RegexMatcher>&
46 getBackref(size_t backrefNo);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070047
Yingdi Yu5e974202014-01-29 16:59:06 -080048private:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070049 std::vector<shared_ptr<RegexMatcher> > m_backrefs;
Yingdi Yu5e974202014-01-29 16:59:06 -080050};
51
Yingdi Yu5e974202014-01-29 16:59:06 -080052
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070053inline
54RegexBackrefManager::~RegexBackrefManager()
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080055{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070056 m_backrefs.clear();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080057}
58
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070059inline size_t
60RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080061{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070062 size_t last = m_backrefs.size();
63 m_backrefs.push_back(matcher);
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080064
65 return last;
66}
67
68inline void
69RegexBackrefManager::popRef()
70{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070071 m_backrefs.pop_back();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080072}
73
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070074inline size_t
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080075RegexBackrefManager::size()
76{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070077 return m_backrefs.size();
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080078}
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070079
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070080inline const shared_ptr<RegexMatcher>&
81RegexBackrefManager::getBackref(size_t backrefNo)
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080082{
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070083 return m_backrefs[backrefNo];
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080084}
85
86
87} // namespace ndn
88
89#endif // NDN_UTIL_REGEX_BACKREF_MANAGER_HPP