Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Config.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2023
5 *
6 * Copyright (c) 2023, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef RooFit_Config_h
14#define RooFit_Config_h
15
16// Define ROOFIT_MEMORY_SAFE_INTERFACES to change RooFit interfaces to be
17// memory safe.
18// #define ROOFIT_MEMORY_SAFE_INTERFACES
19
20// The memory safe interfaces mode implies that all RooFit::OwningPtr<T> are
21// std::unique_ptr<T>.
22#ifdef ROOFIT_MEMORY_SAFE_INTERFACES
23#ifndef ROOFIT_OWNING_PTR_IS_UNIQUE_PTR
24#define ROOFIT_OWNING_PTR_IS_UNIQUE_PTR
25#endif
26#endif
27
28#include <memory>
29
30namespace RooFit {
31
32/// An alias for raw pointers for indicating that the return type of a RooFit
33/// function is an owning pointer that must be deleted by the caller. For
34/// RooFit developers, it can be very useful to make this an alias to
35/// std::unique_ptr<T>, in order to check that your code has no memory
36/// problems. Changing this alias is equivalent to forcing all code immediately
37/// wraps the result of functions returning a RooFit::OwningPtr<T> in a
38/// std::unique_ptr<T>.
39template <typename T>
40#ifdef ROOFIT_OWNING_PTR_IS_UNIQUE_PTR
41using OwningPtr = std::unique_ptr<T>;
42#else
43using OwningPtr = T *;
44#endif
45
46namespace Detail {
47
48/// Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
49template <typename T>
50OwningPtr<T> owningPtr(std::unique_ptr<T> &&ptr)
51{
52#ifdef ROOFIT_OWNING_PTR_IS_UNIQUE_PTR
53 return std::move(ptr);
54#else
55 return ptr.release();
56#endif
57}
58
59/// internal helper to turn a std::unique_ptr<t> into an owningptr.
60template <typename T, typename U>
61OwningPtr<T> owningPtr(std::unique_ptr<U> &&ptr)
62{
63#ifdef ROOFIT_OWNING_PTR_IS_UNIQUE_PTR
64 return std::unique_ptr<T>{static_cast<T *>(ptr.release())};
65#else
66 return static_cast<T *>(ptr.release());
67#endif
68}
69
70} // namespace Detail
71
72} // namespace RooFit
73
74#endif
double T(double x)
OwningPtr< T > owningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
Definition Config.h:50
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:43