|
||||
File indexing completed on 2025-01-18 10:10:27
0001 /* 0002 * Project: RooFit 0003 * Authors: 0004 * Jonas Rembser, CERN 2023 0005 * 0006 * Copyright (c) 2023, CERN 0007 * 0008 * Redistribution and use in source and binary forms, 0009 * with or without modification, are permitted according to the terms 0010 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) 0011 */ 0012 0013 #ifndef RooFit_Config_h 0014 #define RooFit_Config_h 0015 0016 // Define ROOFIT_MEMORY_SAFE_INTERFACES to change RooFit interfaces to be 0017 // memory safe. 0018 // #define ROOFIT_MEMORY_SAFE_INTERFACES 0019 0020 #include <memory> 0021 0022 namespace RooFit { 0023 0024 /// An alias for raw pointers for indicating that the return type of a RooFit 0025 /// function is an owning pointer that must be deleted by the caller. For 0026 /// RooFit developers, it can be very useful to make this an alias to 0027 /// std::unique_ptr<T>, in order to check that your code has no memory 0028 /// problems. Changing this alias is equivalent to forcing all code immediately 0029 /// wraps the result of functions returning a RooFit::OwningPtr<T> in a 0030 /// std::unique_ptr<T>. 0031 template <typename T> 0032 #ifdef ROOFIT_MEMORY_SAFE_INTERFACES 0033 using OwningPtr = std::unique_ptr<T>; 0034 #else 0035 using OwningPtr = T *; 0036 #endif 0037 0038 /// Internal helper to turn a std::unique_ptr<T> into an OwningPtr. 0039 template <typename T> 0040 OwningPtr<T> makeOwningPtr(std::unique_ptr<T> &&ptr) 0041 { 0042 #ifdef ROOFIT_MEMORY_SAFE_INTERFACES 0043 return std::move(ptr); 0044 #else 0045 return ptr.release(); 0046 #endif 0047 } 0048 0049 /// internal helper to turn a std::unique_ptr<t> into an owningptr. 0050 template <typename T, typename U> 0051 OwningPtr<T> makeOwningPtr(std::unique_ptr<U> &&ptr) 0052 { 0053 #ifdef ROOFIT_MEMORY_SAFE_INTERFACES 0054 return std::unique_ptr<T>{static_cast<T *>(ptr.release())}; 0055 #else 0056 return static_cast<T *>(ptr.release()); 0057 #endif 0058 } 0059 0060 } // namespace RooFit 0061 0062 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |