Image Component Library (ICL)
TextTable.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/TextTable.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/StringUtils.h>
35 #include <ICLUtils/Size.h>
36 
37 namespace icl{
38  namespace utils{
39 
41 
86  std::vector<std::string> m_texts;
89 
90  public:
91 
93 
96  inline TextTable(int width=0, int height=0, int maxCellWidth=20):
97  m_texts(width*height),m_size(width,height),m_maxCellWidth(maxCellWidth){}
98 
100 
103  inline std::string &operator()(int xCell, int yCell){
104  ensureSize(xCell+1, yCell+1);
105  return m_texts[xCell + m_size.width*yCell];
106  }
107 
109  void ensureSize(int width, int height);
110 
111 
113 
117  inline int getMaxCellWidth() const { return m_maxCellWidth; }
118 
120  inline void setMaxCellWidth(int maxCellWidth) { m_maxCellWidth = maxCellWidth; }
121 
123  inline const Size &getSize() const { return m_size; }
124 
126  inline const std::vector<std::string> &getData() const { return m_texts; }
127 
129  class RowAssigner{
131  int row;
132  inline RowAssigner(TextTable &t, int row):t(t),row(row){}
133 
135  friend class TextTable;
136 
137  public:
139  inline void operator=(const std::vector<std::string> &rowValues){
140  for(unsigned int i=0;i<rowValues.size();++i){
141  this->t(i,this->row) = rowValues[i];
142  }
143  }
145  inline void operator=(RowAssigner otherRow){
146  for(int i=0;i<otherRow.t.getSize().width;++i){
147  this->t(i,row) = otherRow.t(i,otherRow.row);
148  }
149  }
150  };
151 
153  inline RowAssigner operator[](int row){
154  return RowAssigner(*this,row);
155  }
156 
158  std::string toString() const;
159 
161 
162  void clear();
163  };
164 
166  inline std::ostream &operator<<(std::ostream &stream, const TextTable &t){
167  return stream << t.toString();
168  }
169  } // namespace utils
170 }
171 
int row
parent
Definition: TextTable.h:131
undocument this line if you encounter any issues!
Definition: Any.h:37
Utility class that is used, to assign a table row at once.
Definition: TextTable.h:129
const std::vector< std::string > & getData() const
returns the internal data vector
Definition: TextTable.h:126
int getMaxCellWidth() const
returns the maximum cell width
Definition: TextTable.h:117
TextTable & t
parent TextTable
Definition: TextTable.h:130
void operator=(const std::vector< std::string > &rowValues)
assigns a standard vector of strings (each element is put into a single column)
Definition: TextTable.h:139
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
std::vector< std::string > m_texts
internal text data
Definition: TextTable.h:86
void setMaxCellWidth(int maxCellWidth)
returns the current maxCellWidth value
Definition: TextTable.h:120
RowAssigner operator[](int row)
gives access to the table row (this can be assigned directly if needed)
Definition: TextTable.h:153
RowAssigner(TextTable &t, int row)
Definition: TextTable.h:132
void operator=(RowAssigner otherRow)
assigns the row of another TextTable
Definition: TextTable.h:145
TextTable(int width=0, int height=0, int maxCellWidth=20)
creates a new table with optionally given dimensions
Definition: TextTable.h:96
Size class of the ICL.
Definition: Size.h:61
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.
Size m_size
current size
Definition: TextTable.h:87
Utility class for pretty console output.
Definition: TextTable.h:85
std::string toString() const
serializes the table to a std::string
int m_maxCellWidth
current maximum cell width for serialization
Definition: TextTable.h:88
std::string & operator()(int xCell, int yCell)
returns a reference to the entry at given cell coordinates
Definition: TextTable.h:103
const Size & getSize() const
returns the current table size
Definition: TextTable.h:123