/src/3rdparty/clucene/src/CLucene/queryParser/TokenList.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 79 lines · 37 code · 16 blank · 26 comment · 4 complexity · 9dece8041935a79b1243f91a67eedc14 MD5 · raw file

  1. /*------------------------------------------------------------------------------
  2. * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
  3. *
  4. * Distributable under the terms of either the Apache License (Version 2.0) or
  5. * the GNU Lesser General Public License, as specified in the COPYING file.
  6. ------------------------------------------------------------------------------*/
  7. #include "CLucene/StdHeader.h"
  8. #include "TokenList.h"
  9. #include "CLucene/util/VoidMap.h"
  10. #include "CLucene/util/VoidList.h"
  11. #include "QueryToken.h"
  12. CL_NS_DEF(queryParser)
  13. TokenList::TokenList(){
  14. //Func - Constructor
  15. //Pre - true
  16. //Post - Instance has been created
  17. }
  18. TokenList::~TokenList(){
  19. //Func - Destructor
  20. //Pre - true
  21. //Post - The tokenlist has been destroyed
  22. tokens.clear();
  23. }
  24. void TokenList::add(QueryToken* token){
  25. //Func - Adds a QueryToken token to the TokenList
  26. //Pre - token != NULL
  27. //Post - token has been added to the token list
  28. CND_PRECONDITION(token != NULL, "token != NULL");
  29. tokens.insert(tokens.begin(),token);
  30. }
  31. void TokenList::push(QueryToken* token){
  32. //Func -
  33. //Pre - token != NULL
  34. //Post -
  35. CND_PRECONDITION(token != NULL, "token is NULL");
  36. tokens.push_back(token);
  37. }
  38. QueryToken* TokenList::peek() {
  39. /* DSR:2004.11.01: Reverted my previous (circa April 2004) fix (which
  40. ** raised an exception if Peek was called when there were no tokens) in
  41. ** favor of returning the EOF token. This solution is much better
  42. ** integrated with the rest of the code in the queryParser subsystem. */
  43. size_t nTokens = tokens.size();
  44. if (nTokens == 0) {
  45. push(_CLNEW QueryToken(QueryToken::EOF_));
  46. nTokens++;
  47. }
  48. return tokens[nTokens-1];
  49. }
  50. QueryToken* TokenList::extract(){
  51. //Func - Extract token from the TokenList
  52. //Pre - true
  53. //Post - Retracted token has been returned
  54. QueryToken* token = peek();
  55. //Retract the current peeked token
  56. tokens.delete_back();
  57. return token;
  58. }
  59. int32_t TokenList::count() const
  60. {
  61. return tokens.size();
  62. }
  63. CL_NS_END