cwidget 0.5.18
column_definition.h
Go to the documentation of this file.
1// column_definition.h -*-c++-*-
2//
3// Copyright 2000, 2005, 2007-2008 Daniel Burrows
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; see the file COPYING. If not, write to
17// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18// Boston, MA 02111-1307, USA.
19
36#ifndef COLUMN_DEFINITION_H
37#define COLUMN_DEFINITION_H
38
39#include <list>
40#include <string>
41
42#include <cwidget/generic/util/eassert.h>
43
44#include <cwidget/columnify.h>
45
46namespace cwidget
47{
48 namespace config
49 {
52 {
53 unsigned int width;
54 bool expand, shrink;
55 };
56
65 {
66 public:
67 virtual int param_count()=0;
68 virtual std::wstring get_param(int n)=0;
69
70 virtual ~column_parameters();
71 };
72
75 {
76 public:
77 int param_count();
78 std::wstring get_param(int n);
79 };
80
86 {
89 {
109 };
110
113
119 int ival;
120
125 std::wstring arg;
126
132 unsigned int width;
134 bool expand:1;
136 bool shrink:1;
137
145
147 column_definition(const std::wstring &_arg, bool _expand, bool _shrink)
148 :type(COLUMN_LITERAL), arg(_arg), expand(_expand), shrink(_shrink)
149 {
150 }
151
154 int _ival, int _width, bool _expand, bool _shrink,
155 bool _dynamic_size)
156 :type(_type), ival(_ival), width(_width),
157 expand(_expand), shrink(_shrink), dynamic_size(_dynamic_size)
158 {
159 eassert(_width>=0);
160 }
161 };
162
164 typedef std::list<column_definition> column_definition_list;
165
170 typedef int (*column_parser_func)(char id);
171
179 {
181 public:
183 virtual column_disposition setup_column(int type)=0;
184
189 :columns(_columns) {}
190
191 virtual ~column_generator();
192
203 std::wstring layout_columns(unsigned int width,
205 };
206
218 column_definition_list *parse_columns(std::wstring config,
219 column_parser_func parser,
220 column_type_defaults *defaults);
221 }
222}
223
224#endif
The class that defines how to parse and generate columns.
Definition: column_definition.h:179
virtual column_disposition setup_column(int type)=0
Computes the text and column offset of a column of the given type.
std::wstring layout_columns(unsigned int width, column_parameters &p)
Given the target width and positional parameters, construct an output string to be displayed on the t...
Definition: column_definition.cc:246
column_generator(const column_definition_list &_columns)
Create a column generator for the given list of column specifications.
Definition: column_definition.h:188
Defines the string arguments passed into the layout process.
Definition: column_definition.h:65
An empty list of parameters.
Definition: column_definition.h:75
int(* column_parser_func)(char id)
The type of a function that parses a single-character column type flag and returns an integer identif...
Definition: column_definition.h:170
std::list< column_definition > column_definition_list
The type used to store lists of column definitions.
Definition: column_definition.h:164
The namespace containing everything defined by cwidget.
Definition: columnify.cc:28
Definition: columnify.h:44
Defines how a single column is to be generated.
Definition: column_definition.h:86
std::wstring arg
The text of this column if it is a literal column.
Definition: column_definition.h:125
column_type
The available column types.
Definition: column_definition.h:89
@ COLUMN_LITERAL
A literal column.
Definition: column_definition.h:94
@ COLUMN_GENERATED
A dynamically generated column.
Definition: column_definition.h:100
@ COLUMN_PARAM
A column defined by a positional parameter.
Definition: column_definition.h:108
bool expand
If true, this column is allowed to expand during layout.
Definition: column_definition.h:134
column_type type
The type of this column.
Definition: column_definition.h:112
unsigned int width
The width of this column if it is generated or taken from a positional parameter.
Definition: column_definition.h:132
bool shrink
If true, this column is allowed to shrink during layout.
Definition: column_definition.h:136
bool dynamic_size
Whether to redefine the column width based on the actual string (for generated and parametric columns...
Definition: column_definition.h:144
column_definition(const std::wstring &_arg, bool _expand, bool _shrink)
Create a literal column.
Definition: column_definition.h:147
int ival
The parameter number (for positional parameter columns) or column type (for generated columns).
Definition: column_definition.h:119
column_definition(column_type _type, int _ival, int _width, bool _expand, bool _shrink, bool _dynamic_size)
Create a generated or parametric column.
Definition: column_definition.h:153
Defines the default settings for a particular column type.
Definition: column_definition.h:52