Ardour  9.2-79-gba93f2fe52
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/mode.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 
96 
98 
99 template <>
100 inline bool to_string (ARDOUR::AnyTime const & at, std::string & str)
101 {
102  str = at.str();
103  return true;
104 }
105 
106 template <>
107 inline bool string_to (std::string const & str, ARDOUR::AnyTime & at)
108 {
109  at = ARDOUR::AnyTime (str);
110  return true;
111 }
112 
113 template <>
114 inline std::string to_string (ARDOUR::AnyTime at)
115 {
116  return at.str();
117 }
118 
119 template <>
120 inline ARDOUR::AnyTime string_to (std::string const & str)
121 {
122  return ARDOUR::AnyTime (str);
123 }
124 
125 template <>
126 inline std::string to_string (ARDOUR::timepos_t val)
127 {
128  return val.str ();
129 }
130 
131 template <>
132 inline ARDOUR::timepos_t string_to (std::string const & str)
133 {
134  ARDOUR::timepos_t tmp (Temporal::AudioTime); /* domain may be changed */
135  tmp.string_to (str);
136  return tmp;
137 }
138 
139 template <>
140 inline bool to_string (ARDOUR::timepos_t val, std::string & str)
141 {
142  str = val.str ();
143  return true;
144 }
145 
146 template <>
147 inline bool string_to (std::string const & str, ARDOUR::timepos_t & val)
148 {
149  return val.string_to (str);
150 }
151 
152 
153 template <>
154 inline std::string to_string (ARDOUR::timecnt_t val)
155 {
156  return val.str ();
157 }
158 
159 template <>
160 inline ARDOUR::timecnt_t string_to (std::string const & str)
161 {
162  ARDOUR::timecnt_t tmp (Temporal::AudioTime); /* domain may change */
163  tmp.string_to (str);
164  return tmp;
165 }
166 
167 template <>
168 inline bool to_string (ARDOUR::timecnt_t val, std::string & str)
169 {
170  str = val.str ();
171  return true;
172 }
173 
174 template <>
175 inline bool string_to (std::string const & str, ARDOUR::timecnt_t & val)
176 {
177  return val.string_to (str);
178 }
179 
180 template <>
181 inline bool to_string (ARDOUR::AutoState val, std::string& str)
182 {
183  str = ARDOUR::auto_state_to_string (val);
184  return true;
185 }
186 
187 template <>
188 inline bool string_to (const std::string& str, ARDOUR::AutoState& as)
189 {
190  as = ARDOUR::string_to_auto_state (str);
191  return true;
192 }
193 
194 template <>
195 inline bool to_string (ARDOUR::DataType val, std::string& str)
196 {
197  str = val.to_string();
198  return true;
199 }
200 
201 template <>
202 inline bool string_to (const std::string& str, ARDOUR::DataType& dt)
203 {
204  dt = ARDOUR::DataType(str);
205  return true;
206 }
207 
208 template <>
209 inline bool to_string (ARDOUR::FollowAction fa, std::string& str)
210 {
211  str = fa.to_string();
212  return true;
213 }
214 
215 template <>
216 inline bool string_to (const std::string& str, ARDOUR::FollowAction& fa)
217 {
218  fa = ARDOUR::FollowAction (str);
219  return true;
220 }
221 
222 template<>
223 inline std::string to_string (ARDOUR::FollowAction fa)
224 {
225  return fa.to_string ();
226 }
227 
228 template<>
229 inline ARDOUR::FollowAction string_to (std::string const & str)
230 {
231  return ARDOUR::FollowAction (str);
232 }
233 
234 
235 } // namespace PBD
236 
237 #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