blob: 7d250f0459d064888bb4b216f7d21d45f74a62d3 [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/**
Qiuhan Ding699725d2015-05-24 01:41:09 -07003 * Copyright (c) 2013-2015 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.
Yingdi Yu5e974202014-01-29 16:59:06 -080020 */
21
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080022#ifndef NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
23#define NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
Yingdi Yu5e974202014-01-29 16:59:06 -080024
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080025#include "../../common.hpp"
Yingdi Yu5e974202014-01-29 16:59:06 -080026
27#include "regex-matcher.hpp"
28#include "regex-component-matcher.hpp"
29
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070030#include <set>
31
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080032namespace ndn {
Yingdi Yu5e974202014-01-29 16:59:06 -080033
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070034class RegexComponentSetMatcher : public RegexMatcher
35{
Yingdi Yu5e974202014-01-29 16:59:06 -080036public:
37 /**
38 * @brief Create a RegexComponentSetMatcher matcher from expr
39 * @param expr The standard regular expression to match a component
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070040 * @param backrefManager Shared pointer to back-reference manager
Yingdi Yu5e974202014-01-29 16:59:06 -080041 */
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070042 RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager);
Yingdi Yu5e974202014-01-29 16:59:06 -080043
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070044 virtual
Qiuhan Ding699725d2015-05-24 01:41:09 -070045 ~RegexComponentSetMatcher() NDN_CXX_DECL_FINAL;
Yingdi Yu5e974202014-01-29 16:59:06 -080046
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047 virtual bool
Qiuhan Ding699725d2015-05-24 01:41:09 -070048 match(const Name& name, size_t offset, size_t len = 1) NDN_CXX_DECL_FINAL;
Yingdi Yu5e974202014-01-29 16:59:06 -080049
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070050protected:
Yingdi Yu5e974202014-01-29 16:59:06 -080051 /**
52 * @brief Compile the regular expression to generate the more matchers when necessary
53 * @returns true if compiling succeeds
54 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070055 virtual void
Qiuhan Ding699725d2015-05-24 01:41:09 -070056 compile() NDN_CXX_DECL_FINAL;
Yingdi Yu5e974202014-01-29 16:59:06 -080057
58private:
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070059 size_t
60 extractComponent(size_t index);
Yingdi Yu5e974202014-01-29 16:59:06 -080061
62 void
63 compileSingleComponent();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064
Yingdi Yu5e974202014-01-29 16:59:06 -080065 void
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070066 compileMultipleComponents(size_t start, size_t lastIndex);
Yingdi Yu5e974202014-01-29 16:59:06 -080067
68private:
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080069 typedef std::set<shared_ptr<RegexComponentMatcher> > ComponentsSet;
70 ComponentsSet m_components;
Alexander Afanasyevb6b21b32014-04-28 22:38:03 -070071 bool m_isInclusion;
Yingdi Yu5e974202014-01-29 16:59:06 -080072};
73
Alexander Afanasyev36b84cf2014-02-17 19:34:18 -080074} // namespace ndn
75
76#endif // NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP