<
boolSigned,
classPosition>
64 template<
classPosition>
75 template<
classPosition>
86 template<
classPosition>
95struct SPositionTraits<float> : SPositionTraitsBySignedness<true, float>
100struct SPositionTraits<double> : SPositionTraitsBySignedness<true, double>
105struct SPositionTraits<long double>
106: SPositionTraitsBySignedness<true, long double>
116template<class Position>
120typedef Position position_type;
121typedef COpenRange<Position> TThisType;
125: m_From(GetEmptyFrom()), m_ToOpen(GetEmptyToOpen())
128COpenRange(position_type from, position_type toOpen)
129: m_From(from), m_ToOpen(toOpen)
134position_type GetFrom(void) const
138position_type GetToOpen(void) const
142position_type GetTo(void) const
144return GetToOpen()-1;
148bool Empty(void) const
150return GetToOpen() <= GetFrom();
152bool NotEmpty(void) const
154return GetToOpen() > GetFrom();
158position_type GetLength(void) const
160position_type from = GetFrom(), toOpen = GetToOpen();
161if ( toOpen <= from )
163position_type len = toOpen - from;
164if ( SPositionTraits<position_type>::IsNegative(len) )
165len = GetWholeLength();
170TThisType& SetFrom(position_type from)
175TThisType& SetToOpen(position_type toOpen)
180TThisType& SetTo(position_type to)
182return SetToOpen(to+1);
184TThisType& SetOpen(position_type from, position_type toOpen)
186return SetFrom(from).SetToOpen(toOpen);
188TThisType& Set(position_type from, position_type to)
190return SetFrom(from).SetTo(to);
194TThisType& SetLength(position_type length)
196_ASSERT(!SPositionTraits<position_type>::IsNegative(length));
197position_type from = GetFrom();
198position_type toOpen = from + length;
200toOpen = GetWholeToOpen();
201return SetToOpen(toOpen);
204TThisType& SetLengthDown(position_type length)
206_ASSERT(length >= 0);
207position_type toOpen = GetToOpen();
208position_type from = toOpen - length;
210from = GetWholeFrom();
211return SetFrom(from);
215bool operator==(const TThisType& r) const
217return GetFrom() == r.GetFrom() && GetToOpen() == r.GetToOpen();
219bool operator!=(const TThisType& r) const
221return !(*this == r);
223bool operator<(const TThisType& r) const
225return GetFrom() < r.GetFrom() ||
226(GetFrom() == r.GetFrom() && GetToOpen() < r.GetToOpen());
228bool operator<=(const TThisType& r) const
230return GetFrom() < r.GetFrom() ||
231(GetFrom() == r.GetFrom() && GetToOpen() <= r.GetToOpen());
233bool operator>(const TThisType& r) const
235return GetFrom() > r.GetFrom() ||
236(GetFrom() == r.GetFrom() && GetToOpen() > r.GetToOpen());
238bool operator>=(const TThisType& r) const
240return GetFrom() > r.GetFrom() ||
241(GetFrom() == r.GetFrom() && GetToOpen() >= r.GetToOpen());
246static position_type GetPositionMin(void)
248return numeric_limits<position_type>::min();
250static position_type GetPositionMax(void)
252return numeric_limits<position_type>::max();
256static position_type GetWholeFrom(void)
258return GetPositionMin();
260static position_type GetWholeToOpen(void)
262return GetPositionMax();
264static position_type GetWholeTo(void)
266return GetWholeToOpen()-1;
268static position_type GetWholeLength(void)
270return GetPositionMax();
272static TThisType GetWhole(void)
274return TThisType(GetWholeFrom(), GetWholeToOpen());
276bool IsWholeFrom(void) const
278return GetFrom() == GetWholeFrom();
280bool IsWholeTo(void) const
282return GetToOpen() == GetWholeToOpen();
284bool IsWhole(void) const
286return IsWholeFrom() && IsWholeTo();
290static position_type GetEmptyFrom(void)
292return GetPositionMax();
294static position_type GetEmptyToOpen(void)
296return GetPositionMax();
298static position_type GetEmptyTo(void)
300return GetEmptyToOpen()-1;
302static position_type GetEmptyLength(void)
306static TThisType GetEmpty(void)
308return TThisType(GetEmptyFrom(), GetEmptyToOpen());
312TThisType IntersectionWith(const TThisType& r) const
314return TThisType(max(GetFrom(), r.GetFrom()),
315min(GetToOpen(), r.GetToOpen()));
317TThisType& IntersectWith(const TThisType& r)
319m_From = max(GetFrom(), r.GetFrom());
320m_ToOpen = min(GetToOpen(), r.GetToOpen());
323TThisType operator&(const TThisType& r) const
325return IntersectionWith(r);
327TThisType& operator&=(const TThisType& r)
329return IntersectWith(r);
331bool IntersectingWith(const TThisType& r) const
333return IntersectionWith(r).NotEmpty();
336bool AbuttingWith(const TThisType& r) const
338if (Empty() || IsWhole() || r.Empty() || r.IsWhole()) {
341return GetToOpen() == r.GetFrom() || GetFrom() == r.GetToOpen();
345TThisType& CombineWith(const TThisType& r)
349m_From = min(m_From, r.GetFrom());
350m_ToOpen = max(m_ToOpen, r.GetToOpen());
358TThisType CombinationWith(const TThisType& r) const
362return TThisType(min(m_From, r.GetFrom()),
363max(m_ToOpen, r.GetToOpen()));
371TThisType& operator+=(const TThisType& r)
373return CombineWith(r);
375TThisType operator+(const TThisType& r) const
377return CombinationWith(r);
381position_type m_From, m_ToOpen;
386template<class Position>
387class CRange : public COpenRange<Position>
390typedef COpenRange<Position> TParent;
391typedef typename TParent::position_type position_type;
392typedef CRange<Position> TThisType;
398CRange(position_type from, position_type to)
399: TParent(from, to+1)
402CRange(const TParent& range)
408TThisType& operator=(const TParent& range)
410static_cast<TParent&>(*this) = range;
419typedef CRange<TSeqPos> TSeqRange;
420typedef CRange<TSignedSeqPos> TSignedSeqRange;
424template<class Position>
426CNcbiOstream& operator<<(CNcbiOstream& out, const COpenRange<Position>& range)
428return out << range.GetFrom() << ".." << range.GetTo();
Include a standard set of the NCBI C++ Toolkit most basic headers.
static bool IsNegative(Position)
static bool IsNegative(Position pos)
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4