cwidget  0.5.16
column_definition.h
Go to the documentation of this file.
00001 // column_definition.h   -*-c++-*-
00002 //
00003 //  Copyright 2000, 2005, 2007-2008 Daniel Burrows
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
00016 //  along with this program; see the file COPYING.  If not, write to
00017 //  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018 //  Boston, MA 02111-1307, USA.
00019 
00036 #ifndef COLUMN_DEFINITION_H
00037 #define COLUMN_DEFINITION_H
00038 
00039 #include <list>
00040 #include <string>
00041 
00042 #include <cwidget/generic/util/eassert.h>
00043 
00044 #include <cwidget/columnify.h>
00045 
00046 namespace cwidget
00047 {
00048   namespace config
00049   {
00051     struct column_type_defaults
00052     {
00053       unsigned int width;
00054       bool expand, shrink;
00055     };
00056 
00064     class column_parameters
00065     {
00066     public:
00067       virtual int param_count()=0;
00068       virtual std::wstring get_param(int n)=0;
00069 
00070       virtual ~column_parameters();
00071     };
00072 
00074     class empty_column_parameters : public column_parameters
00075     {
00076     public:
00077       int param_count();
00078       std::wstring get_param(int n);
00079     };
00080 
00085     struct column_definition
00086     {
00088       enum column_type
00089       {
00094         COLUMN_LITERAL,
00100         COLUMN_GENERATED,
00108         COLUMN_PARAM
00109       };
00110 
00112       column_type type;
00113 
00119       int ival;
00120 
00125       std::wstring arg;
00126 
00132       unsigned int width;
00134       bool expand:1;
00136       bool shrink:1;
00137 
00144       bool dynamic_size:1;
00145 
00147       column_definition(const std::wstring &_arg, bool _expand, bool _shrink)
00148         :type(COLUMN_LITERAL), arg(_arg), expand(_expand), shrink(_shrink)
00149       {
00150       }
00151 
00153       column_definition(column_type _type,
00154                         int _ival, int _width, bool _expand, bool _shrink,
00155                         bool _dynamic_size)
00156         :type(_type), ival(_ival), width(_width),
00157          expand(_expand), shrink(_shrink), dynamic_size(_dynamic_size)
00158       {
00159         eassert(_width>=0);
00160       }
00161     };
00162 
00164     typedef std::list<column_definition> column_definition_list;
00165 
00170     typedef int (*column_parser_func)(char id);
00171 
00178     class column_generator
00179     {
00180       column_definition_list columns;
00181     public:
00183       virtual column_disposition setup_column(int type)=0;
00184 
00188       column_generator(const column_definition_list &_columns)
00189         :columns(_columns) {}
00190 
00191       virtual ~column_generator();
00192 
00203       std::wstring layout_columns(unsigned int width,
00204                                   column_parameters &p);
00205     };
00206 
00218     column_definition_list *parse_columns(std::wstring config,
00219                                           column_parser_func parser,
00220                                           column_type_defaults *defaults);
00221   }
00222 }
00223 
00224 #endif