Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLUtils/src/ICLUtils/TextTable.h ** 00010 ** Module : ICLUtils ** 00011 ** Authors: Christof Elbrechter ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <ICLUtils/StringUtils.h> 00035 #include <ICLUtils/Size.h> 00036 00037 namespace icl{ 00038 namespace utils{ 00039 00041 00085 class ICLUtils_API TextTable{ 00086 std::vector<std::string> m_texts; 00087 Size m_size; 00088 int m_maxCellWidth; 00089 00090 public: 00091 00093 00096 inline TextTable(int width=0, int height=0, int maxCellWidth=20): 00097 m_texts(width*height),m_size(width,height),m_maxCellWidth(maxCellWidth){} 00098 00100 00103 inline std::string &operator()(int xCell, int yCell){ 00104 ensureSize(xCell+1, yCell+1); 00105 return m_texts[xCell + m_size.width*yCell]; 00106 } 00107 00109 void ensureSize(int width, int height); 00110 00111 00113 00117 inline int getMaxCellWidth() const { return m_maxCellWidth; } 00118 00120 inline void setMaxCellWidth(int maxCellWidth) { m_maxCellWidth = maxCellWidth; } 00121 00123 inline const Size &getSize() const { return m_size; } 00124 00126 inline const std::vector<std::string> &getData() const { return m_texts; } 00127 00129 class RowAssigner{ 00130 TextTable &t; 00131 int row; 00132 inline RowAssigner(TextTable &t, int row):t(t),row(row){} 00133 00135 friend class TextTable; 00136 00137 public: 00139 inline void operator=(const std::vector<std::string> &rowValues){ 00140 for(unsigned int i=0;i<rowValues.size();++i){ 00141 this->t(i,this->row) = rowValues[i]; 00142 } 00143 } 00145 inline void operator=(RowAssigner otherRow){ 00146 for(int i=0;i<otherRow.t.getSize().width;++i){ 00147 this->t(i,row) = otherRow.t(i,otherRow.row); 00148 } 00149 } 00150 }; 00151 00153 inline RowAssigner operator[](int row){ 00154 return RowAssigner(*this,row); 00155 } 00156 00158 std::string toString() const; 00159 00161 00162 void clear(); 00163 }; 00164 00166 inline std::ostream &operator<<(std::ostream &stream, const TextTable &t){ 00167 return stream << t.toString(); 00168 } 00169 } // namespace utils 00170 } 00171