00001 #ifndef COLUMN_HEADERS_IMPLEMENTATION_FILE
00002 #define COLUMN_HEADERS_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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