| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COURGETTE_REGION_H_ | 5 #ifndef COURGETTE_REGION_H_ |
| 6 #define COURGETTE_REGION_H_ | 6 #define COURGETTE_REGION_H_ |
| 7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <string> | 11 #include <string> |
| 9 | 12 |
| 10 #include "base/basictypes.h" | |
| 11 | 13 |
| 12 namespace courgette { | 14 namespace courgette { |
| 13 | 15 |
| 14 // A Region is a descriptor for a region of memory. It has a start address and | 16 // 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. | 17 // a length measured in bytes. The Region object does not own the memory. |
| 16 // | 18 // |
| 17 class Region { | 19 class Region { |
| 18 public: | 20 public: |
| 19 // Default constructor: and empty region. | 21 // Default constructor: and empty region. |
| 20 Region() : start_(NULL), length_(0) {} | 22 Region() : start_(NULL), length_(0) {} |
| 21 | 23 |
| 22 // Usual constructor for regions given a |start| address and |length|. | 24 // Usual constructor for regions given a |start| address and |length|. |
| 23 Region(const void* start, size_t length) | 25 Region(const void* start, size_t length) |
| 24 : start_(static_cast<const uint8*>(start)), | 26 : start_(static_cast<const uint8_t*>(start)), length_(length) {} |
| 25 length_(length) { | |
| 26 } | |
| 27 | 27 |
| 28 // String constructor. Region is owned by the string, so the string should | 28 // String constructor. Region is owned by the string, so the string should |
| 29 // have a lifetime greater than the region. | 29 // have a lifetime greater than the region. |
| 30 explicit Region(const std::string& string) | 30 explicit Region(const std::string& string) |
| 31 : start_(reinterpret_cast<const uint8*>(string.c_str())), | 31 : start_(reinterpret_cast<const uint8_t*>(string.c_str())), |
| 32 length_(string.length()) { | 32 length_(string.length()) {} |
| 33 } | |
| 34 | 33 |
| 35 // Copy constructor. | 34 // Copy constructor. |
| 36 Region(const Region& other) : start_(other.start_), length_(other.length_) {} | 35 Region(const Region& other) : start_(other.start_), length_(other.length_) {} |
| 37 | 36 |
| 38 // Assignment 'operator' makes |this| region the same as |other|. | 37 // Assignment 'operator' makes |this| region the same as |other|. |
| 39 Region& assign(const Region& other) { | 38 Region& assign(const Region& other) { |
| 40 this->start_ = other.start_; | 39 this->start_ = other.start_; |
| 41 this->length_ = other.length_; | 40 this->length_ = other.length_; |
| 42 return *this; | 41 return *this; |
| 43 } | 42 } |
| 44 | 43 |
| 45 // Returns the starting address of the region. | 44 // Returns the starting address of the region. |
| 46 const uint8* start() const { return start_; } | 45 const uint8_t* start() const { return start_; } |
| 47 | 46 |
| 48 // Returns the length of the region. | 47 // Returns the length of the region. |
| 49 size_t length() const { return length_; } | 48 size_t length() const { return length_; } |
| 50 | 49 |
| 51 // Returns the address after the last byte of the region. | 50 // Returns the address after the last byte of the region. |
| 52 const uint8* end() const { return start_ + length_; } | 51 const uint8_t* end() const { return start_ + length_; } |
| 53 | 52 |
| 54 private: | 53 private: |
| 55 const uint8* start_; | 54 const uint8_t* start_; |
| 56 size_t length_; | 55 size_t length_; |
| 57 | 56 |
| 58 void operator=(const Region&); // Disallow assignment operator. | 57 void operator=(const Region&); // Disallow assignment operator. |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 } // namespace | 60 } // namespace |
| 62 #endif // COURGETTE_REGION_H_ | 61 #endif // COURGETTE_REGION_H_ |
| OLD | NEW |