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