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_
10 #include "base/basictypes.h"
14 // A Region is a descriptor for a region of memory. It has a start address and
15 // a length measured in bytes. The Region object does not own the memory.
19 // Default constructor: and empty region.
20 Region() : start_(NULL), length_(0) {}
22 // Usual constructor for regions given a |start| address and |length|.
23 Region(const void* start, size_t length)
24 : start_(static_cast<const uint8*>(start)),
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*>(string.c_str())),
32 length_(string.length()) {
36 Region(const Region& other) : start_(other.start_), length_(other.length_) {}
38 // Assignment 'operator' makes |this| region the same as |other|.
39 Region& assign(const Region& other) {
40 this->start_ = other.start_;
41 this->length_ = other.length_;
45 // Returns the starting address of the region.
46 const uint8* start() const { return start_; }
48 // Returns the length of the region.
49 size_t length() const { return length_; }
51 // Returns the address after the last byte of the region.
52 const uint8* end() const { return start_ + length_; }
58 void operator=(const Region&); // Disallow assignment operator.
62 #endif // COURGETTE_REGION_H_