libhext: C++ Library Documentation  1.0.8-3ad0ae4
Capture.h
Go to the documentation of this file.
1 // Copyright 2015-2017 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_CAPTURE_H_INCLUDED
16 #define HEXT_CAPTURE_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::Capture
20 
21 #include "hext/Result.h"
22 #include "hext/Visibility.h"
23 
24 #include <memory>
25 #include <optional>
26 
27 #include <gumbo.h>
28 
29 
30 namespace hext {
31 
32 
33 /// Abstract base for every Capture.
34 ///
35 /// Captures are applied to HTML elements with Capture::capture() which will
36 /// return either a ResultPair, or an empty optional if there was nothing to
37 /// capture.
38 ///
39 /// Note: You probably don't want to inherit from this class directly, unless
40 /// you want to provide your own Capture::clone() method. If your subclass
41 /// has a copy constructor, you can extend from
42 /// hext::Cloneable<YourSubclass, hext::Capture> which provides a generic
43 /// clone method.
45 {
46 public:
47  Capture() noexcept = default;
48  Capture(const Capture&) = default;
49  Capture(Capture&&) noexcept = default;
50  Capture& operator=(const Capture&) = default;
51  Capture& operator=(Capture&&) noexcept = default;
52  virtual ~Capture() noexcept = default;
53 
54  /// Clones derived object.
55  virtual std::unique_ptr<Capture> clone() const = 0;
56 
57  /// Returns a name/value pair with the captured contents or an empty optional,
58  /// if there was nothing to capture.
59  virtual std::optional<ResultPair> capture(const GumboNode * node) const = 0;
60 };
61 
62 
63 } // namespace hext
64 
65 
66 #endif // HEXT_CAPTURE_H_INCLUDED
67 
Typedefs for results returned from capturing HTML.
Defines HEXT_PUBLIC and HEXT_PRIVATE.
#define HEXT_PUBLIC
Definition: Visibility.h:26
Abstract base for every Capture.
Definition: Capture.h:45
Capture() noexcept=default
std::pair< std::string, std::string > ResultPair
A string-pair containing a name and a value.
Definition: Result.h:32