All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
AttributeCountMatch.h
Go to the documentation of this file.
1 // Copyright 2015, 2016 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 #include "hext/Visibility.h"
24 
25 #include <gumbo.h>
26 
27 
28 namespace hext {
29 
30 
31 /// Matches HTML elements that have a certain amount of HTML attributes.
32 ///
33 /// @par Example:
34 /// ~~~~~~~~~~~~~
35 /// GumboNode * no_attrs = ...; // <hr/>
36 /// GumboNode * two_attrs = ...; // <img class="picture" src="mona-lisa.jpg"/>
37 ///
38 /// AttributeCountMatch m_no_attr (/* attribute count */ 0);
39 /// AttributeCountMatch m_two_attr(/* attribute count */ 2);
40 ///
41 /// assert(m_no_attr.matches(no_attrs));
42 /// assert(m_two_attr.matches(two_attrs));
43 ///
44 /// assert(!m_two_attr.matches(no_attrs));
45 /// assert(!m_no_attr.matches(two_attrs));
46 /// ~~~~~~~~~~~~~
48  : public Cloneable<AttributeCountMatch, Match>
49 {
50 public:
51  /// Constructs an AttributeCountMatch that matches HTML elements that have a
52  /// certain amount of HTML attributes.
53  ///
54  /// @param attribute_count: The amount of HTML attributes a node must have
55  /// in order to match.
56  explicit AttributeCountMatch(unsigned int attribute_count) noexcept;
57 
58  /// Returns true if node has exactly attribute_count amount of HTML
59  /// attributes.
60  ///
61  /// @param node: A pointer to a GumboNode of type GUMBO_NODE_ELEMENT.
62  bool matches(const GumboNode * node) const noexcept override;
63 
64 private:
65  /// The amount of HTML attributes an HTML element must have in order to match.
66  unsigned int attribute_count_;
67 };
68 
69 
70 } // namespace hext
71 
72 
73 #endif // HEXT_ATTRIBUTE_COUNT_MATCH_H_INCLUDED
74 
Defines HEXT_PUBLIC and HEXT_PRIVATE.
Matches HTML elements that have a certain amount of HTML attributes.
#define HEXT_PUBLIC
Definition: Visibility.h:26
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:36
Declares hext::Match.
Defines template hext::Cloneable.