sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
LineSpecsOf.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 LineSpecsOf : virtual public Specs<DerivedSpecs>
38 {
39  public:
42 
44  auto lineStyle(int value) -> DerivedSpecs&;
45 
47  auto lineType(int value) -> DerivedSpecs&;
48 
50  auto lineWidth(int value) -> DerivedSpecs&;
51 
53  auto lineColor(std::string value) -> DerivedSpecs&;
54 
56  auto dashType(int value) -> DerivedSpecs&;
57 
59  auto repr() const -> std::string;
60 
61  private:
63  std::string m_linestyle;
64 
66  std::string m_linetype;
67 
69  std::string m_linewidth;
70 
72  std::string m_linecolor;
73 
75  std::string m_dashtype;
76 };
77 
79 class LineSpecs : public LineSpecsOf<LineSpecs> {};
80 
81 template <typename DerivedSpecs>
83 {
84 }
85 
86 template <typename DerivedSpecs>
87 auto LineSpecsOf<DerivedSpecs>::lineStyle(int value) -> DerivedSpecs&
88 {
89  m_linestyle = "linestyle " + internal::str(value);
90  return static_cast<DerivedSpecs&>(*this);
91 }
92 
93 template <typename DerivedSpecs>
94 auto LineSpecsOf<DerivedSpecs>::lineType(int value) -> DerivedSpecs&
95 {
96  m_linetype = "linetype " + internal::str(value);
97  return static_cast<DerivedSpecs&>(*this);
98 }
99 
100 template <typename DerivedSpecs>
101 auto LineSpecsOf<DerivedSpecs>::lineWidth(int value) -> DerivedSpecs&
102 {
103  m_linewidth = "linewidth " + internal::str(value);
104  return static_cast<DerivedSpecs&>(*this);
105 }
106 
107 template <typename DerivedSpecs>
108 auto LineSpecsOf<DerivedSpecs>::lineColor(std::string value) -> DerivedSpecs&
109 {
110  m_linecolor = "linecolor '" + value + "'";
111  return static_cast<DerivedSpecs&>(*this);
112 }
113 
114 template <typename DerivedSpecs>
115 auto LineSpecsOf<DerivedSpecs>::dashType(int value) -> DerivedSpecs&
116 {
117  m_dashtype = "dashtype " + internal::str(value);
118  return static_cast<DerivedSpecs&>(*this);
119 }
120 
121 template <typename DerivedSpecs>
122 auto LineSpecsOf<DerivedSpecs>::repr() const -> std::string
123 {
124  std::stringstream ss; // ensure it remains empty if no line style option has been given!
125  ss << m_linestyle << " ";
126  ss << m_linetype << " ";
127  ss << m_linewidth << " ";
128  ss << m_linecolor << " ";
129  ss << m_dashtype << " ";
130  return internal::removeExtraWhitespaces(ss.str());
131 }
132 
133 } // namespace sciplot
auto lineWidth(int value) -> DerivedSpecs &
Set the line width of the underlying line object.
Definition: LineSpecsOf.hpp:101
auto repr() const -> std::string
Convert this LineSpecsOf object into a gnuplot formatted string.
Definition: LineSpecsOf.hpp:122
auto lineColor(std::string value) -> DerivedSpecs &
Set the line color of the underlying line object.
Definition: LineSpecsOf.hpp:108
The class used to attach line options to a type.
Definition: LineSpecsOf.hpp:38
auto lineType(int value) -> DerivedSpecs &
Set the line type of the underlying line object.
Definition: LineSpecsOf.hpp:94
The class used to specify line options.
Definition: LineSpecsOf.hpp:79
The base class for other specs classes (e.g., LineSpecsOf, DrawSpecs, BorderSpecs,...
Definition: Specs.hpp:36
auto lineStyle(int value) -> DerivedSpecs &
Set the line style of the underlying line object.
Definition: LineSpecsOf.hpp:87
LineSpecsOf()
Construct a default LineSpecsOf instance.
Definition: LineSpecsOf.hpp:82
auto dashType(int value) -> DerivedSpecs &
Set the dash type of the underlying line object.
Definition: LineSpecsOf.hpp:115