stlab.adobe.com Adobe Systems Incorporated

macintosh_metric_extractor.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_METRICS_EXTRACTOR_MAC_HPP
00010 #define ADOBE_METRICS_EXTRACTOR_MAC_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <adobe/dictionary.hpp>
00017 #include <adobe/array.hpp>
00018 
00019 /****************************************************************************************************/
00020 
00021 namespace adobe {
00022 
00023 /****************************************************************************************************/
00024 
00129 struct metric_extractor_t
00130 {
00132     enum array_index_t
00133     {
00135         index_left = 0,
00137         index_top = 1,
00139         index_right = 2,
00141         index_bottom = 3,
00143         index_width = index_left,
00145         index_height = index_top
00146     };
00147 
00150     explicit metric_extractor_t(const dictionary_t& dictionary = dictionary_t()) :
00151         dictionary_m(dictionary)
00152     { }
00153 
00157     long operator () (const name_t& tag) const
00158     {
00159         long result(0);
00160 
00161         if (empty())
00162             return result;
00163 
00164         get_value(dictionary_m, tag, result);
00165 
00166         return result;
00167     }
00168 
00173     long operator () (const name_t& tag, array_index_t index) const
00174     {
00175         if (empty()) return 0;
00176             
00177         dictionary_t::const_iterator i = dictionary_m.find(tag);
00178         if (i == dictionary_m.end()) return 0;
00179         
00180         const array_t& array_result = i->second.cast<array_t>();
00181         
00182         if (!(std::size_t(index) < array_result.size())) return 0;
00183         
00184         return array_result[std::size_t(index)].cast<long>();
00185     }
00186 
00190     bool empty() const { return dictionary_m.empty(); }
00191 
00192     friend inline bool operator==(const metric_extractor_t& x, const metric_extractor_t& y)
00193     { return x.dictionary_m == y.dictionary_m; }
00194     
00195     metric_extractor_t&  operator=(const metric_extractor_t& x) 
00196     {
00197         dictionary_m = x.dictionary_m;
00198         return *this;
00199     }
00200 
00201 private:
00202     dictionary_t dictionary_m;
00203 };
00204 
00205 /****************************************************************************************************/
00206 
00207 }
00208 
00209 /****************************************************************************************************/
00210 
00211 #endif
00212 
00213 /****************************************************************************************************/

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