A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
definitions.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_FORMATS_SVG_DEFINITIONS_H_
2 #define GENESIS_UTILS_FORMATS_SVG_DEFINITIONS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
36 
37 #include <iosfwd>
38 #include <string>
39 
40 namespace genesis {
41 namespace utils {
42 
43 // =================================================================================================
44 // Svg Definitions
45 // =================================================================================================
46 
48 {
49 public:
50 
51  // -------------------------------------------------------------
52  // Typedefs and Enums
53  // -------------------------------------------------------------
54 
56 
57  // -------------------------------------------------------------
58  // Constructors and Rule of Five
59  // -------------------------------------------------------------
60 
61  template< typename T >
62  SvgDefinitions( T const& object )
63  : pimpl_( make_unique< Model<T> >( object ))
64  {}
65 
67  : pimpl_( other.pimpl_->clone() )
68  {}
69 
70  SvgDefinitions( SvgDefinitions&& ) = default;
71 
73  {
74  std::swap( pimpl_, other.pimpl_ );
75  return *this;
76  }
77 
78  // SvgDefinitions& operator= ( SvgDefinitions const& ) = default;
79  // SvgDefinitions& operator= ( SvgDefinitions&& ) = default;
80 
81  ~SvgDefinitions() = default;
82 
83  // -------------------------------------------------------------
84  // Members
85  // -------------------------------------------------------------
86 
87  void write(
88  std::ostream& out,
89  size_t indent = 0
90  ) const {
91  pimpl_->write_( out, indent );
92  }
93 
94  // -------------------------------------------------------------
95  // Internal Members
96  // -------------------------------------------------------------
97 
98 private:
99 
100  struct Concept
101  {
102  virtual ~Concept() {}
103 
104  virtual void write_(
105  std::ostream& out,
106  size_t indent = 0
107  ) const = 0;
108 
109  virtual std::unique_ptr< Concept > clone() const = 0;
110  };
111 
112  template< typename T >
113  struct Model : Concept
114  {
115  Model( T const& value )
116  : object_( value )
117  {}
118 
119  void write_(
120  std::ostream& out,
121  size_t indent = 0
122  ) const {
123  object_.write( out, indent );
124  }
125 
126  std::unique_ptr< Concept > clone() const
127  {
128  return make_unique< Model<T> >( object_ );
129  }
130 
131  T object_;
132  };
133 
134  std::unique_ptr< Concept > pimpl_;
135 
136 };
137 
138 } // namespace utils
139 } // namespace genesis
140 
141 #endif // include guard
void swap(SequenceSet &lhs, SequenceSet &rhs)
void write(std::ostream &out, size_t indent=0) const
Definition: definitions.hpp:87
Provides some valuable additions to STD.
SvgDefinitions(T const &object)
Definition: definitions.hpp:62
std::string indent(std::string const &text, std::string const &indentation)
Indent each line of text with indentation and return the result.
Definition: string.cpp:272
std::unique_ptr< T > make_unique(Args &&...args)
Returns a std::unique_ptr for a given type.
Definition: std.hpp:68
SvgDefinitions(SvgDefinitions const &other)
Definition: definitions.hpp:66
SvgDefinitions & operator=(SvgDefinitions other)
Definition: definitions.hpp:72