blob: 7f134b3e577650bceb72d2cc82a6409d72d0e691 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/***************************************************************************
kcoordrange.h - description
-------------------
begin : Sun 03.08.2003
copyright : (C) 2003 by Friedrich W. H. Kossebau
email : Friedrich.W.H@Kossebau.de
****************************************************************************/
/***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License version 2 as published by the Free Software Foundation. *
* *
***************************************************************************/
#ifndef KHE_KCOORDRANGE_H
#define KHE_KCOORDRANGE_H
// lib specific
#include "krange.h"
#include "kbuffercoord.h"
#include "ksection.h"
namespace KHE
{
template<>
inline const TDEBufferCoord KRange<TDEBufferCoord>::null() const { return TDEBufferCoord(-1,-1);}
typedef KRange<TDEBufferCoord> KBasicCoordRange;
/** describes a range in the buffercoord
*@author Friedrich W. H. Kossebau
*/
class KCoordRange : public KRange<TDEBufferCoord>
{
public:
/**
* @param SC start coord
* @param EC end coord
*/
KCoordRange( TDEBufferCoord SC, TDEBufferCoord EC );
/**
* @param Pos start and end pos
* @param Lines start and end line
*/
KCoordRange( KSection Pos, KSection Lines );
KCoordRange();
~KCoordRange();
public:
KCoordRange &operator=( const KCoordRange &S );
public:
bool operator==( const KCoordRange &S ) const;
public:
/** calculates the number of coords that are covered if a line has the given length.
* If the range is invalid the behaviour is undefined.
* @param LineLength
* @return the number of points covered if a line has a length of LineLength.
*/
int width( int LineLength ) const;
/** calculates the number of lines that are covered by the range.
* If the range is invalid the behaviour is undefined.
* @return number of lines covered
*/
int lines() const;
/** tests if the given line is included by the range.
* If the range is invalid or the line < 0 the behaviour is undefined.
* @param Line index of line
* @return @c true if Line is included, otherwise @c false
*/
bool includesLine( int Line ) const;
};
inline KCoordRange::KCoordRange( TDEBufferCoord SC, TDEBufferCoord EC ) : KBasicCoordRange(SC,EC) {}
inline KCoordRange::KCoordRange( KSection Pos, KSection Lines )
: KBasicCoordRange( TDEBufferCoord(Pos.start(),Lines.start()), TDEBufferCoord(Pos.end(),Lines.end()) ) {}
inline KCoordRange::KCoordRange() {}
inline KCoordRange::~KCoordRange() {}
inline bool KCoordRange::operator==( const KCoordRange &R ) const { return KBasicCoordRange::operator==(R); }
inline KCoordRange &KCoordRange::operator=( const KCoordRange &R ) { KBasicCoordRange::operator=(R); return *this; }
inline int KCoordRange::width( int LineLength ) const { return LineLength*(lines()-1) + End.pos() - Start.pos()+1; }
inline int KCoordRange::lines() const { return End.line() - Start.line() + 1; }
inline bool KCoordRange::includesLine( int Line ) const { return Line >= Start.line() && Line <= End.line(); }
}
#endif
|