hcxselect
1.1
A CSS selector engine for htmlcxx
|
00001 /* 00002 * hcxselect - A CSS selector engine for htmlcxx 00003 * Copyright (C) 2011 Jonas Gehring 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the copyright holders nor the 00014 * names of its contributors may be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 00031 #ifndef HCXSELECT_H_ 00032 #define HCXSELECT_H_ 00033 00034 #include <exception> 00035 #include <string> 00036 #include <set> 00037 00038 #include <htmlcxx/html/Node.h> 00039 #include <htmlcxx/html/tree.h> 00040 00041 #define HCXSELECT_VERSION_STR "1.1" 00042 #define HCXSELECT_VERSION_MAJOR 1 00043 #define HCXSELECT_VERSION_MINOR 1 00044 #define HCXSELECT_VERSION_RELEASE 0 00045 00046 00050 namespace hcxselect 00051 { 00052 00057 typedef tree_node_<htmlcxx::HTML::Node> Node; 00058 00062 struct NodeComp { 00063 bool operator()(Node *a, Node *b) const; 00064 }; 00065 00072 typedef std::set<Node *, NodeComp> NodeSet; 00073 00074 00083 NodeSet select(const tree<htmlcxx::HTML::Node> &tree, const std::string &expr); 00084 00093 NodeSet select(const NodeSet &nodes, const std::string &expr); 00094 00095 00102 class Selection : public NodeSet 00103 { 00104 public: 00105 Selection(); 00106 Selection(const tree<htmlcxx::HTML::Node> &tree, const std::string &expr = std::string()); 00107 Selection(const NodeSet &nodes, const std::string &expr = std::string()); 00108 00109 Selection select(const std::string &expr); 00110 }; 00111 00112 typedef Selection Selector; 00113 00114 00118 class ParseException : std::exception 00119 { 00120 public: 00124 ParseException(int pos, const char *info = NULL) 00125 : m_pos(pos), m_info(info) { } 00126 00130 const char *what() const throw() { return m_info; } 00131 00135 int position() const throw() { return m_pos; } 00136 00137 private: 00138 int m_pos; 00139 const char *m_info; 00140 }; 00141 00142 } // namespace hcxselect 00143 00144 #endif // HCXSELECT_H_