Belle II Software development
DBObjPtr.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/database/DBAccessorBase.h>
11
12namespace Belle2 {
17
21 template<class T> class DBObjPtr: public DBAccessorBase {
22 public:
23
31 explicit DBObjPtr(const std::string& name = "", bool required = true):
32 DBAccessorBase(DBStore::objectName<T>(name), T::Class(), false, required) {}
33
34 inline const T& operator *() const {return *getObject<T>(); }
35 inline const T* operator ->() const {return getObject<T>(); }
36 };
37
48 template<class T> class OptionalDBObjPtr: public DBObjPtr<T> {
49 public:
52 explicit OptionalDBObjPtr(const std::string& name = ""): DBObjPtr<T>(name, false) {}
53 };
54
55}
DBAccessorBase(const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Constructor to access an object in the DBStore.
const T * getObject() const
Return a pointer to the Object already cast to the correct type.
const T & operator*() const
Imitate pointer functionality.
Definition DBObjPtr.h:34
const T * operator->() const
Imitate pointer functionality.
Definition DBObjPtr.h:35
DBObjPtr(const std::string &name="", bool required=true)
Constructor to access an object in the DBStore.
Definition DBObjPtr.h:31
Singleton class to cache database objects.
Definition DBStore.h:31
OptionalDBObjPtr(const std::string &name="")
Construct a new Array with a given name or with the default name which is identical to the class name...
Definition DBObjPtr.h:52
Abstract base class for different kinds of events.