src: configuration file parsing
used boost::property_tree::info_parser for parsing nlsr's configuration file and
changed configuration command style to info command style. Removed tokenizer from
nlsr
Refs: #1542
Change-Id: If017ddd7eef5caa59b33940bfc27a71aa4de266b
diff --git a/src/utility/name-helper.hpp b/src/utility/name-helper.hpp
index 5a01a1a..90b3eca 100644
--- a/src/utility/name-helper.hpp
+++ b/src/utility/name-helper.hpp
@@ -1,6 +1,9 @@
#ifndef NLSR_NAME_HELPER_HPP
#define NLSR_NAME_HELPER_HPP
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/regex_find_format.hpp>
+#include <boost/regex.hpp>
#include <boost/cstdint.hpp>
#include <ndn-cxx/name-component.hpp>
#include <ndn-cxx/name.hpp>
@@ -20,10 +23,8 @@
{
ndn::name::Component component(searchString);
size_t nameSize = name.size();
- for (uint32_t i = 0; i < nameSize; i++)
- {
- if (component == name[i])
- {
+ for (uint32_t i = 0; i < nameSize; i++) {
+ if (component == name[i]) {
return (int32_t)i;
}
}
diff --git a/src/utility/tokenizer.cpp b/src/utility/tokenizer.cpp
deleted file mode 100644
index 095e55d..0000000
--- a/src/utility/tokenizer.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <iostream>
-#include <boost/tokenizer.hpp>
-#include <boost/algorithm/string.hpp>
-#include <string>
-#include <algorithm>
-
-#include <ndn-cxx/face.hpp>
-
-#include "tokenizer.hpp"
-
-namespace nlsr {
-
-using namespace std;
-using namespace boost;
-
-void
-Tokenizer::makeToken()
-{
- char_separator<char> sep(m_seps.c_str());
- tokenizer<char_separator<char> >tokens(m_originalString, sep);
- tokenizer<char_separator<char> >::iterator tok_iter = tokens.begin();
- for (; tok_iter != tokens.end(); ++tok_iter)
- {
- string oneToken(*tok_iter);
- trim(oneToken);
- if (!oneToken.empty())
- {
- insertToken(oneToken);
- }
- }
- m_firstToken = m_vTokenList[0];
- makeRestOfTheLine();
-}
-
-void
-Tokenizer::insertToken(const string& token)
-{
- m_tokenList.push_back(token);
- m_vTokenList.push_back(token);
-}
-
-uint32_t
-Tokenizer::getTokenPosition(string& token)
-{
- uint32_t pos = -1;
- uint32_t i = 0;
- for (std::list<string>::iterator it = m_tokenList.begin();
- it != m_tokenList.end(); it++)
- {
- if ((*it) == token)
- {
- break;
- }
- i++;
- }
- if (i < m_tokenList.size())
- {
- pos = i;
- }
- return pos;
-}
-
-string
-Tokenizer::getTokenString(uint32_t from , uint32_t to)
-{
- string returnString = "";
- if ((to < m_tokenList.size()) &&
- (to >= from && to < m_tokenList.size()))
- {
- for (uint32_t i = from; i <= to; i++)
- {
- returnString += m_seps;
- returnString += m_vTokenList[i];
- }
- }
- trim(returnString);
- return returnString;
-}
-
-string
-Tokenizer::getTokenString(uint32_t from)
-{
- return getTokenString(from, m_tokenList.size() - 1);
-}
-
-static bool
-tokenCompare(string& s1, string& s2)
-{
- return s1 == s2;
-}
-
-void
-Tokenizer::makeRestOfTheLine()
-{
- m_restOfTheLine = getTokenString(1);
-}
-
-bool
-Tokenizer::doesTokenExist(string token)
-{
- std::list<string>::iterator it = std::find_if(m_tokenList.begin(),
- m_tokenList.end(),
- ndn::bind(&tokenCompare, _1 , token));
- if (it != m_tokenList.end())
- {
- return true;
- }
- return false;
-}
-
-}//namespace nlsr
diff --git a/src/utility/tokenizer.hpp b/src/utility/tokenizer.hpp
deleted file mode 100644
index 8ae6f88..0000000
--- a/src/utility/tokenizer.hpp
+++ /dev/null
@@ -1,117 +0,0 @@
-#ifndef NLSR_TOKENIZER_HPP
-#define NLSR_TOKENIZER_HPP
-
-#include <iostream>
-#include <boost/tokenizer.hpp>
-#include <boost/algorithm/string.hpp>
-#include <string>
-#include <list>
-#include <vector>
-
-namespace nlsr {
-
-class Tokenizer
-{
-public:
- Tokenizer(const std::string& inputString)
- : m_firstToken()
- , m_restOfTheLine()
- , m_currentPosition(0)
- {
- m_seps = " ";
- m_originalString = inputString;
- makeToken();
- }
-
- Tokenizer(const std::string& inputString, const std::string& separator)
- : m_firstToken()
- , m_restOfTheLine()
- , m_currentPosition(0)
- {
- m_seps = separator;
- m_originalString = inputString;
- makeToken();
- }
-
- std::string
- getFirstToken()
- {
- return m_firstToken;
- }
-
- std::string
- getRestOfLine()
- {
- return m_restOfTheLine;
- }
-
- void
- resetCurrentPosition(uint32_t cp = 0)
- {
- if (cp <= m_vTokenList.size())
- {
- m_currentPosition = cp;
- }
- }
-
- std::string
- getNextToken()
- {
- if (m_currentPosition <= (m_vTokenList.size() - 1))
- {
- return m_vTokenList[m_currentPosition++];
- }
- return "";
- }
-
- uint32_t
- getTokenNumber()
- {
- return m_tokenList.size();
- }
-
- std::string
- getToken(unsigned int position)
- {
- if (position < m_vTokenList.size())
- {
- return m_vTokenList[position];
- }
- return "";
- }
-
- uint32_t
- getTokenPosition(std::string& token);
-
- std::string
- getTokenString(uint32_t from , uint32_t to);
-
- std::string
- getTokenString(uint32_t from);
-
- bool
- doesTokenExist(std::string token);
-
-
-private:
-
- void
- makeToken();
-
- void
- insertToken(const std::string& token);
-
- void
- makeRestOfTheLine();
-
- std::string m_seps;
- std::string m_originalString;
- std::string m_firstToken;
- std::string m_restOfTheLine;
- std::list<std::string> m_tokenList;
- std::vector<std::string> m_vTokenList;
- uint32_t m_currentPosition;
-};
-
-}//namespace nlsr
-#endif //NLSR_TOKENIZER_HPP