sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
PointSpecsOf.hpp
1 // sciplot - a modern C++ scientific plotting library powered by gnuplot
2 // https://github.com/sciplot/sciplot
3 //
4 // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
5 //
6 // Copyright (c) 2018-2021 Allan Leal
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 // sciplot includes
29 #include <sciplot/Default.hpp>
30 #include <sciplot/specs/Specs.hpp>
31 #include <sciplot/Utils.hpp>
32 
33 namespace sciplot {
34 
36 template <typename DerivedSpecs>
37 class PointSpecsOf : virtual public Specs<DerivedSpecs>
38 {
39  public:
42 
44  auto pointType(int value) -> DerivedSpecs&;
45 
47  auto pointSize(int value) -> DerivedSpecs&;
48 
50  auto repr() const -> std::string;
51 
52  private:
54  std::string m_pointtype;
55 
57  std::string m_pointsize;
58 };
59 
61 class PointSpecs : public PointSpecsOf<PointSpecs> {};
62 
63 template <typename DerivedSpecs>
65 {
66 }
67 
68 template <typename DerivedSpecs>
69 auto PointSpecsOf<DerivedSpecs>::pointType(int value) -> DerivedSpecs&
70 {
71  m_pointtype = "pointtype " + internal::str(value);
72  return static_cast<DerivedSpecs&>(*this);
73 }
74 
75 template <typename DerivedSpecs>
76 auto PointSpecsOf<DerivedSpecs>::pointSize(int value) -> DerivedSpecs&
77 {
78  m_pointsize = "pointsize " + internal::str(value);
79  return static_cast<DerivedSpecs&>(*this);
80 }
81 
82 template <typename DerivedSpecs>
83 auto PointSpecsOf<DerivedSpecs>::repr() const -> std::string
84 {
85  std::stringstream ss; // ensure it remains empty if no point style option has been given!
86  ss << m_pointtype << " ";
87  ss << m_pointsize;
88  return internal::removeExtraWhitespaces(ss.str());
89 }
90 
91 } // namespace sciplot
auto repr() const -> std::string
Convert this PointSpecsOf object into a gnuplot formatted string.
Definition: PointSpecsOf.hpp:83
auto pointSize(int value) -> DerivedSpecs &
Set the point size of the underlying plot object.
Definition: PointSpecsOf.hpp:76
PointSpecsOf()
Construct a default PointSpecsOf instance.
Definition: PointSpecsOf.hpp:64
The base class for other specs classes (e.g., LineSpecsOf, DrawSpecs, BorderSpecs,...
Definition: Specs.hpp:36
The class used to specify point options.
Definition: PointSpecsOf.hpp:61
auto pointType(int value) -> DerivedSpecs &
Set the point type of the underlying plot object.
Definition: PointSpecsOf.hpp:69
The class used to attach point options to a type.
Definition: PointSpecsOf.hpp:38