2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
24 #include "../variable.h"
26 namespace caspar { namespace core { namespace scene {
28 typedef std::function<variable& (const std::wstring& name)> variable_repository;
30 boost::any parse_expression(
31 std::wstring::const_iterator& cursor,
32 const std::wstring& str,
33 const variable_repository& var_repo);
36 bool is(const boost::any& value)
38 return value.type() == typeid(T);
42 T as(const boost::any& value)
44 return boost::any_cast<T>(value);
48 static binding<T> parse_expression(
49 const std::wstring& str, const variable_repository& var_repo)
51 auto cursor = str.cbegin();
52 auto expr = parse_expression(cursor, str, var_repo);
54 if (is<binding<T>>(expr))
55 return boost::any_cast<binding<T>>(expr);
57 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(
58 L"parse_expression() Unsupported type "
59 + u16(expr.type().name())));
63 binding<std::wstring> parse_expression(
64 const std::wstring& str, const variable_repository& var_repo)
66 auto cursor = str.cbegin();
67 auto expr = parse_expression(cursor, str, var_repo);
69 if (is<binding<std::wstring>>(expr))
70 return as<binding<std::wstring>>(expr);
71 else if (is<binding<double>>(expr))
72 return as<binding<double>>(expr).as<std::wstring>();
74 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(
75 L"parse_expression() Unsupported type "
76 + u16(expr.type().name())));