Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RFieldValue.hxx
Go to the documentation of this file.
1 /// \file ROOT/RFieldValue.hxx
2 /// \ingroup NTuple ROOT7
3 /// \author Jakob Blomer <jblomer@cern.ch>
4 /// \date 2018-10-09
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RFieldValue
17 #define ROOT7_RFieldValue
18 
19 #include <ROOT/RColumnElement.hxx>
20 
21 #include <new>
22 
23 namespace ROOT {
24 namespace Experimental {
25 
26 namespace Detail {
27 
28 class RFieldBase;
29 
30 // clang-format off
31 /**
32 \class ROOT::Experimental::RFieldValue
33 \ingroup NTuple
34 \brief Represents transient storage of simple or complex C++ values.
35 
36 The data carried by the value is used by the computational code and it is supposed to be serialized on Fill
37 or deserialized into by reading. Only fields can generate their corresponding values. This class is a mere
38 wrapper around the memory location, it does not own it. Memory ownership is managed through the REntry.
39 */
40 // clang-format on
41 class RFieldValue {
42  friend class RFieldBase;
43 
44 protected:
45  /// Every value is connected to a field of the corresponding type that has created the value.
46  RFieldBase* fField;
47  /// The memory location containing (constructed) data of a certain C++ type
48  void* fRawPtr;
49 
50  /// For simple types, the mapped element drills through the layers from the C++ data representation
51  /// to the primitive columns. Otherwise, using fMappedElements is undefined.
52  /// Only RFieldBase uses fMappedElement
53  RColumnElementBase fMappedElement;
54 
55 public:
56  RFieldValue() : fField(nullptr), fRawPtr(nullptr) {}
57 
58  // Constructors that wrap around existing objects; prefixed with a bool in order to help the constructor overload
59  // selection.
60  RFieldValue(bool /*captureTag*/, Detail::RFieldBase* field, void* value) : fField(field), fRawPtr(value) {}
61  RFieldValue(bool /*captureTag*/, const Detail::RColumnElementBase& elem, Detail::RFieldBase* field, void* value)
62  : fField(field), fRawPtr(value), fMappedElement(elem) {}
63 
64  // Typed constructors that initialize the given memory location
65  template <typename T, typename... ArgsT>
66  RFieldValue(RFieldBase* field, T* where, ArgsT&&... args) : fField(field), fRawPtr(where)
67  {
68  new (where) T(std::forward<ArgsT>(args)...);
69  }
70 
71  template <typename T, typename... ArgsT>
72  RFieldValue(const Detail::RColumnElementBase& elem, Detail::RFieldBase* field, T* where, ArgsT&&... args)
73  : fField(field), fRawPtr(where), fMappedElement(elem)
74  {
75  new (where) T(std::forward<ArgsT>(args)...);
76  }
77 
78  template <typename T>
79  T* Get() const { return static_cast<T*>(fRawPtr); }
80 
81  void* GetRawPtr() const { return fRawPtr; }
82  RFieldBase* GetField() const { return fField; }
83 };
84 
85 } // namespace Detail
86 } // namespace Experimental
87 } // namespace ROOT
88 
89 #endif