blob: 02d6eeab5a6f4ecd743b1eca1416ad25afb1c8d3 [file] [log] [blame]
akmhoqueba094742014-02-28 11:47:21 -06001#ifndef NLSR_TOKENIZER_HPP
2#define NLSR_TOKENIZER_HPP
3
4#include <iostream>
5#include <boost/tokenizer.hpp>
6#include <boost/algorithm/string.hpp>
7#include <string>
8#include <list>
9#include <vector>
10#include <ndn-cpp-dev/face.hpp>
11
12namespace nlsr
13{
14
akmhoque5a44dd42014-03-12 18:11:32 -050015 using namespace std;
16 using namespace boost;
akmhoqueba094742014-02-28 11:47:21 -060017
akmhoque5a44dd42014-03-12 18:11:32 -050018 class nlsrTokenizer
19 {
20 public:
21 nlsrTokenizer(const string& inputString)
akmhoque05d5fcf2014-04-15 14:58:45 -050022 : m_firstToken()
23 , m_restOfTheLine()
24 , m_currentPosition(0)
akmhoqueba094742014-02-28 11:47:21 -060025 {
akmhoque05d5fcf2014-04-15 14:58:45 -050026 m_seps = " ";
27 m_originalString = inputString;
akmhoque5a44dd42014-03-12 18:11:32 -050028 makeToken();
29 }
akmhoqueba094742014-02-28 11:47:21 -060030
akmhoque5a44dd42014-03-12 18:11:32 -050031 nlsrTokenizer(const string& inputString, const string& separator)
akmhoque05d5fcf2014-04-15 14:58:45 -050032 : m_firstToken()
33 , m_restOfTheLine()
34 , m_currentPosition(0)
akmhoque5a44dd42014-03-12 18:11:32 -050035 {
akmhoque05d5fcf2014-04-15 14:58:45 -050036 m_seps = separator;
37 m_originalString = inputString;
akmhoque5a44dd42014-03-12 18:11:32 -050038 makeToken();
39 }
akmhoqueba094742014-02-28 11:47:21 -060040
akmhoque5a44dd42014-03-12 18:11:32 -050041 string getFirstToken()
42 {
akmhoque05d5fcf2014-04-15 14:58:45 -050043 return m_firstToken;
akmhoque5a44dd42014-03-12 18:11:32 -050044 }
akmhoqueba094742014-02-28 11:47:21 -060045
akmhoque5a44dd42014-03-12 18:11:32 -050046 string getRestOfLine()
47 {
akmhoque05d5fcf2014-04-15 14:58:45 -050048 return m_restOfTheLine;
akmhoque5a44dd42014-03-12 18:11:32 -050049 }
akmhoqueba094742014-02-28 11:47:21 -060050
akmhoque5a44dd42014-03-12 18:11:32 -050051 void resetCurrentPosition(uint32_t cp=0)
52 {
akmhoque05d5fcf2014-04-15 14:58:45 -050053 if( cp >=0 && cp <= m_vTokenList.size() )
akmhoque5a44dd42014-03-12 18:11:32 -050054 {
akmhoque05d5fcf2014-04-15 14:58:45 -050055 m_currentPosition=cp;
akmhoque5a44dd42014-03-12 18:11:32 -050056 }
57 }
akmhoqueba094742014-02-28 11:47:21 -060058
akmhoque5a44dd42014-03-12 18:11:32 -050059 string getNextToken()
60 {
akmhoque05d5fcf2014-04-15 14:58:45 -050061 if(m_currentPosition >= 0 && m_currentPosition <= (m_vTokenList.size()-1))
akmhoque5a44dd42014-03-12 18:11:32 -050062 {
akmhoque05d5fcf2014-04-15 14:58:45 -050063 return m_vTokenList[m_currentPosition++];
akmhoque5a44dd42014-03-12 18:11:32 -050064 }
65 return "";
66 }
akmhoqueba094742014-02-28 11:47:21 -060067
akmhoque5a44dd42014-03-12 18:11:32 -050068 uint32_t getTokenNumber()
69 {
akmhoque05d5fcf2014-04-15 14:58:45 -050070 return m_tokenList.size();
akmhoque5a44dd42014-03-12 18:11:32 -050071 }
akmhoqueba094742014-02-28 11:47:21 -060072
akmhoque5a44dd42014-03-12 18:11:32 -050073 string getToken(int position)
74 {
akmhoque05d5fcf2014-04-15 14:58:45 -050075 if( position >=0 && position <m_vTokenList.size() )
akmhoque5a44dd42014-03-12 18:11:32 -050076 {
akmhoque05d5fcf2014-04-15 14:58:45 -050077 return m_vTokenList[position];
akmhoque5a44dd42014-03-12 18:11:32 -050078 }
79 return "";
80 }
akmhoqueba094742014-02-28 11:47:21 -060081
akmhoque5a44dd42014-03-12 18:11:32 -050082 int getTokenPosition(string& token);
83 string getTokenString(int from , int to);
84 string getTokenString(int from);
85 bool doesTokenExist(string token);
akmhoqueba094742014-02-28 11:47:21 -060086
87
akmhoque5a44dd42014-03-12 18:11:32 -050088 private:
akmhoqueba094742014-02-28 11:47:21 -060089
akmhoque5a44dd42014-03-12 18:11:32 -050090 void makeToken();
91 void insertToken(const string& token);
92 void makeRestOfTheLine();
akmhoqueba094742014-02-28 11:47:21 -060093
akmhoque05d5fcf2014-04-15 14:58:45 -050094 string m_seps;
95 string m_originalString;
96 string m_firstToken;
97 string m_restOfTheLine;
98 std::list<string> m_tokenList;
99 std::vector<string> m_vTokenList;
100 uint32_t m_currentPosition;
akmhoque5a44dd42014-03-12 18:11:32 -0500101 };
akmhoqueba094742014-02-28 11:47:21 -0600102
103}//namespace nlsr
104#endif