stlab.adobe.com Adobe Systems Incorporated

extents.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_EXTENTS_HPP
00010 #define ADOBE_EXTENTS_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <boost/array.hpp>
00015 #include <boost/operators.hpp>
00016 
00017 #include <vector>
00018 
00019 /****************************************************************************************************/
00020 
00021 namespace adobe {
00022 
00023 /****************************************************************************************************/
00024 
00025 template <typename T = int>
00026 struct point_2d : boost::equality_comparable<point_2d<T> >
00027 {
00028     point_2d() :
00029         x_m(T()), y_m(T())
00030     { }
00031 
00032     point_2d(const T& x, const T& y) :
00033         x_m(x), y_m(y)
00034     { }
00035 
00036     T   x_m;
00037     T   y_m;
00038 
00039     friend inline void swap(const point_2d& x, const point_2d& y)
00040     {
00041         swap(x.x_m, y.x_m);
00042         swap(x.y_m, y.y_m);
00043     }
00044 
00045     friend inline bool operator==(const point_2d& x, const point_2d& y)
00046     {
00047         return (x.x_m == y.x_m) && (x.y_m == y.y_m);
00048     }
00049 };
00050 
00051 typedef std::pair<int, int>   pair_long_t;
00052 typedef point_2d<int>         point_2d_t;
00053 typedef std::vector<int>      guide_set_t;
00054 
00055 // REVISIT (sparent) : points of interest need to be named entities. This will become:
00056 
00057 #if 0
00058 struct guide_set_t
00059 {
00060     name_t name_m;
00061     int    offset_m;
00062 };
00063 typedef std::vector<guide_set_t> point_of_interest_set_t;
00064 #endif
00065 
00066 // REVISIT (sparent) : Open issue - are there "alignment" attributes on POIs?
00067 
00068 struct extents_slices_t
00069 {
00070     enum slice_select_t { horizontal, vertical };
00071 };
00072 
00073 /****************************************************************************************************/
00074 
00075 struct extents_t :
00076 #if !defined(ADOBE_NO_DOCUMENTATION)
00077     private extents_slices_t, boost::equality_comparable<extents_t>
00078 #endif
00079 {
00080     struct slice_t : boost::equality_comparable<slice_t>
00081     {
00082         slice_t() : length_m(0) { };
00083 
00084         int         length_m;
00085         pair_long_t outset_m;
00086         pair_long_t frame_m;
00087         pair_long_t inset_m;
00088         guide_set_t guide_set_m;
00089         
00090         friend bool operator ==(const slice_t& x, const slice_t& y);
00091     };
00092 
00093     boost::array<slice_t, 2>    slice_m;
00094 
00095     slice_t&                    vertical()          { return slice_m[extents_slices_t::vertical]; }
00096     slice_t&                    horizontal()        { return slice_m[extents_slices_t::horizontal]; }
00097 
00098     const slice_t&              vertical() const    { return slice_m[extents_slices_t::vertical]; }
00099     const slice_t&              horizontal() const  { return slice_m[extents_slices_t::horizontal]; }
00100 
00101     int&                        height()            { return vertical().length_m; }
00102     int&                        width()             { return horizontal().length_m; }
00103 
00104     const int&                  height() const      { return vertical().length_m; }
00105     const int&                  width() const       { return horizontal().length_m; }
00106     
00107     friend  bool operator == (const extents_t& x, const extents_t& y);
00108 };
00109 
00110 /****************************************************************************************************/
00111 
00112 #ifndef NDEBUG
00113 std::ostream&   operator << (std::ostream& s, const extents_t& x);
00114 #endif
00115 
00116 #ifndef NDEBUG
00117 std::ostream&   operator << (std::ostream& s, const extents_t::slice_t& x);
00118 #endif
00119 
00120 /*************************************************************************************************/
00121 
00122 } // namespace adobe
00123 
00124 /****************************************************************************************************/
00125 
00126 namespace std {
00127 
00128 template <> inline void swap(adobe::extents_t::slice_t& x, adobe::extents_t::slice_t& y)
00129 {
00130     swap(x.length_m, y.length_m);
00131     swap(x.outset_m, y.outset_m);
00132     swap(x.frame_m, y.frame_m);
00133     swap(x.inset_m, y.inset_m);
00134     swap(x.guide_set_m, y.guide_set_m);
00135 }
00136 
00137 template <> inline void swap(adobe::extents_t& x, adobe::extents_t& y)
00138 { swap(x.slice_m, y.slice_m); }
00139 
00140 } // namespace std
00141 
00142 /****************************************************************************************************/
00143 
00144 #endif
00145 
00146 /****************************************************************************************************/

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