MarlinMT  0.1.0
Handle.h
Go to the documentation of this file.
1 #pragma once
2 
3 // -- std includes
4 #include <functional>
5 #include <memory>
6 #include <typeinfo>
7 
8 // -- MarlinBook includes
10 #include "marlinmt/book/Types.h"
11 
12 namespace marlinmt {
13  namespace book {
14 
15  // -- MarlinBook forward declaration
16  class BookStore ;
17  class MemLayout ;
18 
23  template < typename T >
24  class BaseHandle {
25  protected:
26  BaseHandle( std::shared_ptr< MemLayout > mem, std::shared_ptr< T > obj )
27  : _mem{std::move( mem )}, _obj{std::move( obj )} {}
28 
30  T &get() { return *_obj; }
31 
32  public:
40  const T &merged() { return *_mem->template merged< T >(); }
41 
42  private:
44  std::shared_ptr< MemLayout > _mem ;
46  std::shared_ptr< T > _obj ;
47  } ;
48 
53  template < typename T >
54  class Handle : public BaseHandle< T > {
55  public:
57  Handle( const std::shared_ptr< T > &obj,
58  const std::shared_ptr< MemLayout > &mem )
59  : BaseHandle< T >( obj, mem ) {}
60  } ;
61 
62  } // end namespace book
63 } // end namespace marlinmt
std::shared_ptr< MemLayout > _mem
pointer to memory from instances.
Definition: Handle.h:44
BaseHandle(std::shared_ptr< MemLayout > mem, std::shared_ptr< T > obj)
Definition: Handle.h:26
Handle(const std::shared_ptr< T > &obj, const std::shared_ptr< MemLayout > &mem)
constructor
Definition: Handle.h:57
std::shared_ptr< T > _obj
pointer to the one managed instance.
Definition: Handle.h:46
class which basic functionality for every handle.
Definition: Handle.h:24
vanilla Handle.
Definition: Handle.h:54
const T & merged()
get final object.
Definition: Handle.h:40