00001 #ifndef __table_h__
00002 #define __table_h__
00003
00004 #include <iostream>
00005 #include <vector>
00006 #include <list>
00007
00008 #include "asserts.h"
00009 #include "estring.h"
00010
00011 class table;
00012
00013 class table_cell_base
00014 {
00015 public:
00016 typedef estring::size_type size_type;
00017 static const size_type npos;
00018
00019 table_cell_base();
00020 table_cell_base(const table_cell_base& a_class);
00021 virtual ~table_cell_base();
00022
00023 virtual void assign(const table_cell_base& a_class);
00024
00025 virtual size_type height(void) const;
00026 virtual size_type width(void) const;
00027 virtual void write(
00028 std::ostream& out,
00029 size_type a_line,
00030 size_type a_width
00031 ) const;
00032
00033 table_cell_base& operator=(const table_cell_base& a_class);
00034
00035 size_type x;
00036 size_type y;
00037 bool repeat;
00038
00039 private:
00040 };
00041
00042 bool operator==(const table_cell_base& a_1, const table_cell_base& a_2);
00043
00044 class table_cell_estring : public table_cell_base
00045 {
00046 public:
00047 table_cell_estring();
00048 table_cell_estring(const table_cell_estring& a_class);
00049 table_cell_estring(const estring& a_class);
00050 virtual ~table_cell_estring();
00051
00052 virtual void assign(const table_cell_estring& a_class);
00053 virtual void assign(const estring& a_class);
00054
00055 virtual size_type height(void) const;
00056 virtual size_type width(void) const;
00057 virtual void write(
00058 std::ostream& out,
00059 size_type a_line,
00060 size_type a_width
00061 ) const;
00062
00063 table_cell_estring& operator=(const table_cell_estring& a_class);
00064 table_cell_estring& operator=(const estring& a_class);
00065
00066 private:
00067 estring m_value;
00068 };
00069
00070 class table_cell_table : public table_cell_base
00071 {
00072 public:
00073 table_cell_table();
00074 table_cell_table(const table_cell_table& a_class);
00075 table_cell_table(const table& a_class);
00076 virtual ~table_cell_table();
00077
00078 virtual void assign(const table_cell_table& a_class);
00079 virtual void assign(const table& a_class);
00080
00081 virtual size_type height(void) const;
00082 virtual size_type width(void) const;
00083 virtual void write(
00084 std::ostream& out,
00085 size_type a_line,
00086 size_type a_width
00087 ) const;
00088
00089 table_cell_table& operator=(const table_cell_table& a_class);
00090 table_cell_table& operator=(const table& a_class);
00091
00092 private:
00093 table * m_value;
00094 };
00095
00096 class table
00097 {
00098 public:
00099 typedef std::vector<table_cell_base *> table_row_type;
00100 typedef std::vector<table_row_type> table_type;
00101 typedef table_cell_base::size_type size_type;
00102
00103 table();
00104 table(const size_type a_ncols, const size_type a_nrows);
00105 table(const table& a_class);
00106 virtual ~table();
00107
00108 virtual void resize(const size_type a_x, const size_type a_y);
00109 virtual void insert_row(const size_type a_y);
00110 virtual void insert_col(const size_type a_x);
00111
00112 virtual void assign(const table& a_class);
00113 virtual void assign(
00114 const size_type a_x,
00115 const size_type a_y,
00116 const estring& a_class
00117 );
00118 virtual void assign(
00119 const size_type a_x,
00120 const size_type a_y,
00121 const table& a_class
00122 );
00123
00124 size_type table::col_width(const size_type a_x) const;
00125 size_type table::row_width(void) const;
00126 size_type table::col_height(void) const;
00127 size_type table::row_height(const size_type a_y) const;
00128
00129 virtual size_type height(void) const;
00130 virtual size_type width(void) const;
00131 virtual void write(
00132 std::ostream& out,
00133 size_type a_line,
00134 size_type a_width
00135 ) const;
00136
00137 const size_type ncols(void) const;
00138 const size_type nrows(void) const;
00139
00140 table& operator=(const table& a_class);
00141
00142 size_type cursor_x(void) const;
00143 size_type cursor_y(void) const;
00144 void set_cursor(size_type a_x, size_type a_y);
00145 bool eot(void) const;
00146
00147 void repeat(const bool a_bool);
00148
00149 private:
00150 table_type m_table;
00151 std::list<table_cell_estring> m_list_estring;
00152 std::list<table_cell_table> m_list_table;
00153 size_type m_cursor_x;
00154 size_type m_cursor_y;
00155 bool m_repeat;
00156
00157 void mf_init(void);
00158 void mf_add_elt(const table_cell_estring& a_class);
00159 void mf_add_elt(const table_cell_table& a_class);
00160 void mf_remove_elt(const table_cell_estring& a_class);
00161 void mf_remove_elt(const table_cell_table& a_class);
00162 void mf_remove_elt(
00163 size_type a_x,
00164 size_type a_y
00165 );
00166 void mf_remove_row(size_type a_y);
00167 };
00168
00169 std::ostream& operator<<(std::ostream& a_out, table& a_class);
00170
00171 table& table_write(table& a_table, const estring& a_estr);
00172 table& table_write(table& a_table, const table& a_subtable);
00173 table& table_endl(table& a_table);
00174 table& table_rewind(table& a_table);
00175 table& table_skip(table& a_table);
00176 table& table_repeat(table& a_table);
00177 table& operator<<(table& a_table, const estring& a_estr);
00178 table& operator<<(table& a_table, const table& a_subtable);
00179 table& operator<<(table& a_table, table& (*a_arg)(table&));
00180
00181 #endif