libyui  3.10.0
YTableHeader.cc
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: YTableHeader.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <vector>
27 
28 #define YUILogComponent "ui"
29 #include "YUILog.h"
30 
31 #include "YTableHeader.h"
32 #include "YUIException.h"
33 
34 using std::string;
35 using std::vector;
36 
37 
39 {
41  {}
42 
43  vector<string> headers;
44  vector<YAlignmentType> alignments;
45 };
46 
47 
48 
49 
51  : priv( new YTableHeaderPrivate )
52 {
53  YUI_CHECK_NEW( priv );
54 }
55 
56 
58 {
59  // NOP
60 }
61 
62 
63 void
64 YTableHeader::addColumn( const string & header, YAlignmentType alignment )
65 {
66  priv->headers.push_back( header );
67  priv->alignments.push_back( alignment );
68 }
69 
70 
71 int
73 {
74  return (int) priv->headers.size();
75 }
76 
77 
78 bool
79 YTableHeader::hasColumn( int column ) const
80 {
81  return column >= 0 && column < (int) priv->headers.size();
82 }
83 
84 
85 string
86 YTableHeader::header( int column ) const
87 {
88  if ( column >= 0 && column < (int) priv->headers.size() )
89  return priv->headers[ column ];
90  else
91  return "";
92 }
93 
94 
95 YAlignmentType
96 YTableHeader::alignment( int column ) const
97 {
98  if ( column >= 0 && column < (int) priv->alignments.size() )
99  return priv->alignments[ column ];
100  else
101  return YAlignBegin;
102 }
YTableHeaderPrivate
Definition: YTableHeader.cc:39
YTableHeader::YTableHeader
YTableHeader()
Constructor.
Definition: YTableHeader.cc:50
YTableHeader::header
std::string header(int column) const
Return the header text for the specified column.
Definition: YTableHeader.cc:86
YTableHeader::hasColumn
bool hasColumn(int column) const
Return 'true' if this table header has a column no.
Definition: YTableHeader.cc:79
YTableHeader::alignment
YAlignmentType alignment(int column) const
Return the alignment for the specified column.
Definition: YTableHeader.cc:96
YTableHeader::~YTableHeader
virtual ~YTableHeader()
Destructor.
Definition: YTableHeader.cc:57
YTableHeader::addColumn
void addColumn(const std::string &header, YAlignmentType alignment=YAlignBegin)
Add a column with the specified colum header text and alignment.
Definition: YTableHeader.cc:64
YTableHeader::columns
int columns() const
Return the number of columns.
Definition: YTableHeader.cc:72