Logo ROOT   6.18/05
Reference Guide
REntry.hxx
Go to the documentation of this file.
1/// \file ROOT/REntry.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-07-19
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_REntry
17#define ROOT7_REntry
18
19#include <ROOT/RField.hxx>
20#include <ROOT/RFieldValue.hxx>
21#include <ROOT/RStringView.hxx>
22
23#include <TError.h>
24
25#include <memory>
26#include <utility>
27#include <vector>
28
29namespace ROOT {
30namespace Experimental {
31
32// clang-format off
33/**
34\class ROOT::Experimental::REntry
35\ingroup NTuple
36\brief The REntry is a collection of values in an ntuple corresponding to a complete row in the data set
37
38The entry provides a memory-managed binder for a set of values. Through shared pointers, the memory locations
39that are associated to values are managed.
40*/
41// clang-format on
42class REntry {
43 std::vector<Detail::RFieldValue> fValues;
44 /// The objects involed in serialization and deserialization might be used long after the entry is gone:
45 /// hence the shared pointer
46 std::vector<std::shared_ptr<void>> fValuePtrs;
47 /// Points into fValues and indicates the values that are owned by the entry and need to be destructed
48 std::vector<std::size_t> fManagedValues;
49
50public:
51 REntry() = default;
52 REntry(const REntry& other) = delete;
53 REntry& operator=(const REntry& other) = delete;
54 ~REntry();
55
56 /// Adds a value whose storage is managed by the entry
57 void AddValue(const Detail::RFieldValue& value);
58
59 /// Adds a value whose storage is _not_ managed by the entry
60 void CaptureValue(const Detail::RFieldValue& value);
61
62 /// While building the entry, adds a new value to the list and return the value's shared pointer
63 template<typename T, typename... ArgsT>
64 std::shared_ptr<T> AddValue(RField<T>* field, ArgsT&&... args) {
65 auto ptr = std::make_shared<T>(std::forward<ArgsT>(args)...);
66 fValues.emplace_back(Detail::RFieldValue(field->CaptureValue(ptr.get())));
67 fValuePtrs.emplace_back(ptr);
68 return ptr;
69 }
70
72 for (auto& v : fValues) {
73 if (v.GetField()->GetName() == fieldName)
74 return v;
75 }
76 return Detail::RFieldValue();
77 }
78
79 template<typename T>
80 T* Get(std::string_view fieldName) {
81 for (auto& v : fValues) {
82 if (v.GetField()->GetName() == fieldName) {
83 R__ASSERT(v.GetField()->GetType() == RField<T>::MyTypeName());
84 return static_cast<T*>(v.GetRawPtr());
85 }
86 }
87 return nullptr;
88 }
89
90 decltype(fValues)::iterator begin() { return fValues.begin(); }
91 decltype(fValues)::iterator end() { return fValues.end(); }
92};
93
94} // namespace Experimental
95} // namespace ROOT
96
97#endif
SVector< double, 2 > v
Definition: Dict.h:5
#define R__ASSERT(e)
Definition: TError.h:96
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition: REntry.hxx:42
T * Get(std::string_view fieldName)
Definition: REntry.hxx:80
REntry & operator=(const REntry &other)=delete
std::vector< std::shared_ptr< void > > fValuePtrs
The objects involed in serialization and deserialization might be used long after the entry is gone: ...
Definition: REntry.hxx:46
std::vector< std::size_t > fManagedValues
Points into fValues and indicates the values that are owned by the entry and need to be destructed.
Definition: REntry.hxx:48
void AddValue(const Detail::RFieldValue &value)
Adds a value whose storage is managed by the entry.
Definition: REntry.cxx:26
Detail::RFieldValue GetValue(std::string_view fieldName)
Definition: REntry.hxx:71
decltype(fValues) ::iterator begin()
Definition: REntry.hxx:90
std::shared_ptr< T > AddValue(RField< T > *field, ArgsT &&... args)
While building the entry, adds a new value to the list and return the value's shared pointer.
Definition: REntry.hxx:64
decltype(fValues) ::iterator end()
Definition: REntry.hxx:91
void CaptureValue(const Detail::RFieldValue &value)
Adds a value whose storage is not managed by the entry.
Definition: REntry.cxx:32
REntry(const REntry &other)=delete
std::vector< Detail::RFieldValue > fValues
Definition: REntry.hxx:43
Detail::RFieldValue CaptureValue(void *where) final
Creates a value from a memory location with an already constructed object.
Definition: RField.cxx:389
Classes with dictionaries that can be inspected by TClass.
Definition: RField.hxx:294
basic_string_view< char > string_view
double T(double x)
Definition: ChebyshevPol.h:34
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21