1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COURGETTE_REGION_H_
6 #define COURGETTE_REGION_H_
16 // A Region is a descriptor for a region of memory. It has a start address and
17 // a length measured in bytes. The Region object does not own the memory.
21 // Default constructor: and empty region.
22 Region() : start_(NULL), length_(0) {}
24 // Usual constructor for regions given a |start| address and |length|.
25 Region(const void* start, size_t length)
26 : start_(static_cast<const uint8_t*>(start)), length_(length) {}
28 // String constructor. Region is owned by the string, so the string should
29 // have a lifetime greater than the region.
30 explicit Region(const std::string& string)
31 : start_(reinterpret_cast<const uint8_t*>(string.c_str())),
32 length_(string.length()) {}
35 Region(const Region& other) : start_(other.start_), length_(other.length_) {}
37 // Assignment 'operator' makes |this| region the same as |other|.
38 Region& assign(const Region& other) {
39 this->start_ = other.start_;
40 this->length_ = other.length_;
44 // Returns the starting address of the region.
45 const uint8_t* start() const { return start_; }
47 // Returns the length of the region.
48 size_t length() const { return length_; }
50 // Returns the address after the last byte of the region.
51 const uint8_t* end() const { return start_ + length_; }
54 const uint8_t* start_;
57 void operator=(const Region&); // Disallow assignment operator.
61 #endif // COURGETTE_REGION_H_