From 62e6b31a175f105b404b7b1c8d2e46ee9f6c18d2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Apr 2008 00:09:59 -0400 Subject: [PATCH] - Integrated new Grid object into build - not yet integrated into Table. --- src/.deps/Config.Po | 6 +- src/.deps/Date.Po | 7 +- src/.deps/T.Po | 6 +- src/.deps/TDB.Po | 6 +- src/.deps/Table.Po | 18 +-- src/.deps/parse.Po | 8 +- src/.deps/rules.Po | 8 +- src/.deps/task.Po | 8 +- src/.deps/text.Po | 6 +- src/.deps/util.Po | 9 +- src/Grid.cpp | 386 ++++++++++++++++++++++++++++++++++++++++++++ src/Grid.h | 75 +++++++++ src/Makefile.am | 2 +- src/Table.cpp | 34 +--- src/Table.h | 5 +- 15 files changed, 530 insertions(+), 54 deletions(-) create mode 100644 src/Grid.cpp create mode 100644 src/Grid.h diff --git a/src/.deps/Config.Po b/src/.deps/Config.Po index f241e9789..2ded9a7ad 100644 --- a/src/.deps/Config.Po +++ b/src/.deps/Config.Po @@ -98,7 +98,7 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ /usr/include/c++/4.0.0/bits/stl_multimap.h /usr/include/sys/types.h \ - Config.h Table.h color.h TDB.h T.h stlmacros.h ../auto.h + Config.h Table.h color.h Grid.h color.h TDB.h T.h stlmacros.h ../auto.h /usr/include/c++/4.0.0/iostream: @@ -392,6 +392,10 @@ Table.h: color.h: +Grid.h: + +color.h: + TDB.h: T.h: diff --git a/src/.deps/Date.Po b/src/.deps/Date.Po index cec666332..93cd62d16 100644 --- a/src/.deps/Date.Po +++ b/src/.deps/Date.Po @@ -95,7 +95,8 @@ Date.o Date.o: Date.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ /usr/include/c++/4.0.0/bits/stl_multimap.h /usr/include/sys/types.h \ - Config.h Table.h color.h TDB.h T.h stlmacros.h ../auto.h Date.h + Config.h Table.h color.h Grid.h color.h TDB.h T.h stlmacros.h ../auto.h \ + Date.h /usr/include/c++/4.0.0/iostream: @@ -379,6 +380,10 @@ Table.h: color.h: +Grid.h: + +color.h: + TDB.h: T.h: diff --git a/src/.deps/T.Po b/src/.deps/T.Po index c47324474..dfd7997e2 100644 --- a/src/.deps/T.Po +++ b/src/.deps/T.Po @@ -95,7 +95,7 @@ T.o T.o: T.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ /usr/include/c++/4.0.0/bits/stl_multimap.h /usr/include/sys/types.h \ - Config.h Table.h color.h TDB.h T.h stlmacros.h ../auto.h + Config.h Table.h color.h Grid.h color.h TDB.h T.h stlmacros.h ../auto.h /usr/include/c++/4.0.0/iostream: @@ -379,6 +379,10 @@ Table.h: color.h: +Grid.h: + +color.h: + TDB.h: T.h: diff --git a/src/.deps/TDB.Po b/src/.deps/TDB.Po index 87a8f59ca..bffd65226 100644 --- a/src/.deps/TDB.Po +++ b/src/.deps/TDB.Po @@ -99,7 +99,7 @@ TDB.o TDB.o: TDB.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ /usr/include/c++/4.0.0/bits/stl_multimap.h Config.h Table.h color.h \ - TDB.h T.h stlmacros.h ../auto.h + Grid.h color.h TDB.h T.h stlmacros.h ../auto.h /usr/include/c++/4.0.0/iostream: @@ -395,6 +395,10 @@ Table.h: color.h: +Grid.h: + +color.h: + TDB.h: T.h: diff --git a/src/.deps/Table.Po b/src/.deps/Table.Po index 1544cca60..9de5daf3d 100644 --- a/src/.deps/Table.Po +++ b/src/.deps/Table.Po @@ -94,8 +94,8 @@ Table.o Table.o: Table.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_multimap.h \ /usr/include/c++/4.0.0/vector /usr/include/c++/4.0.0/bits/stl_vector.h \ /usr/include/c++/4.0.0/bits/stl_bvector.h \ - /usr/include/c++/4.0.0/bits/vector.tcc color.h Date.h stlmacros.h \ - task.h /usr/include/sys/types.h Config.h TDB.h T.h ../auto.h + /usr/include/c++/4.0.0/bits/vector.tcc color.h Grid.h Date.h library.h \ + /usr/include/sys/types.h stlmacros.h /usr/include/c++/4.0.0/iostream: @@ -373,18 +373,12 @@ Table.h: color.h: +Grid.h: + Date.h: -stlmacros.h: - -task.h: +library.h: /usr/include/sys/types.h: -Config.h: - -TDB.h: - -T.h: - -../auto.h: +stlmacros.h: diff --git a/src/.deps/parse.Po b/src/.deps/parse.Po index bbe41942e..902f49d40 100644 --- a/src/.deps/parse.Po +++ b/src/.deps/parse.Po @@ -95,8 +95,8 @@ parse.o parse.o: parse.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ /usr/include/c++/4.0.0/bits/stl_multimap.h Date.h task.h \ - /usr/include/sys/types.h Config.h Table.h color.h TDB.h T.h stlmacros.h \ - ../auto.h + /usr/include/sys/types.h Config.h Table.h color.h Grid.h color.h TDB.h \ + T.h stlmacros.h ../auto.h /usr/include/c++/4.0.0/iostream: @@ -382,6 +382,10 @@ Table.h: color.h: +Grid.h: + +color.h: + TDB.h: T.h: diff --git a/src/.deps/rules.Po b/src/.deps/rules.Po index 657421bb2..b316ee34b 100644 --- a/src/.deps/rules.Po +++ b/src/.deps/rules.Po @@ -94,8 +94,8 @@ rules.o rules.o: rules.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_multimap.h \ /usr/include/c++/4.0.0/vector /usr/include/c++/4.0.0/bits/stl_vector.h \ /usr/include/c++/4.0.0/bits/stl_bvector.h \ - /usr/include/c++/4.0.0/bits/vector.tcc Table.h color.h Date.h T.h \ - task.h /usr/include/sys/types.h TDB.h stlmacros.h ../auto.h + /usr/include/c++/4.0.0/bits/vector.tcc Table.h color.h Grid.h Date.h \ + T.h task.h /usr/include/sys/types.h color.h TDB.h stlmacros.h ../auto.h /usr/include/c++/4.0.0/iostream: @@ -375,6 +375,8 @@ Table.h: color.h: +Grid.h: + Date.h: T.h: @@ -383,6 +385,8 @@ task.h: /usr/include/sys/types.h: +color.h: + TDB.h: stlmacros.h: diff --git a/src/.deps/task.Po b/src/.deps/task.Po index 6f26ec7b9..18f0e7597 100644 --- a/src/.deps/task.Po +++ b/src/.deps/task.Po @@ -98,8 +98,8 @@ task.o task.o: task.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/bits/stl_multimap.h \ /usr/include/c++/4.0.0/vector /usr/include/c++/4.0.0/bits/stl_vector.h \ /usr/include/c++/4.0.0/bits/stl_bvector.h \ - /usr/include/c++/4.0.0/bits/vector.tcc Date.h Table.h color.h \ - stlmacros.h TDB.h T.h task.h ../auto.h /usr/include/ncurses.h \ + /usr/include/c++/4.0.0/bits/vector.tcc Date.h Table.h color.h Grid.h \ + stlmacros.h TDB.h T.h task.h color.h ../auto.h /usr/include/ncurses.h \ /usr/include/ncurses_dll.h /usr/include/unctrl.h /usr/include/curses.h /usr/include/c++/4.0.0/iostream: @@ -396,6 +396,8 @@ Table.h: color.h: +Grid.h: + stlmacros.h: TDB.h: @@ -404,6 +406,8 @@ T.h: task.h: +color.h: + ../auto.h: /usr/include/ncurses.h: diff --git a/src/.deps/text.Po b/src/.deps/text.Po index 0ff7176cd..7048c875c 100644 --- a/src/.deps/text.Po +++ b/src/.deps/text.Po @@ -95,7 +95,7 @@ text.o text.o: text.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/c++/4.0.0/map /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ /usr/include/c++/4.0.0/bits/stl_multimap.h /usr/include/sys/types.h \ - Config.h Table.h color.h TDB.h T.h stlmacros.h ../auto.h + Config.h Table.h color.h Grid.h color.h TDB.h T.h stlmacros.h ../auto.h /usr/include/c++/4.0.0/iostream: @@ -379,6 +379,10 @@ Table.h: color.h: +Grid.h: + +color.h: + TDB.h: T.h: diff --git a/src/.deps/util.Po b/src/.deps/util.Po index 5501f80b1..3cef528cb 100644 --- a/src/.deps/util.Po +++ b/src/.deps/util.Po @@ -95,8 +95,9 @@ util.o util.o: util.cpp /usr/include/c++/4.0.0/iostream \ /usr/include/sys/time.h Table.h /usr/include/c++/4.0.0/map \ /usr/include/c++/4.0.0/bits/stl_tree.h \ /usr/include/c++/4.0.0/bits/stl_map.h \ - /usr/include/c++/4.0.0/bits/stl_multimap.h color.h task.h Config.h \ - TDB.h T.h stlmacros.h ../auto.h /usr/include/uuid/uuid.h + /usr/include/c++/4.0.0/bits/stl_multimap.h color.h Grid.h task.h \ + Config.h color.h TDB.h T.h stlmacros.h ../auto.h \ + /usr/include/uuid/uuid.h /usr/include/c++/4.0.0/iostream: @@ -378,10 +379,14 @@ Table.h: color.h: +Grid.h: + task.h: Config.h: +color.h: + TDB.h: T.h: diff --git a/src/Grid.cpp b/src/Grid.cpp new file mode 100644 index 000000000..ce6c21357 --- /dev/null +++ b/src/Grid.cpp @@ -0,0 +1,386 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 2007 - 2008, Paul Beckingham. All rights reserved. +// +// Grid implements a sparse 2D array of Cell objects. Grid makes every effort +// to perform well on cell insertion and retrieval. A Cell is a variant type, +// capable of storing char, bool, int, float, double and std::string types. +// +// Every cell is accessible from both mColumns and mRows. This allows the +// client code to specify which method is used, because there will be a +// performance penalty with one of the methods, depending on the layout of +// cells within the grid. +// +// mColumns, like mRows, is a vector of a vector of Cell*. +// +// mColumns +// [0..n] +// +---+---+-----------+---+ +// | 0 | 1 | | n | +// +---+---+-----------+---+ +// | | +// v | +// +---+ . +---+ . | . +// mRows | 0 | -------> | x | v +// [0..1] +---+ . +---+ +---+ +// | 1 | -------> | y | --------> | z | +// +---+ . +---+ +---+ +// | | +// | | +// | | +// +---+ . . . . . +// | n | +// +---+ . . . . . +// +// +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +Grid::Grid () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// The cells are deleted via their mRows reference, not by their mColumns +// reference. This is because the cells are doubly-linked, and so the +// convention is that rows own cells, columns merely own pointers. +Grid::~Grid () +{ + std::vector < std::vector * >::iterator row; + std::vector ::iterator col; + for (row = mRows.begin (); row != mRows.end (); ++row) + if (*row) + for (col = (*row)->begin (); col != (*row)->end (); ++col) + if (*col) + delete *col; + + std::vector < std::vector * >::iterator it; + for (it = mRows.begin (); it != mRows.end (); ++it) + if (*it) + delete *it; + + for (it = mColumns.begin (); it != mColumns.end (); ++it) + if (*it) + delete *it; +} + +//////////////////////////////////////////////////////////////////////////////// +void Grid::add ( + const unsigned int row, + const unsigned int col, + const bool value) +{ + expandGrid (row, col); + insertCell (row, col, new Cell (value)); +} + +void Grid::add ( + const unsigned int row, + const unsigned int col, + const char value) +{ + expandGrid (row, col); + insertCell (row, col, new Cell (value)); +} + +void Grid::add ( + const unsigned int row, + const unsigned int col, + const int value) +{ + expandGrid (row, col); + insertCell (row, col, new Cell (value)); +} + +void Grid::add ( + const unsigned int row, + const unsigned int col, + const float value) +{ + expandGrid (row, col); + insertCell (row, col, new Cell (value)); +} + +void Grid::add ( + const unsigned int row, + const unsigned int col, + const double value) +{ + expandGrid (row, col); + insertCell (row, col, new Cell (value)); +} + +void Grid::add ( + const unsigned int row, + const unsigned int col, + const std::string& value) +{ + expandGrid (row, col); + insertCell (row, col, new Cell (value)); +} + +//////////////////////////////////////////////////////////////////////////////// +unsigned int Grid::width () const +{ + return mColumns.size (); +} + +unsigned int Grid::height () const +{ + return mRows.size (); +} + +//////////////////////////////////////////////////////////////////////////////// +Grid::Cell* Grid::byRow (const unsigned int row, const unsigned int col) const +{ + if (row <= mRows.size () && + mRows[row] != NULL && + col <= mRows[row]->size ()) + return (*mRows[row])[col]; + + return NULL; +} + +Grid::Cell* Grid::byColumn (const unsigned int row, const unsigned int col) const +{ + if (col <= mColumns.size () && + mColumns[col] != NULL && + row <= mColumns[col]->size ()) + return (*mColumns[col])[row]; + + return NULL; +} + +//////////////////////////////////////////////////////////////////////////////// +void Grid::expandGrid (const unsigned int row, const unsigned int col) +{ + // If the new row is outside the bounds of the current grid, add blank rows to + // pad, then a new row vector. + if (row >= mRows.size ()) + { + for (unsigned int r = mRows.size (); r <= row; ++r) + if (r < row) +// { +// std::cout << "additional mRows[" << r << "] = NULL" << std::endl; + mRows.push_back (NULL); +// } + else +// { +// std::cout << "additional mRows[" << r << "] = new std::vector " << std::endl; + mRows.push_back (new std::vector ); +// } + } + // If the new row is within the bounds of the current grid, ensure that the + // row points to a vector of cells. + else if (mRows[row] == NULL) +// { +// std::cout << "existing mRows[" << row << "] = new std::vector " << std::endl; + mRows[row] = new std::vector ; +// } + + if (col >= mRows[row]->size ()) + for (unsigned int c = mRows[row]->size (); c <= col; ++c) +// { +// std::cout << "additional mRows[" << row << "][" << c << "] = NULL" << std::endl; + mRows[row]->push_back (NULL); +// } + + // If the new col is outside the bounds of the current grid, add blank cols to + // pad, then a new col vector. + if (col >= mColumns.size ()) + { + for (unsigned int c = mColumns.size (); c <= col; ++c) + if (c < col) +// { +// std::cout << "additional mColumns[" << c << "] = NULL" << std::endl; + mColumns.push_back (NULL); +// } + else +// { +// std::cout << "additional mColumns[" << c << "] = new std::vector " << std::endl; + mColumns.push_back (new std::vector ); +// } + } + // If the new col is within the bounds of the current grid, ensure that the + // col points to a vector of cells. + else if (mColumns[col] == NULL) +// { +// std::cout << "existing mColumns[" << col << "] = new std::vector " << std::endl; + mColumns[col] = new std::vector ; +// } + + if (row >= mColumns[col]->size ()) + for (unsigned int r = mColumns[col]->size (); r <= row; ++r) +// { +// std::cout << "additional mColumns[" << col << "][" << r << "] = NULL" << std::endl; + mColumns[col]->push_back (NULL); +// } +} + +//////////////////////////////////////////////////////////////////////////////// +void Grid::insertCell ( + const unsigned int row, + const unsigned int col, + Cell* cell) +{ + // Delete any existing cell, because cells are owned by rows, not columns. + if ((*mRows[row])[col] != NULL) +// { +// std::cout << "deleted old cell mRows[" << row << "][" << col << "]" << std::endl; + delete (*mRows[row])[col]; +// } + + (*mRows[row])[col] = cell; + (*mColumns[col])[row] = cell; +// std::cout << "assigned new cell mRows[" << row << "][" << col << "]" << std::endl; +// std::cout << "assigned new cell mColumns[" << col << "][" << row << "]" << std::endl; +} + +//////////////////////////////////////////////////////////////////////////////// +Grid::Cell::Cell (const bool value) +: mType (CELL_BOOL) +, mBool (value) +{ +} + +Grid::Cell::Cell (const char value) +: mType (CELL_CHAR) +, mChar (value) +{ +} + +Grid::Cell::Cell (const int value) +: mType (CELL_INT) +, mInt (value) +{ +} + +Grid::Cell::Cell (const float value) +: mType (CELL_FLOAT) +, mFloat (value) +{ +} + +Grid::Cell::Cell (const double value) +: mType (CELL_DOUBLE) +, mDouble (value) +{ +} + +Grid::Cell::Cell (const std::string& value) +: mType (CELL_STRING) +, mString (value) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// These cast operators make a best approximation to an appropriate rendering, +// given the format change. +Grid::Cell::operator bool () const +{ + switch (mType) + { + case CELL_BOOL: return mBool; + case CELL_CHAR: return mChar != '\0' && + mChar != ' ' && + mChar != '0'; + case CELL_INT: return mInt != 0; + case CELL_FLOAT: return mFloat != 0.0; + case CELL_DOUBLE: return mDouble != 0.0; + case CELL_STRING: return mString.length () > 0; + } + + return false; +} + +Grid::Cell::operator char () const +{ + switch (mType) + { + case CELL_BOOL: return mBool ? 'Y' : 'N'; + case CELL_CHAR: return mChar; + case CELL_INT: return (char) mInt; + case CELL_FLOAT: return (char) (int) mFloat; + case CELL_DOUBLE: return (char) (int) mDouble; + case CELL_STRING: return mString[0]; + } + + return '\0'; +} + +Grid::Cell::operator int () const +{ + switch (mType) + { + case CELL_BOOL: return mBool ? 1 : 0; + case CELL_CHAR: return (int) mChar; + case CELL_INT: return mInt; + case CELL_FLOAT: return (int) mFloat; + case CELL_DOUBLE: return (int) mDouble; + case CELL_STRING: return mString.length (); + } + + return 0; +} + +Grid::Cell::operator float () const +{ + switch (mType) + { + case CELL_BOOL: return mBool ? 1.0 : 0.0; + case CELL_CHAR: return (float) (int) mChar; + case CELL_INT: return (float) mInt; + case CELL_FLOAT: return mFloat; + case CELL_DOUBLE: return (float) mDouble; + case CELL_STRING: return (float) mString.length (); + } + + return 0.0; +} + +Grid::Cell::operator double () const +{ + switch (mType) + { + case CELL_BOOL: return mBool ? 1.0 : 0.0; + case CELL_CHAR: return (double) (int) mChar; + case CELL_INT: return (double) mInt; + case CELL_FLOAT: return (double) mFloat; + case CELL_DOUBLE: return mDouble; + case CELL_STRING: return (double) mString.length (); + } + + return 0.0; +} + +Grid::Cell::operator std::string () const +{ + char s[64] = {0}; + + switch (mType) + { + case CELL_BOOL: return mBool ? "true" : "false"; + case CELL_CHAR: sprintf (s, "%c", mChar); + return std::string (s); + case CELL_INT: sprintf (s, "%d", mInt); + return std::string (s); + case CELL_FLOAT: sprintf (s, "%f", mFloat); + return std::string (s); + case CELL_DOUBLE: sprintf (s, "%f", mDouble); + return std::string (s); + case CELL_STRING: return mString; + } + + return std::string (""); +} + +//////////////////////////////////////////////////////////////////////////////// +Grid::Cell::cellType Grid::Cell::type () const +{ + return mType; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Grid.h b/src/Grid.h new file mode 100644 index 000000000..8c36d682d --- /dev/null +++ b/src/Grid.h @@ -0,0 +1,75 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 2007 - 2008, Paul Beckingham. All rights reserved. +// +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_GRID +#define INCLUDED_GRID + +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +class Grid +{ +public: + class Cell + { + public: + Cell (const bool); + Cell (const char); + Cell (const int); + Cell (const float); + Cell (const double); + Cell (const std::string&); + + operator bool () const; + operator char () const; + operator int () const; + operator float () const; + operator double () const; + operator std::string () const; + + enum cellType {CELL_BOOL, CELL_CHAR, CELL_INT, CELL_FLOAT, CELL_DOUBLE, CELL_STRING}; + + cellType type () const; + + private: + cellType mType; + bool mBool; + char mChar; + int mInt; + float mFloat; + double mDouble; + std::string mString; + }; + +public: + Grid (); + ~Grid (); + + void add (const unsigned int, const unsigned int, const bool); + void add (const unsigned int, const unsigned int, const char); + void add (const unsigned int, const unsigned int, const int); + void add (const unsigned int, const unsigned int, const float); + void add (const unsigned int, const unsigned int, const double); + void add (const unsigned int, const unsigned int, const std::string&); + + unsigned int width () const; + unsigned int height () const; + + Cell* byRow (const unsigned int, const unsigned int) const; + Cell* byColumn (const unsigned int, const unsigned int) const; + +private: + void expandGrid (const unsigned int, const unsigned int); + void insertCell (const unsigned int, const unsigned int, Cell*); + +private: + std::vector < std::vector * > mRows; + std::vector < std::vector * > mColumns; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// + diff --git a/src/Makefile.am b/src/Makefile.am index 611286339..247011973 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,2 +1,2 @@ bin_PROGRAMS = task -task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp color.cpp parse.cpp task.cpp util.cpp text.cpp rules.cpp Config.h Date.h T.h TDB.h Table.h color.h stlmacros.h task.h +task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp Grid.cpp color.cpp parse.cpp task.cpp util.cpp text.cpp rules.cpp Config.h Date.h T.h TDB.h Table.h Grid.h color.h stlmacros.h task.h diff --git a/src/Table.cpp b/src/Table.cpp index e2921abdb..786c3591e 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -22,10 +22,10 @@ // //////////////////////////////////////////////////////////////////////////////// #include -#include "Table.h" -#include "Date.h" -#include "stlmacros.h" -#include "task.h" +#include +#include +#include +#include //////////////////////////////////////////////////////////////////////////////// Table::Table () @@ -153,9 +153,7 @@ void Table::setColumnCommify (int column) //////////////////////////////////////////////////////////////////////////////// void Table::setColumnJustification (int column, just j) { - char id[12]; - sprintf (id, "col:%d", column); - mJustification[id] = j; + mJustification[column] = j; } //////////////////////////////////////////////////////////////////////////////// @@ -505,20 +503,8 @@ void Table::calculateColumnWidths () //////////////////////////////////////////////////////////////////////////////// Table::just Table::getJustification (int row, int col) { - char idCell[24]; - sprintf (idCell, "cell:%d,%d", row, col); - if (mJustification.find (idCell) != mJustification.end ()) - return mJustification[idCell]; - - char idRow[12]; - sprintf (idRow, "row:%d", row); - if (mJustification.find (idRow) != mJustification.end ()) - return mJustification[idRow]; - - char idCol[12]; - sprintf (idCol, "col:%d", col); - if (mJustification.find (idCol) != mJustification.end ()) - return mJustification[idCol]; + if (mJustification.find (col) != mJustification.end ()) + return mJustification[col]; return left; } @@ -526,11 +512,7 @@ Table::just Table::getJustification (int row, int col) //////////////////////////////////////////////////////////////////////////////// Table::just Table::getHeaderJustification (int col) { - char idCol[12]; - sprintf (idCol, "col:%d", col); - - return mJustification.find (idCol) != mJustification.end () ? mJustification[idCol] - : mJustification.find ("table") != mJustification.end () ? mJustification["table"] + return mJustification.find (col) != mJustification.end () ? mJustification[col] : left; } diff --git a/src/Table.h b/src/Table.h index d49d70e4f..1be6d3e22 100644 --- a/src/Table.h +++ b/src/Table.h @@ -10,7 +10,8 @@ #include #include #include -#include "color.h" +#include +#include class Table { @@ -100,7 +101,7 @@ private: std::vector mMaxDataWidth; std::vector mCalculatedWidth; - std::map mJustification; + std::map mJustification; std::map mCommify; std::map mData; std::vector mSortColumns;