mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
textTable.cpp
Go to the documentation of this file.
1 /** \file textTable.cpp
2  * \brief implementation for a simple text table manager
3  *
4  * \author Jared R. Males (jaredmales@gmail.com)
5  *
6  * \ingroup asciiutils
7  *
8  */
9 
10 //***********************************************************************//
11 // Copyright 2021 Jared R. Males (jaredmales@gmail.com)
12 //
13 // This file is part of mxlib.
14 //
15 // mxlib is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 // mxlib is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
27 //***********************************************************************//
28 
29 #include "ioutils/textTable.hpp"
30 
31 /// The mxlib c++ namespace
32 namespace mx
33 {
34 namespace ioutils
35 {
36 void textTable::addCell( size_t row,
37  size_t col,
38  const std::string & cell
39  )
40 {
41  //Increase size if needed.
42  if( row >= m_rows.size() )
43  {
44  size_t N = m_rows.size();
45  for(size_t i=0; i < row - N +1; ++i)
46  {
47  m_rows.push_back( std::vector<std::vector<std::string>>( m_colWidths.size()));
48  }
49  }
50 
51  m_rows[row][col].clear();
52  stringWrap(m_rows[row][col], cell, m_colWidths[col]);
53 }
54 
55 
56 void textTable::addCell(size_t row,
57  size_t col,
58  const char * cell
59  )
60 {
61  addCell(row, col, std::string(cell));
62 }
63 
64 template
65 void textTable::outPut<std::ostream>(std::ostream & ios);
66 
67 } //namespace ioutils
68 } //namespace mx
69 
int stringWrap(std::vector< std::string > &lines, const std::string &str, int width)
Wrap a string by breaking it into smaller sized portions of a desired width.
The mxlib c++ namespace.
Definition: mxError.hpp:107
std::vector< int > m_colWidths
The widths of each column, not including the separator.
Definition: textTable.hpp:62
void addCell(size_t row, size_t col, const std::string &cell)
Add one cell to the table, overwriting if it already exists.
Definition: textTable.cpp:36
std::vector< std::vector< std::vector< std::string > > > m_rows
The table cells.
Definition: textTable.hpp:67
declares and defines a simple text table manager