summaryrefslogtreecommitdiffstats
path: root/3rdparty/clucene/src/CLucene/queryParser/TokenList.cpp
blob: 7d30b931fc70ae968d623d7cbdf16dc46e1a7d4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
* 
* Distributable under the terms of either the Apache License (Version 2.0) or 
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#include "CLucene/StdHeader.h"
#include "TokenList.h"

#include "CLucene/util/VoidMap.h"
#include "CLucene/util/VoidList.h"
#include "QueryToken.h"

CL_NS_DEF(queryParser)
  
    TokenList::TokenList(){
    //Func - Constructor
    //Pre  - true
    //Post - Instance has been created
    }

    TokenList::~TokenList(){
    //Func - Destructor
	//Pre  - true
	//Post - The tokenlist has been destroyed

        tokens.clear();
    }

	void TokenList::add(QueryToken* token){
    //Func - Adds a QueryToken token to the TokenList
	//Pre  - token != NULL
	//Post - token has been added to the token list

       CND_PRECONDITION(token != NULL, "token != NULL");

       tokens.insert(tokens.begin(),token);
    }

    void TokenList::push(QueryToken* token){
    //Func - 
	//Pre  - token != NULL
	//Post - 

      CND_PRECONDITION(token != NULL, "token is NULL");

      tokens.push_back(token);
    }

    QueryToken* TokenList::peek() {
      /* DSR:2004.11.01: Reverted my previous (circa April 2004) fix (which
      ** raised an exception if Peek was called when there were no tokens) in
      ** favor of returning the EOF token.  This solution is much better
      ** integrated with the rest of the code in the queryParser subsystem. */
      size_t nTokens = tokens.size();
      if (nTokens == 0) {
		push(_CLNEW QueryToken(QueryToken::EOF_));
        nTokens++;
      }
      return tokens[nTokens-1];
    }

    QueryToken* TokenList::extract(){
    //Func - Extract token from the TokenList
	//Pre  - true
	//Post - Retracted token has been returned

        QueryToken* token = peek();
        //Retract the current peeked token
        tokens.delete_back();

        return token;
    }

    int32_t TokenList::count() const
    {
      return tokens.size();
    }
CL_NS_END