Ardour  8.7-14-g57a6773833
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 std::string to_string (ARDOUR::timepos_t val)
99 {
100  return val.str ();
101 }
102 
103 template <>
104 inline ARDOUR::timepos_t string_to (std::string const & str)
105 {
106  ARDOUR::timepos_t tmp (Temporal::AudioTime); /* domain may be changed */
107  tmp.string_to (str);
108  return tmp;
109 }
110 
111 template <>
112 inline bool to_string (ARDOUR::timepos_t val, std::string & str)
113 {
114  str = val.str ();
115  return true;
116 }
117 
118 template <>
119 inline bool string_to (std::string const & str, ARDOUR::timepos_t & val)
120 {
121  return val.string_to (str);
122 }
123 
124 
125 template <>
126 inline std::string to_string (ARDOUR::timecnt_t val)
127 {
128  return val.str ();
129 }
130 
131 template <>
132 inline ARDOUR::timecnt_t string_to (std::string const & str)
133 {
134  ARDOUR::timecnt_t tmp (Temporal::AudioTime); /* domain may change */
135  tmp.string_to (str);
136  return tmp;
137 }
138 
139 template <>
140 inline bool to_string (ARDOUR::timecnt_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::timecnt_t & val)
148 {
149  return val.string_to (str);
150 }
151 
152 template <>
153 inline bool to_string (ARDOUR::AutoState val, std::string& str)
154 {
155  str = ARDOUR::auto_state_to_string (val);
156  return true;
157 }
158 
159 template <>
160 inline bool string_to (const std::string& str, ARDOUR::AutoState& as)
161 {
162  as = ARDOUR::string_to_auto_state (str);
163  return true;
164 }
165 
166 template <>
167 inline bool to_string (ARDOUR::DataType val, std::string& str)
168 {
169  str = val.to_string();
170  return true;
171 }
172 
173 template <>
174 inline bool string_to (const std::string& str, ARDOUR::DataType& dt)
175 {
176  dt = ARDOUR::DataType(str);
177  return true;
178 }
179 
180 template <>
181 inline bool to_string (ARDOUR::FollowAction fa, std::string& str)
182 {
183  str = fa.to_string();
184  return true;
185 }
186 
187 template <>
188 inline bool string_to (const std::string& str, ARDOUR::FollowAction& fa)
189 {
190  fa = ARDOUR::FollowAction (str);
191  return true;
192 }
193 
194 template<>
195 inline std::string to_string (ARDOUR::FollowAction fa)
196 {
197  return fa.to_string ();
198 }
199 
200 template<>
201 inline ARDOUR::FollowAction string_to (std::string const & str)
202 {
203  return ARDOUR::FollowAction (str);
204 }
205 
206 
207 } // namespace PBD
208 
209 #endif // ARDOUR_TYPES_CONVERT_H
const char * to_string() const
Definition: data_type.h:83
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::Track::FreezeState)
std::string to_string(ARDOUR::timepos_t val)
ARDOUR::timepos_t string_to(std::string const &str)
TimecodeFormat
Definition: time.h:39
std::string to_string() const