11#ifndef ROOT_TEmulatedCollectionProxy
12#define ROOT_TEmulatedCollectionProxy
28 template <std::
size_t Align>
34 using Cont1_t = std::vector<AlignedStorage< 1>>;
35 using Cont2_t = std::vector<AlignedStorage< 2>>;
36 using Cont4_t = std::vector<AlignedStorage< 4>>;
37 using Cont8_t = std::vector<AlignedStorage< 8>>;
38 using Cont16_t = std::vector<AlignedStorage< 16>>;
39 using Cont32_t = std::vector<AlignedStorage< 32>>;
40 using Cont64_t = std::vector<AlignedStorage< 64>>;
41 using Cont128_t = std::vector<AlignedStorage< 128>>;
42 using Cont256_t = std::vector<AlignedStorage< 256>>;
43 using Cont512_t = std::vector<AlignedStorage< 512>>;
61 std::size_t align =
alignof(std::max_align_t);
64 align =
alignof(
void*);
67 align = vcl->GetClassAlignment();
69 switch(
int(
fVal->fKind) ) {
71 case kUChar_t: align =
alignof(char);
break;
73 case kUShort_t: align =
alignof(short);
break;
77 case kULong_t: align =
alignof(long);
break;
79 case kULong64_t:align =
alignof(
long long);
break;
81 case kFloat_t: align =
alignof(float);
break;
85 Fatal(
"TEmulatedCollectionProxy::WithCont",
"Unsupported value type %d for value class %s",
fVal->fKind,
86 vcl ? vcl->GetName() :
"<unknown>");
92 case 4096: fn(
reinterpret_cast<Cont4096_t*
>(obj), std::size_t(4096));
break;
93 case 2048: fn(
reinterpret_cast<Cont2048_t*
>(obj), std::size_t(2048));
break;
94 case 1024: fn(
reinterpret_cast<Cont1024_t*
>(obj), std::size_t(1024));
break;
95 case 512: fn(
reinterpret_cast<Cont512_t *
>(obj), std::size_t( 512));
break;
96 case 256: fn(
reinterpret_cast<Cont256_t *
>(obj), std::size_t( 256));
break;
97 case 128: fn(
reinterpret_cast<Cont128_t *
>(obj), std::size_t( 128));
break;
98 case 64: fn(
reinterpret_cast<Cont64_t *
>(obj), std::size_t( 64));
break;
99 case 32: fn(
reinterpret_cast<Cont32_t *
>(obj), std::size_t( 32));
break;
100 case 16: fn(
reinterpret_cast<Cont16_t *
>(obj), std::size_t( 16));
break;
101 case 8: fn(
reinterpret_cast<Cont8_t *
>(obj), std::size_t( 8));
break;
102 case 4: fn(
reinterpret_cast<Cont4_t *
>(obj), std::size_t( 4));
break;
103 case 2: fn(
reinterpret_cast<Cont2_t *
>(obj), std::size_t( 2));
break;
104 case 1: fn(
reinterpret_cast<Cont1_t *
>(obj), std::size_t( 1));
break;
106 Fatal(
"TEmulatedCollectionProxy::WithCont",
"Unsupported alignment %zu for value class %s",
107 align, vcl ? vcl->GetName() :
"<unknown>");
116 void ReadItems(
int nElements,
TBuffer &
b);
119 void WriteItems(
int nElements,
TBuffer &
b);
144 void *
New()
const override
146 void *mem = ::operator
new(
sizeof(
Cont_t));
147 WithCont(mem, [](
auto *
c, std::size_t) {
new (
c) std::decay_t<
decltype(*
c)>(); });
152 void *
New(
void *memory)
const override
154 WithCont(memory, [](
auto *
c, std::size_t) {
new (
c) std::decay_t<
decltype(*
c)>(); });
167 void *arr = ::operator
new(nElements *
sizeof(
Cont_t));
168 for (
Int_t i = 0; i < nElements; ++i)
170 [](
auto *
c, std::size_t) {
new (
c) std::decay_t<
decltype(*
c)>(); });
177 for (
Int_t i = 0; i < nElements; ++i)
179 [](
auto *
c, std::size_t) {
new (
c) std::decay_t<
decltype(*
c)>(); });
189 return {
NewArray(nElements, memory),
nullptr};
193 void Destructor(
void* p,
Bool_t dtorOnly =
kFALSE)
const override;
196 void DeleteArray(
void* p,
Bool_t dtorOnly =
kFALSE)
const override;
202 void *At(
UInt_t idx)
override;
205 void Clear(
const char *opt =
"")
override;
211 UInt_t Size()
const override;
217 void Commit(
void* env)
override;
221 void Insert(
const void *data,
void *container,
size_t size)
override;
244 const char *writeStlWithoutProxyMsg =
245 "The class requested (%s) for the branch \"%s\" "
246 "is an instance of an stl collection and does not have a compiled CollectionProxy. "
247 "Please generate the dictionary for this collection (%s) to avoid writing corrupted data.";
249 Error(where, writeStlWithoutProxyMsg, clName, BranchName, clName);
T ReadBuffer(TBufferFile *buf)
One of the template functions used to read objects from messages.
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Streamer(TBuffer &) override
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Buffer base class used for serializing objects.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Streamer around an arbitrary STL like container, which implements basic container functionality.
TEmulatedCollectionProxy & operator=(const TEmulatedCollectionProxy &)
std::vector< AlignedStorage< 512 > > Cont512_t
std::vector< AlignedStorage< 2048 > > Cont2048_t
TClass::ObjectPtr NewObjectArray(Int_t nElements) const override
Construct an array of nElements container objects and return the base address of the array.
std::vector< AlignedStorage< 4096 > > Cont4096_t
std::vector< AlignedStorage< 8 > > Cont8_t
void * NewArray(Int_t nElements) const override
Construct an array of nElements container objects and return the base address of the array.
std::vector< AlignedStorage< 256 > > Cont256_t
friend class TCollectionProxy
std::vector< AlignedStorage< 1 > > Cont1_t
std::vector< AlignedStorage< 1024 > > Cont1024_t
TClass::ObjectPtr NewObject() const override
Construct a new container object and return its address.
std::vector< AlignedStorage< 64 > > Cont64_t
std::vector< AlignedStorage< 128 > > Cont128_t
std::vector< AlignedStorage< 2 > > Cont2_t
void * New() const override
Construct a new container object and return its address.
void * New(void *memory) const override
Construct a new container object at the address given by arena.
TClass::ObjectPtr NewObject(void *memory) const override
Construct a new container object at the address given by arena.
TVirtualCollectionProxy * Generate() const override
Returns a clean object of the actual class that derives from TVirtualCollectionProxy.
std::vector< char > Cont_t
std::vector< AlignedStorage< 16 > > Cont16_t
void Streamer(TBuffer &buff, void *pObj, int siz) override
Streamer I/O overload.
std::vector< AlignedStorage< 4 > > Cont4_t
void * NewArray(Int_t nElements, void *memory) const override
Construct an array of nElements container objects at the address given by arena.
std::vector< AlignedStorage< 32 > > Cont32_t
void WithCont(void *obj, F &&fn) const
Invoke fn(typed_ptr, elemSize) where typed_ptr is the container pointer cast to the correct AlignedSt...
TClass::ObjectPtr NewObjectArray(Int_t nElements, void *memory) const override
Construct an array of nElements container objects at the address given by arena.
TEmulatedCollectionProxy(const TEmulatedCollectionProxy ©)
UInt_t Sizeof() const override
Return the sizeof() of the collection object.
Proxy around an arbitrary container, which implements basic functionality and iteration.
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
TClass * GetValueClass() const override
Return a pointer to the TClass representing the content.
Value * fKey
Descriptor of the key_type.
Value * fVal
Descriptor of the Value_type.
TVirtualCollectionProxy(const TVirtualCollectionProxy &)=delete
bool HasEmulatedProxy(TClass *cl)
void PrintWriteStlWithoutProxyMsg(const char *where, const char *clName, const char *BranchName)
constexpr bool IsValidAlignment(std::size_t align) noexcept
Return true if align is a valid C++ alignment value: strictly positive and a power of two.
Storage type whose alignment matches Align bytes.