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.hpp b/src/util/regex.hpp
index 0e7d6a0..9f9d306 100644
--- a/src/util/regex.hpp
+++ b/src/util/regex.hpp
@@ -5,17 +5,15 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_HPP
-#define NDN_REGEX_HPP
+#ifndef NDN_UTIL_REGEX_HPP
+#define NDN_UTIL_REGEX_HPP
 
 #include "regex/regex-top-matcher.hpp"
 
-namespace ndn
-{
+namespace ndn {
 
 typedef RegexTopMatcher Regex;
 
-}
+} // namespace ndn
 
-#endif
-
+#endif // NDN_UTIL_REGEX_HPP
diff --git a/src/util/regex/regex-backref-manager.cpp b/src/util/regex/regex-backref-manager.cpp
deleted file mode 100644
index ed17250..0000000
--- a/src/util/regex/regex-backref-manager.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "regex-backref-manager.hpp"
-
-namespace ndn
-{
-
-RegexBackrefManager::~RegexBackrefManager()
-{ m_backRefs.clear(); }
-
-int 
-RegexBackrefManager::pushRef(ptr_lib::shared_ptr<RegexMatcher> matcher)
-{
-  int last = m_backRefs.size();
-  m_backRefs.push_back(matcher);
-
-  return last;
-}
-
-void
-RegexBackrefManager::popRef()
-{ m_backRefs.pop_back(); }
-
-}//ndn
diff --git a/src/util/regex/regex-backref-manager.hpp b/src/util/regex/regex-backref-manager.hpp
index 7604b42..bebaedb 100644
--- a/src/util/regex/regex-backref-manager.hpp
+++ b/src/util/regex/regex-backref-manager.hpp
@@ -5,14 +5,12 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_BACKREF_MANAGER_HPP
-#define NDN_REGEX_BACKREF_MANAGER_HPP
+#ifndef NDN_UTIL_REGEX_BACKREF_MANAGER_HPP
+#define NDN_UTIL_REGEX_BACKREF_MANAGER_HPP
 
-#include <vector>
 #include "../../common.hpp"
 
-namespace ndn
-{
+namespace ndn {
 
 class RegexMatcher;
 
@@ -24,23 +22,55 @@
   virtual ~RegexBackrefManager();
     
   int 
-  pushRef(ptr_lib::shared_ptr<RegexMatcher> matcher);
+  pushRef(shared_ptr<RegexMatcher> matcher);
     
   void 
   popRef();
 
   int 
-  size()
-  { return m_backRefs.size(); }
+  size();
     
-  ptr_lib::shared_ptr<RegexMatcher> 
-  getBackRef(int i)
-  { return m_backRefs[i]; }
+  shared_ptr<RegexMatcher> 
+  getBackRef(int i);
     
 private:
-  std::vector<ptr_lib::shared_ptr<RegexMatcher> > m_backRefs;
+  std::vector<shared_ptr<RegexMatcher> > m_backRefs;
 };
 
-}//ndn
 
-#endif
+inline RegexBackrefManager::~RegexBackrefManager()
+{
+  m_backRefs.clear();
+}
+
+inline int 
+RegexBackrefManager::pushRef(shared_ptr<RegexMatcher> matcher)
+{
+  int last = m_backRefs.size();
+  m_backRefs.push_back(matcher);
+
+  return last;
+}
+
+inline void
+RegexBackrefManager::popRef()
+{
+  m_backRefs.pop_back();
+}
+
+inline int 
+RegexBackrefManager::size()
+{
+  return m_backRefs.size();
+}
+    
+inline shared_ptr<RegexMatcher> 
+RegexBackrefManager::getBackRef(int i)
+{
+  return m_backRefs[i];
+}
+
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_BACKREF_MANAGER_HPP
diff --git a/src/util/regex/regex-backref-matcher.cpp b/src/util/regex/regex-backref-matcher.cpp
deleted file mode 100644
index 1982623..0000000
--- a/src/util/regex/regex-backref-matcher.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <boost/regex.hpp>
-
-#include "regex-backref-matcher.hpp"
-#include "regex-pattern-list-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexBackrefMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-
-RegexBackrefMatcher::RegexBackrefMatcher(const string expr, ptr_lib::shared_ptr<RegexBackrefManager> backRefManager)
-  : RegexMatcher (expr, EXPR_BACKREF, backRefManager)
-{
-  // _LOG_TRACE ("Enter RegexBackrefMatcher Constructor: ");
-  // compile();
-  // _LOG_TRACE ("Exit RegexBackrefMatcher Constructor: ");
-}
-
-void 
-RegexBackrefMatcher::compile()
-{
-  // _LOG_TRACE ("Enter RegexBackrefMatcher::compile()");
-
-  string errMsg = "Error: RegexBackrefMatcher.Compile(): ";
-    
-  // _LOG_DEBUG ("m_backRefManager: " << m_backRefManager);
-
-  int lastIndex = m_expr.size() - 1;
-  if('(' == m_expr[0] && ')' == m_expr[lastIndex]){
-    // m_backRefManager->pushRef(this);
-
-    ptr_lib::shared_ptr<RegexMatcher> matcher = ptr_lib::make_shared<RegexPatternListMatcher>(m_expr.substr(1, lastIndex - 1), m_backrefManager);
-    m_matcherList.push_back(matcher);
-      
-  }
-  else
-    throw RegexMatcher::Error(errMsg + " Unrecognoized format " + m_expr);
-    
-  // _LOG_TRACE ("Exit RegexBackrefMatcher::compile");
-}
-
-}//ndn
-
-
-
-
diff --git a/src/util/regex/regex-backref-matcher.hpp b/src/util/regex/regex-backref-matcher.hpp
index de04b19..5ae5f35 100644
--- a/src/util/regex/regex-backref-matcher.hpp
+++ b/src/util/regex/regex-backref-matcher.hpp
@@ -5,20 +5,19 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_BACKREF_MATCHER_HPP
-#define NDN_REGEX_BACKREF_MATCHER_HPP
+#ifndef NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
+#define NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
+
+#include "../../common.hpp"
 
 #include "regex-matcher.hpp"
 
-#include <boost/enable_shared_from_this.hpp>
-
-namespace ndn
-{
+namespace ndn {
 
 class RegexBackrefMatcher : public RegexMatcher
 {
 public:
-  RegexBackrefMatcher(const std::string expr, ptr_lib::shared_ptr<RegexBackrefManager> backRefManager);
+  RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
     
   virtual ~RegexBackrefMatcher(){}
 
@@ -36,8 +35,36 @@
   int m_refNum;
 };
 
-}//ndn
+} // namespace ndn
 
-#endif
+#include "regex-pattern-list-matcher.hpp"
+
+namespace ndn {
+
+inline RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager)
+  : RegexMatcher (expr, EXPR_BACKREF, backRefManager)
+{
+  // compile();
+}
+
+inline void 
+RegexBackrefMatcher::compile()
+{
+  int lastIndex = m_expr.size() - 1;
+  if('(' == m_expr[0] && ')' == m_expr[lastIndex]){
+    // m_backRefManager->pushRef(this);
+
+    shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1), m_backrefManager));
+    m_matcherList.push_back(matcher);
+  }
+  else
+    throw RegexMatcher::Error(std::string("Error: RegexBackrefMatcher.Compile(): ")
+                              + " Unrecognoized format " + m_expr);
+}
+
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
 
 
diff --git a/src/util/regex/regex-component-matcher.cpp b/src/util/regex/regex-component-matcher.cpp
deleted file mode 100644
index e3bbe0e..0000000
--- a/src/util/regex/regex-component-matcher.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "regex-component-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexComponentMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-
-RegexComponentMatcher::RegexComponentMatcher (const 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: ");
-}
-
-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");
-}
-
-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;
-      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;
-}
-
-} //ndn
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
diff --git a/src/util/regex/regex-component-set-matcher.cpp b/src/util/regex/regex-component-set-matcher.cpp
deleted file mode 100644
index dddebfc..0000000
--- a/src/util/regex/regex-component-set-matcher.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "regex-component-set-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexComponentSetMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-RegexComponentSetMatcher::RegexComponentSetMatcher(const string expr, ptr_lib::shared_ptr<RegexBackrefManager> backRefManager)
-  : RegexMatcher(expr, EXPR_COMPONENT_SET, backRefManager),
-    m_include(true)
-{
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher Constructor");
-  compile();
-  // _LOG_TRACE ("Exit RegexComponentSetMatcher Constructor");
-}
-
-RegexComponentSetMatcher::~RegexComponentSetMatcher()
-{
-  // set<Ptr<RegexComponent> >::iterator it = m_components.begin();
-
-  // for(; it != m_components.end(); it++)
-  //   delete *it;
-}
-
-void 
-RegexComponentSetMatcher::compile()
-{
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher::compile");
-
-  string errMsg = "Error: RegexComponentSetMatcher.compile(): ";
-  int index = 0;
-
-
-  switch(m_expr[0]){
-  case '<':
-    return compileSingleComponent();
-  case '[':
-    {
-      int lastIndex = m_expr.size() - 1;
-      if(']' != m_expr[lastIndex])
-        throw RegexMatcher::Error(errMsg + " No matched ']' " + m_expr);
-      
-      if('^' == m_expr[1]){
-        m_include = false;
-        compileMultipleComponents(2, lastIndex);
-      }
-      else
-        compileMultipleComponents(1, lastIndex);
-      break;
-    }
-  default:
-    throw RegexMatcher::Error(errMsg + "Parsing error in expr " + m_expr);
-  }
-
-  // _LOG_TRACE ("Exit RegexComponentSetMatcher::compile");
-}
-
-void 
-RegexComponentSetMatcher::compileSingleComponent()
-{
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher::compileSingleComponent");
-
-  string errMsg = "Error: RegexComponentSetMatcher.compileSingleComponent: ";
-
-  int end = extractComponent(1);
-
-  if(m_expr.size() != end)
-    throw RegexMatcher::Error(errMsg + m_expr);
-  else{
-    // _LOG_DEBUG ("RegexComponentSetMatcher::compileSingleComponent expr: " << m_expr.substr(1, end - 2));
-    ptr_lib::shared_ptr<RegexComponentMatcher> component = ptr_lib::make_shared<RegexComponentMatcher>(m_expr.substr(1, end - 2), m_backrefManager);
-    m_components.insert(component);
-      
-  }
-
-  // _LOG_TRACE ("Exit RegexComponentSetMatcher::compileSingleComponent");
-}
-
-void 
-RegexComponentSetMatcher::compileMultipleComponents(const int start, const int lastIndex)
-{
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher::compileMultipleComponents");
-
-  string errMsg = "Error: RegexComponentSetMatcher.compileMultipleComponents: ";
-
-  int index = start;
-  int tmp_index = start;
-    
-  while(index < lastIndex){
-    if('<' != m_expr[index])
-      throw RegexMatcher::Error(errMsg + "Component expr error " + m_expr);
-      
-    tmp_index = index + 1;
-    index = extractComponent(tmp_index);
-
-    ptr_lib::shared_ptr<RegexComponentMatcher> component = ptr_lib::make_shared<RegexComponentMatcher>(m_expr.substr(tmp_index, index - tmp_index - 1), m_backrefManager);
-    m_components.insert(component);
-  }
-    
-  if(index != lastIndex)
-    throw RegexMatcher::Error(errMsg + "Not sufficient expr to parse " + m_expr);        
-
-  // _LOG_TRACE ("Exit RegexComponentSetMatcher::compileMultipleComponents");
-}
-
-bool 
-RegexComponentSetMatcher::match(const Name & name, const int & offset, const int & len)
-{
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher::match");
-
-  bool matched = false;
-
-  /* componentset only matches one component */
-  if(len != 1){
-    // _LOG_DEBUG ("Match Fail: ComponentSet matches only one component");
-    return false;
-  }
-
-  set<ptr_lib::shared_ptr<RegexComponentMatcher> >::iterator it = m_components.begin();
-
-  for(; it != m_components.end(); it++){
-    if((*it)->match(name, offset, len)){
-      matched = true;
-      break;
-    }
-  }
-    
-  m_matchResult.clear();
-
-  if(m_include ? matched : !matched){
-    m_matchResult.push_back(name.get(offset));
-    return true;
-  }
-  else 
-    return false;
-}
-
-int 
-RegexComponentSetMatcher::extractComponent(int index)
-{
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher::extractComponent");
-
-  int lcount = 1;
-  int rcount = 0;
-
-  while(lcount > rcount){
-    switch(m_expr[index]){
-    case '<':
-      lcount++;
-      break;
-
-    case '>':
-      rcount++;
-      break;
-
-    case 0:
-      throw RegexMatcher::Error("Error: square brackets mismatch");
-      break;
-    }
-    index++;
-
-  }
-
-  // _LOG_TRACE ("Exit RegexComponentSetMatcher::extractComponent");
-  return index;
-
-}
-
-}//ndn
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index d4c576e..ffb4c6d 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -5,19 +5,17 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef REGEX_COMPONENT_SET_MATCHER_HPP
-#define REGEX_COMPONENT_SET_MATCHER_HPP
+#ifndef NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
+#define NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
 
-#include <set>
+#include "../../common.hpp"
 
 #include "regex-matcher.hpp"
 #include "regex-component-matcher.hpp"
 
-namespace ndn
-{
+namespace ndn {
 
-class RegexComponentSetMatcher : public RegexMatcher
-{
+class RegexComponentSetMatcher : public RegexMatcher {
 
 public:
   /**
@@ -26,12 +24,12 @@
    * @param exact The flag to provide exact match
    * @param backRefNum The starting back reference number
    */
-  RegexComponentSetMatcher(const std::string expr, ptr_lib::shared_ptr<RegexBackrefManager> backRefManager);    
+  RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);    
 
   virtual ~RegexComponentSetMatcher();
 
   virtual bool 
-  match(const Name & name, const int & offset, const int & len = 1);
+  match(const Name& name, const int& offset, const int& len = 1);
 
 protected:    
   /**
@@ -52,10 +50,164 @@
   compileMultipleComponents(const int start, const int lastIndex);
 
 private:
-  std::set<ptr_lib::shared_ptr<RegexComponentMatcher> > m_components;
+  typedef std::set<shared_ptr<RegexComponentMatcher> > ComponentsSet;
+  ComponentsSet m_components;
   bool m_include;
 };
 
-}//ndn
 
-#endif
+inline
+RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager)
+  : RegexMatcher(expr, EXPR_COMPONENT_SET, backRefManager),
+    m_include(true)
+{
+  // _LOG_TRACE ("Enter RegexComponentSetMatcher Constructor");
+  compile();
+  // _LOG_TRACE ("Exit RegexComponentSetMatcher Constructor");
+}
+
+inline
+RegexComponentSetMatcher::~RegexComponentSetMatcher()
+{
+  // ComponentsSet::iterator it = m_components.begin();
+
+  // for(; it != m_components.end(); it++)
+  //   delete *it;
+}
+
+inline void 
+RegexComponentSetMatcher::compile()
+{
+  int index = 0;
+
+  switch(m_expr[0]){
+  case '<':
+    return compileSingleComponent();
+  case '[':
+    {
+      int lastIndex = m_expr.size() - 1;
+      if(']' != m_expr[lastIndex])
+        throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
+                                  + " No matched ']' " + m_expr);
+      
+      if('^' == m_expr[1]){
+        m_include = false;
+        compileMultipleComponents(2, lastIndex);
+      }
+      else
+        compileMultipleComponents(1, lastIndex);
+      break;
+    }
+  default:
+    throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
+                              + "Parsing error in expr " + m_expr);
+  }
+}
+
+inline void 
+RegexComponentSetMatcher::compileSingleComponent()
+{
+  int end = extractComponent(1);
+
+  if(m_expr.size() != end)
+    {
+      throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileSingleComponent: ")
+                                + m_expr);
+    }
+  else
+    {
+      shared_ptr<RegexComponentMatcher> component =
+        make_shared<RegexComponentMatcher>(m_expr.substr(1, end - 2), m_backrefManager);
+      
+      m_components.insert(component);      
+    }
+}
+
+inline void 
+RegexComponentSetMatcher::compileMultipleComponents(const int start, const int lastIndex)
+{
+  int index = start;
+  int tmp_index = start;
+    
+  while(index < lastIndex){
+    if('<' != m_expr[index])
+      throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ")
+                                + "Component expr error " + m_expr);
+      
+    tmp_index = index + 1;
+    index = extractComponent(tmp_index);
+
+    shared_ptr<RegexComponentMatcher> component =
+      make_shared<RegexComponentMatcher>(m_expr.substr(tmp_index, index - tmp_index - 1), m_backrefManager);
+    
+    m_components.insert(component);
+  }
+    
+  if(index != lastIndex)
+    throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ")
+                              + "Not sufficient expr to parse " + m_expr);        
+}
+
+inline bool 
+RegexComponentSetMatcher::match(const Name & name, const int & offset, const int & len)
+{
+  bool matched = false;
+
+  /* componentset only matches one component */
+  if (len != 1)
+    {
+      return false;
+    }
+
+  for (ComponentsSet::iterator it = m_components.begin();
+       it != m_components.end();
+       ++it)
+    {
+      if((*it)->match(name, offset, len))
+        {
+          matched = true;
+          break;
+        }
+    }
+    
+  m_matchResult.clear();
+
+  if (m_include ? matched : !matched)
+    {
+      m_matchResult.push_back(name.get(offset));
+      return true;
+    }
+  else 
+    return false;
+}
+
+inline int 
+RegexComponentSetMatcher::extractComponent(int index)
+{
+  int lcount = 1;
+  int rcount = 0;
+
+  while(lcount > rcount){
+    switch(m_expr[index]){
+    case '<':
+      lcount++;
+      break;
+
+    case '>':
+      rcount++;
+      break;
+
+    case 0:
+      throw RegexMatcher::Error("Error: square brackets mismatch");
+      break;
+    }
+    index++;
+
+  }
+
+  return index;
+}
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
diff --git a/src/util/regex/regex-matcher.cpp b/src/util/regex/regex-matcher.cpp
deleted file mode 100644
index b83aa2e..0000000
--- a/src/util/regex/regex-matcher.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "regex-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-RegexMatcher::RegexMatcher(const std::string& expr, 
-                           const RegexExprType& type,  
-                           ptr_lib::shared_ptr<RegexBackrefManager> backrefManager) 
-  : m_expr(expr), 
-    m_type(type),
-    m_backrefManager(backrefManager)
-{
-  if(NULL == m_backrefManager)
-    m_backrefManager = ptr_lib::shared_ptr<RegexBackrefManager>(new RegexBackrefManager);
-}
-
-RegexMatcher::~RegexMatcher()
-{}
-
-bool 
-RegexMatcher::match (const Name& name, const int& offset, const int& len)
-{
-  // _LOG_TRACE ("Enter RegexMatcher::match");
-  bool result = false;
-
-  m_matchResult.clear();
-
-  if(recursiveMatch(0, name, offset, len))
-    {
-      for(int i = offset; i < offset + len ; i++)
-        m_matchResult.push_back(name.get(i));
-      result = true;
-    }
-  else
-    {
-      result = false;
-    }
-
-  // _LOG_TRACE ("Exit RegexMatcher::match");
-  return result;
-}
-  
-bool 
-RegexMatcher::recursiveMatch(const int& mId, const Name& name, const int& offset, const int& len)
-{
-  // _LOG_TRACE ("Enter RegexMatcher::recursiveMatch");
-
-  int tried = len;
-
-  if(mId >= m_matcherList.size())
-    return (len != 0 ? false : true);
-    
-  ptr_lib::shared_ptr<RegexMatcher> matcher = m_matcherList[mId];
-
-  while(tried >= 0)
-    {
-      if(matcher->match(name, offset, tried) && recursiveMatch(mId + 1, name, offset + tried, len - tried))
-        return true;      
-      tried--;
-    }
-
-  return false;
-}
-
-}//ndn
-
diff --git a/src/util/regex/regex-matcher.hpp b/src/util/regex/regex-matcher.hpp
index ba465ac..baa8bf3 100644
--- a/src/util/regex/regex-matcher.hpp
+++ b/src/util/regex/regex-matcher.hpp
@@ -5,22 +5,20 @@
  * See COPYING for copyright and distribution information.
  */
 
+#ifndef NDN_UTIL_REGEX_REGEX_MATCHER_H
+#define NDN_UTIL_REGEX_REGEX_MATCHER_H
 
-#ifndef NDN_REGEX_MATCHER_H
-#define NDN_REGEX_MATCHER_H
-
-#include <string>
+#include "../../common.hpp"
 #include "../../name.hpp"
-#include "regex-backref-manager.hpp"
 
-namespace ndn
-{
-class RegexMatcher;
+namespace ndn {
+
+class RegexBackrefManager;
 
 class RegexMatcher
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  struct Error : public std::runtime_error { Error(const std::string& what) : std::runtime_error(what) {} };
 
   enum RegexExprType{
     EXPR_TOP,
@@ -38,7 +36,7 @@
 
   RegexMatcher(const std::string& expr, 
                const RegexExprType& type,  
-               ptr_lib::shared_ptr<RegexBackrefManager> backrefManager = ptr_lib::shared_ptr<RegexBackrefManager>());
+               shared_ptr<RegexBackrefManager> backrefManager = shared_ptr<RegexBackrefManager>());
 
   virtual 
   ~RegexMatcher();
@@ -50,7 +48,7 @@
    * @brief get the matched name components
    * @returns the matched name components
    */
-  const std::vector<Name::Component>& 
+  const std::vector<name::Component>& 
   getMatchResult() const
   { return m_matchResult; }
 
@@ -74,12 +72,81 @@
 protected:
   const std::string m_expr;
   const RegexExprType m_type; 
-  ptr_lib::shared_ptr<RegexBackrefManager> m_backrefManager;
-  std::vector<ptr_lib::shared_ptr<RegexMatcher> > m_matcherList;
-  std::vector<Name::Component> m_matchResult;
-
+  shared_ptr<RegexBackrefManager> m_backrefManager;
+  std::vector<shared_ptr<RegexMatcher> > m_matcherList;
+  std::vector<name::Component> m_matchResult;
 };
-}//ndn
+
+} // namespace ndn
+
+#include "regex-backref-manager.hpp"
+
+namespace ndn {
+
+inline
+RegexMatcher::RegexMatcher(const std::string& expr, 
+                           const RegexExprType& type,  
+                           shared_ptr<RegexBackrefManager> backrefManager) 
+  : m_expr(expr), 
+    m_type(type),
+    m_backrefManager(backrefManager)
+{
+  if(NULL == m_backrefManager)
+    m_backrefManager = make_shared<RegexBackrefManager>();
+}
+
+inline
+RegexMatcher::~RegexMatcher()
+{
+}
+
+inline bool 
+RegexMatcher::match (const Name& name, const int& offset, const int& len)
+{
+  // _LOG_TRACE ("Enter RegexMatcher::match");
+  bool result = false;
+
+  m_matchResult.clear();
+
+  if(recursiveMatch(0, name, offset, len))
+    {
+      for(int i = offset; i < offset + len ; i++)
+        m_matchResult.push_back(name.get(i));
+      result = true;
+    }
+  else
+    {
+      result = false;
+    }
+
+  // _LOG_TRACE ("Exit RegexMatcher::match");
+  return result;
+}
+  
+inline bool 
+RegexMatcher::recursiveMatch(const int& mId, const Name& name, const int& offset, const int& len)
+{
+  // _LOG_TRACE ("Enter RegexMatcher::recursiveMatch");
+
+  int tried = len;
+
+  if(mId >= m_matcherList.size())
+    return (len != 0 ? false : true);
+    
+  shared_ptr<RegexMatcher> matcher = m_matcherList[mId];
+
+  while(tried >= 0)
+    {
+      if(matcher->match(name, offset, tried) && recursiveMatch(mId + 1, name, offset + tried, len - tried))
+        return true;      
+      tried--;
+    }
+
+  return false;
+}
 
 
-#endif
+} // namespace ndn
+
+
+#endif // NDN_UTIL_REGEX_REGEX_MATCHER_H
diff --git a/src/util/regex/regex-pattern-list-matcher.cpp b/src/util/regex/regex-pattern-list-matcher.cpp
deleted file mode 100644
index 28f0037..0000000
--- a/src/util/regex/regex-pattern-list-matcher.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "regex-pattern-list-matcher.hpp"
-#include "regex-backref-matcher.hpp"
-#include "regex-repeat-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexPatternListMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-RegexPatternListMatcher::RegexPatternListMatcher(const string expr, ptr_lib::shared_ptr<RegexBackrefManager> backrefManager)
-  :RegexMatcher(expr, EXPR_PATTERNLIST, backrefManager)
-{
-  // _LOG_TRACE ("Enter RegexPatternListMatcher Constructor");
-  compile();
-  // _LOG_TRACE ("Exit RegexPatternListMatcher Constructor");
-}
-  
-void 
-RegexPatternListMatcher::compile()
-{
-  // _LOG_TRACE ("Enter RegexPatternListMatcher::compile");
-
-  const int len = m_expr.size();
-  int index = 0;
-  int subHead = index;
-    
-  while(index < len){
-    subHead = index;
-
-    if(!extractPattern(subHead, &index))
-      throw RegexMatcher::Error("RegexPatternListMatcher compile: cannot compile");
-  }
-  // _LOG_TRACE ("Exit RegexPatternListMatcher::compile");
-}
-
-bool 
-RegexPatternListMatcher::extractPattern(int index, int* next)
-{
-  // _LOG_DEBUG ("Enter RegexPatternListMatcher::ExtractPattern()");
-
-  string errMsg = "Error: RegexPatternListMatcher.ExtractSubPattern(): ";
-    
-  const int start = index;
-  int end = index;
-  int indicator = index;
-    
-
-  // _LOG_DEBUG ("m_expr: " << m_expr << " index: " << index);
-
-  switch(m_expr[index]){
-  case '(':
-    index++;
-    index = extractSubPattern('(', ')', index);
-    indicator = index;
-    end = extractRepetition(index);
-    if(indicator == end){
-      ptr_lib::shared_ptr<RegexMatcher> matcher = ptr_lib::make_shared<RegexBackrefMatcher>(m_expr.substr(start, end - start), m_backrefManager);
-      m_backrefManager->pushRef(matcher);
-      boost::dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
-
-      m_matcherList.push_back(matcher);
-    }
-    else
-      m_matcherList.push_back(ptr_lib::make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
-    break;
-      
-  case '<':
-    index++;
-    index = extractSubPattern ('<', '>', index);
-    indicator = index;
-    end = extractRepetition(index);
-    m_matcherList.push_back(ptr_lib::make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
-    break;
-
-  case '[':
-    index++;
-    index = extractSubPattern ('[', ']', index);
-    indicator = index;
-    end = extractRepetition(index);
-    m_matcherList.push_back(ptr_lib::make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
-    break;
-
-  default:
-    throw RegexMatcher::Error("Error: unexpected syntax");
-  }
-
-  *next = end;
-
-  return true;
-}
-  
-int 
-RegexPatternListMatcher::extractSubPattern(const char left, const char right, int index)
-{
-  // _LOG_DEBUG ("Enter RegexPatternListMatcher::ExtractSubPattern()");
-
-  int lcount = 1;
-  int rcount = 0;
-
-  while(lcount > rcount){
-
-    if(index >= m_expr.size())
-      throw RegexMatcher::Error("Error: parenthesis mismatch");
-
-    if(left == m_expr[index])
-      lcount++;
-
-    if(right == m_expr[index])
-      rcount++;
-
-    index++;
-  }
-  return index;
-}
-
-int 
-RegexPatternListMatcher::extractRepetition(int index)
-{
-  // _LOG_DEBUG ("Enter RegexPatternListMatcher::ExtractRepetition()");
-
-  int exprSize = m_expr.size();
-
-  // _LOG_DEBUG ("expr: " << m_expr << " index: " << index << " char: " << (index == exprSize ? 0 : m_expr[index]));
-
-  string errMsg = "Error: RegexPatternListMatcher.ExtractRepetition(): ";
-    
-  if(index == exprSize)
-    return index;
-    
-  if(('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])){
-    return ++index;
-  }
-
-    
-  if('{' == m_expr[index]){
-    while('}' != m_expr[index]){
-      index++;
-      if(index == exprSize)
-        break;
-    }
-    if(index == exprSize)
-      throw RegexMatcher::Error(errMsg + "Missing right brace bracket");
-    else
-      return ++index;
-  }
-  else{
-    // _LOG_DEBUG ("return index: " << index);
-    return index;
-  }
-}
-
-}//ndn
diff --git a/src/util/regex/regex-pattern-list-matcher.hpp b/src/util/regex/regex-pattern-list-matcher.hpp
index 7240905..84b5c46 100644
--- a/src/util/regex/regex-pattern-list-matcher.hpp
+++ b/src/util/regex/regex-pattern-list-matcher.hpp
@@ -5,20 +5,21 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_PATTERN_LIST_MATCHER_HPP
-#define NDN_REGEX_PATTERN_LIST_MATCHER_HPP
+#ifndef NDN_UTIL_REGEX_REGEX_PATTERN_LIST_MATCHER_HPP
+#define NDN_UTIL_REGEX_REGEX_PATTERN_LIST_MATCHER_HPP
 
-#include <string>
+#include "../../common.hpp"
 
 #include "regex-matcher.hpp"
 
-namespace ndn
-{
+namespace ndn {
+
+class RegexBackrefManager;
 
 class RegexPatternListMatcher : public RegexMatcher
 {
 public:
-  RegexPatternListMatcher(const std::string expr, ptr_lib::shared_ptr<RegexBackrefManager> backRefManager);
+  RegexPatternListMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
     
   virtual ~RegexPatternListMatcher(){};
 
@@ -39,6 +40,138 @@
 private:
 
 };
-}//ndn
 
-#endif
+} // namespace ndn
+
+#include "regex-repeat-matcher.hpp"
+#include "regex-backref-matcher.hpp"
+
+namespace ndn {
+
+inline RegexPatternListMatcher::RegexPatternListMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager)
+  :RegexMatcher(expr, EXPR_PATTERNLIST, backrefManager)
+{
+  compile();
+}
+  
+inline void 
+RegexPatternListMatcher::compile()
+{
+  const int len = m_expr.size();
+  int index = 0;
+  int subHead = index;
+    
+  while(index < len){
+    subHead = index;
+
+    if(!extractPattern(subHead, &index))
+      throw RegexMatcher::Error("RegexPatternListMatcher compile: cannot compile");
+  }
+}
+
+inline bool 
+RegexPatternListMatcher::extractPattern(int index, int* next)
+{
+  // std::string errMsg = "Error: RegexPatternListMatcher.ExtractSubPattern(): ";
+    
+  const int start = index;
+  int end = index;
+  int indicator = index;
+
+  switch(m_expr[index]){
+  case '(':
+    index++;
+    index = extractSubPattern('(', ')', index);
+    indicator = index;
+    end = extractRepetition(index);
+    if(indicator == end){
+      shared_ptr<RegexMatcher> matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(start, end - start), m_backrefManager);
+      m_backrefManager->pushRef(matcher);
+      boost::dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
+
+      m_matcherList.push_back(matcher);
+    }
+    else
+      m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
+    break;
+      
+  case '<':
+    index++;
+    index = extractSubPattern ('<', '>', index);
+    indicator = index;
+    end = extractRepetition(index);
+    m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
+    break;
+
+  case '[':
+    index++;
+    index = extractSubPattern ('[', ']', index);
+    indicator = index;
+    end = extractRepetition(index);
+    m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
+    break;
+
+  default:
+    throw RegexMatcher::Error("Error: unexpected syntax");
+  }
+
+  *next = end;
+
+  return true;
+}
+  
+inline int 
+RegexPatternListMatcher::extractSubPattern(const char left, const char right, int index)
+{
+  int lcount = 1;
+  int rcount = 0;
+
+  while(lcount > rcount){
+
+    if(index >= m_expr.size())
+      throw RegexMatcher::Error("Error: parenthesis mismatch");
+
+    if(left == m_expr[index])
+      lcount++;
+
+    if(right == m_expr[index])
+      rcount++;
+
+    index++;
+  }
+  return index;
+}
+
+inline int 
+RegexPatternListMatcher::extractRepetition(int index)
+{
+  int exprSize = m_expr.size();
+
+  if(index == exprSize)
+    return index;
+    
+  if(('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])){
+    return ++index;
+  }
+    
+  if('{' == m_expr[index]){
+    while('}' != m_expr[index]){
+      index++;
+      if(index == exprSize)
+        break;
+    }
+    if(index == exprSize)
+      throw RegexMatcher::Error(std::string("Error: RegexPatternListMatcher.ExtractRepetition(): ")
+                                + "Missing right brace bracket");
+    else
+      return ++index;
+  }
+  else {
+    return index;
+  }
+}
+
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_REGEX_PATTERN_LIST_MATCHER_HPP
diff --git a/src/util/regex/regex-pseudo-matcher.cpp b/src/util/regex/regex-pseudo-matcher.cpp
deleted file mode 100644
index abebaff..0000000
--- a/src/util/regex/regex-pseudo-matcher.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "regex-pseudo-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexPseudoMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-RegexPseudoMatcher::RegexPseudoMatcher()
-  :RegexMatcher ("", EXPR_PSEUDO)
-{}
-
-void 
-RegexPseudoMatcher::setMatchResult(const string & str)
-{ m_matchResult.push_back(Name::Component((const uint8_t *)str.c_str(), str.size())); }
-    
-void 
-RegexPseudoMatcher::resetMatchResult()
-{ m_matchResult.clear(); }
-
-}//ndn
diff --git a/src/util/regex/regex-pseudo-matcher.hpp b/src/util/regex/regex-pseudo-matcher.hpp
index 9bb1e9f..0aeea57 100644
--- a/src/util/regex/regex-pseudo-matcher.hpp
+++ b/src/util/regex/regex-pseudo-matcher.hpp
@@ -5,24 +5,27 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_PSEUDO_MATCHER_HPP
-#define NDN_REGEX_PSEUDO_MATCHER_HPP
+#ifndef NDN_UTIL_REGEX_REGEX_PSEUDO_MATCHER_HPP
+#define NDN_UTIL_REGEX_REGEX_PSEUDO_MATCHER_HPP
 
+#include "../../common.hpp"
 #include "regex-matcher.hpp"
 
-namespace ndn
-{
+namespace ndn {
+
 class RegexPseudoMatcher : public RegexMatcher
 {
 public:
   RegexPseudoMatcher();
 
-  ~RegexPseudoMatcher() 
-  {}
+  virtual ~RegexPseudoMatcher() 
+  {
+  }
 
   virtual void 
   compile() 
-  {}
+  {
+  }
 
   void 
   setMatchResult(const std::string& str);
@@ -31,6 +34,24 @@
   resetMatchResult();
 };
 
-}//ndn
+inline RegexPseudoMatcher::RegexPseudoMatcher()
+  :RegexMatcher ("", EXPR_PSEUDO)
+{
+}
 
-#endif
+inline void 
+RegexPseudoMatcher::setMatchResult(const std::string& str)
+{
+  m_matchResult.push_back(Name::Component((const uint8_t *)str.c_str(), str.size()));
+}
+    
+inline void 
+RegexPseudoMatcher::resetMatchResult()
+{
+  m_matchResult.clear();
+}
+
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_REGEX_PSEUDO_MATCHER_HPP
diff --git a/src/util/regex/regex-repeat-matcher.cpp b/src/util/regex/regex-repeat-matcher.cpp
deleted file mode 100644
index d121b9e..0000000
--- a/src/util/regex/regex-repeat-matcher.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Yingdi Yu <yingdi@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <limits>
-#include <stdlib.h>
-
-#include <boost/regex.hpp>
-
-#include "regex-repeat-matcher.hpp"
-#include "regex-backref-matcher.hpp"
-#include "regex-component-set-matcher.hpp"
-
-#include "../logging.hpp"
-
-INIT_LOGGER ("RegexRepeatMatcher");
-
-using namespace std;
-
-namespace ndn
-{
-RegexRepeatMatcher::RegexRepeatMatcher(const string expr, ptr_lib::shared_ptr<RegexBackrefManager> backrefManager, int indicator)
-  : RegexMatcher (expr, EXPR_REPEAT_PATTERN, backrefManager),
-    m_indicator(indicator)
-{
-  // _LOG_TRACE ("Enter RegexRepeatMatcher Constructor");
-  compile();
-  // _LOG_TRACE ("Exit RegexRepeatMatcher Constructor");
-}
-
-void 
-RegexRepeatMatcher::compile()
-{
-  // _LOG_TRACE ("Enter RegexRepeatMatcher::compile");
-    
-  ptr_lib::shared_ptr<RegexMatcher> matcher;
-
-  if('(' == m_expr[0]){
-    matcher = ptr_lib::make_shared<RegexBackrefMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
-    m_backrefManager->pushRef(matcher);
-    boost::dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
-  }
-  else{
-    matcher = ptr_lib::make_shared<RegexComponentSetMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
-  }
-  m_matcherList.push_back(matcher);
-      
-  parseRepetition();
-
-  // _LOG_TRACE ("Exit RegexRepeatMatcher::compile");
-
-}
-
-bool 
-RegexRepeatMatcher::parseRepetition()
-{
-  // _LOG_DEBUG ("Enter RegexRepeatMatcher::ParseRepetition()" << m_expr << " indicator: " << m_indicator);
-
-  string errMsg = "Error: RegexRepeatMatcher.ParseRepetition(): ";
-    
-  int exprSize = m_expr.size();
-  int intMax = numeric_limits<int>::max();
-    
-  if(exprSize == m_indicator){
-    m_repeatMin = 1;
-    m_repeatMax = 1;
-
-    return true;
-  }
-  else{
-    if(exprSize == (m_indicator + 1)){
-      if('?' == m_expr[m_indicator]){
-        m_repeatMin = 0;
-        m_repeatMax = 1;
-        return true;
-      }
-      if('+' == m_expr[m_indicator]){
-        m_repeatMin = 1;
-        m_repeatMax = intMax;
-        return true;
-      }
-      if('*' == m_expr[m_indicator]){
-        m_repeatMin = 0;
-        m_repeatMax = intMax;
-        return true;
-      }
-    }
-    else{
-      string repeatStruct = m_expr.substr(m_indicator, exprSize - m_indicator);
-      int rsSize = repeatStruct.size();
-      int min = 0;
-      int max = 0;
-
-      if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))){
-        int separator = repeatStruct.find_first_of(',', 0);
-        min = atoi(repeatStruct.substr(1, separator - 1).c_str());
-        max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
-      }
-      else if(boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))){
-        int separator = repeatStruct.find_first_of(',', 0);
-        min = 0;
-        max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
-      }
-      else if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))){
-        int separator = repeatStruct.find_first_of(',', 0);
-        min = atoi(repeatStruct.substr(1, separator).c_str());
-        max = intMax;
-      }
-      else if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))){
-        min = atoi(repeatStruct.substr(1, rsSize - 1).c_str());
-        max = min;
-      }
-      else
-        throw RegexMatcher::Error(errMsg + "Unrecognized format "+ m_expr);
-        
-      if(min > intMax || max > intMax || min > max)
-        throw RegexMatcher::Error(errMsg + "Wrong number " + m_expr);
-          
-      m_repeatMin = min;
-      m_repeatMax = max;
-        
-      return true;
-    }
-  }
-  return false;
-}
-
-bool
-RegexRepeatMatcher::match(const Name & name, const int & offset, const int & len)
-{
-  // _LOG_TRACE ("Enter RegexRepeatMatcher::match");
-
-  m_matchResult.clear();
-
-  if (0 == m_repeatMin)
-    if (0 == len)
-      return true;
-
-  if (recursiveMatch(0, name, offset, len))
-    {
-      for (int i = offset; i < offset + len; i++)
-        m_matchResult.push_back(name.get(i));
-      return true;
-    }
-  else
-    return false;
-}
-
-bool 
-RegexRepeatMatcher::recursiveMatch(int repeat, const Name & name, const int & offset, const int & len)
-{
-  // _LOG_TRACE ("Enter RegexRepeatMatcher::recursiveMatch");
-
-  // _LOG_DEBUG ("repeat: " << repeat << " offset: " << offset << " len: " << len);
-  // _LOG_DEBUG ("m_repeatMin: " << m_repeatMin << " m_repeatMax: " << m_repeatMax);
-
-  int tried = len;
-  ptr_lib::shared_ptr<RegexMatcher> matcher = m_matcherList[0];
-
-  if (0 < len && repeat >= m_repeatMax)
-    {
-      // _LOG_DEBUG("Match Fail: Reach m_repeatMax && More components");
-      return false;
-    }
-
-  if (0 == len && repeat < m_repeatMin)
-    {
-      // _LOG_DEBUG("Match Fail: No more components && have NOT reached m_repeatMin " << len << ", " << m_repeatMin);
-      return false;
-    }
-
-  if (0 == len && repeat >= m_repeatMin)
-    {
-      // _LOG_DEBUG("Match Succeed: No more components && reach m_repeatMin");
-      return true;
-    }
-    
-  while(tried >= 0)
-    {
-      // _LOG_DEBUG("Attempt tried: " << tried);
-
-      if (matcher->match(name, offset, tried) and recursiveMatch(repeat + 1, name, offset + tried, len - tried))
-        return true;
-      // _LOG_DEBUG("Failed at tried: " << tried);
-      tried --;
-    }
-
-  return false;
-}
-}//ndn
diff --git a/src/util/regex/regex-repeat-matcher.hpp b/src/util/regex/regex-repeat-matcher.hpp
index 9cc0212..fb42042 100644
--- a/src/util/regex/regex-repeat-matcher.hpp
+++ b/src/util/regex/regex-repeat-matcher.hpp
@@ -5,23 +5,26 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_REPEAT_MATCHER_HPP
-#define NDN_REGEX_REPEAT_MATCHER_HPP
+#ifndef NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP
+#define NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP
+
+#include "../../common.hpp"
+
+#include <boost/regex.hpp>
 
 #include "regex-matcher.hpp"
 
-namespace ndn
-{
+namespace ndn {
 
 class RegexRepeatMatcher : public RegexMatcher
 {
 public:
-  RegexRepeatMatcher(const std::string expr, ptr_lib::shared_ptr<RegexBackrefManager> backRefManager, int indicator);
+  RegexRepeatMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager, int indicator);
     
   virtual ~RegexRepeatMatcher(){}
 
   virtual bool 
-  match(const Name & name, const int & offset, const int & len);
+  match(const Name& name, const int& offset, const int& len);
 
 protected:
   /**
@@ -31,7 +34,6 @@
   virtual void 
   compile();
 
-
 private:
   bool 
   parseRepetition();
@@ -48,6 +50,184 @@
   int m_repeatMax;
 };
 
-}//ndn
+} // namespace ndn
 
-#endif
+#include "regex-backref-matcher.hpp"
+#include "regex-component-set-matcher.hpp"
+
+namespace ndn {
+
+inline
+RegexRepeatMatcher::RegexRepeatMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager, int indicator)
+  : RegexMatcher (expr, EXPR_REPEAT_PATTERN, backrefManager),
+    m_indicator(indicator)
+{
+  // _LOG_TRACE ("Enter RegexRepeatMatcher Constructor");
+  compile();
+  // _LOG_TRACE ("Exit RegexRepeatMatcher Constructor");
+}
+
+inline void 
+RegexRepeatMatcher::compile()
+{
+  // _LOG_TRACE ("Enter RegexRepeatMatcher::compile");
+    
+  shared_ptr<RegexMatcher> matcher;
+
+  if('(' == m_expr[0]){
+    matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
+    m_backrefManager->pushRef(matcher);
+    boost::dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
+  }
+  else{
+    matcher = make_shared<RegexComponentSetMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
+  }
+  m_matcherList.push_back(matcher);
+      
+  parseRepetition();
+
+  // _LOG_TRACE ("Exit RegexRepeatMatcher::compile");
+
+}
+
+inline bool 
+RegexRepeatMatcher::parseRepetition()
+{
+  // _LOG_DEBUG ("Enter RegexRepeatMatcher::ParseRepetition()" << m_expr << " indicator: " << m_indicator);
+    
+  int exprSize = m_expr.size();
+  int intMax = std::numeric_limits<int>::max();
+    
+  if(exprSize == m_indicator){
+    m_repeatMin = 1;
+    m_repeatMax = 1;
+
+    return true;
+  }
+  else{
+    if(exprSize == (m_indicator + 1)){
+      if('?' == m_expr[m_indicator]){
+        m_repeatMin = 0;
+        m_repeatMax = 1;
+        return true;
+      }
+      if('+' == m_expr[m_indicator]){
+        m_repeatMin = 1;
+        m_repeatMax = intMax;
+        return true;
+      }
+      if('*' == m_expr[m_indicator]){
+        m_repeatMin = 0;
+        m_repeatMax = intMax;
+        return true;
+      }
+    }
+    else{
+      std::string repeatStruct = m_expr.substr(m_indicator, exprSize - m_indicator);
+      int rsSize = repeatStruct.size();
+      int min = 0;
+      int max = 0;
+
+      if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))){
+        int separator = repeatStruct.find_first_of(',', 0);
+        min = atoi(repeatStruct.substr(1, separator - 1).c_str());
+        max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
+      }
+      else if(boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))){
+        int separator = repeatStruct.find_first_of(',', 0);
+        min = 0;
+        max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
+      }
+      else if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))){
+        int separator = repeatStruct.find_first_of(',', 0);
+        min = atoi(repeatStruct.substr(1, separator).c_str());
+        max = intMax;
+      }
+      else if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))){
+        min = atoi(repeatStruct.substr(1, rsSize - 1).c_str());
+        max = min;
+      }
+      else
+        throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
+                                  + "Unrecognized format "+ m_expr);
+        
+      if(min > intMax || max > intMax || min > max)
+        throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
+                                  + "Wrong number " + m_expr);
+          
+      m_repeatMin = min;
+      m_repeatMax = max;
+        
+      return true;
+    }
+  }
+  return false;
+}
+
+inline bool
+RegexRepeatMatcher::match(const Name & name, const int & offset, const int & len)
+{
+  // _LOG_TRACE ("Enter RegexRepeatMatcher::match");
+
+  m_matchResult.clear();
+
+  if (0 == m_repeatMin)
+    if (0 == len)
+      return true;
+
+  if (recursiveMatch(0, name, offset, len))
+    {
+      for (int i = offset; i < offset + len; i++)
+        m_matchResult.push_back(name.get(i));
+      return true;
+    }
+  else
+    return false;
+}
+
+inline bool 
+RegexRepeatMatcher::recursiveMatch(int repeat, const Name & name, const int & offset, const int & len)
+{
+  // _LOG_TRACE ("Enter RegexRepeatMatcher::recursiveMatch");
+
+  // _LOG_DEBUG ("repeat: " << repeat << " offset: " << offset << " len: " << len);
+  // _LOG_DEBUG ("m_repeatMin: " << m_repeatMin << " m_repeatMax: " << m_repeatMax);
+
+  int tried = len;
+  shared_ptr<RegexMatcher> matcher = m_matcherList[0];
+
+  if (0 < len && repeat >= m_repeatMax)
+    {
+      // _LOG_DEBUG("Match Fail: Reach m_repeatMax && More components");
+      return false;
+    }
+
+  if (0 == len && repeat < m_repeatMin)
+    {
+      // _LOG_DEBUG("Match Fail: No more components && have NOT reached m_repeatMin " << len << ", " << m_repeatMin);
+      return false;
+    }
+
+  if (0 == len && repeat >= m_repeatMin)
+    {
+      // _LOG_DEBUG("Match Succeed: No more components && reach m_repeatMin");
+      return true;
+    }
+    
+  while(tried >= 0)
+    {
+      // _LOG_DEBUG("Attempt tried: " << tried);
+
+      if (matcher->match(name, offset, tried) and recursiveMatch(repeat + 1, name, offset + tried, len - tried))
+        return true;
+      // _LOG_DEBUG("Failed at tried: " << tried);
+      tried --;
+    }
+
+  return false;
+}
+
+
+} // namespace ndn
+
+#endif // NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP
diff --git a/src/util/regex/regex-top-matcher.cpp b/src/util/regex/regex-top-matcher.cpp
index 3e7d4ce..2c93f17 100644
--- a/src/util/regex/regex-top-matcher.cpp
+++ b/src/util/regex/regex-top-matcher.cpp
@@ -5,28 +5,26 @@
  * See COPYING for copyright and distribution information.
  */
 
-#include <stdlib.h>
-
 #include "regex-top-matcher.hpp"
 
-#include "../logging.hpp"
+#include "regex-backref-manager.hpp"
+#include "regex-pattern-list-matcher.hpp"
 
-INIT_LOGGER ("RegexTopMatcher");
+// #include "../logging.hpp"
 
-using namespace std;
+// INIT_LOGGER ("RegexTopMatcher");
 
-namespace ndn
-{
+namespace ndn {
 
-RegexTopMatcher::RegexTopMatcher(const string & expr, const string & expand)
+RegexTopMatcher::RegexTopMatcher(const std::string& expr, const std::string& expand)
   : RegexMatcher(expr, EXPR_TOP),
     m_expand(expand),
     m_secondaryUsed(false)
 {
   // _LOG_TRACE ("Enter RegexTopMatcher Constructor");
 
-  m_primaryBackRefManager = ptr_lib::make_shared<RegexBackrefManager>();
-  m_secondaryBackRefManager = ptr_lib::make_shared<RegexBackrefManager>();
+  m_primaryBackRefManager = make_shared<RegexBackrefManager>();
+  m_secondaryBackRefManager = make_shared<RegexBackrefManager>();
   compile();
 
   // _LOG_TRACE ("Exit RegexTopMatcher Constructor");
@@ -42,9 +40,9 @@
 {
   // _LOG_TRACE ("Enter RegexTopMatcher::compile");
 
-  string errMsg = "Error: RegexTopMatcher.Compile(): ";
+  std::string errMsg = "Error: RegexTopMatcher.Compile(): ";
 
-  string expr = m_expr;
+  std::string expr = m_expr;
 
   if('$' != expr[expr.size() - 1])
     expr = expr + "<.*>*";
@@ -52,14 +50,15 @@
     expr = expr.substr(0, expr.size()-1);
 
   if('^' != expr[0])
-    m_secondaryMatcher = ptr_lib::make_shared<RegexPatternListMatcher>("<.*>*" + expr, m_secondaryBackRefManager);
+    m_secondaryMatcher = make_shared<RegexPatternListMatcher>(boost::cref("<.*>*" + expr),
+                                                              boost::cref(m_secondaryBackRefManager));
   else
     expr = expr.substr(1, expr.size()-1);
 
   // _LOG_DEBUG ("reconstructed expr: " << expr);
-                                                        
-                                                        
-  m_primaryMatcher = ptr_lib::make_shared<RegexPatternListMatcher>(expr, m_primaryBackRefManager);
+
+  m_primaryMatcher = make_shared<RegexPatternListMatcher>(boost::cref(expr),
+                                                          boost::cref(m_primaryBackRefManager));
 
   // _LOG_TRACE ("Exit RegexTopMatcher::compile");
 }
@@ -97,17 +96,17 @@
 }
 
 Name 
-RegexTopMatcher::expand (const string & expandStr)
+RegexTopMatcher::expand (const std::string& expandStr)
 {
   // _LOG_TRACE("Enter RegexTopMatcher::expand");
 
   Name result;
     
-  ptr_lib::shared_ptr<RegexBackrefManager> backRefManager = (m_secondaryUsed ? m_secondaryBackRefManager : m_primaryBackRefManager);
+  shared_ptr<RegexBackrefManager> backRefManager = (m_secondaryUsed ? m_secondaryBackRefManager : m_primaryBackRefManager);
     
   int backRefNum = backRefManager->size();
 
-  string expand;
+  std::string expand;
     
   if(expandStr != "")
     expand = expandStr;
@@ -117,7 +116,7 @@
   int offset = 0;
   while(offset < expand.size())
     {
-      string item = getItemFromExpand(expand, offset);
+      std::string item = getItemFromExpand(expand, offset);
       if(item[0] == '<')
         {
           result.append(item.substr(1, item.size() - 2));
@@ -128,15 +127,15 @@
           int index = atoi(item.substr(1, item.size() - 1).c_str());
 
           if(0 == index){
-            vector<Name::Component>::iterator it = m_matchResult.begin();
-            vector<Name::Component>::iterator end = m_matchResult.end();
+            std::vector<name::Component>::iterator it = m_matchResult.begin();
+            std::vector<name::Component>::iterator end = m_matchResult.end();
             for(; it != end; it++)
               result.append (*it);
           }
           else if(index <= backRefNum)
             {
-              vector<Name::Component>::const_iterator it = backRefManager->getBackRef (index - 1)->getMatchResult ().begin();
-              vector<Name::Component>::const_iterator end = backRefManager->getBackRef (index - 1)->getMatchResult ().end();
+              std::vector<name::Component>::const_iterator it = backRefManager->getBackRef (index - 1)->getMatchResult ().begin();
+              std::vector<name::Component>::const_iterator end = backRefManager->getBackRef (index - 1)->getMatchResult ().end();
               for(; it != end; it++)
                 result.append (*it);
             }
@@ -147,8 +146,8 @@
   return result;
 }
 
-string
-RegexTopMatcher::getItemFromExpand(const string & expand, int & offset)
+std::string
+RegexTopMatcher::getItemFromExpand(const std::string& expand, int & offset)
 {
   // _LOG_TRACE("Enter RegexTopMatcher::getItemFromExpand ");
   int begin = offset;
@@ -193,11 +192,11 @@
     throw RegexMatcher::Error("wrong format of expand string!");
 }
 
-ptr_lib::shared_ptr<RegexTopMatcher>
+shared_ptr<RegexTopMatcher>
 RegexTopMatcher::fromName(const Name& name, bool hasAnchor)
 {
   Name::const_iterator it = name.begin();
-  string regexStr("^");
+  std::string regexStr("^");
     
   for(; it != name.end(); it++)
     {
@@ -209,13 +208,13 @@
   if(hasAnchor)
     regexStr.append("$");
 
-  return ptr_lib::make_shared<RegexTopMatcher>(regexStr);
+  return make_shared<RegexTopMatcher>(boost::cref(regexStr));
 }
 
-string
-RegexTopMatcher::convertSpecialChar(const string& str)
+std::string
+RegexTopMatcher::convertSpecialChar(const std::string& str)
 {
-  string newStr;
+  std::string newStr;
   for(int i = 0; i < str.size(); i++)
     {
       char c = str[i];
diff --git a/src/util/regex/regex-top-matcher.hpp b/src/util/regex/regex-top-matcher.hpp
index 764726f..fc4a0df 100644
--- a/src/util/regex/regex-top-matcher.hpp
+++ b/src/util/regex/regex-top-matcher.hpp
@@ -5,33 +5,36 @@
  * See COPYING for copyright and distribution information.
  */
 
-#ifndef NDN_REGEX_TOP_MATCHER_HPP
-#define NDN_REGEX_TOP_MATCHER_HPP
+#ifndef NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP
+#define NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP
 
-#include <string>
+#include "../../common.hpp"
 
 #include "regex-matcher.hpp"
-#include "regex-pattern-list-matcher.hpp"
 
-namespace ndn
-{
+namespace ndn {
+
+class RegexPatternListMatcher;
+class RegexBackrefManager;
+
 class RegexTopMatcher: public RegexMatcher
 {
 public:
-  RegexTopMatcher(const std::string & expr, const std::string & expand = "");
+  RegexTopMatcher(const std::string & expr, const std::string& expand = "");
     
-  virtual ~RegexTopMatcher();
+  virtual
+  ~RegexTopMatcher();
 
   bool 
-  match(const Name & name);
+  match(const Name& name);
 
   virtual bool
-  match (const Name & name, const int & offset, const int & len);
+  match (const Name& name, const int& offset, const int& len);
 
   virtual Name 
-  expand (const std::string & expand = "");
+  expand (const std::string& expand = "");
 
-  static ptr_lib::shared_ptr<RegexTopMatcher>
+  static shared_ptr<RegexTopMatcher>
   fromName(const Name& name, bool hasAnchor=false);
 
 protected:
@@ -40,21 +43,20 @@
 
 private:
   std::string
-  getItemFromExpand(const std::string & expand, int & offset);
+  getItemFromExpand(const std::string& expand, int & offset);
 
   static std::string
   convertSpecialChar(const std::string& str);
 
 private:
   const std::string m_expand;
-  ptr_lib::shared_ptr<RegexPatternListMatcher> m_primaryMatcher;
-  ptr_lib::shared_ptr<RegexPatternListMatcher> m_secondaryMatcher;
-  ptr_lib::shared_ptr<RegexBackrefManager> m_primaryBackRefManager;
-  ptr_lib::shared_ptr<RegexBackrefManager> m_secondaryBackRefManager;
+  shared_ptr<RegexPatternListMatcher> m_primaryMatcher;
+  shared_ptr<RegexPatternListMatcher> m_secondaryMatcher;
+  shared_ptr<RegexBackrefManager> m_primaryBackRefManager;
+  shared_ptr<RegexBackrefManager> m_secondaryBackRefManager;
   bool m_secondaryUsed;
 };
 
-}
+} // namespace ndn
 
-#endif
-
+#endif // NDN_UTIL_REGEX_REGEX_TOP_MATCHER_HPP