PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/strigi-0.7.7/libstreams/lib/signatureinputstream.cpp

#
C++ | 79 lines | 51 code | 4 blank | 24 comment | 0 complexity | c13020e7c6e692341b33e8588e8f09ea MD5 | raw file
Possible License(s): LGPL-2.0
  1. /* This file is part of Strigi Desktop Search
  2. *
  3. * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include "signatureinputstream.h"
  21. #include <strigi/strigiconfig.h>
  22. #include "kmpsearcher.h"
  23. #include <cassert>
  24. #include <iostream>
  25. using namespace std;
  26. using namespace Strigi;
  27. /**
  28. * There are two cases:
  29. * - the stream size is known in advance.
  30. * - the stream size is no known
  31. **/
  32. class SignatureInputStream::Private {
  33. public:
  34. int32_t signaturesize;
  35. InputStream* input;
  36. std::string signature;
  37. Private(InputStream* i, int32_t s)
  38. : signaturesize(s), input(i) {
  39. }
  40. };
  41. SignatureInputStream::SignatureInputStream(InputStream* i,
  42. int32_t signaturesize) :p(new Private(i, signaturesize)) {
  43. m_size = i->size();
  44. }
  45. SignatureInputStream::~SignatureInputStream() {
  46. delete p;
  47. }
  48. int32_t
  49. SignatureInputStream::read(const char*& start, int32_t min, int32_t max) {
  50. int32_t r = p->input->read(start, min, max);
  51. m_status = p->input->status();
  52. m_position = p->input->position();
  53. m_size = p->input->size();
  54. return r;
  55. }
  56. int64_t
  57. SignatureInputStream::reset(int64_t newpos) {
  58. int64_t r = p->input->reset(newpos);
  59. m_status = p->input->status();
  60. m_position = p->input->position();
  61. m_size = p->input->size();
  62. return r;
  63. }
  64. int64_t
  65. SignatureInputStream::skip(int64_t ntoskip) {
  66. int64_t r = p->input->skip(ntoskip);
  67. m_status = p->input->status();
  68. m_position = p->input->position();
  69. m_size = p->input->size();
  70. return r;
  71. }
  72. std::string
  73. SignatureInputStream::signature() const {
  74. return p->signature;
  75. }