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