Directory Structuring
diff --git a/src/utility/nlsr_logger.cpp b/src/utility/nlsr_logger.cpp
new file mode 100644
index 0000000..804ef98
--- /dev/null
+++ b/src/utility/nlsr_logger.cpp
@@ -0,0 +1,59 @@
+#include "nlsr_logger.hpp"
+
+namespace nlsr
+{
+
+ string
+ NlsrLogger::getEpochTime()
+ {
+ std::stringstream ss;
+ boost::posix_time::ptime time_t_epoch(boost::gregorian::date(1970,1,1));
+ boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
+ boost::posix_time::time_duration diff = now - time_t_epoch;
+ ss<<diff.total_seconds()<<"."<<boost::format("%06i")%(diff.total_microseconds()
+ %1000000);
+ return ss.str();
+ }
+
+ string
+ NlsrLogger::getUserHomeDirectory()
+ {
+ string homeDirPath(getpwuid(getuid())->pw_dir);
+ if( homeDirPath.empty() )
+ {
+ homeDirPath = getenv("HOME");
+ }
+ return homeDirPath;
+ }
+
+ void
+ NlsrLogger::initNlsrLogger(std::string dirPath)
+ {
+ string logDirPath(dirPath);
+ if( dirPath.empty() )
+ {
+ logDirPath=getUserHomeDirectory()+"/nlsrLog";
+ }
+ cout<<"Log Dir Path: "<< logDirPath<<endl;
+ typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
+ shared_ptr< file_sink > sink(new file_sink(
+ keywords::file_name = logDirPath
+ +"/NLSR%Y%m%d%H%M%S_%3N.log",
+ keywords::rotation_size = 128 * 1024 * 1024,
+ keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0),
+ keywords::auto_flush = true
+ ));
+ sink->locked_backend()->set_file_collector(sinks::file::make_collector(
+ keywords::target = logDirPath,
+ keywords::max_size = 16 * 1024 * 1024 * 1024,
+ keywords::min_free_space = 128 * 1024 * 1024
+ ));
+ sink->set_formatter(
+ expr::format("%1%: %2%")
+ % getEpochTime()
+ % expr::smessage
+ );
+ logging::core::get()->add_sink(sink);
+ }
+
+}//namespace nlsr
diff --git a/src/utility/nlsr_logger.hpp b/src/utility/nlsr_logger.hpp
new file mode 100644
index 0000000..222ac52
--- /dev/null
+++ b/src/utility/nlsr_logger.hpp
@@ -0,0 +1,62 @@
+#ifndef NLSR_LOGGER_HPP
+#define NLSR_LOGGER_HPP
+
+#define BOOST_LOG_DYN_LINK 1
+
+#include <stdexcept>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <pwd.h>
+#include <cstdlib>
+#include <string>
+#include <unistd.h>
+#include <boost/format.hpp>
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/local_time/local_time.hpp>
+#include <boost/log/common.hpp>
+#include <boost/log/expressions.hpp>
+#include <boost/log/attributes.hpp>
+#include <boost/log/sources/logger.hpp>
+#include <boost/log/sinks/sync_frontend.hpp>
+#include <boost/log/sinks/text_file_backend.hpp>
+
+namespace nlsr
+{
+
+ namespace logging = boost::log;
+ namespace attrs = boost::log::attributes;
+ namespace src = boost::log::sources;
+ namespace sinks = boost::log::sinks;
+ namespace expr = boost::log::expressions;
+ namespace keywords = boost::log::keywords;
+
+ using boost::shared_ptr;
+ using namespace std;
+
+
+ class NlsrLogger
+ {
+ public:
+ NlsrLogger()
+ {
+ }
+
+ void initNlsrLogger(std::string dirPath);
+
+ src::logger& getLogger()
+ {
+ return mLogger;
+ }
+
+ private:
+ string getEpochTime();
+ string getUserHomeDirectory();
+
+ private:
+ src::logger mLogger;
+ };
+
+}//namespace nlsr
+#endif
diff --git a/src/utility/nlsr_tokenizer.cpp b/src/utility/nlsr_tokenizer.cpp
new file mode 100644
index 0000000..809e395
--- /dev/null
+++ b/src/utility/nlsr_tokenizer.cpp
@@ -0,0 +1,110 @@
+#include <iostream>
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string.hpp>
+#include <string>
+#include <algorithm>
+
+#include "nlsr_tokenizer.hpp"
+
+namespace nlsr
+{
+
+ using namespace std;
+ using namespace boost;
+
+ void
+ nlsrTokenizer::makeToken()
+ {
+ char_separator<char> sep(seps.c_str());
+ tokenizer< char_separator<char> >tokens(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);
+ }
+ }
+ firstToken=vTokenList[0];
+ makeRestOfTheLine();
+ }
+
+ void
+ nlsrTokenizer::insertToken(const string& token)
+ {
+ tokenList.push_back(token);
+ vTokenList.push_back(token);
+ }
+
+ int
+ nlsrTokenizer::getTokenPosition(string& token)
+ {
+ int pos=-1;
+ int i=0;
+ for(std::list<string>::iterator it=tokenList.begin();
+ it!=tokenList.end(); it++)
+ {
+ if( (*it) == token )
+ {
+ break;
+ }
+ i++;
+ }
+ if( i < tokenList.size() )
+ {
+ pos=i;
+ }
+ return pos;
+ }
+
+ string
+ nlsrTokenizer::getTokenString(int from , int to)
+ {
+ string returnString="";
+ if((from>=0 && to<tokenList.size()) &&
+ (to>=from && to <tokenList.size()))
+ {
+ for(int i=from; i<=to; i++)
+ {
+ returnString+=seps;
+ returnString+=vTokenList[i];
+ }
+ }
+ trim(returnString);
+ return returnString;
+ }
+
+ string
+ nlsrTokenizer::getTokenString(int from)
+ {
+ return getTokenString(from,tokenList.size()-1);
+ }
+
+ static bool
+ tokenCompare(string& s1, string& s2)
+ {
+ return s1==s2;
+ }
+
+ void
+ nlsrTokenizer::makeRestOfTheLine()
+ {
+ restOfTheLine=getTokenString(1);
+ }
+
+ bool
+ nlsrTokenizer::doesTokenExist(string token)
+ {
+ std::list<string >::iterator it = std::find_if( tokenList.begin(),
+ tokenList.end(),
+ bind(&tokenCompare, _1 , token));
+ if( it != tokenList.end() )
+ {
+ return true;
+ }
+ return false;
+ }
+
+}//namespace nlsr
diff --git a/src/utility/nlsr_tokenizer.hpp b/src/utility/nlsr_tokenizer.hpp
new file mode 100644
index 0000000..6cd97e0
--- /dev/null
+++ b/src/utility/nlsr_tokenizer.hpp
@@ -0,0 +1,104 @@
+#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>
+#include <ndn-cpp-dev/face.hpp>
+
+namespace nlsr
+{
+
+ using namespace std;
+ using namespace boost;
+
+ class nlsrTokenizer
+ {
+ public:
+ nlsrTokenizer(const string& inputString)
+ : firstToken()
+ , restOfTheLine()
+ , currentPosition(0)
+ {
+ seps = " ";
+ originalString = inputString;
+ makeToken();
+ }
+
+ nlsrTokenizer(const string& inputString, const string& separator)
+ : firstToken()
+ , restOfTheLine()
+ , currentPosition(0)
+ {
+ seps = separator;
+ originalString = inputString;
+ makeToken();
+ }
+
+ string getFirstToken()
+ {
+ return firstToken;
+ }
+
+ string getRestOfLine()
+ {
+ return restOfTheLine;
+ }
+
+ void resetCurrentPosition(uint32_t cp=0)
+ {
+ if( cp >=0 && cp <= vTokenList.size() )
+ {
+ currentPosition=cp;
+ }
+ }
+
+ string getNextToken()
+ {
+ if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1))
+ {
+ return vTokenList[currentPosition++];
+ }
+ return "";
+ }
+
+ uint32_t getTokenNumber()
+ {
+ return tokenList.size();
+ }
+
+ string getToken(int position)
+ {
+ if( position >=0 && position <vTokenList.size() )
+ {
+ return vTokenList[position];
+ }
+ return "";
+ }
+
+ int getTokenPosition(string& token);
+ string getTokenString(int from , int to);
+ string getTokenString(int from);
+ bool doesTokenExist(string token);
+
+
+ private:
+
+ void makeToken();
+ void insertToken(const string& token);
+ void makeRestOfTheLine();
+
+ string seps;
+ string originalString;
+ string firstToken;
+ string restOfTheLine;
+ std::list<string> tokenList;
+ std::vector<string> vTokenList;
+ uint32_t currentPosition;
+ };
+
+}//namespace nlsr
+#endif