PageRenderTime 819ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/strigi-0.7.7/strigiutils/bin/xmlindexer/xmlindexwriter.cpp

#
C++ | 60 lines | 39 code | 1 blank | 20 comment | 10 complexity | c8bc3cfe974e9cbe2de097b643746cc4 MD5 | raw file
Possible License(s): LGPL-2.0
  1. /* This file is part of Strigi Desktop Search
  2. *
  3. * Copyright (C) 2007 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 "xmlindexwriter.h"
  21. using namespace std;
  22. using namespace Strigi;
  23. void
  24. XmlIndexWriter::initWriterData(const FieldRegister& f) {
  25. map<string, RegisteredField*>::const_iterator i;
  26. map<string, RegisteredField*>::const_iterator end(f.fields().end());
  27. for (i = f.fields().begin(); i != end; ++i) {
  28. Tag* tag = static_cast<Tag*>(i->second->writerData());
  29. if (tag) {
  30. tag->refcount++;
  31. continue;
  32. }
  33. tag = new Tag();
  34. tag->refcount = 1;
  35. const string s(i->first);
  36. const string& n = mapping.map(s);
  37. if (s == n) {
  38. tag->open = " <value name='" + n + "'>";
  39. tag->close = "</value>\n";
  40. } else {
  41. tag->open = " <" + n + '>';
  42. tag->close = "</" + n + ">\n";
  43. }
  44. i->second->setWriterData(tag);
  45. }
  46. }
  47. void
  48. XmlIndexWriter::releaseWriterData(const FieldRegister& f) {
  49. map<string, RegisteredField*>::const_iterator i;
  50. map<string, RegisteredField*>::const_iterator end(f.fields().end());
  51. for (i = f.fields().begin(); i != end; ++i) {
  52. Tag* tag = static_cast<Tag*>(i->second->writerData());
  53. if (tag->refcount-- == 1) {
  54. //fprintf(stderr, "free for %s\n", i->second->key().c_str());
  55. delete tag;
  56. i->second->setWriterData(0);
  57. }
  58. }
  59. }