Project
Loading...
Searching...
No Matches
TObjectWrapper.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_TOBJECTWRAPPER_H
13#define O2_TOBJECTWRAPPER_H
14
15#include <TClass.h>
16#include <TObject.h>
17#include <cxxabi.h>
18#include <iosfwd>
19#include <memory>
20#include <stdexcept>
21#include <typeinfo>
22
23namespace o2
24{
25// anonymous namespace to prevent usage outside of this file
26namespace
27{
29std::string demangle(const char* name)
30{
31 int status = -4; // some arbitrary value to eliminate the compiler warning
32 std::unique_ptr<char, void (*)(void*)> res{abi::__cxa_demangle(name, nullptr, nullptr, &status), std::free};
33 return (status == 0) ? res.get() : name;
34}
35} // end anonymous namespace
36
40template <typename T>
41class TObjectWrapper : public TObject
42{
43 public:
44 TObjectWrapper(T* obj) : mObj(obj), TObject()
45 {
46 // make sure that a dictionary for this wrapper exists
47 auto& t = typeid(*this);
48 std::string message("Need dicionary for type ");
49 auto typestring = demangle(t.name());
50 message.append(typestring);
51 message.append("\n");
52 auto hasdict = TClass::HasDictionarySelection(typestring.c_str());
53 if (!hasdict) {
54 throw std::runtime_error(message);
55 }
56 }
57
59 {
60 }
61
62 void setObj(T* obj)
63 {
64 mObj = obj;
65 }
66
67 T* getObj() const
68 {
69 return mObj;
70 }
71
72 ~TObjectWrapper() override = default;
73
74 private:
75 T* mObj;
76
77 ClassDefOverride(TObjectWrapper, 1);
78};
79} // namespace o2
80
81#endif
uint32_t res
Definition RawData.h:0
~TObjectWrapper() override=default
void setObj(T *obj)
GLuint const GLchar * name
Definition glcorearb.h:781
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
std::string demangle(const char *name)
utility function to demangle cxx type names
Definition Detector.h:246
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...