//
//Open source under the BSD License.
//
-//Copyright © 2001 Robert Penner
+//Copyright � 2001 Robert Penner
//All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#include "tweener.h"
#include "except.h"
+#include "linq.h"
#include <boost/regex.hpp>
#include <boost/lexical_cast.hpp>
-#include <boost/range/adaptor/map.hpp>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <vector>
-namespace caspar { namespace core {
+namespace caspar {
typedef std::function<double(double, double, double, double)> tweener_t;
tweener_t get_tweener(std::wstring name)
{
- std::transform(name.begin(), name.end(), name.begin(), std::tolower);
+ std::transform(name.begin(), name.end(), name.begin(), std::towlower);
if(name == L"linear")
return [](double t, double b, double c, double d){return ease_none(t, b, c, d, std::vector<double>());};
params.push_back(boost::lexical_cast<double>(what["V1"].str()));
}
- auto tweens = get_tweens();
-
- auto it = tweens.find(name);
- if(it == tweens.end())
- CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Could not find tween.") << arg_value_info(name));
+ auto it = get_tweens().find(name);
+ if(it == get_tweens().end())
+ CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Could not find tween " + name));
auto tween = it->second;
return [=](double t, double b, double c, double d)
tweener::tweener(const std::wstring& name)
: func_(get_tweener(name))
+ , name_(name)
{
}
-tweener::tweener(const wchar_t* name)
- : func_(get_tweener(name))
+double tweener::operator()(double t, double b , double c, double d) const
{
+ return func_(t, b, c, d);
}
-double tweener::operator()(double t, double b , double c, double d) const
+bool tweener::operator==(const tweener& other) const
{
- return func_(t, b, c, d);
+ return name_ == other.name_;
+}
+
+bool tweener::operator!=(const tweener& other) const
+{
+ return !(*this == other);
}
const std::vector<std::wstring>& tweener::names()
{
- using namespace boost::adaptors;
+ /*static const auto names = cpplinq::from(get_tweens())
+ .select(keys())
+ .to_vector();*/
+
+ static const auto result = []
+ {
+ std::vector<std::wstring> tweens;
+
+ for (auto& tween : get_tweens())
+ tweens.push_back(tween.first);
- static const std::vector<std::wstring> names(
- (get_tweens() | map_keys).begin(),
- (get_tweens() | map_keys).end());
+ return tweens;
+ }();
+ //static const std::vector<std::wstring> result;
- return names;
+ return result;
}
-}}
+}