PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/strigi-0.7.7/libstreamanalyzer/lib/xmlparser/xmlstream.h

#
C++ Header | 89 lines | 40 code | 7 blank | 42 comment | 0 complexity | af88992bcc4baad51804d841c97c289f 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. #ifndef XMLSTREAM_H
  21. #define XMLSTREAM_H
  22. #include <string>
  23. #include <map>
  24. #include <list>
  25. // Although ostream isn't used *here*, other generated code
  26. // which #includes this file does use std::ostream (while
  27. // it doesn't #include <ostream> itself) so pull the header
  28. // in here.
  29. #include <ostream>
  30. class SimpleNode;
  31. class XMLStream {
  32. private:
  33. class Private;
  34. Private* p;
  35. public:
  36. XMLStream(const std::string& xml);
  37. ~XMLStream();
  38. void setFromAttribute(bool&, const char*);
  39. void setFromAttribute(int&, const char*);
  40. void setFromAttribute(std::string&, const char*);
  41. const std::string& getTagName() const;
  42. /**
  43. * The node at which the XMLStream is currently positioned.
  44. **/
  45. const SimpleNode& currentNode() const;
  46. /**
  47. * Moves the XMLStream to the first visible child of the current node, and
  48. * returns the new node. If the current node has no visible children,
  49. * returns null, and retains the current node.
  50. **/
  51. const SimpleNode* firstChild() const;
  52. /**
  53. * Moves the XMLStream to the next sibling of the current node, and
  54. * returns the new node. If the current node has no visible next sibling,
  55. * returns null, and retains the current node.
  56. **/
  57. const SimpleNode* nextSibling() const;
  58. /**
  59. * Moves to and returns the closest visible ancestor node of the current
  60. * node. If the search for parentNode attempts to step upward from the
  61. * XMLStream's root node, or if it fails to find a visible ancestor node,
  62. * this method retains the current position and returns null.
  63. **/
  64. const SimpleNode* parentNode() const;
  65. };
  66. XMLStream& operator>>(XMLStream& in, bool& e);
  67. XMLStream& operator>>(XMLStream& in, int& e);
  68. XMLStream& operator>>(XMLStream& in, std::string& e);
  69. class SimpleNode {
  70. friend class SimpleNodeParser;
  71. private:
  72. SimpleNode() :parent(0), next(0) {}
  73. public:
  74. const SimpleNode* parent;
  75. const SimpleNode* next;
  76. std::string tagname;
  77. std::map<std::string, std::string> atts;
  78. std::list<SimpleNode> nodes;
  79. std::string text;
  80. SimpleNode(const std::string& xml);
  81. };
  82. #endif