/usr/include/root/TVirtualCollectionIterators.h is in libroot-io-dev 5.34.19+dfsg-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | // @(#)root/cont:$Id: e00edea30f17233d3f97a85eba14e20c201eb980 $
// Author: Philippe Canal 20/08/2010
/*************************************************************************
* Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TVirtualCollectionIterators
#define ROOT_TVirtualCollectionIterators
//////////////////////////////////////////////////////////////////////////
// //
// TVirtualCollectionIterators //
// //
// Small helper class to generically acquire and release iterators //
// //
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TVirtualCollectionProxy
#include "TVirtualCollectionProxy.h"
#endif
#ifndef ROOT_TError
#include "TError.h"
#endif
class TVirtualCollectionIterators
{
private:
TVirtualCollectionIterators(); // Intentionally unimplemented.
TVirtualCollectionIterators(const TVirtualCollectionIterators&); // Intentionally unimplemented.
public:
// Note when the collection is a vector, fBegin and fEnd points to
// the start and end of the memory content rather than to the address
// of iterators (saving one dereference when being used).
typedef TVirtualCollectionProxy::CreateIterators_t CreateIterators_t;
typedef TVirtualCollectionProxy::DeleteTwoIterators_t DeleteTwoIterators_t;
char fBeginBuffer[TVirtualCollectionProxy::fgIteratorArenaSize];
char fEndBuffer[TVirtualCollectionProxy::fgIteratorArenaSize];
void *fBegin; // Pointer to the starting iterator (collection->begin())
void *fEnd; // Pointer to the ending iterator (collection->end())
CreateIterators_t fCreateIterators;
DeleteTwoIterators_t fDeleteTwoIterators;
TVirtualCollectionIterators(TVirtualCollectionProxy *proxy, Bool_t read = kTRUE) : fBegin( &(fBeginBuffer[0]) ), fEnd(&(fEndBuffer[0])), fCreateIterators(0), fDeleteTwoIterators(0)
{
// memset(fBeginBuffer,0,TVirtualCollectionProxy::fgIteratorArenaSize);
// memset(fEndBuffer,0,TVirtualCollectionProxy::fgIteratorArenaSize);
if (proxy) {
fCreateIterators = proxy->GetFunctionCreateIterators(read);
fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(read);
} else {
::Fatal("TIterators::TIterators","Created with out a collection proxy!\n");
}
}
TVirtualCollectionIterators(CreateIterators_t creator, DeleteTwoIterators_t destruct) : fBegin( &(fBeginBuffer[0]) ), fEnd(&(fEndBuffer[0])), fCreateIterators(creator), fDeleteTwoIterators(destruct)
{
}
inline void CreateIterators(void *collection, TVirtualCollectionProxy *proxy)
{
// Initialize the fBegin and fEnd iterators.
fCreateIterators(collection, &fBegin, &fEnd, proxy);
}
inline ~TVirtualCollectionIterators()
{
if (fBegin != &(fBeginBuffer[0])) {
// assert(end != endbuf);
fDeleteTwoIterators(fBegin,fEnd);
}
}
};
class TVirtualCollectionPtrIterators
{
public:
typedef TVirtualCollectionProxy::Next_t Next_t;
typedef TVirtualCollectionProxy::CopyIterator_t Copy_t;
typedef TVirtualCollectionProxy::CreateIterators_t CreateIterators_t;
typedef TVirtualCollectionProxy::DeleteIterator_t Delete_t;
typedef TVirtualCollectionProxy::DeleteTwoIterators_t DeleteTwoIterators_t;
private:
TVirtualCollectionPtrIterators(); // Intentionally unimplemented.
TVirtualCollectionPtrIterators(const TVirtualCollectionPtrIterators&); // Intentionally unimplemented.
CreateIterators_t fCreateIterators;
DeleteTwoIterators_t fDeleteTwoIterators;
Bool_t fAllocated;
char fRawBeginBuffer[TVirtualCollectionProxy::fgIteratorArenaSize];
char fRawEndBuffer[TVirtualCollectionProxy::fgIteratorArenaSize];
struct TInternalIterator {
private:
TInternalIterator &operator=(const TInternalIterator&); // intentionally not implemented
public:
TInternalIterator() : fCopy(0),fDelete(0),fNext(0),fIter(0) {}
TInternalIterator(const TInternalIterator &source) : fCopy(source.fCopy),fDelete(source.fDelete),fNext(source.fNext),fIter(0) {}
Copy_t fCopy;
Delete_t fDelete;
Next_t fNext;
void *fIter;
};
TInternalIterator fBeginBuffer;
TInternalIterator fEndBuffer;
public:
// Note when the collection is a vector, fBegin and fEnd points to
// the start and end of the memory content rather than to the address
// of iterators (saving one dereference when being used).
void *fBegin; // Pointer to the starting iterator (collection->begin())
void *fEnd; // Pointer to the ending iterator (collection->end())
TVirtualCollectionPtrIterators(TVirtualCollectionProxy *proxy) : fCreateIterators(0), fDeleteTwoIterators(0), fAllocated(kFALSE),
fBegin( &(fRawBeginBuffer[0]) ),
fEnd( &(fRawEndBuffer[0]) )
{
// memset(fBeginBuffer,0,TVirtualCollectionProxy::fgIteratorArenaSize);
// memset(fEndBuffer,0,TVirtualCollectionProxy::fgIteratorArenaSize);
if (proxy) {
fCreateIterators = proxy->GetFunctionCreateIterators();
fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators();
fEndBuffer.fCopy = fBeginBuffer.fCopy = proxy->GetFunctionCopyIterator();
fEndBuffer.fNext = fBeginBuffer.fNext = proxy->GetFunctionNext();
fEndBuffer.fDelete = fBeginBuffer.fDelete = proxy->GetFunctionDeleteIterator();
} else {
::Fatal("TIterators::TIterators","Created with out a collection proxy!\n");
}
}
inline void CreateIterators(void *collection, TVirtualCollectionProxy *proxy)
{
// Initialize the fBegin and fEnd iterators.
fBegin = &(fRawBeginBuffer[0]);
fEnd = &(fRawEndBuffer[0]);
fCreateIterators(collection, &fBegin, &fEnd, proxy);
if (fBegin != &(fRawBeginBuffer[0])) {
// The iterator where too large to buffer in the buffer
fAllocated = kTRUE;
}
fBeginBuffer.fIter = fBegin;
fEndBuffer.fIter = fEnd;
fBegin = &fBeginBuffer;
fEnd = &fEndBuffer;
}
inline ~TVirtualCollectionPtrIterators()
{
if (fAllocated) {
// assert(end != endbuf);
fDeleteTwoIterators(fBeginBuffer.fIter,fEndBuffer.fIter);
}
}
static void *Next(void *iter, const void *end)
{
TInternalIterator *internal_iter = (TInternalIterator*) iter;
TInternalIterator *internal_end = (TInternalIterator*) end;
void **ptr = (void**)internal_iter->fNext(internal_iter->fIter,internal_end->fIter);
if(ptr) return *ptr;
else return 0;
}
static void DeleteIterator(void *iter)
{
TInternalIterator *internal_iter = (TInternalIterator*) iter;
if (internal_iter->fDelete) {
internal_iter->fDelete(internal_iter->fIter);
}
}
static void *CopyIterator(void *dest, const void *source)
{
TInternalIterator *internal_source = (TInternalIterator*)source;
TInternalIterator *internal_dest = new TInternalIterator(*internal_source);
void *newiter = internal_source->fCopy(dest,internal_source->fIter);
if (newiter == dest) {
internal_dest->fDelete = 0;
}
internal_dest->fIter = newiter;
return internal_dest;
}
};
// Specialization of TVirtualCollectionIterators when we know the collection
// to be a vector (hence there is nothing to delete at the end).
struct TVirtualVectorIterators
{
private:
TVirtualVectorIterators(const TVirtualVectorIterators&); // Intentionally unimplemented.
public:
// Note when the collection is a vector, fBegin and fEnd points to
// the start and end of the memory content rather than to the address
// of iterators (saving one dereference when being used).
typedef TVirtualCollectionProxy::CreateIterators_t CreateIterators_t;
void *fBegin; // Pointer to the starting iterator (collection->begin())
void *fEnd; // Pointer to the ending iterator (collection->end())
TVirtualVectorIterators(TVirtualCollectionProxy * /* proxy */) : fBegin(0), fEnd(0)
{
// fCreateIterators = proxy->GetFunctionCreateIterators();
}
TVirtualVectorIterators(CreateIterators_t /* creator */) : fBegin(0), fEnd(0)
{
// fCreateIterators = creator;
}
TVirtualVectorIterators() : fBegin(0), fEnd(0)
{
// Default constructor.
}
inline void CreateIterators(void *collection)
{
// Initialize the fBegin and fEnd iterators.
// We can safely assume that the std::vector layout does not really depend on
// the content!
std::vector<char> *vec = (std::vector<char>*)collection;
if (vec->empty()) {
fBegin = 0;
fEnd = 0;
return;
}
fBegin= &(*vec->begin());
#ifdef R__VISUAL_CPLUSPLUS
fEnd = &(*(vec->end()-1)) + 1; // On windows we can not dererence the end iterator at all.
#else
// coverity[past_the_end] Safe on other platforms
fEnd = &(*vec->end());
#endif
//fCreateIterators(collection, &fBegin, &fEnd);
}
};
#endif // ROOT_TVirtualCollectionIterators
|