1/*
2 * Copyright 2011, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef MEM_CHUNK_H
18#define MEM_CHUNK_H
19
20#include <stddef.h>
21#include <stdlib.h>
22
23class MemChunk {
24private:
25  unsigned char *buf;
26  size_t buf_size;
27
28public:
29  MemChunk();
30
31  ~MemChunk();
32
33  bool allocate(size_t size);
34
35  void print() const;
36
37  bool protect(int prot);
38
39  unsigned char const *getBuffer() const {
40    return buf;
41  }
42
43  unsigned char *getBuffer() {
44    return buf;
45  }
46
47  unsigned char &operator[](size_t index) {
48    return buf[index];
49  }
50
51  unsigned char const &operator[](size_t index) const {
52    return buf[index];
53  }
54
55  size_t size() const {
56    return buf_size;
57  }
58
59};
60
61#endif // MEM_CHUNK_H
62