/cvmfs/atlas.cern.ch/repo/sw/ASG/AnalysisBase/2.4.31/AthContainers/AthContainers/ConstDataList.h File Reference

DataList adapter that acts like it holds const pointers. More...

#include "AthContainers/DataList.h"
#include "SGTools/ClassID_traits.h"
#include "AthContainers/ConstDataList.icc"

Go to the source code of this file.

Classes

class  ConstDataList< DL >
 DataList adapter that acts like it holds const pointers. More...
struct  ClassID_traits< ConstDataList< DL > >
 Specialize ClassID_traits for ConstDataList so that they will be automatically made const when recorded in StoreGate. More...
class  SG::DVLConstDataListBucket< T >
 DataBucket class for ConstDataList. More...
struct  SG::DataBucketTrait< ConstDataList< T >, U >
 Metafunction to find the proper DataBucket class for the first template argument. More...
class  SG::BaseInfo< ConstDataList< T > >
 Let the BaseInfo for ConstDataList forward to that of the base DataList. More...

Namespaces

namespace  SG
 

Constructor from a payload object.


Functions

template<class T >
void swap (ConstDataList< T > &a, ConstDataList< T > &b)
 See DataList<T, BASE>::swap().

Detailed Description

DataList adapter that acts like it holds const pointers.

Author:
scott snyder <snyder@bnl.gov>
Date:
Sep, 2011 A DataList<T> acts as a container of T*. This means, though, that one cannot put a const T* into a DataList<T>. However, one sometimes wants to do that. A typical case is that one retrieves a const DataList from StoreGate, filters the contents, and then stores them in a new DataList. Recall that a const DataList will return const T*. So the pointers one gets from a const DataList cannot be inserted into another DataList. (The root cause of this is that we don't want to have to deal with distinct DataList<T> and DataList<const T> types, and thus DataList [and StoreGate] don't have standard const semantics.)

To solve this, we introduce the template class ConstDataList<DL>. The template argument should be a DataList class or something that derives from one. (The reason the template argument is the DataList class rather than the element type T is to allow for types that derive from DataList.) ConstDataList<DL> derives from DL, but privately --- so it is a DL, but clients cannot use it as a DL. Instead, we provide only methods that retrieve const pointers. Further, the insertion methods will take const rather than non-const pointers.

There are two ways (short of casting) to convert a ConstDataList<DL> to a const DL. The asDataList method will directly do this conversion. Also, if the object is recorded in StoreGate, it will automatically be made const, so a retrieval will get a const DL. A ConstDataList should not convert to a non-const DL.

So, for example, filtering might look something like this:

  const DataList<T>* v_in = 0;
  CHECK( sg->retrieve (v_in) );
  ConstDataList<DataList<T> >* v_out =
    new ConstDataList<DataList<T> > (SG::VIEW_ELEMENTS);
  CHECK( sg->record (v_out, "key") );
  for (const T* t : *v_in) {
    if (filter (*it))
      v_out->push_back (*it);
  }

Note that if you are not recording the result in StoreGate, it may well be preferable to just use a std::list<const T*> rather than ConstDataList.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 1 Dec 2017 for RootCore Packages by  doxygen 1.6.1