[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API
[platform/framework/web/chromium-efl.git] / courgette / region.h
1 // Copyright 2009 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COURGETTE_REGION_H_
6 #define COURGETTE_REGION_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <string>
12
13
14 namespace courgette {
15
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.
18 //
19 class Region {
20  public:
21   // Default constructor: and empty region.
22   Region() : start_(nullptr), length_(0) {}
23
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) {}
27
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()) {}
33
34   // Copy constructor.
35   Region(const Region& other) : start_(other.start_), length_(other.length_) {}
36
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_;
41     return *this;
42   }
43
44   // Returns the starting address of the region.
45   const uint8_t* start() const { return start_; }
46
47   // Returns the length of the region.
48   size_t length() const { return length_; }
49
50   // Returns the address after the last byte of the region.
51   const uint8_t* end() const { return start_ + length_; }
52
53  private:
54   const uint8_t* start_;
55   size_t length_;
56
57   void operator=(const Region&);  // Disallow assignment operator.
58 };
59
60 }  // namespace
61 #endif  // COURGETTE_REGION_H_