ServiceWorker: Enqueue state change events until the worker thread gets ready
[chromium-blink-merge.git] / courgette / region.h
blob4aafbca8b05ba9c1da50ac0427855586249619e6
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_
8 #include <string>
10 #include "base/basictypes.h"
12 namespace courgette {
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.
17 class Region {
18 public:
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)),
25 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*>(string.c_str())),
32 length_(string.length()) {
35 // Copy constructor.
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_;
42 return *this;
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_; }
54 private:
55 const uint8* start_;
56 size_t length_;
58 void operator=(const Region&); // Disallow assignment operator.
61 } // namespace
62 #endif // COURGETTE_REGION_H_