libstorage-ng
 All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
Region.h
1 /*
2  * Copyright (c) [2004-2015] Novell, Inc.
3  * Copyright (c) 2016 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 
34 
35 namespace storage
36 {
37 
38  class InvalidBlockSize : public Exception
39  {
40  public:
41  InvalidBlockSize(unsigned int block_size);
42  };
43 
44 
46  {
47  public:
48  DifferentBlockSizes(unsigned int seen, unsigned int expected);
49  };
50 
51 
52  class NoIntersection : public Exception
53  {
54  public:
56  };
57 
58 
59  class NotInside : public Exception
60  {
61  public:
62  NotInside();
63  };
64 
65 
71  class Region
72  {
73  public:
74 
75  Region();
76  Region(unsigned long long start, unsigned long long length, unsigned int block_size);
77  Region(const Region& region);
78  ~Region();
79 
80  Region& operator=(const Region& region);
81 
82  bool empty() const;
83 
84  unsigned long long get_start() const;
85  unsigned long long get_length() const;
86  unsigned long long get_end() const;
87 
88  void set_start(unsigned long long start);
89  void set_length(unsigned long long length);
90 
91  void adjust_start(long long delta);
92  void adjust_length(long long delta);
93 
94  unsigned int get_block_size() const;
95  void set_block_size(unsigned int block_size);
96 
97  unsigned long long to_bytes(unsigned long long blocks) const;
98  unsigned long long to_blocks(unsigned long long bytes) const;
99 
100  bool operator==(const Region& rhs) const;
101  bool operator!=(const Region& rhs) const;
102  bool operator<(const Region& rhs) const;
103  bool operator>(const Region& rhs) const;
104 
105  bool inside(const Region& rhs) const;
106 
107  bool intersect(const Region& rhs) const;
108  Region intersection(const Region& rhs) const;
109 
115  std::vector<Region> unused_regions(const std::vector<Region>& used_regions) const;
116 
117  friend std::ostream& operator<<(std::ostream& s, const Region& region);
118 
119  public:
120 
121  class Impl;
122 
123  Impl& get_impl();
124  const Impl& get_impl() const;
125 
126  friend bool getChildValue(const xmlNode* node, const char* name, Region& value);
127  friend void setChildValue(xmlNode* node, const char* name, const Region& value);
128 
129  private:
130 
131  const std::unique_ptr<Impl> impl;
132 
133  };
134 
135 }
136 
137 #endif
A start/length pair with a block size.
Definition: Region.h:71
std::vector< Region > unused_regions(const std::vector< Region > &used_regions) const
Returns all regions not included in used_regions.
Definition: Region.h:59
Definition: Region.h:45
Base class for storage exceptions.
Definition: Exception.h:113
Definition: Region.h:52
The storage namespace.
Definition: Actiongraph.h:36
Definition: Region.h:38