1 /* 2 * Copyright (C) 2017 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 #pragma once 18 19 #include "common.h" 20 21 #include <assert.h> 22 #include <stdlib.h> 23 24 namespace slicer { 25 26 // A shallow, non-owning reference to a "view" inside a memory buffer 27 class MemView { 28 public: MemView()29 MemView() : ptr_(nullptr), size_(0) {} 30 MemView(const void * ptr,size_t size)31 MemView(const void* ptr, size_t size) : ptr_(ptr), size_(size) { 32 assert(size > 0); 33 } 34 35 ~MemView() = default; 36 37 template <class T = void> ptr()38 const T* ptr() const { 39 return static_cast<const T*>(ptr_); 40 } 41 size()42 size_t size() const { return size_; } 43 44 private: 45 const void* ptr_; 46 size_t size_; 47 }; 48 49 } // namespace slicer 50 51