15 #ifndef ROOT7_TDirectory 16 #define ROOT7_TDirectory 23 #include <type_traits> 24 #include <unordered_map> 28 namespace Experimental {
37 const char*
what() const noexcept final {
return fKeyName.c_str(); }
50 const char*
what() const noexcept final {
return fKeyName.c_str(); }
71 using ContentMap_t = std::unordered_map<std::string, Internal::TDirectoryEntry>;
79 using type =
typename std::enable_if<
80 !std::is_pointer<decaytype>::value
81 && !std::is_member_pointer<decaytype>::value
82 && !std::is_void<decaytype>::value,
94 template <
class T,
class...
ARGS>
95 std::shared_ptr<ToContentType_t<T>>
Create(
const std::string&
name,
ARGS&&... args) {
96 auto ptr = std::make_shared<ToContentType_t<T>>(std::forward<ARGS>(args)...);
104 auto idx = fContent.find(name);
105 if (idx == fContent.end())
128 std::pair<Internal::TDirectoryEntry, EFindStatus>
130 auto idx = fContent.find(name);
131 if (idx == fContent.end())
132 return {
nullptr, EFindStatus::kKeyNameNotFound};
134 return {idx->second, EFindStatus::kValidValue};
136 return {idx->second, EFindStatus::kValidValueBase};
137 return {
nullptr, EFindStatus::kTypeMismatch};
149 std::shared_ptr<ToContentType_t<T>>
Get(
const std::string&
name) {
150 const auto& pair = Find<T>(
name);
154 case EFindStatus::kValidValue:
156 case EFindStatus::kValidValueBase:
158 case EFindStatus::kTypeMismatch:
161 case EFindStatus::kKeyNameNotFound:
170 void Add(
const std::string&
name,
const std::shared_ptr<T>& ptr) {
173 auto idx = fContent.find(name);
174 if (idx != fContent.end()) {
176 <<
"Replacing object with name \"" << name <<
"\"" << std::endl;
177 idx->second.swap(entry);
179 fContent[
name].swap(entry);
Namespace for new ROOT classes and functions.
TDirectoryUnknownKey(const std::string &keyName)
typename ToContentType< T >::type ToContentType_t
std::shared_ptr< ToContentType_t< T > > Get(const std::string &name)
Get the object for a key.
EFindStatus
Status of the call to Find<T>(name).
std::unordered_map< std::string, Internal::TDirectoryEntry > ContentMap_t
The directory content is a hashed map of name => Internal::TDirectoryEntry.
Warnings about likely unexpected behavior.
void Add(const std::string &name, const std::shared_ptr< T > &ptr)
Add an existing object (rather a shared_ptr to it) to the TDirectory.
ContentMap_t fContent
The TDirectory's content.
Objects of this class are thrown to signal that the value known under the given name ...
typename std::decay< T >::type decaytype
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
std::shared_ptr< U > CastPointer() const
const char * what() const noexcept final
const char * what() const noexcept final
typename std::enable_if< !std::is_pointer< decaytype >::value &&!std::is_member_pointer< decaytype >::value &&!std::is_void< decaytype >::value, decaytype >::type type
Internal::TDirectoryEntry Find(const std::string &name) const
Find the TDirectoryEntry associated to the name.
#define R__LOG_HERE(LEVEL, GROUP)
Key/value store of objects.
TDirectoryTypeMismatch(const std::string &keyName)
std::shared_ptr< ToContentType_t< T > > Create(const std::string &name, ARGS &&... args)
Create an object of type T (passing some arguments to its constructor).
Objects of this class are thrown to signal that no key with that name exists.
std::pair< Internal::TDirectoryEntry, EFindStatus > Find(const std::string &name) const
Find the TDirectoryEntry associated with the name.