stlab.adobe.com Adobe Systems Incorporated

value_range_format.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /****************************************************************************************************/
00008 
00009 #ifndef ADOBE_VALUE_RANGE_FORMAT_HPP
00010 #define ADOBE_VALUE_RANGE_FORMAT_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <adobe/any_regular.hpp>
00017 #include <adobe/cmath.hpp>
00018 #include <adobe/dictionary.hpp>
00019 #include <adobe/name.hpp>
00020 
00021 #include <adobe/future/widgets/headers/widget_tokens.hpp>
00022 
00023 /*************************************************************************************************/
00024 
00025 namespace adobe {
00026 
00027 /*************************************************************************************************/
00028 
00029 /*
00030     REVISIT (sparent) : This is a simple filter for handling sliders. The general notion of a
00031     filter should describe a set of valid values (potentially infinite - such as all positive
00032     numbers).
00033 
00034     This should be considered a starting point for such a classification.
00035 */
00036 
00037 class value_range_format_t
00038 {
00039 public:
00040     value_range_format_t() :
00041         first_m (0.0),
00042         last_m (0.0),
00043         interval_count_m (0)
00044     { }
00045 
00046     void set(const dictionary_t& parameters)
00047     {
00048         get_value(parameters, key_first, first_m);
00049         get_value(parameters, key_last, last_m);
00050 
00051         double interval_count_double(last_m - first_m);
00052         get_value(parameters, key_interval_count, interval_count_double);
00053         interval_count_m = static_cast<std::size_t>(interval_count_double);
00054     }
00055 
00056     std::size_t size() const
00057     { return interval_count_m; }
00058 
00059     const any_regular_t& at(std::size_t index) const
00060     {
00061         double result(double(index) / double(interval_count_m) * (last_m - first_m) + first_m);
00062 
00063         result = (std::min)((std::max)(first_m, result), last_m);
00064 
00065         result_m.assign(result);
00066 
00067         return result_m;
00068     }
00069 
00070     std::size_t find(const any_regular_t& source) const
00071     {
00072         double result = adobe::round(double(interval_count_m) * (source.cast<double>() - first_m) / (last_m - first_m));
00073 
00074         return static_cast<std::size_t>(std::min<double>(std::max<double>(0, result), double(interval_count_m)));
00075     }
00076 
00077     friend bool operator==(const value_range_format_t& lhs, const value_range_format_t& rhs)
00078     {
00079         return lhs.first_m == rhs.first_m &&
00080                lhs.last_m == rhs.last_m &&
00081                lhs.interval_count_m == rhs.interval_count_m &&
00082                lhs.result_m == rhs.result_m;
00083     }
00084 
00085 private:
00086     double                       first_m;
00087     double                       last_m;
00088     std::size_t                  interval_count_m;
00089     mutable any_regular_t result_m;
00090 };
00091 
00092 /****************************************************************************************************/
00093 
00094 } // namespace adobe
00095 
00096 /****************************************************************************************************/
00097 
00098 #endif
00099 
00100 /****************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google