cwidget  0.5.17
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 
46 namespace 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  {
108  COLUMN_PARAM
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 
144  bool dynamic_size:1;
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  {
180  column_definition_list columns;
181  public:
183  virtual column_disposition setup_column(int type)=0;
184 
188  column_generator(const column_definition_list &_columns)
189  :columns(_columns) {}
190 
191  virtual ~column_generator();
192 
203  std::wstring layout_columns(unsigned int width,
204  column_parameters &p);
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
unsigned int width
The width of this column if it is generated or taken from a positional parameter. ...
Definition: column_definition.h:132
A literal column.
Definition: column_definition.h:94
std::wstring arg
The text of this column if it is a literal column.
Definition: column_definition.h:125
bool shrink
If true, this column is allowed to shrink during layout.
Definition: column_definition.h:136
column_generator(const column_definition_list &_columns)
Create a column generator for the given list of column specifications.
Definition: column_definition.h:188
bool expand
If true, this column is allowed to expand during layout.
Definition: column_definition.h:134
The class that defines how to parse and generate columns.
Definition: column_definition.h:178
bool dynamic_size
Whether to redefine the column width based on the actual string (for generated and parametric columns...
Definition: column_definition.h:144
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
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
int ival
The parameter number (for positional parameter columns) or column type (for generated columns)...
Definition: column_definition.h:119
std::list< column_definition > column_definition_list
The type used to store lists of column definitions.
Definition: column_definition.h:164
column_type type
The type of this column.
Definition: column_definition.h:112
Definition: columnify.h:42
Defines how a single column is to be generated.
Definition: column_definition.h:85
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 string arguments passed into the layout process.
Definition: column_definition.h:64
column_type
The available column types.
Definition: column_definition.h:88
Defines the default settings for a particular column type.
Definition: column_definition.h:51
column_definition(const std::wstring &_arg, bool _expand, bool _shrink)
Create a literal column.
Definition: column_definition.h:147
A dynamically generated column.
Definition: column_definition.h:100
An empty list of parameters.
Definition: column_definition.h:74