]> git.sesse.net Git - casparcg/blobdiff - common/tweener.cpp
[ffmpeg] Removed unused code path
[casparcg] / common / tweener.cpp
index d19ba7f0435a95d9a21748ef035a6b8451bcbff3..e92cec8dbd3cf293437372707bbc5193a55b31e5 100644 (file)
@@ -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:
 #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>
@@ -55,7 +55,7 @@
 #include <algorithm>
 #include <vector>
 
-namespace caspar { namespace core {
+namespace caspar {
 
 typedef std::function<double(double, double, double, double)> tweener_t;
                        
@@ -435,7 +435,7 @@ const std::unordered_map<std::wstring, tween_t>& 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<double>());};
@@ -453,11 +453,9 @@ tweener_t get_tweener(std::wstring name)
                        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)
@@ -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<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;
 }
 
-}}
+}