"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Rose/FormattedTable.h" between
rose-0.11.53.0.tar.gz and rose-0.11.54.0.tar.gz

About: ROSE is a compiler infrastructure to build source-to-source program transformation and analysis tools for large-scale C, C++, UPC, Fortran, OpenMP, Java, Python and PHP applications.

FormattedTable.h  (rose-0.11.53.0):FormattedTable.h  (rose-0.11.54.0)
#ifndef ROSE_StringUtility_FormattedTable_H #ifndef ROSE_StringUtility_FormattedTable_H
#define ROSE_StringUtility_FormattedTable_H #define ROSE_StringUtility_FormattedTable_H
#include <Rose/Color.h> #include <Rose/Color.h>
#include <boost/lexical_cast.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
namespace Rose { namespace Rose {
/** Class for printing nicely formattated tables. /** Class for printing nicely formattated tables.
* *
* A table is a two-dimensional grid containing cells. A @ref FormattedTable ob ject holds information about how to * A table is a two-dimensional grid containing cells. A @ref FormattedTable ob ject holds information about how to
* format cells, functions to populate the cells, and functions to print the ta ble. */ * format cells, functions to populate the cells, and functions to print the ta ble. */
class FormattedTable { class FormattedTable {
public: public:
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
// Public types // Public types
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
/** Format when generating output. */
enum class Format {
PLAIN, /**< Use ASCII-art to dr
aw the table borders. */
HTML, /**< Generate HTML outpu
t. */
CSV, /**< Comma separated val
ues, RFC 4180. */
SHELL /**< A format friendly f
or shell scripts. No header columns. Lines
* are separated by AS
CII line feed characters (not carriage returns).
* Values are separate
d by horizontal tab characters. Line feeds and
* tabs are escaped in
the values. Shell <code>$"</code> style
* escaping is used (C
-like) in addition to escaped tabs and
* linefeeds. */
};
/** How text is aligned in a table cell. */
enum class Alignment {
LEFT, /**< Text is aligned to
the left edge of the cell. */
RIGHT, /**< Text is aligned to
the right edge of the cell. */
CENTER /**< Text is centered in
the cell. */
};
/** Properties for a particular cell. */ /** Properties for a particular cell. */
class CellProperties { class CellProperties {
Sawyer::Optional<Color::HSV> foreground_; Sawyer::Optional<Color::HSV> foreground_;
Sawyer::Optional<Color::HSV> background_; Sawyer::Optional<Color::HSV> background_;
Sawyer::Optional<Alignment> alignment_;
public: public:
/** Default constructor.
*
* No specific properties are set. */
CellProperties();
/** Constructor.
*
* Sets properties as specified. */
CellProperties(const Sawyer::Optional<Color::HSV> &foreground,
const Sawyer::Optional<Color::HSV> &background,
const Sawyer::Optional<Alignment> &alignment);
/** Property: Foreground color. /** Property: Foreground color.
* *
* @{ */ * @{ */
const Sawyer::Optional<Color::HSV>& foreground() const; const Sawyer::Optional<Color::HSV>& foreground() const;
void foreground(const Sawyer::Optional<Color::HSV>&); void foreground(const Sawyer::Optional<Color::HSV>&);
/** @} */ /** @} */
/** Property: Background color. /** Property: Background color.
* *
* @{ */ * @{ */
const Sawyer::Optional<Color::HSV>& background() const; const Sawyer::Optional<Color::HSV>& background() const;
void background(const Sawyer::Optional<Color::HSV>&); void background(const Sawyer::Optional<Color::HSV>&);
/** @} */ /** @} */
/** Property: Horizontal alignment.
*
* @{ */
const Sawyer::Optional<Alignment>& alignment() const;
void alignment(const Sawyer::Optional<Alignment>&);
/** @} */
/** Create new properties by merging two properties. /** Create new properties by merging two properties.
* *
* The return value has values from object @p a or object @p b, whichev er is set, in that order. */ * The return value has values from object @p a or object @p b, whichev er is set, in that order. */
static CellProperties merge(const CellProperties &a, const CellPropertie s &b); static CellProperties merge(const CellProperties &a, const CellPropertie s &b);
}; };
private: private:
std::vector<std::vector<std::string>> cells_; // data std::vector<std::vector<std::string>> cells_; // data
std::vector<std::vector<CellProperties>> props_; // data properties std::vector<std::vector<CellProperties>> props_; // data properties
std::vector<std::vector<std::string>> columnHeaders_; // titles for columns std::vector<std::vector<std::string>> columnHeaders_; // titles for columns
std::vector<std::vector<CellProperties>> columnHeaderProps_;
std::string indentation_; // to be printed befor e each line of output std::string indentation_; // to be printed befor e each line of output
Format format_ = Format::PLAIN;
public: public:
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
// Constructors, etc. // Constructors, etc.
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
/** Construct an empty table. */ /** Construct an empty table. */
FormattedTable(); FormattedTable();
/** Construct a table with a certain number of cells. */ /** Construct a table with a certain number of cells. */
FormattedTable(size_t nRows, size_t nColumns); FormattedTable(size_t nRows, size_t nColumns);
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
// Table-wide properties // Table-wide properties
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
/** Property: Output format.
*
* How the table is formatted in general.
*
* @{ */
Format format() const;
void format(Format);
/** @} */
/** Property: Indentation. /** Property: Indentation.
* *
* This property holds a string that is printed at the beginning of every l * This property holds a string that is printed at the beginning of every l
ine of output. ine of output. This used for the plain-text
* format; it's ignored for HTML output.
* *
* @{ */ * @{ */
const std::string& indentation() const; const std::string& indentation() const;
void indentation(const std::string&); void indentation(const std::string&);
/** @} */ /** @} */
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
// FormattedTable data // FormattedTable data
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
skipping to change at line 107 skipping to change at line 160
/** @} */ /** @} */
/** Insert data into a table. /** Insert data into a table.
* *
* If the row and/or column number is outside the current size of the table , then the table is automatically resized, but * If the row and/or column number is outside the current size of the table , then the table is automatically resized, but
* it's more efficient to resize the table before adding data. * it's more efficient to resize the table before adding data.
* *
* @{ */ * @{ */
void insert(size_t rowIdx, size_t columnIdx, const std::string &repr); void insert(size_t rowIdx, size_t columnIdx, const std::string &repr);
void insert(size_t rowIdx, size_t columnIdx, const std::string &repr, const CellProperties&); void insert(size_t rowIdx, size_t columnIdx, const std::string &repr, const CellProperties&);
template<typename T> void insert(size_t rowIdx, size_t columnIdx, const T &v
alue) {
insert(rowIdx, columnIdx, boost::lexical_cast<std::string>(value));
}
template<typename T> void insert(size_t rowIdx, size_t columnIdx, const T &v
alue, const CellProperties &prop) {
insert(rowIdx, columnIdx, boost::lexical_cast<std::string>(value), prop)
;
}
/** @} */ /** @} */
/** Properties for a data cell. /** Properties for a data cell.
* *
* When inserting properties, the table is automatically extended. * When inserting properties, the table is automatically extended.
* *
* @{ */ * @{ */
const CellProperties& cellProperties(size_t rowIdx, size_t columnIdx) const; const CellProperties& cellProperties(size_t rowIdx, size_t columnIdx) const;
void cellProperties(size_t rowIdx, size_t columnIdx, const CellProperties&); void cellProperties(size_t rowIdx, size_t columnIdx, const CellProperties&);
/** @} */ /** @} */
skipping to change at line 143 skipping to change at line 202
/** Property: Name for column headers. /** Property: Name for column headers.
* *
* Column headers occupy one or more rows, but the rows do not count as dat a. Column information is extended as necessary * Column headers occupy one or more rows, but the rows do not count as dat a. Column information is extended as necessary
* when new column headers are added. When querying a column header that do esn't exist, an empty string is returned. * when new column headers are added. When querying a column header that do esn't exist, an empty string is returned.
* *
* @{ */ * @{ */
const std::string& columnHeader(size_t rowIdx, size_t columnIdx) const; const std::string& columnHeader(size_t rowIdx, size_t columnIdx) const;
void columnHeader(size_t rowIdx, size_t columnIdx, const std::string &title) ; void columnHeader(size_t rowIdx, size_t columnIdx, const std::string &title) ;
/** @} */ /** @} */
/** Properties for column headers.
*
* These are the properties for formatting column header cells. Column head
er row indices are indpendent of the data
* cell indices.
*
* @{ */
const CellProperties& columnHeaderProperties(size_t rowIdx, size_t columnIdx
) const;
void columnHeaderProperties(size_t rowIdx, size_t columnIdx, const CellPrope
rties&);
/** @} */
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
// Printing // Printing
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
/** Print a table. */ /** Print a table. */
void print(std::ostream&) const; void print(std::ostream&) const;
private: private:
std::string ansiPropertiesBegin(const CellProperties&) const; std::string cellPropertiesBegin(const CellProperties&) const;
std::string ansiPropertiesEnd(const CellProperties&) const; std::string cellPropertiesEnd(const CellProperties&) const;
void printHorizontalRule(std::ostream&, const std::vector<size_t> &widths) c onst; void printHorizontalRule(std::ostream&, const std::vector<size_t> &widths) c onst;
void printRow(std::ostream&, const std::vector<size_t> &widths, const std::v ector<CellProperties> &props, void printRow(std::ostream&, const std::vector<size_t> &widths, const std::v ector<CellProperties> &props,
const std::vector<std::string> &row, std::string(*justify)(con st std::string&, size_t, char)) const; const std::vector<std::string> &row) const;
std::vector<size_t> computeColumnWidths() const; std::vector<size_t> computeColumnWidths() const;
}; };
} // namespace } // namespace
std::ostream& operator<<(std::ostream &out, const Rose::FormattedTable &table); std::ostream& operator<<(std::ostream &out, const Rose::FormattedTable &table);
#endif #endif
 End of changes. 13 change blocks. 
5 lines changed or deleted 91 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)