libyui
2.42.5
Main Page
Classes
Files
File List
All
Classes
Functions
Variables
Enumerations
Friends
YBothDim.h
1
/*
2
Copyright (C) 2000-2012 Novell, Inc
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of the GNU Lesser General Public License as
5
published by the Free Software Foundation; either version 2.1 of the
6
License, or (at your option) version 3.0 of the License. This library
7
is distributed in the hope that it will be useful, but WITHOUT ANY
8
WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10
License for more details. You should have received a copy of the GNU
11
Lesser General Public License along with this library; if not, write
12
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13
Floor, Boston, MA 02110-1301 USA
14
*/
15
16
17
/*-/
18
19
File: YBothDim.h
20
21
Author: Stefan Hundhammer <sh@suse.de>
22
23
/-*/
24
25
#ifndef YBothDim_h
26
#define YBothDim_h
27
28
#include "YTypes.h"
29
#include "YUIException.h"
30
31
32
/**
33
* Template class for two-dimensional entities, such as
34
* - width, height
35
* - x_pos, y_pos
36
* - hStretchable, vStretchable
37
*
38
* Precondition: type T needs to have a default constructor
39
* (which all simple types like int, long, bool have).
40
**/
41
template
<
typename
T>
class
YBothDim
42
{
43
public
:
44
45
// Data Members - intentionally public
46
T vert;
47
T hor;
48
49
/**
50
* Constructor with explicit initialization for both values
51
**/
52
YBothDim
( T hor, T vert )
53
: vert( vert )
54
, hor( hor )
55
{}
56
57
/**
58
* Default constructor (calls T default constructor for both values)
59
**/
60
YBothDim
()
61
{}
62
63
/**
64
* operator[] for alternative access via myVar[ YD_HORIZ ]
65
* Please note that this returns a non-const reference, so this can be used
66
* as an lvalue (e.g., in assignments)
67
**/
68
T &
operator[]
( YUIDimension dim )
69
{
70
switch
( dim )
71
{
72
case
YD_HORIZ:
return
hor;
73
case
YD_VERT:
return
vert;
74
default
: YUI_THROW(
YUIInvalidDimensionException
() );
75
}
76
77
// never reached (but gcc will complain otherwise)
78
return
hor;
79
}
80
81
/**
82
* Same as above for const objects
83
**/
84
const
T &
operator[]
( YUIDimension dim )
const
85
{
86
switch
( dim )
87
{
88
case
YD_HORIZ:
return
hor;
89
case
YD_VERT:
return
vert;
90
default
: YUI_THROW(
YUIInvalidDimensionException
() );
91
}
92
93
// never reached (but gcc will complain otherwise)
94
return
hor;
95
}
96
};
97
98
99
#endif // YBothDim_h
src
YBothDim.h
Generated by
1.8.3