• 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
range.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 2003,2007-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 KDE_RANGE_H
24 #define KDE_RANGE_H
25 
26 
27 namespace KDE
28 {
29 
37 template<typename T>
38 class Range
39 {
40  public:
41  Range( T S, T E ) : Start( S ), End( E ) {}
42  Range() : Start( null() ), End( null() ) {}
43  ~Range() {}
44 
45  public:
46  Range &operator=( const Range &R ) { Start = R.Start; End = R.End; return *this; }
47 
48  public:
49  bool operator==( const Range &R ) const
50  { return (Start == R.Start && End == R.End) || (!isValid() && !R.isValid()); }
51 
52  public: // modification access
54  void set( T S, T E ) { Start = S; End = E; }
56  void set( const Range &R ) { Start = R.Start; End = R.End; }
58  void setStart( T S ) { Start = S; }
60  void setEnd( T E ) { End = E; }
62  void unset() { Start = End = null(); }
64  void restrictTo( const Range &Limit )
65  { if( Start < Limit.start() ) Start = Limit.start(); if( End > Limit.end() ) End = Limit.end(); }
67  void restrictStartTo( T Limit ) { if( Start < Limit ) Start = Limit; }
69  void restrictEndTo( T Limit ) { if( End > Limit ) End = Limit; }
71  void extendTo( const Range &Limit )
72  { if( Start > Limit.start() ) Start = Limit.start(); if( End < Limit.end() ) End = Limit.end(); }
74  void extendStartTo( T Limit ) { if( Start > Limit ) Start = Limit; }
76  void extendEndTo( T Limit ) { if( End < Limit ) End = Limit; }
78  void moveStartBy( T D ) { Start += D; }
80  void moveEndBy( T D ) { End += D; }
82  void moveBy( T D ) { Start += D; End += D; }
83 
84  public: // value access
86  T start() const { return Start; }
88  T end() const { return End; }
89 
90 
91  public: // logic access
93  bool includes( T Value ) const { return Start <= Value && Value <= End; }
95  bool includesInside( T Value ) const { return Start < Value && Value < End; }
97  bool startsBehind( T Value ) const { return Value < Start; }
99  bool startsBefore( T Value ) const { return Start < Value; }
101  bool endsBehind( T Value ) const { return Value < End; }
103  bool endsBefore( T Value ) const { return End < Value; }
104 
106  bool includes( const Range &R ) const { return R.End <= End && Start <= R.Start; }
108  bool includesInside( const Range &R ) const { return R.End < End && Start < R.Start; }
110  bool endsBefore( const Range &R ) const { return End < R.Start; }
112  bool startsBehind( const Range &R ) const { return R.End < Start; }
114  bool startsBefore( const Range &R ) const { return Start < R.Start; }
116  bool endsBehind( const Range &R ) const { return R.End < End; }
118  bool overlaps( const Range &R ) const { return Start <= R.End && R.Start <= End; }
119 
120  // TODO: this is wrong, a empty range is valid, too
122  bool isValid() const { return Start != null() && Start <= End; }
124  bool isEmpty() const { return Start == null() && End == null(); }
125 
126 
127  protected:
129  const T null () const { return T(-1);}
130 
131  protected:
133  T Start;
135  T End;
136 };
137 
138 }
139 
140 #endif
KDE::Range::includesInside
bool includesInside(T Value) const
returns true if Value is covered and not at a side
Definition: range.h:95
KDE::Range::restrictStartTo
void restrictStartTo(T Limit)
restricts the start to Limit.
Definition: range.h:67
KDE::Range::includes
bool includes(const Range &R) const
returns true is the range covers R.
Definition: range.h:106
KDE::Range::extendEndTo
void extendEndTo(T Limit)
extends the end to Limit.
Definition: range.h:76
KDE::Range::extendTo
void extendTo(const Range &Limit)
extends the range to Limit.
Definition: range.h:71
KDE::Range::moveStartBy
void moveStartBy(T D)
moves the start by D.
Definition: range.h:78
KDE::Range::moveBy
void moveBy(T D)
moves the range by D.
Definition: range.h:82
KDE::Range::Range
Range(T S, T E)
Definition: range.h:41
KDE::Range::End
T End
last value of the range
Definition: range.h:135
KDE::Range::start
T start() const
Definition: range.h:86
KDE::Range::setEnd
void setEnd(T E)
sets the last index of the range
Definition: range.h:60
KDE::Range::null
const T null() const
delivers a null element.
Definition: range.h:129
KDE::Range::Start
T Start
first value of the range
Definition: range.h:133
KDE::Range
This template describes a range.
Definition: range.h:38
KDE::Range::restrictTo
void restrictTo(const Range &Limit)
restricts the range to Limit.
Definition: range.h:64
KDE::Range::endsBefore
bool endsBefore(const Range &R) const
returns true is the range ends before R starts.
Definition: range.h:110
KDE::Range::~Range
~Range()
Definition: range.h:43
KDE::Range::startsBefore
bool startsBefore(const Range &R) const
returns true is the range starts prior than R.
Definition: range.h:114
KDE::Range::restrictEndTo
void restrictEndTo(T Limit)
restricts the end to Limit.
Definition: range.h:69
KDE::Range::end
T end() const
Definition: range.h:88
KDE::Range::operator=
Range & operator=(const Range &R)
Definition: range.h:46
KDE::Range::endsBehind
bool endsBehind(T Value) const
returns true if the range ends later than index.
Definition: range.h:101
KDE::Range::overlaps
bool overlaps(const Range &R) const
returns true is the range shares at least one index with R.
Definition: range.h:118
KDE::Range::extendStartTo
void extendStartTo(T Limit)
extends the start to Limit.
Definition: range.h:74
KDE::Range::operator==
bool operator==(const Range &R) const
Definition: range.h:49
KDE::Range::includes
bool includes(T Value) const
returns true if Value is covered
Definition: range.h:93
KDE::Range::unset
void unset()
sets the range to null
Definition: range.h:62
KDE::Range::startsBehind
bool startsBehind(const Range &R) const
returns true is the range starts later than R ends.
Definition: range.h:112
KDE::Range::startsBefore
bool startsBefore(T Value) const
returns true is the range starts before index.
Definition: range.h:99
KDE::Range::endsBefore
bool endsBefore(T Value) const
returns true if range is before index.
Definition: range.h:103
KDE::Range::startsBehind
bool startsBehind(T Value) const
returns true if range is behind index.
Definition: range.h:97
KDE::Range::setStart
void setStart(T S)
sets the first index of the range
Definition: range.h:58
KDE::Range::Range
Range()
Definition: range.h:42
KDE::Range::endsBehind
bool endsBehind(const Range &R) const
returns true is the range ends later than R.
Definition: range.h:116
KDE::Range::isValid
bool isValid() const
returns true if the range covers at least one index
Definition: range.h:122
KDE::Range::moveEndBy
void moveEndBy(T D)
moves the end by D.
Definition: range.h:80
KDE::Range::isEmpty
bool isEmpty() const
returns true if the range has not been set
Definition: range.h:124
KDE::Range::set
void set(const Range &R)
sets the first and the last index of the range
Definition: range.h:56
KDE::Range::set
void set(T S, T E)
sets the first and the last index of the range
Definition: range.h:54
KDE::Range::includesInside
bool includesInside(const Range &R) const
returns true is the range covers R.
Definition: range.h:108
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 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