| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/lib/buffer.h" | 8 #include "mojo/public/cpp/bindings/lib/buffer.h" |
| 9 #include "mojo/public/cpp/system/macros.h" | 9 #include "mojo/public/cpp/system/macros.h" |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // } | 36 // } |
| 37 // | 37 // |
| 38 class FixedBuffer : public Buffer { | 38 class FixedBuffer : public Buffer { |
| 39 public: | 39 public: |
| 40 explicit FixedBuffer(size_t size); | 40 explicit FixedBuffer(size_t size); |
| 41 virtual ~FixedBuffer(); | 41 virtual ~FixedBuffer(); |
| 42 | 42 |
| 43 // Grows the buffer by |num_bytes| and returns a pointer to the start of the | 43 // Grows the buffer by |num_bytes| and returns a pointer to the start of the |
| 44 // addition. The resulting address is 8-byte aligned, and the content of the | 44 // addition. The resulting address is 8-byte aligned, and the content of the |
| 45 // memory is zero-filled. | 45 // memory is zero-filled. |
| 46 virtual void* Allocate(size_t num_bytes) MOJO_OVERRIDE; | 46 virtual void* Allocate(size_t num_bytes) override; |
| 47 | 47 |
| 48 size_t size() const { return size_; } | 48 size_t size() const { return size_; } |
| 49 | 49 |
| 50 // Returns the internal memory owned by the Buffer to the caller. The Buffer | 50 // Returns the internal memory owned by the Buffer to the caller. The Buffer |
| 51 // relinquishes its pointer, effectively resetting the state of the Buffer | 51 // relinquishes its pointer, effectively resetting the state of the Buffer |
| 52 // and leaving the caller responsible for freeing the returned memory address | 52 // and leaving the caller responsible for freeing the returned memory address |
| 53 // when no longer needed. | 53 // when no longer needed. |
| 54 void* Leak(); | 54 void* Leak(); |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 char* ptr_; | 57 char* ptr_; |
| 58 size_t cursor_; | 58 size_t cursor_; |
| 59 size_t size_; | 59 size_t size_; |
| 60 | 60 |
| 61 MOJO_DISALLOW_COPY_AND_ASSIGN(FixedBuffer); | 61 MOJO_DISALLOW_COPY_AND_ASSIGN(FixedBuffer); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 } // namespace internal | 64 } // namespace internal |
| 65 } // namespace mojo | 65 } // namespace mojo |
| 66 | 66 |
| 67 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ | 67 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_FIXED_BUFFER_H_ |
| OLD | NEW |