OpenMEEG
Loading...
Searching...
No Matches
ranges.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
13#include <range.h>
14#include <OMMathExceptions.H>
15
16#include "OpenMEEGMathsConfig.h"
17
18namespace OpenMEEG::maths {
19
20 class Ranges: public std::vector<Range> {
21
22 typedef std::vector<Range> base;
23
24 public:
25
26 using base::base;
27
28 unsigned add(const Range& range) {
29 for (unsigned i=0;i<size();++i)
30 if ((*this)[i].intersect(range)) {
31 if (range!=(*this)[i])
32 throw OverlappingRanges(range,(*this)[i]);
33 return i;
34 }
35 push_back(range);
36 return size()-1;
37 }
38
39 unsigned find_index(const size_t ind) const {
40 for (unsigned i=0;i<size();++i)
41 if ((*this)[i].contains(ind))
42 return i;
43 throw NonExistingBlock(ind);
44 }
45
46 unsigned find_index(const Range& range) const {
47 for (unsigned i=0;i<size();++i)
48 if ((*this)[i].intersect(range)) {
49 if (range!=(*this)[i])
50 throw OverlappingRanges(range,(*this)[i]);
51 return i;
52 }
53 throw NonExistingRange(range);
54 }
55 };
56}
unsigned add(const Range &range)
Definition ranges.h:28
unsigned find_index(const Range &range) const
Definition ranges.h:46
unsigned find_index(const size_t ind) const
Definition ranges.h:39