X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Ftweener.cpp;h=e92cec8dbd3cf293437372707bbc5193a55b31e5;hb=92e13a827000914bc26d2839292f46098f53ee78;hp=d19ba7f0435a95d9a21748ef035a6b8451bcbff3;hpb=de5b6c0f75961f39927449ca45e7c0045c996204;p=casparcg diff --git a/common/tweener.cpp b/common/tweener.cpp index d19ba7f04..e92cec8db 100644 --- a/common/tweener.cpp +++ b/common/tweener.cpp @@ -28,7 +28,7 @@ // //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: @@ -43,10 +43,10 @@ #include "tweener.h" #include "except.h" +#include "linq.h" #include #include -#include #include #include @@ -55,7 +55,7 @@ #include #include -namespace caspar { namespace core { +namespace caspar { typedef std::function tweener_t; @@ -435,7 +435,7 @@ const std::unordered_map& get_tweens() 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());}; @@ -453,11 +453,9 @@ tweener_t get_tweener(std::wstring name) params.push_back(boost::lexical_cast(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) @@ -468,28 +466,43 @@ tweener_t get_tweener(std::wstring name) 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& tweener::names() { - using namespace boost::adaptors; + /*static const auto names = cpplinq::from(get_tweens()) + .select(keys()) + .to_vector();*/ + + static const auto result = [] + { + std::vector tweens; + + for (auto& tween : get_tweens()) + tweens.push_back(tween.first); - static const std::vector names( - (get_tweens() | map_keys).begin(), - (get_tweens() | map_keys).end()); + return tweens; + }(); + //static const std::vector result; - return names; + return result; } -}} +}