Ardour  9.2-541-gc1841a13dd
ardour/ardour/types_convert.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef ARDOUR_TYPES_CONVERT_H
21 #define ARDOUR_TYPES_CONVERT_H
22 
23 #ifdef COMPILER_MSVC
24 #pragma warning(disable:4101)
25 #endif
26 
27 #include "pbd/enum_convert.h"
28 
29 #include "ardour/types.h"
30 #include "ardour/data_type.h"
31 #include "ardour/scale.h"
32 
33 /* NOTE: when adding types to this file, you must add four functions:
34 
35  std::string to_string (T);
36  T string_to (std::string const &);
37  bool to_string (T, std::string &);
38  bool string_to (std::string const &, T&);
39 */
40 
41 namespace PBD {
42 
44 
97 
99 
100 template <>
101 inline bool to_string (ARDOUR::AnyTime const & at, std::string & str)
102 {
103  str = at.str();
104  return true;
105 }
106 
107 template <>
108 inline bool string_to (std::string const & str, ARDOUR::AnyTime & at)
109 {
110  at = ARDOUR::AnyTime (str);
111  return true;
112 }
113 
114 template <>
115 inline std::string to_string (ARDOUR::AnyTime at)
116 {
117  return at.str();
118 }
119 
120 template <>
121 inline ARDOUR::AnyTime string_to (std::string const & str)
122 {
123  return ARDOUR::AnyTime (str);
124 }
125 
126 template <>
127 inline std::string to_string (ARDOUR::timepos_t val)
128 {
129  return val.str ();
130 }
131 
132 template <>
133 inline ARDOUR::timepos_t string_to (std::string const & str)
134 {
135  ARDOUR::timepos_t tmp (Temporal::AudioTime); /* domain may be changed */
136  tmp.string_to (str);
137  return tmp;
138 }
139 
140 template <>
141 inline bool to_string (ARDOUR::timepos_t val, std::string & str)
142 {
143  str = val.str ();
144  return true;
145 }
146 
147 template <>
148 inline bool string_to (std::string const & str, ARDOUR::timepos_t & val)
149 {
150  return val.string_to (str);
151 }
152 
153 
154 template <>
155 inline std::string to_string (ARDOUR::timecnt_t val)
156 {
157  return val.str ();
158 }
159 
160 template <>
161 inline ARDOUR::timecnt_t string_to (std::string const & str)
162 {
163  ARDOUR::timecnt_t tmp (Temporal::AudioTime); /* domain may change */
164  tmp.string_to (str);
165  return tmp;
166 }
167 
168 template <>
169 inline bool to_string (ARDOUR::timecnt_t val, std::string & str)
170 {
171  str = val.str ();
172  return true;
173 }
174 
175 template <>
176 inline bool string_to (std::string const & str, ARDOUR::timecnt_t & val)
177 {
178  return val.string_to (str);
179 }
180 
181 template <>
182 inline bool to_string (ARDOUR::AutoState val, std::string& str)
183 {
184  str = ARDOUR::auto_state_to_string (val);
185  return true;
186 }
187 
188 template <>
189 inline bool string_to (const std::string& str, ARDOUR::AutoState& as)
190 {
191  as = ARDOUR::string_to_auto_state (str);
192  return true;
193 }
194 
195 template <>
196 inline bool to_string (ARDOUR::DataType val, std::string& str)
197 {
198  str = val.to_string();
199  return true;
200 }
201 
202 template <>
203 inline bool string_to (const std::string& str, ARDOUR::DataType& dt)
204 {
205  dt = ARDOUR::DataType(str);
206  return true;
207 }
208 
209 template <>
210 inline bool to_string (ARDOUR::FollowAction fa, std::string& str)
211 {
212  str = fa.to_string();
213  return true;
214 }
215 
216 template <>
217 inline bool string_to (const std::string& str, ARDOUR::FollowAction& fa)
218 {
219  fa = ARDOUR::FollowAction (str);
220  return true;
221 }
222 
223 template<>
224 inline std::string to_string (ARDOUR::FollowAction fa)
225 {
226  return fa.to_string ();
227 }
228 
229 template<>
230 inline ARDOUR::FollowAction string_to (std::string const & str)
231 {
232  return ARDOUR::FollowAction (str);
233 }
234 
235 
236 } // namespace PBD
237 
238 #endif // ARDOUR_TYPES_CONVERT_H
std::string str() const
const char * to_string() const
Definition: data_type.h:82
std::string str() const
bool string_to(std::string const &str)
bool string_to(std::string const &str)
std::string str() const
std::string auto_state_to_string(AutoState)
AutoState string_to_auto_state(std::string)
TimeSelectionAfterSectionPaste
Definition: axis_view.h:42
DEFINE_ENUM_CONVERT(ARDOUR::DSP::PerceptualAnalyzer::Speed)
bool to_string(ARDOUR::AnyTime const &at, std::string &str)
bool string_to(std::string const &str, ARDOUR::AnyTime &at)
TimecodeFormat
Definition: time.h:38
std::string to_string() const