All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Capture.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_CAPTURE_H_INCLUDED
16 #define HEXT_CAPTURE_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::Capture
20 
21 #include "hext/Result.h"
22 
23 #include <memory>
24 
25 #include <boost/optional.hpp>
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.
44 class Capture
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 boost::optional<ResultPair> capture(const GumboNode * node) const = 0;
60 };
61 
62 
63 } // namespace hext
64 
65 
66 #endif // HEXT_CAPTURE_H_INCLUDED
67 
virtual boost::optional< ResultPair > capture(const GumboNode *node) const =0
Returns a name/value pair with the captured contents or an empty optional, if there was nothing to ca...
virtual std::unique_ptr< Capture > clone() const =0
Clones derived object.
Capture() noexcept=default
Typedefs for results returned from capturing HTML.
Abstract base for every Capture.
Definition: Capture.h:44
virtual ~Capture() noexcept=default
Capture & operator=(const Capture &)=default