libstorage-ng
 
Loading...
Searching...
No Matches
Region.h
1/*
2 * Copyright (c) [2004-2015] Novell, Inc.
3 * Copyright (c) [2016-2022] SUSE LLC
4 *
5 * All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as published
9 * by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, contact Novell, Inc.
18 *
19 * To contact Novell about this file by physical or electronic mail, you may
20 * find current contact information at www.novell.com.
21 */
22
23
24#ifndef STORAGE_REGION_H
25#define STORAGE_REGION_H
26
27
28#include <libxml/tree.h>
29#include <memory>
30#include <vector>
31
32#include "storage/Utils/Exception.h"
33#include "storage/Utils/Swig.h"
34
35
36namespace storage
37{
38
39 // TODO make block_size unsigned long long everywhere and remove ull_hack
40
41 // ull_hack_t is only used to resolve ambiguities (esp. for the constructors of
42 // Region). With simple overloading there are several hundreds ambiguities, mainly in
43 // the testsuite.
44 enum ull_hack_t { ULL_HACK };
45
46
47 class InvalidBlockSize : public Exception
48 {
49 public:
50 InvalidBlockSize(unsigned int block_size) ST_DEPRECATED;
51 InvalidBlockSize(unsigned long long block_size);
52 };
53
54
55 class DifferentBlockSizes : public Exception
56 {
57 public:
58 DifferentBlockSizes(unsigned int seen, unsigned int expected) ST_DEPRECATED;
59 DifferentBlockSizes(unsigned long long seen, unsigned long long expected);
60 };
61
62
63 class NoIntersection : public Exception
64 {
65 public:
66 NoIntersection();
67 };
68
69
70 class NotInside : public Exception
71 {
72 public:
73 NotInside();
74 };
75
76
84 class Region
85 {
86 public:
87
88 Region();
89 Region(unsigned long long start, unsigned long long length, unsigned int block_size);
90 Region(unsigned long long start, unsigned long long length, unsigned long long block_size, ull_hack_t);
91 Region(const Region& region);
92 Region(Region&& region) = default;
93 ~Region();
94
95 Region& operator=(const Region& region);
96 Region& operator=(Region&& region) = default;
97
98 bool empty() const;
99
103 unsigned long long get_start() const;
104
108 unsigned long long get_length() const;
109
116 unsigned long long get_end() const;
117
121 void set_start(unsigned long long start);
122
126 void set_length(unsigned long long length);
127
133 void adjust_start(long long delta);
134
140 void adjust_length(long long delta);
141
142 unsigned int get_block_size() const;
143 unsigned long long get_block_size(ull_hack_t) const;
144 void set_block_size(unsigned int block_size);
145 void set_block_size(unsigned long long block_size, ull_hack_t);
146
147 unsigned long long to_bytes(unsigned long long blocks) const;
148 unsigned long long to_blocks(unsigned long long bytes) const;
149
155 bool operator==(const Region& rhs) const;
156
162 bool operator!=(const Region& rhs) const;
163
169 bool operator<(const Region& rhs) const;
170
176 bool operator>(const Region& rhs) const;
177
183 bool operator<=(const Region& rhs) const;
184
190 bool operator>=(const Region& rhs) const;
191
197 bool inside(const Region& rhs) const;
198
204 bool intersect(const Region& rhs) const;
205
206 Region intersection(const Region& rhs) const;
207
214 std::vector<Region> unused_regions(const std::vector<Region>& used_regions) const;
215
216 friend std::ostream& operator<<(std::ostream& s, const Region& region);
217
218 public:
219
220 class Impl;
221
222 Impl& get_impl();
223 const Impl& get_impl() const;
224
225 friend bool getChildValue(const xmlNode* node, const char* name, Region& value);
226 friend void setChildValue(xmlNode* node, const char* name, const Region& value);
227
228 private:
229
230 const std::unique_ptr<Impl> impl;
231
232 };
233
234}
235
236#endif
Exception(LogLevel log_level=LogLevel::ERROR)
Default constructor.
std::vector< Region > unused_regions(const std::vector< Region > &used_regions) const
Returns all regions not included in used_regions.
void adjust_start(long long delta)
Adjusts the start while keeping the length.
unsigned long long get_end() const
Returns the end of the region.
unsigned long long get_length() const
Returns the length of the region.
void set_length(unsigned long long length)
Sets the length while keeping the start.
bool operator==(const Region &rhs) const
Compare start and length of two regions.
bool operator<=(const Region &rhs) const
Compare start of two regions.
bool operator>=(const Region &rhs) const
Compare start of two regions.
bool operator<(const Region &rhs) const
Compare start of two regions.
bool inside(const Region &rhs) const
Check whether the region is contained inside other.
unsigned long long get_start() const
Returns the start of the region.
void adjust_length(long long delta)
Adjusts the length while keeping the start.
bool operator>(const Region &rhs) const
Compare start of two regions.
bool intersect(const Region &rhs) const
Check whether the region intersects with other.
bool operator!=(const Region &rhs) const
Compare start and length of two regions.
void set_start(unsigned long long start)
Sets the start while keeping the length.
The storage namespace.
Definition Actiongraph.h:40