• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • core
  • piecetable
piecelist.h
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Core library, made within the KDE community.
3 
4  Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef KPIECETABLE_PIECELIST_H
24 #define KPIECETABLE_PIECELIST_H
25 
26 // lib
27 #include "piece.h"
28 // Qt
29 #include <QtCore/QList>
30 
31 
32 namespace KPieceTable
33 {
34 
35 class PieceList
36 {
37  public:
38  PieceList();
39  explicit PieceList( const Piece& piece );
40 
41  ~PieceList();
42 
43  public:
44  int size() const;
45  bool isEmpty() const;
46  Size totalLength() const;
47  const Piece& at( int i ) const;
48 
49  public:
50  void append( const PieceList& other );
51  void append( const Piece& piece );
52  void prepend( const PieceList& other );
53 
54  protected:
55  QList<Piece> mList;
56  Size mTotalLength;
57 };
58 
59 
60 inline PieceList::PieceList() : mTotalLength( 0 ) {}
61 inline PieceList::PieceList( const Piece& piece )
62  : mTotalLength( 0 )
63 {
64  append( piece );
65 }
66 
67 inline int PieceList::size() const { return mList.size(); }
68 inline bool PieceList::isEmpty() const { return mList.isEmpty(); }
69 inline Size PieceList::totalLength() const { return mTotalLength; }
70 inline const Piece& PieceList::at( int i ) const { return mList.at( i ); }
71 
72 inline void PieceList::append( const Piece& piece )
73 {
74  bool isMerged = false;
75  if( !mList.isEmpty() )
76  isMerged = mList.last().append( piece );
77  if( !isMerged )
78  mList.append( piece );
79  mTotalLength += piece.width();
80 }
81 inline void PieceList::append( const PieceList& other )
82 {
83  QList<Piece>::ConstIterator it = other.mList.begin();
84 
85  // see if the ones at the border can be merged
86  bool isMerged = false;
87  if( !mList.isEmpty() && !other.mList.isEmpty() )
88  isMerged = mList.last().append( other.mList.first() );
89  if( isMerged )
90  ++it;
91 
92  for( ; it != other.mList.end(); ++it )
93  mList.append( *it );
94 //was: mList += other.mList;
95 
96  mTotalLength += other.mTotalLength;
97 }
98 inline void PieceList::prepend( const PieceList& other )
99 {
100  QList<Piece> otherCopy = other.mList;
101  QList<Piece>::Iterator it = mList.begin();
102 
103  // see if the ones at the border can be merged
104  bool isMerged = false;
105  if( !otherCopy.isEmpty() && !mList.isEmpty() )
106  isMerged = otherCopy.last().append( mList.first() );
107  if( isMerged )
108  ++it;
109 
110  for( ; it != mList.end(); ++it )
111  otherCopy.append( *it );
112  mList = otherCopy;
113 //was: mList = other.mList + mList;
114 
115  mTotalLength += other.mTotalLength;
116 }
117 
118 inline PieceList::~PieceList() {}
119 
120 }
121 
122 #endif
KPieceTable::PieceList::append
void append(const PieceList &other)
Definition: piecelist.h:81
KPieceTable::Size
Okteta::Size Size
Definition: piece.h:33
KPieceTable::PieceList::mList
QList< Piece > mList
Definition: piecelist.h:55
KPieceTable::PieceList::mTotalLength
Size mTotalLength
Definition: piecelist.h:56
KDE::NumberRange::width
S width() const
Definition: numberrange.h:141
KPieceTable::PieceList::size
int size() const
Definition: piecelist.h:67
KPieceTable::PieceList
Definition: piecelist.h:35
KPieceTable::PieceList::isEmpty
bool isEmpty() const
Definition: piecelist.h:68
KPieceTable::PieceList::PieceList
PieceList()
Definition: piecelist.h:60
KPieceTable::PieceList::at
const Piece & at(int i) const
Definition: piecelist.h:70
KPieceTable::Piece
Definition: piece.h:38
KPieceTable::PieceList::totalLength
Size totalLength() const
Definition: piecelist.h:69
KPieceTable::PieceList::prepend
void prepend(const PieceList &other)
Definition: piecelist.h:98
piece.h
QList
Definition: bookmarkable.h:29
KPieceTable::PieceList::~PieceList
~PieceList()
Definition: piecelist.h:118
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal