/usr/include/root/TCollectionProxyInfo.h is in libroot-core-dev 5.34.00-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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | // @(#)root/cont:$Id: TCollectionProxyInfo.h 43515 2012-03-27 21:15:53Z pcanal $
// Author: Markus Frank 28/10/04. Philippe Canal 02/01/2007
/*************************************************************************
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TCollectionProxyInfo
#define ROOT_TCollectionProxyInfo
//////////////////////////////////////////////////////////////////////////
// //
// Small helper to gather the information neede to generate a //
// Collection Proxy //
//
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TError
#include "TError.h"
#endif
#include <vector>
#if defined(_WIN32)
#if _MSC_VER<1300
#define TYPENAME
#define R__VCXX6
#else
#define TYPENAME typename
#endif
#else
#define TYPENAME typename
#endif
namespace ROOT {
class TCollectionProxyInfo {
// This class is a place holder for the information needed
// to create the proper Collection Proxy.
// This is similar to Reflex's CollFuncTable.
public:
/** @class TCollectionProxyInfo::Environ TCollectionProxyInfo.h TCollectionProxyInfo.h
*
* Small helper to save proxy environment in the event of
* recursive calls.
*
* @author M.Frank
* @version 1.0
* @date 10/10/2004
*/
#ifndef __CINT__
struct EnvironBase {
private:
EnvironBase(const EnvironBase&); // Intentionally not implement, copy is not supported
EnvironBase &operator=(const EnvironBase&); // Intentionally not implement, copy is not supported
public:
EnvironBase() : fIdx(0), fSize(0), fObject(0), fStart(0), fTemp(0), fUseTemp(kFALSE), fRefCount(1), fSpace(0)
{
}
virtual ~EnvironBase() {}
size_t fIdx;
size_t fSize;
void* fObject;
void* fStart;
void* fTemp;
Bool_t fUseTemp;
int fRefCount;
size_t fSpace;
};
template <typename T> struct Environ : public EnvironBase {
typedef T Iter_t;
Iter_t fIterator;
T& iter() { return fIterator; }
static void *Create() {
return new Environ();
}
};
#else
struct EnvironBase;
template <typename T> struct Environ;
#endif
template <class T, class Q> struct PairHolder {
T first;
Q second;
PairHolder() {}
PairHolder(const PairHolder& c) : first(c.first), second(c.second) {}
virtual ~PairHolder() {}
private:
PairHolder& operator=(const PairHolder&); // not implemented
};
template <class T> struct Address {
virtual ~Address() {}
static void* address(T ref) {
return (void*)&ref;
}
};
/** @class TCollectionProxyInfo::Type TCollectionProxyInfo.h TCollectionProxyInfo.h
*
* Small helper to encapsulate basic data accesses for
* all STL continers.
*
* @author M.Frank
* @version 1.0
* @date 10/10/2004
*/
template <class T> struct Type
: public Address<TYPENAME T::const_reference>
{
typedef T Cont_t;
typedef typename T::iterator Iter_t;
typedef typename T::value_type Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
virtual ~Type() {}
static inline PCont_t object(void* ptr) {
return PCont_t(PEnv_t(ptr)->fObject);
}
static void* size(void* env) {
PEnv_t e = PEnv_t(env);
e->fSize = PCont_t(e->fObject)->size();
return &e->fSize;
}
static void* clear(void* env) {
object(env)->clear();
return 0;
}
static void* first(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
#if 0
// Assume iterators do not need destruction
::new(e->buff) Iter_t(c->begin());
#endif
e->fIterator = c->begin();
e->fSize = c->size();
if ( 0 == e->fSize ) return e->fStart = 0;
TYPENAME T::const_reference ref = *(e->iter());
return e->fStart = Type<T>::address(ref);
}
static void* next(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
for (; e->fIdx > 0 && e->iter() != c->end(); ++(e->iter()), --e->fIdx){ }
// TODO: Need to find something for going backwards....
if ( e->iter() == c->end() ) return 0;
TYPENAME T::const_reference ref = *(e->iter());
return Type<T>::address(ref);
}
static void* construct(void *what, size_t size) {
PValue_t m = PValue_t(what);
for (size_t i=0; i<size; ++i, ++m)
::new(m) Value_t();
return 0;
}
static void* collect(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
PValue_t m = PValue_t(e->fStart);
for (Iter_t i=c->begin(); i != c->end(); ++i, ++m )
::new(m) Value_t(*i);
return 0;
}
static void destruct(void *what, size_t size) {
PValue_t m = PValue_t(what);
for (size_t i=0; i < size; ++i, ++m )
m->~Value_t();
}
};
/** @class TCollectionProxyInfo::Map TCollectionProxyInfo.h TCollectionProxyInfo.h
*
* Small helper to encapsulate all necessary data accesses for
* containers like vector, list, deque
*
* @author M.Frank
* @version 1.0
* @date 10/10/2004
*/
template <class T> struct Pushback : public Type<T> {
typedef T Cont_t;
typedef typename T::iterator Iter_t;
typedef typename T::value_type Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
static void resize(void* obj, size_t n) {
PCont_t c = PCont_t(obj);
c->resize(n);
}
static void* feed(void *from, void *to, size_t size) {
PCont_t c = PCont_t(to);
PValue_t m = PValue_t(from);
for (size_t i=0; i<size; ++i, ++m)
c->push_back(*m);
return 0;
}
static int value_offset() {
return 0;
}
};
/** @class TCollectionProxyInfo::Map TCollectionProxyInfo.h TCollectionProxyInfo.h
*
* Small helper to encapsulate all necessary data accesses for
* containers like set, multiset etc.
*
* @author M.Frank
* @version 1.0
* @date 10/10/2004
*/
template <class T> struct Insert : public Type<T> {
typedef T Cont_t;
typedef typename T::iterator Iter_t;
typedef typename T::value_type Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
static void* feed(void *from, void *to, size_t size) {
PCont_t c = PCont_t(to);
PValue_t m = PValue_t(from);
for (size_t i=0; i<size; ++i, ++m)
c->insert(*m);
return 0;
}
static void resize(void* /* obj */, size_t ) {
;
}
static int value_offset() {
return 0;
}
};
/** @class TCollectionProxyInfo::Map TCollectionProxyInfo.h TCollectionProxyInfo.h
*
* Small helper to encapsulate all necessary data accesses for
* containers like set, multiset etc.
*
* @author M.Frank
* @version 1.0
* @date 10/10/2004
*/
template <class T> struct MapInsert : public Type<T> {
typedef T Cont_t;
typedef typename T::iterator Iter_t;
typedef typename T::value_type Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
static void* feed(void *from, void *to, size_t size) {
PCont_t c = PCont_t(to);
PValue_t m = PValue_t(from);
for (size_t i=0; i<size; ++i, ++m)
c->insert(*m);
return 0;
}
static void resize(void* /* obj */, size_t ) {
;
}
static int value_offset() {
return ((char*)&((PValue_t(0x1000))->second)) - ((char*)PValue_t(0x1000));
}
};
public:
#ifndef __CINT__
const type_info &fInfo;
#endif
size_t fIterSize;
size_t fValueDiff;
int fValueOffset;
void* (*fSizeFunc)(void*);
void (*fResizeFunc)(void*,size_t);
void* (*fClearFunc)(void*);
void* (*fFirstFunc)(void*);
void* (*fNextFunc)(void*);
void* (*fConstructFunc)(void*,size_t);
void (*fDestructFunc)(void*,size_t);
void* (*fFeedFunc)(void*,void*,size_t);
void* (*fCollectFunc)(void*);
void* (*fCreateEnv)();
// Set of function of direct iteration of the collections.
void (*fGetIterators)(void *collection, void *&begin_arena, void *&end_arena);
// begin_arena and end_arena should contain the location of memory arena of size fgIteratorSize.
// If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
// Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
void (*fCopyIterator)(void *&dest, const void *source);
// Copy the iterator source, into dest. dest should contain should contain the location of memory arena of size fgIteratorSize.
// If the collection iterator are of that size or less, the iterator will be constructed in place in this location (new with placement)
// Otherwise the iterator will be allocated via a regular new and its address returned by modifying the value of dest.
void* (*fNext)(void *iter, void *end);
// iter and end should be pointer to respectively an iterator to be incremented and the result of colleciton.end()
// 'Next' will increment the iterator 'iter' and return 0 if the iterator reached the end.
// If the end is not reached, 'Next' will return the address of the content unless the collection contains pointers in
// which case 'Next' will return the value of the pointer.
void (*fDeleteSingleIterator)(void *iter);
void (*fDeleteTwoIterators)(void *begin, void *end);
// If the sizeof iterator is greater than fgIteratorArenaSize, call delete on the addresses,
// Otherwise just call the iterator's destructor.
public:
TCollectionProxyInfo(const type_info& info,
size_t iter_size,
size_t value_diff,
int value_offset,
void* (*size_func)(void*),
void (*resize_func)(void*,size_t),
void* (*clear_func)(void*),
void* (*first_func)(void*),
void* (*next_func)(void*),
void* (*construct_func)(void*,size_t),
void (*destruct_func)(void*,size_t),
void* (*feed_func)(void*,void*,size_t),
void* (*collect_func)(void*),
void* (*create_env)()
) :
fInfo(info), fIterSize(iter_size), fValueDiff(value_diff),
fValueOffset(value_offset),
fSizeFunc(size_func),fResizeFunc(resize_func),fClearFunc(clear_func),
fFirstFunc(first_func),fNextFunc(next_func),fConstructFunc(construct_func),
fDestructFunc(destruct_func),fFeedFunc(feed_func),fCollectFunc(collect_func),
fCreateEnv(create_env),
fGetIterators(0),fCopyIterator(0),fNext(0),fDeleteSingleIterator(0),fDeleteTwoIterators(0)
{
}
/// Generate proxy from template
template <class T> static ROOT::TCollectionProxyInfo* Generate(const T&) {
// Generate a TCollectionProxyInfo given a TCollectionProxyInfo::Type
// template (used to described the behavior of the stl collection.
// Typical use looks like:
// ::ROOT::TCollectionProxyInfo::Generate(TCollectionProxyInfo::Pushback< vector<string> >()));
PairHolder<TYPENAME T::Value_t, TYPENAME T::Value_t>* p =
(PairHolder<TYPENAME T::Value_t, TYPENAME T::Value_t>*)0x1000;
return new ROOT::TCollectionProxyInfo(typeid(TYPENAME T::Cont_t),
sizeof(TYPENAME T::Iter_t),
(((char*)&p->second)-((char*)&p->first)),
T::value_offset(),
T::size,
T::resize,
T::clear,
T::first,
T::next,
T::construct,
T::destruct,
T::feed,
T::collect,
T::Env_t::Create);
}
template <class T> static ROOT::TCollectionProxyInfo Get(const T&) {
// Generate a TCollectionProxyInfo given a TCollectionProxyInfo::Type
// template (used to described the behavior of the stl collection.
// Typical use looks like:
// ::ROOT::TCollectionProxyInfo::Get(TCollectionProxyInfo::Pushback< vector<string> >()));
PairHolder<TYPENAME T::Value_t, TYPENAME T::Value_t>* p =
(PairHolder<TYPENAME T::Value_t, TYPENAME T::Value_t>*)0x1000;
return ROOT::TCollectionProxyInfo(typeid(TYPENAME T::Cont_t),
sizeof(TYPENAME T::Iter_t),
(((char*)&p->second)-((char*)&p->first)),
T::value_offset(),
T::size,
T::resize,
T::clear,
T::first,
T::next,
T::construct,
T::destruct,
T::feed,
T::collect,
T::Env_t::Create);
}
};
template <> struct TCollectionProxyInfo::Type<std::vector<Bool_t> >
: public TCollectionProxyInfo::Address<std::vector<Bool_t>::const_reference>
{
typedef std::vector<Bool_t> Cont_t;
typedef std::vector<Bool_t>::iterator Iter_t;
typedef std::vector<Bool_t>::value_type Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
virtual ~Type() {}
static inline PCont_t object(void* ptr) {
return PCont_t(PEnv_t(ptr)->fObject);
}
static void* size(void* env) {
PEnv_t e = PEnv_t(env);
e->fSize = PCont_t(e->fObject)->size();
return &e->fSize;
}
static void* clear(void* env) {
object(env)->clear();
return 0;
}
static void* first(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
#if 0
// Assume iterators do not need destruction
::new(e->buff) Iter_t(c->begin());
#endif
e->fIterator = c->begin();
e->fSize = c->size();
return 0;
}
static void* next(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
for (; e->fIdx > 0 && e->iter() != c->end(); ++(e->iter()), --e->fIdx){ }
// TODO: Need to find something for going backwards....
return 0;
}
static void* construct(void*,size_t) {
// Nothing to construct.
return 0;
}
static void* collect(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
PValue_t m = PValue_t(e->fStart); // 'start' is a buffer outside the container.
for (Iter_t i=c->begin(); i != c->end(); ++i, ++m )
::new(m) Value_t(*i);
return 0;
}
static void destruct(void*,size_t) {
// Nothing to destruct.
}
};
template <> struct TCollectionProxyInfo::Pushback<std::vector<bool> > : public TCollectionProxyInfo::Type<std::vector<Bool_t> > {
typedef std::vector<Bool_t> Cont_t;
typedef Cont_t::iterator Iter_t;
typedef Cont_t::value_type Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
static void resize(void* obj,size_t n) {
PCont_t c = PCont_t(obj);
c->resize(n);
}
static void* feed(void* from, void *to, size_t size) {
PCont_t c = PCont_t(to);
PValue_t m = PValue_t(from);
for (size_t i=0; i<size; ++i, ++m)
c->push_back(*m);
return 0;
}
static int value_offset() {
return 0;
}
};
#ifndef __CINT__
// Need specialization for boolean references due to stupid STL vector<bool>
template<> inline void* ::ROOT::TCollectionProxyInfo::Address<std::vector<Bool_t>::const_reference>::address(std::vector<Bool_t>::const_reference ) {
R__ASSERT(0);
return 0;
}
#endif
template <typename T> class TStdBitsetHelper {
// This class is intentionally empty, this is scaffolding to allow the equivalent
// of 'template <int N> struct TCollectionProxyInfo::Type<std::bitset<N> >' which
// is not effective in C++ (as of gcc 4.3.3).
};
#ifndef __CINT__
template <typename Bitset_t> struct TCollectionProxyInfo::Type<ROOT::TStdBitsetHelper<Bitset_t> > : public TCollectionProxyInfo::Address<const Bool_t &>
{
typedef Bitset_t Cont_t;
typedef std::pair<size_t,Bool_t> Iter_t;
typedef Bool_t Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
virtual ~Type() {}
static inline PCont_t object(void* ptr) {
return PCont_t(PEnv_t(ptr)->fObject);
}
static void* size(void* env) {
PEnv_t e = PEnv_t(env);
e->fSize = PCont_t(e->fObject)->size();
return &e->fSize;
}
static void* clear(void* env) {
object(env)->reset();
return 0;
}
static void* first(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
e->fIterator.first = 0;
e->fIterator.second = c->size() > 0 ? c->test(e->fIterator.first) : false ; // Iterator actually hold the value.
e->fSize = c->size();
return 0;
}
static void* next(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
for (; e->fIdx > 0 && e->fIterator.first != c->size(); ++(e->fIterator.first), --e->fIdx){ }
e->fIterator.second = (e->fIterator.first != c->size()) ? c->test(e->fIterator.first) : false;
return 0;
}
static void* construct(void*,size_t) {
// Nothing to construct.
return 0;
}
static void* collect(void* env) {
PEnv_t e = PEnv_t(env);
PCont_t c = PCont_t(e->fObject);
PValue_t m = PValue_t(e->fStart); // 'start' is a buffer outside the container.
for (size_t i=0; i != c->size(); ++i, ++m )
*m = c->test(i);
return 0;
}
static void destruct(void*,size_t) {
// Nothing to destruct.
}
};
template <typename Bitset_t>
struct TCollectionProxyInfo::Pushback<ROOT::TStdBitsetHelper<Bitset_t> > : public TCollectionProxyInfo::Type<TStdBitsetHelper<Bitset_t> > {
typedef Bitset_t Cont_t;
typedef bool Iter_t;
typedef bool Value_t;
typedef Environ<Iter_t> Env_t;
typedef Env_t *PEnv_t;
typedef Cont_t *PCont_t;
typedef Value_t *PValue_t;
static void resize(void*,size_t) {
}
static void* feed(void *from, void *to, size_t size) {
PCont_t c = PCont_t(to);
PValue_t m = PValue_t(from);
for (size_t i=0; i<size; ++i, ++m)
c->set(i,*m);
return 0;
}
static int value_offset() {
return 0;
}
};
#endif
}
#endif
|