• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

History.h

Go to the documentation of this file.
00001 /*
00002     This file is part of Konsole, an X terminal.
00003     Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018     02110-1301  USA.
00019 */
00020 
00021 #ifndef TEHISTORY_H
00022 #define TEHISTORY_H
00023 
00024 // Qt
00025 #include <QtCore/QBitRef>
00026 #include <QtCore/QHash>
00027 #include <QtCore/QVector>
00028 
00029 // KDE
00030 #include <ktemporaryfile.h>
00031 
00032 // Konsole
00033 #include "BlockArray.h"
00034 #include "Character.h"
00035 
00036 namespace Konsole
00037 {
00038 
00039 #if 1
00040 /*
00041    An extendable tmpfile(1) based buffer.
00042 */
00043 
00044 class HistoryFile
00045 {
00046 public:
00047   HistoryFile();
00048   virtual ~HistoryFile();
00049 
00050   virtual void add(const unsigned char* bytes, int len);
00051   virtual void get(unsigned char* bytes, int len, int loc);
00052   virtual int  len();
00053 
00054   //mmaps the file in read-only mode
00055   void map();
00056   //un-mmaps the file
00057   void unmap();
00058   //returns true if the file is mmap'ed
00059   bool isMapped();
00060 
00061 
00062 private:
00063   int  ion;
00064   int  length;
00065   KTemporaryFile tmpFile;
00066 
00067   //pointer to start of mmap'ed file data, or 0 if the file is not mmap'ed
00068   char* fileMap;
00069  
00070   //incremented whenver 'add' is called and decremented whenever
00071   //'get' is called.
00072   //this is used to detect when a large number of lines are being read and processed from the history
00073   //and automatically mmap the file for better performance (saves the overhead of many lseek-read calls).
00074   int readWriteBalance;
00075 
00076   //when readWriteBalance goes below this threshold, the file will be mmap'ed automatically
00077   static const int MAP_THRESHOLD = -1000;
00078 };
00079 #endif
00080 
00082 
00084 // Abstract base class for file and buffer versions
00086 class HistoryType;
00087 
00088 class HistoryScroll
00089 {
00090 public:
00091   HistoryScroll(HistoryType*);
00092  virtual ~HistoryScroll();
00093 
00094   virtual bool hasScroll();
00095 
00096   // access to history
00097   virtual int  getLines() = 0;
00098   virtual int  getLineLen(int lineno) = 0;
00099   virtual void getCells(int lineno, int colno, int count, Character res[]) = 0;
00100   virtual bool isWrappedLine(int lineno) = 0;
00101 
00102   // backward compatibility (obsolete)
00103   Character   getCell(int lineno, int colno) { Character res; getCells(lineno,colno,1,&res); return res; }
00104 
00105   // adding lines.
00106   virtual void addCells(const Character a[], int count) = 0;
00107   // convenience method - this is virtual so that subclasses can take advantage
00108   // of QVector's implicit copying
00109   virtual void addCellsVector(const QVector<Character>& cells)
00110   {
00111     addCells(cells.data(),cells.size());
00112   }
00113 
00114   virtual void addLine(bool previousWrapped=false) = 0;
00115 
00116   //
00117   // FIXME:  Passing around constant references to HistoryType instances
00118   // is very unsafe, because those references will no longer
00119   // be valid if the history scroll is deleted.
00120   //
00121   const HistoryType& getType() { return *m_histType; }
00122 
00123 protected:
00124   HistoryType* m_histType;
00125 
00126 };
00127 
00128 #if 1
00129 
00131 // File-based history (e.g. file log, no limitation in length)
00133 
00134 class HistoryScrollFile : public HistoryScroll
00135 {
00136 public:
00137   HistoryScrollFile(const QString &logFileName);
00138   virtual ~HistoryScrollFile();
00139 
00140   virtual int  getLines();
00141   virtual int  getLineLen(int lineno);
00142   virtual void getCells(int lineno, int colno, int count, Character res[]);
00143   virtual bool isWrappedLine(int lineno);
00144 
00145   virtual void addCells(const Character a[], int count);
00146   virtual void addLine(bool previousWrapped=false);
00147 
00148 private:
00149   int startOfLine(int lineno);
00150 
00151   QString m_logFileName;
00152   HistoryFile index; // lines Row(int)
00153   HistoryFile cells; // text  Row(Character)
00154   HistoryFile lineflags; // flags Row(unsigned char)
00155 };
00156 
00157 
00159 // Buffer-based history (limited to a fixed nb of lines)
00161 class HistoryScrollBuffer : public HistoryScroll
00162 {
00163 public:
00164   typedef QVector<Character> HistoryLine;
00165 
00166   HistoryScrollBuffer(unsigned int maxNbLines = 1000);
00167   virtual ~HistoryScrollBuffer();
00168 
00169   virtual int  getLines();
00170   virtual int  getLineLen(int lineno);
00171   virtual void getCells(int lineno, int colno, int count, Character res[]);
00172   virtual bool isWrappedLine(int lineno);
00173 
00174   virtual void addCells(const Character a[], int count);
00175   virtual void addCellsVector(const QVector<Character>& cells);
00176   virtual void addLine(bool previousWrapped=false);
00177 
00178   void setMaxNbLines(unsigned int nbLines);
00179   unsigned int maxNbLines() { return _maxLineCount; }
00180   
00181 
00182 private:
00183   int bufferIndex(int lineNumber);
00184 
00185   HistoryLine* _historyBuffer;
00186   QBitArray _wrappedLine;
00187   int _maxLineCount;
00188   int _usedLines;  
00189   int _head;
00190   
00191   //QVector<histline*> m_histBuffer;
00192   //QBitArray m_wrappedLine;
00193   //unsigned int m_maxNbLines;
00194   //unsigned int m_nbLines;
00195   //unsigned int m_arrayIndex;
00196   //bool         m_buffFilled;
00197 };
00198 
00199 /*class HistoryScrollBufferV2 : public HistoryScroll
00200 {
00201 public:
00202   virtual int  getLines();
00203   virtual int  getLineLen(int lineno);
00204   virtual void getCells(int lineno, int colno, int count, Character res[]);
00205   virtual bool isWrappedLine(int lineno);
00206 
00207   virtual void addCells(const Character a[], int count);
00208   virtual void addCells(const QVector<Character>& cells);
00209   virtual void addLine(bool previousWrapped=false);
00210 
00211 };*/
00212 
00213 #endif
00214 
00216 // Nothing-based history (no history :-)
00218 class HistoryScrollNone : public HistoryScroll
00219 {
00220 public:
00221   HistoryScrollNone();
00222   virtual ~HistoryScrollNone();
00223 
00224   virtual bool hasScroll();
00225 
00226   virtual int  getLines();
00227   virtual int  getLineLen(int lineno);
00228   virtual void getCells(int lineno, int colno, int count, Character res[]);
00229   virtual bool isWrappedLine(int lineno);
00230 
00231   virtual void addCells(const Character a[], int count);
00232   virtual void addLine(bool previousWrapped=false);
00233 };
00234 
00236 // BlockArray-based history
00238 class HistoryScrollBlockArray : public HistoryScroll
00239 {
00240 public:
00241   HistoryScrollBlockArray(size_t size);
00242   virtual ~HistoryScrollBlockArray();
00243 
00244   virtual int  getLines();
00245   virtual int  getLineLen(int lineno);
00246   virtual void getCells(int lineno, int colno, int count, Character res[]);
00247   virtual bool isWrappedLine(int lineno);
00248 
00249   virtual void addCells(const Character a[], int count);
00250   virtual void addLine(bool previousWrapped=false);
00251 
00252 protected:
00253   BlockArray m_blockArray;
00254   QHash<int,size_t> m_lineLengths;
00255 };
00256 
00258 // History type
00260 
00261 class HistoryType
00262 {
00263 public:
00264   HistoryType();
00265   virtual ~HistoryType();
00266 
00271   virtual bool isEnabled()           const = 0;
00275   bool isUnlimited() const { return maximumLineCount() == 0; }
00280   virtual int maximumLineCount()    const = 0;
00281 
00282   virtual HistoryScroll* scroll(HistoryScroll *) const = 0;
00283 };
00284 
00285 class HistoryTypeNone : public HistoryType
00286 {
00287 public:
00288   HistoryTypeNone();
00289 
00290   virtual bool isEnabled() const;
00291   virtual int maximumLineCount() const;
00292 
00293   virtual HistoryScroll* scroll(HistoryScroll *) const;
00294 };
00295 
00296 class HistoryTypeBlockArray : public HistoryType
00297 {
00298 public:
00299   HistoryTypeBlockArray(size_t size);
00300   
00301   virtual bool isEnabled() const;
00302   virtual int maximumLineCount() const;
00303 
00304   virtual HistoryScroll* scroll(HistoryScroll *) const;
00305 
00306 protected:
00307   size_t m_size;
00308 };
00309 
00310 #if 1 
00311 class HistoryTypeFile : public HistoryType
00312 {
00313 public:
00314   HistoryTypeFile(const QString& fileName=QString());
00315 
00316   virtual bool isEnabled() const;
00317   virtual const QString& getFileName() const;
00318   virtual int maximumLineCount() const;
00319 
00320   virtual HistoryScroll* scroll(HistoryScroll *) const;
00321 
00322 protected:
00323   QString m_fileName;
00324 };
00325 
00326 
00327 class HistoryTypeBuffer : public HistoryType
00328 {
00329     friend class HistoryScrollBuffer;
00330 
00331 public:
00332   HistoryTypeBuffer(unsigned int nbLines);
00333    
00334   virtual bool isEnabled() const;
00335   virtual int maximumLineCount() const;
00336   
00337   virtual HistoryScroll* scroll(HistoryScroll *) const;
00338 
00339 protected:
00340   unsigned int m_nbLines;
00341 };
00342 
00343 #endif
00344 
00345 }
00346 
00347 #endif // TEHISTORY_H

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal