/*! * \brief ノードと位置の関係を表現するクラスです。 */ class Point { public: enum : int { Open = -1, Close = -2, Null = -3, }; public: Point(); Point(QDomNode const &node, int point = Open); int position() const; void clear(); bool operator ==(Point const &rhs) const; QDomNode& operator *(); QDomNode const& operator *() const; QDomNode* operator ->(); QDomNode const* operator ->() const; private: QDomNode m_node; int m_point; }; /*! * \brief QDomNodeの木構造に対するイテレータです。 * * 木構造を文書内の出現順に巡回します。 * 要素ノードは開始タグと終了タグの位置でマークします。 * * 要素ノードの終わり(終了タグ)は、NULLノードを返します。 * TEXTノードの終わりは、NULLノードを返しません。 * * 内容を持たない要素であっても、終了タグがあるかのようにふるまいます。 * 派生クラスでフィルター可能であること、終了マーカは深さ方向の移動時しか記録が必要ない * のでコストが低いことから、この動作を採用しました。 */ class NodeIterator { public: NodeIterator(); NodeIterator(QDomNode const &root); NodeIterator& operator ++(); NodeIterator operator ++(int); bool operator ==(NodeIterator const &rhs) const; bool operator !=(NodeIterator const &rhs) const; QDomNode& operator *(); QDomNode const& operator *() const; QDomNode* operator ->(); Point& point(); private: NodeIterator(Point const &point); Point const current() const; private: QStack<Point> m_stack; QDomNode m_null; }; TM::DOM::Point::Point() : m_point(Null) { } TM::DOM::Point::Point(QDomNode const &node, int point) : m_node(node) , m_point(point) { } int TM::DOM::Point::position() const { return m_point; } void TM::DOM::Point::clear() { m_point = Null; m_node.clear(); } bool TM::DOM::Point::operator ==(Point const &rhs) const { return m_node == rhs.m_node && m_point == rhs.m_point; } QDomNode& TM::DOM::Point::operator *() { return m_node; } QDomNode const& TM::DOM::Point::operator *() const { return m_node; } QDomNode* TM::DOM::Point::operator ->() { return &m_node; } QDomNode const* TM::DOM::Point::operator ->() const { return &m_node; } // NodeIterator --------------------------------------------------------------- /*! * \brief 末尾を示すイテレータを作成します。 */ TM::DOM::NodeIterator::NodeIterator() { } /*! * \brief 引数として与えられるノードから始まるイテレータを作成します。 * \param root 最初のノード。 */ TM::DOM::NodeIterator::NodeIterator(QDomNode const &root) { m_stack.push(Point(root, Point::Open)); } /*! * \brief 前置インクリメントです。 * \return インクリメントした後、自身への参照を返します。 */ TM::DOM::NodeIterator& TM::DOM::NodeIterator::operator ++() { Point current = m_stack.pop(); Q_ASSERT(current.position() != Point::Null); if(current.position() == Point::Open) { if(current->isElement()) m_stack.push(Point(*current, Point::Close)); // 終了マーカ QDomNode node = current->lastChild(); while(!node.isNull()) { m_stack.push(Point(node, Point::Open)); node = node.previousSibling(); } } return *this; } /*! * \brief 後置インクリメントです。 * \return インクリメントする前の自身のコピーを返します。 */ TM::DOM::NodeIterator TM::DOM::NodeIterator::operator ++(int) { NodeIterator self(current()); ++(*this); return self; } bool TM::DOM::NodeIterator::operator ==(NodeIterator const &rhs) const { return current() == rhs.current(); } bool TM::DOM::NodeIterator::operator !=(NodeIterator const &rhs) const { return !(*this == rhs); } QDomNode& TM::DOM::NodeIterator::operator *() { Q_ASSERT(!m_stack.isEmpty()); Point &point = m_stack.top(); return (point.position() == Point::Close) ? m_null : *point; } QDomNode const& TM::DOM::NodeIterator::operator *() const { Q_ASSERT(!m_stack.isEmpty()); Point const &point = m_stack.top(); return (point.position() == Point::Close) ? m_null : *point; } QDomNode* TM::DOM::NodeIterator::operator ->() { Q_ASSERT(!m_stack.isEmpty()); return &(**this); } TM::DOM::Point& TM::DOM::NodeIterator::point() { Q_ASSERT(!m_stack.isEmpty()); return m_stack.top(); } TM::DOM::NodeIterator::NodeIterator(const Point &point) { m_stack.push(point); } TM::DOM::Point const TM::DOM::NodeIterator::current() const { return m_stack.isEmpty() ? Point() : m_stack.top(); }
Standard input is empty
prog.cpp:12:17: error: expected ')' before 'const' Point(QDomNode const &node, int point = Open); ^ prog.cpp:18:2: error: 'QDomNode' does not name a type QDomNode& operator *(); ^ prog.cpp:19:2: error: 'QDomNode' does not name a type QDomNode const& operator *() const; ^ prog.cpp:20:2: error: 'QDomNode' does not name a type QDomNode* operator ->(); ^ prog.cpp:21:2: error: 'QDomNode' does not name a type QDomNode const* operator ->() const; ^ prog.cpp:24:2: error: 'QDomNode' does not name a type QDomNode m_node; ^ prog.cpp:45:24: error: expected ')' before 'const' NodeIterator(QDomNode const &root); ^ prog.cpp:53:2: error: 'QDomNode' does not name a type QDomNode& operator *(); ^ prog.cpp:54:2: error: 'QDomNode' does not name a type QDomNode const& operator *() const; ^ prog.cpp:55:2: error: 'QDomNode' does not name a type QDomNode* operator ->(); ^ prog.cpp:64:2: error: 'QStack' does not name a type QStack<Point> m_stack; ^ prog.cpp:65:2: error: 'QDomNode' does not name a type QDomNode m_null; ^ prog.cpp:68:1: error: 'TM' does not name a type TM::DOM::Point::Point() ^ prog.cpp:74:1: error: 'TM' does not name a type TM::DOM::Point::Point(QDomNode const &node, int point) ^ prog.cpp:81:5: error: 'TM' has not been declared int TM::DOM::Point::position() const ^ prog.cpp:81:32: error: non-member function 'int position()' cannot have cv-qualifier int TM::DOM::Point::position() const ^ prog.cpp: In function 'int position()': prog.cpp:83:9: error: 'm_point' was not declared in this scope return m_point; ^ prog.cpp: At global scope: prog.cpp:86:6: error: 'TM' has not been declared void TM::DOM::Point::clear() ^ prog.cpp: In function 'void clear()': prog.cpp:88:2: error: 'm_point' was not declared in this scope m_point = Null; ^ prog.cpp:88:12: error: 'Null' was not declared in this scope m_point = Null; ^ prog.cpp:89:2: error: 'm_node' was not declared in this scope m_node.clear(); ^ prog.cpp: At global scope: prog.cpp:92:6: error: 'TM' has not been declared bool TM::DOM::Point::operator ==(Point const &rhs) const ^ prog.cpp:92:52: error: non-member function 'bool operator==(const Point&)' cannot have cv-qualifier bool TM::DOM::Point::operator ==(Point const &rhs) const ^ prog.cpp:92:52: error: 'bool operator==(const Point&)' must take exactly two arguments prog.cpp:97:1: error: 'QDomNode' does not name a type QDomNode& TM::DOM::Point::operator *() ^ prog.cpp:102:1: error: 'QDomNode' does not name a type QDomNode const& TM::DOM::Point::operator *() const ^ prog.cpp:107:1: error: 'QDomNode' does not name a type QDomNode* TM::DOM::Point::operator ->() ^ prog.cpp:112:1: error: 'QDomNode' does not name a type QDomNode const* TM::DOM::Point::operator ->() const ^ prog.cpp:122:1: error: 'TM' does not name a type TM::DOM::NodeIterator::NodeIterator() ^ prog.cpp:131:1: error: 'TM' does not name a type TM::DOM::NodeIterator::NodeIterator(QDomNode const &root) ^ prog.cpp:140:1: error: 'TM' does not name a type TM::DOM::NodeIterator& TM::DOM::NodeIterator::operator ++() ^ prog.cpp:162:1: error: 'TM' does not name a type TM::DOM::NodeIterator TM::DOM::NodeIterator::operator ++(int) ^ prog.cpp:169:6: error: 'TM' has not been declared bool TM::DOM::NodeIterator::operator ==(NodeIterator const &rhs) const ^ prog.cpp:169:66: error: non-member function 'bool operator==(const NodeIterator&)' cannot have cv-qualifier bool TM::DOM::NodeIterator::operator ==(NodeIterator const &rhs) const ^ prog.cpp:169:66: error: 'bool operator==(const NodeIterator&)' must take exactly two arguments prog.cpp:174:6: error: 'TM' has not been declared bool TM::DOM::NodeIterator::operator !=(NodeIterator const &rhs) const ^ prog.cpp:174:66: error: non-member function 'bool operator!=(const NodeIterator&)' cannot have cv-qualifier bool TM::DOM::NodeIterator::operator !=(NodeIterator const &rhs) const ^ prog.cpp:174:66: error: 'bool operator!=(const NodeIterator&)' must take exactly two arguments prog.cpp:179:1: error: 'QDomNode' does not name a type QDomNode& TM::DOM::NodeIterator::operator *() ^ prog.cpp:186:1: error: 'QDomNode' does not name a type QDomNode const& TM::DOM::NodeIterator::operator *() const ^ prog.cpp:193:1: error: 'QDomNode' does not name a type QDomNode* TM::DOM::NodeIterator::operator ->() ^ prog.cpp:199:1: error: 'TM' does not name a type TM::DOM::Point& TM::DOM::NodeIterator::point() ^ prog.cpp:205:1: error: 'TM' does not name a type TM::DOM::NodeIterator::NodeIterator(const Point &point) ^ prog.cpp:210:1: error: 'TM' does not name a type TM::DOM::Point const TM::DOM::NodeIterator::current() const ^
Standard output is empty