OpenMEEG
Loading...
Searching...
No Matches
range.h
Go to the documentation of this file.
1// Project Name: OpenMEEG (http://openmeeg.github.io)
2// © INRIA and ENPC under the French open source license CeCILL-B.
3// See full copyright notice in the file LICENSE.txt
4// If you make a copy of this file, you must either:
5// - provide also LICENSE.txt and modify this header to refer to it.
6// - replace this header by the LICENSE.txt content.
7
8#pragma once
9
10#include <iostream>
11#include <vector>
12
13namespace OpenMEEG::maths {
14
15 class Range {
16 public:
17
18 Range(): start_index(0),end_index(0) { }
19 Range(const size_t s,const size_t e): start_index(s),end_index(e) { }
20
21 size_t start() const { return start_index; }
22 size_t end() const { return end_index; }
23
24 size_t length() const { return end()-start()+1; }
25
26 bool contains(const size_t ind) const { return ind>=start() && ind<=end(); }
27 bool intersect(const Range& r) const { return contains(r.start()) || contains(r.end()); }
28
29 bool operator==(const Range& r) const { return start()==r.start() && end()==r.end(); }
30 bool operator!=(const Range& r) const { return start()!=r.start() || end()!=r.end(); }
31
32 private:
33
34 size_t start_index;
35 size_t end_index;
36 };
37
38 inline std::ostream& operator<<(std::ostream& os,const Range& r) {
39 return os << '(' << r.start() << ',' << r.end() << ')';
40 }
41}
size_t end() const
Definition range.h:22
bool operator==(const Range &r) const
Definition range.h:29
Range(const size_t s, const size_t e)
Definition range.h:19
bool intersect(const Range &r) const
Definition range.h:27
size_t start() const
Definition range.h:21
bool operator!=(const Range &r) const
Definition range.h:30
bool contains(const size_t ind) const
Definition range.h:26
size_t length() const
Definition range.h:24
std::ostream & operator<<(std::ostream &os, const BlockMatrix &bm)