00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 00002 /* 00003 * This file is part of the libetonyek project. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this 00007 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 */ 00009 00010 #ifndef KEYXMLREADER_H_INCLUDED 00011 #define KEYXMLREADER_H_INCLUDED 00012 00013 #include <boost/function.hpp> 00014 00015 class WPXInputStream; 00016 00017 namespace libetonyek 00018 { 00019 00020 class KEYXMLReader 00021 { 00022 // -Weffc++ 00023 KEYXMLReader(const KEYXMLReader &other); 00024 KEYXMLReader &operator=(const KEYXMLReader &other); 00025 00026 struct Impl; 00027 00028 enum Type 00029 { 00030 TYPE_ELEMENT = 0x1, 00031 TYPE_TEXT = 0x2 00032 }; 00033 00034 class NodeIterator 00035 { 00036 friend class KEYXMLReader; 00037 00038 public: 00039 NodeIterator(const KEYXMLReader &reader, int types); 00040 00041 bool next(); 00042 00043 Impl *getImpl() const; 00044 00045 private: 00046 bool test() const; 00047 00048 private: 00049 Impl *const m_impl; 00050 const int m_types; 00051 int m_level; 00052 bool m_last; 00053 }; 00054 00055 public: 00056 00057 class AttributeIterator 00058 { 00059 friend class KEYXMLReader; 00060 00061 public: 00062 explicit AttributeIterator(const KEYXMLReader &reader); 00063 00064 bool next(); 00065 00066 const char *getName() const; 00067 const char *getNamespace() const; 00068 const char *getValue() const; 00069 00070 int getToken(const char *token) const; 00071 00072 private: 00073 bool move(); 00074 void read(); 00075 bool test(); 00076 00077 private: 00078 Impl *const m_impl; 00079 bool m_first; 00080 bool m_last; 00081 }; 00082 00083 class ElementIterator 00084 { 00085 public: 00086 explicit ElementIterator(const KEYXMLReader &reader); 00087 00088 bool next(); 00089 00090 const char *getName() const; 00091 const char *getNamespace() const; 00092 const char *getText() const; 00093 bool isEmpty() const; 00094 00095 int getToken(const char *token) const; 00096 00097 const NodeIterator &getNodeIterator() const; 00098 00099 private: 00100 NodeIterator m_iterator; 00101 }; 00102 00103 class MixedIterator 00104 { 00105 public: 00106 explicit MixedIterator(const KEYXMLReader &reader); 00107 00108 bool next(); 00109 00110 bool isElement() const; 00111 bool isText() const; 00112 00113 const char *getName() const; 00114 const char *getNamespace() const; 00115 const char *getText() const; 00116 bool isEmpty() const; 00117 00118 int getToken(const char *token) const; 00119 00120 const NodeIterator &getNodeIterator() const; 00121 00122 private: 00123 NodeIterator m_iterator; 00124 }; 00125 00126 typedef boost::function<int(const char *)> TokenizerFunction_t; 00127 00128 public: 00129 explicit KEYXMLReader(WPXInputStream *input); 00130 KEYXMLReader(WPXInputStream *input, TokenizerFunction_t tokenizer); 00131 KEYXMLReader(const ElementIterator &iterator); 00132 KEYXMLReader(const MixedIterator &iterator); 00133 ~KEYXMLReader(); 00134 00139 const char *getName() const; 00140 00145 const char *getNamespace() const; 00146 00147 int getToken(const char *token) const; 00148 00149 private: 00150 void initialize(WPXInputStream *input); 00151 00152 private: 00153 Impl *const m_impl; 00154 bool m_owner; 00155 }; 00156 00157 int getNameId(const KEYXMLReader::AttributeIterator &attribute); 00158 int getNamespaceId(const KEYXMLReader::AttributeIterator &attribute); 00159 int getId(const KEYXMLReader::AttributeIterator &attribute); 00160 int getValueId(const KEYXMLReader::AttributeIterator &attribute); 00161 00162 int getNameId(const KEYXMLReader::ElementIterator &element); 00163 int getNamespaceId(const KEYXMLReader::ElementIterator &element); 00164 int getId(const KEYXMLReader::ElementIterator &element); 00165 int getTextId(const KEYXMLReader::ElementIterator &element); 00166 00167 int getNameId(const KEYXMLReader &reader); 00168 int getNamespaceId(const KEYXMLReader &reader); 00169 int getId(const KEYXMLReader &reader); 00170 00171 } 00172 00173 #endif // KEYXMLREADER_H_INCLUDED 00174 00175 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */