Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TextTable.h
Go to the documentation of this file.
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.GPL  **
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/StringUtils.h>
00034 #include <ICLUtils/Size.h>
00035 
00036 namespace icl{
00037   namespace utils{
00038   
00040 
00084     class TextTable{
00085       std::vector<std::string> m_texts; 
00086       Size m_size;  
00087       int m_maxCellWidth; 
00088 
00089       public:
00090     
00092 
00095       inline TextTable(int width=0, int height=0, int maxCellWidth=20):
00096       m_texts(width*height),m_size(width,height),m_maxCellWidth(maxCellWidth){}
00097 
00099 
00102       inline std::string &operator()(int xCell, int yCell){
00103         ensureSize(xCell+1, yCell+1);
00104         return m_texts[xCell + m_size.width*yCell];
00105       }
00106     
00108       void ensureSize(int width, int height);
00109     
00110     
00112 
00116       inline int getMaxCellWidth() const { return m_maxCellWidth; }
00117     
00119       inline void setMaxCellWidth(int maxCellWidth) { m_maxCellWidth = maxCellWidth; }
00120     
00122       inline const Size &getSize() const { return m_size; }
00123     
00125       inline const std::vector<std::string> &getData() const { return m_texts; }
00126 
00128       class RowAssigner{
00129         TextTable &t; 
00130         int row;      
00131         inline RowAssigner(TextTable &t, int row):t(t),row(row){}
00132 
00134         friend class TextTable;
00135 
00136         public:
00138         inline void operator=(const std::vector<std::string> &rowValues){
00139           for(unsigned int i=0;i<rowValues.size();++i){
00140             this->t(i,this->row) = rowValues[i];
00141           }
00142         }
00144         inline void operator=(RowAssigner otherRow){
00145           for(int i=0;i<otherRow.t.getSize().width;++i){
00146             this->t(i,row) = otherRow.t(i,otherRow.row);
00147           }
00148         }
00149       };
00150     
00152       inline RowAssigner operator[](int row){
00153         return RowAssigner(*this,row);
00154       }
00155     
00157       std::string toString() const;
00158     
00160 
00161       void clear();
00162     };
00163   
00165     inline std::ostream &operator<<(std::ostream &stream, const TextTable &t){
00166       return stream << t.toString();
00167     }
00168   } // namespace utils
00169 }
00170 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines