libyui

/data/gitorious.org/libyui/libyui-master/src/YBothDim.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                        (C) SuSE GmbH |
00032 \----------------------------------------------------------------------/
00033 
00034   File:         YBothDim.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 #ifndef YBothDim_h
00041 #define YBothDim_h
00042 
00043 #include "YTypes.h"
00044 #include "YUIException.h"
00045 
00046 
00056 template<typename T> class YBothDim
00057 {
00058 public:
00059 
00060     // Data Members - intentionally public
00061     T vert;
00062     T hor;
00063 
00067     YBothDim( T hor, T vert )
00068         : vert( vert )
00069         , hor( hor )
00070         {}
00071 
00075     YBothDim()
00076         {}
00077 
00083     T & operator[]( YUIDimension dim )
00084     {
00085         switch ( dim )
00086         {
00087             case YD_HORIZ:      return hor;
00088             case YD_VERT:       return vert;
00089             default:            YUI_THROW( YUIInvalidDimensionException() );
00090         }
00091         
00092         // never reached (but gcc will complain otherwise)
00093         return hor; 
00094     }
00095 
00099     const T & operator[]( YUIDimension dim ) const
00100     {
00101         switch ( dim )
00102         {
00103             case YD_HORIZ:      return hor;
00104             case YD_VERT:       return vert;
00105             default:            YUI_THROW( YUIInvalidDimensionException() );
00106         }
00107         
00108         // never reached (but gcc will complain otherwise)
00109         return hor; 
00110     }
00111 };
00112 
00113 
00114 #endif // YBothDim_h
 All Classes Functions Variables Enumerations Friends