1 #ifndef ANDROID_PDX_RPC_POINTER_WRAPPER_H_
2 #define ANDROID_PDX_RPC_POINTER_WRAPPER_H_
3 
4 namespace android {
5 namespace pdx {
6 namespace rpc {
7 
8 // Wrapper class for pointers to any serializable type. This class is used by
9 // serialization/deserialization to handle pointers to objects that are to be
10 // serialized or deserialized.
11 template <typename T>
12 class PointerWrapper {
13  public:
14   using BaseType = T;
15 
PointerWrapper(T * pointer)16   explicit PointerWrapper(T* pointer) : pointer_(pointer) {}
17   PointerWrapper(const PointerWrapper&) = default;
18   PointerWrapper(PointerWrapper&&) noexcept = default;
19   PointerWrapper& operator=(const PointerWrapper&) = default;
20   PointerWrapper& operator=(PointerWrapper&&) noexcept = default;
21 
Dereference()22   T& Dereference() { return *pointer_; }
Dereference()23   const T& Dereference() const { return *pointer_; }
24 
25  private:
26   T* pointer_;
27 };
28 
29 template <typename T>
WrapPointer(T * pointer)30 PointerWrapper<T> WrapPointer(T* pointer) {
31   return PointerWrapper<T>(pointer);
32 }
33 
34 }  // namespace rpc
35 }  // namespace pdx
36 }  // namespace android
37 
38 #endif  // ANDROID_PDX_RPC_POINTER_WRAPPER_H_
39