All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
AttributeCountMatch.h
Go to the documentation of this file.
1 // Copyright 2015 Thomas Trapp
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEXT_ATTRIBUTE_COUNT_MATCH_H_INCLUDED
16 #define HEXT_ATTRIBUTE_COUNT_MATCH_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::AttributeCountMatch
20 
21 #include "hext/Cloneable.h"
22 #include "hext/Match.h"
23 
24 #include <gumbo.h>
25 
26 
27 namespace hext {
28 
29 
30 /// Matches HTML elements that have a certain amount of HTML attributes.
31 ///
32 /// @par Example:
33 /// ~~~~~~~~~~~~~
34 /// GumboNode * no_attrs = ...; // <hr/>
35 /// GumboNode * two_attrs = ...; // <img class="picture" src="mona-lisa.jpg"/>
36 ///
37 /// AttributeCountMatch m_no_attr (/* attribute count */ 0);
38 /// AttributeCountMatch m_two_attr(/* attribute count */ 2);
39 ///
40 /// assert(m_no_attr.matches(no_attrs));
41 /// assert(m_two_attr.matches(two_attrs));
42 ///
43 /// assert(!m_two_attr.matches(no_attrs));
44 /// assert(!m_no_attr.matches(two_attrs));
45 /// ~~~~~~~~~~~~~
46 class AttributeCountMatch final : public Cloneable<AttributeCountMatch, Match>
47 {
48 public:
49  /// Constructs an AttributeCountMatch that matches HTML elements that have a
50  /// certain amount of HTML attributes.
51  ///
52  /// @param attribute_count: The amount of HTML attributes a node must have
53  /// in order to match.
54  explicit AttributeCountMatch(unsigned int attribute_count) noexcept;
55 
56  /// Returns true if node has exactly attribute_count amount of HTML
57  /// attributes.
58  ///
59  /// @param node: A pointer to a GumboNode of type GUMBO_NODE_ELEMENT.
60  bool matches(const GumboNode * node) const noexcept override;
61 
62 private:
63  /// The amount of HTML attributes an HTML element must have in order to match.
64  unsigned int attribute_count_;
65 };
66 
67 
68 } // namespace hext
69 
70 
71 #endif // HEXT_ATTRIBUTE_COUNT_MATCH_H_INCLUDED
72 
AttributeCountMatch(unsigned int attribute_count) noexcept
Constructs an AttributeCountMatch that matches HTML elements that have a certain amount of HTML attri...
Matches HTML elements that have a certain amount of HTML attributes.
bool matches(const GumboNode *node) const noexceptoverride
Returns true if node has exactly attribute_count amount of HTML attributes.
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:34
Declares hext::Match.
Defines template hext::Cloneable.