File indexing completed on 2025-01-18 10:10:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT7_RDirectoryEntry
0017 #define ROOT7_RDirectoryEntry
0018
0019 #include "TClass.h"
0020
0021 #include <chrono>
0022 #include <memory>
0023
0024 namespace ROOT {
0025 namespace Experimental {
0026
0027 namespace Internal {
0028
0029 class RDirectoryEntry {
0030 public:
0031 using clock_t = std::chrono::system_clock;
0032 using time_point_t = std::chrono::time_point<clock_t>;
0033
0034 private:
0035 time_point_t fDate = clock_t::now();
0036 TClass *fType;
0037 std::shared_ptr<void> fObj;
0038
0039 public:
0040 RDirectoryEntry(): RDirectoryEntry(nullptr) {}
0041
0042 RDirectoryEntry(std::nullptr_t): RDirectoryEntry(std::make_shared<std::nullptr_t>(nullptr)) {}
0043
0044 template <class T>
0045 explicit RDirectoryEntry(T *ptr): RDirectoryEntry(std::make_shared<T>(*ptr))
0046 {}
0047
0048 template <class T>
0049 explicit RDirectoryEntry(const std::shared_ptr<T> &ptr): fType(TClass::GetClass<T>()), fObj(ptr)
0050 {}
0051
0052
0053 const time_point_t &GetDate() const { return fDate; }
0054
0055
0056
0057 void SetChanged() { fDate = clock_t::now(); }
0058
0059
0060 const std::type_info &GetTypeInfo() const { return *fType->GetTypeInfo(); }
0061
0062
0063 TClass *GetType() const { return fType; }
0064
0065
0066 std::shared_ptr<void> &GetPointer() { return fObj; }
0067 const std::shared_ptr<void> &GetPointer() const { return fObj; }
0068
0069 template <class U>
0070 std::shared_ptr<U> CastPointer() const;
0071
0072 explicit operator bool() const { return !!fObj; }
0073
0074 void swap(RDirectoryEntry &other) noexcept;
0075 };
0076
0077 template <class U>
0078 std::shared_ptr<U> RDirectoryEntry::CastPointer() const
0079 {
0080 if (auto ptr = fType->DynamicCast(TClass::GetClass<U>(), fObj.get()))
0081 return std::shared_ptr<U>(fObj, static_cast<U *>(ptr));
0082 return std::shared_ptr<U>();
0083 }
0084
0085 inline void RDirectoryEntry::swap(RDirectoryEntry &other) noexcept
0086 {
0087 using std::swap;
0088
0089 swap(fDate, other.fDate);
0090 swap(fType, other.fType);
0091 swap(fObj, other.fObj);
0092 }
0093
0094 inline void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
0095 {
0096 e1.swap(e2);
0097 }
0098
0099 }
0100
0101 }
0102 }
0103 #endif