util+build: Build optimization with regex util
Now only one class (RegexTopMatcher) is getting compiled and other
classes are implemented in header-only way.
Change-Id: I5310c2b1c9ad40366a7b159fe0cec597caca638b
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index 830b45c..b102316 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -5,8 +5,8 @@
* See COPYING for copyright and distribution information.
*/
-#ifndef NDN_REGEX_COMPONENT_HPP
-#define NDN_REGEX_COMPONENT_HPP
+#ifndef NDN_UTIL_REGEX_REGEX_COMPONENT_MATCHER_HPP
+#define NDN_UTIL_REGEX_REGEX_COMPONENT_MATCHER_HPP
#include <boost/regex.hpp>
@@ -14,8 +14,8 @@
#include "regex-pseudo-matcher.hpp"
-namespace ndn
-{
+namespace ndn {
+
class RegexComponentMatcher : public RegexMatcher
{
public:
@@ -48,7 +48,78 @@
std::vector<ptr_lib::shared_ptr<RegexPseudoMatcher> > m_pseudoMatcher;
};
-
-}//ndn
-#endif
+
+inline
+RegexComponentMatcher::RegexComponentMatcher (const std::string& expr,
+ ptr_lib::shared_ptr<RegexBackrefManager> backRefManager,
+ bool exact)
+ : RegexMatcher (expr, EXPR_COMPONENT, backRefManager),
+ m_exact(exact)
+{
+ // _LOG_TRACE ("Enter RegexComponentMatcher Constructor: ");
+ compile();
+ // _LOG_TRACE ("Exit RegexComponentMatcher Constructor: ");
+}
+
+inline void
+RegexComponentMatcher::compile ()
+{
+ // _LOG_TRACE ("Enter RegexComponentMatcher::compile");
+
+ m_componentRegex = boost::regex (m_expr);
+
+ m_pseudoMatcher.clear();
+ m_pseudoMatcher.push_back(ptr_lib::make_shared<RegexPseudoMatcher>());
+
+ for (int i = 1; i < m_componentRegex.mark_count(); i++)
+ {
+ ptr_lib::shared_ptr<RegexPseudoMatcher> pMatcher = ptr_lib::make_shared<RegexPseudoMatcher>();
+ m_pseudoMatcher.push_back(pMatcher);
+ m_backrefManager->pushRef(ptr_lib::static_pointer_cast<RegexMatcher>(pMatcher));
+ }
+
+
+ // _LOG_TRACE ("Exit RegexComponentMatcher::compile");
+}
+
+inline bool
+RegexComponentMatcher::match (const Name & name, const int & offset, const int & len)
+{
+ // _LOG_TRACE ("Enter RegexComponentMatcher::match ");
+
+ m_matchResult.clear();
+
+ if("" == m_expr)
+ {
+ m_matchResult.push_back(name.get(offset));
+ return true;
+ }
+
+ if(true == m_exact)
+ {
+ boost::smatch subResult;
+ std::string targetStr = name.get(offset).toEscapedString();
+ if(boost::regex_match(targetStr, subResult, m_componentRegex))
+ {
+ for (int i = 1; i < m_componentRegex.mark_count(); i++)
+ {
+ m_pseudoMatcher[i]->resetMatchResult();
+ m_pseudoMatcher[i]->setMatchResult(subResult[i]);
+ }
+ m_matchResult.push_back(name.get(offset));
+ return true;
+ }
+ }
+ else
+ {
+ throw RegexMatcher::Error("Non-exact component search is not supported yet!");
+ }
+
+ return false;
+}
+
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_REGEX_COMPONENT_MATCHER_HPP