column_headers.cpp

Go to the documentation of this file.
00001 #ifndef COLUMN_HEADERS_IMPLEMENTATION_FILE
00002 #define COLUMN_HEADERS_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : column_headers                                                    *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "column_headers.h"
00019 
00020 #include <basis/array.h>
00021 #include <basis/function.h>
00022 #include <basis/istring.h>
00023 #include <basis/string_array.h>
00024 #include <data_struct/matrix.h>
00025 
00026 struct column_info {
00027   istring _name;
00028   column_headers::justifications _just;
00029   int _max_width;
00030 
00031   column_info(const istring &name = "",
00032       column_headers::justifications just = column_headers::LEFT_JUSTIFY,
00033       int max_width = -1) : _name(name), _just(just), _max_width(max_width) {}
00034 };
00035 
00036 class column_info_array : public array<column_info> {};
00037 
00038 column_headers::column_headers()
00039 : _cols(new column_info_array)
00040 {
00041 }
00042 
00043 column_headers::~column_headers()
00044 {
00045   WHACK(_cols);
00046 }
00047 
00048 int column_headers::columns() const { return _cols->length(); }
00049 
00051 
00052 void column_headers::add(const istring &column_name,
00053     justifications placement, int maximum_width)
00054 {
00055 
00056 if (!column_name || maximum_width || placement) {}
00057 
00058 }
00059 
00060 bool column_headers::get(int index, istring &column_name,
00061     justifications &placement, int &maximum_width)
00062 {
00063 
00064 if (index || !column_name || maximum_width || placement) {}
00065 
00066 return false;
00067 }
00068 
00069 bool column_headers::zap(int start, int end)
00070 {
00071   if (negative(start)) return false;
00072   if (start >= columns()) return false;
00073   if (negative(end)) { _cols->zap(start, start); return true; }
00074   if (end >= columns()) return false;
00075   _cols->zap(start, end);
00076   return true;
00077 }
00078 
00079 bool column_headers::format(istring &to_fill, const string_array &to_format)
00080 {
00081 
00082 if (!to_fill || to_format.length()) {}
00083 
00084 return false;
00085 }
00086 
00087 bool column_headers::format(istring &to_fill, const string_matrix &to_format)
00088 {
00089 
00090 if (!to_fill || to_format.rows()) {}
00091 
00092 return false;
00093 }
00094 
00095 void column_headers::pack(byte_array &packed_form) const
00096 {
00097   basis::attach(packed_form, columns());
00098   for (int i = 0; i < columns(); i++) {
00099     column_info &info = _cols->operator [] (i);
00100     basis::attach(packed_form, int(info._just));
00101     basis::attach(packed_form, info._max_width);
00102     info._name.pack(packed_form);
00103   }
00104 }
00105 
00106 bool column_headers::unpack(byte_array &packed_form)
00107 {
00108   int cols;
00109   if (!basis::detach(packed_form, cols)) return false;
00110   // make columns large enough for packed list.
00111   _cols->reset(cols);
00112   for (int i = 0; i < cols; i++) {
00113     column_info &info = _cols->operator [] (i);
00114     int just;
00115     if (!basis::detach(packed_form, just)) return false;
00116     info._just = justifications(just);
00117     if (!basis::detach(packed_form, info._max_width)) return false;
00118     if (!info._name.unpack(packed_form)) return false;
00119   }
00120   return true;
00121 }
00122 
00123 
00124 #endif //COLUMN_HEADERS_IMPLEMENTATION_FILE
00125 

Generated on Fri Nov 28 04:29:33 2008 for HOOPLE Libraries by  doxygen 1.5.1