Logo ROOT   6.10/09
Reference Guide
TStreamerInfoActions.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Philippe Canal 05/2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TStreamerInfoActions
13 #define ROOT_TStreamerInfoActions
14 
15 #include <vector>
16 
17 #include "TStreamerInfo.h"
18 #include <assert.h>
19 
20 /**
21 \class TStreamerInfoActions::TConfiguration
22 \ingroup IO
23 */
24 
25 namespace TStreamerInfoActions {
26 
27  /// Base class of the Configurations.
29  protected:
30  public:
32  TVirtualStreamerInfo *fInfo; ///< TStreamerInfo form which the action is derived
33  UInt_t fElemId; ///< Identifier of the TStreamerElement
34  TCompInfo_t *fCompInfo;///< Access to compiled information (for legacy code)
35  Int_t fOffset; ///< Offset within the object
36  UInt_t fLength; ///< Number of element in a fixed length array.
37  public:
38  TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset) : fInfo(info), fElemId(id), fCompInfo(compinfo), fOffset(offset),fLength(1) {};
39  TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset, UInt_t length) : fInfo(info), fElemId(id), fCompInfo(compinfo), fOffset(offset),fLength(length) {};
40  virtual ~TConfiguration() {};
41 
42  virtual void AddToOffset(Int_t delta);
43 
44  virtual TConfiguration *Copy() { return new TConfiguration(*this); }
45 
46  virtual void Print() const;
47  virtual void PrintDebug(TBuffer &buffer, void *object) const;
48  };
49 
50  /// Base class of the Configurations for the member wise looping routines.
52  public:
54  // virtual void PrintDebug(TBuffer &buffer, void *object) const;
55  virtual ~TLoopConfiguration() {};
56  virtual void Print() const;
57  virtual void *GetFirstAddress(void *start, const void *end) const = 0;
58  virtual TLoopConfiguration* Copy() = 0; // { return new TLoopConfiguration(*this); }
59  };
60 
62 
63  typedef Int_t (*TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf);
64  typedef Int_t (*TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf);
65  typedef Int_t (*TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf);
66 
67  class TConfiguredAction : public TObject {
68  public:
69  union {
73  };
75  private:
76  // assignment operator must be the default because the 'copy' constructor is actually a move constructor and must be used.
77  public:
78  TConfiguredAction() : fAction(0), fConfiguration(0) {}
79  TConfiguredAction(const TConfiguredAction &rval) : TObject(rval), fAction(rval.fAction), fConfiguration(rval.fConfiguration)
80  {
81  // WARNING: Technically this is a move constructor ...
82  const_cast<TConfiguredAction&>(rval).fConfiguration = 0;
83  }
85  {
86  // WARNING: Technically this is a move assignment!.
87 
88  TConfiguredAction tmp(rval); // this does a move.
89  TObject::operator=(tmp); // we are missing TObject::Swap
90  std::swap(fAction,tmp.fAction);
91  std::swap(fConfiguration,tmp.fConfiguration);
92  return *this;
93  };
94 
95  TConfiguredAction(TStreamerInfoAction_t action, TConfiguration *conf) : fAction(action), fConfiguration(conf)
96  {
97  // Usual constructor.
98  }
99  TConfiguredAction(TStreamerInfoVecPtrLoopAction_t action, TConfiguration *conf) : fVecPtrLoopAction(action), fConfiguration(conf)
100  {
101  // Usual constructor.
102  }
103  TConfiguredAction(TStreamerInfoLoopAction_t action, TConfiguration *conf) : fLoopAction(action), fConfiguration(conf)
104  {
105  // Usual constructor.
106  }
108  // Usual destructor.
109  // Idea: the configuration ownership might be moved to a single list so that
110  // we can shared them between the optimized and non-optimized list of actions.
111  delete fConfiguration;
112  }
113  void PrintDebug(TBuffer &buffer, void *object) const;
114 
115  inline Int_t operator()(TBuffer &buffer, void *object) const {
116  return fAction(buffer, object, fConfiguration);
117  }
118 
119  inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const {
120  return fVecPtrLoopAction(buffer, start_collection, end_collection, fConfiguration);
121  }
122 
123  inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const {
124  return fLoopAction(buffer, start_collection, end_collection, loopconf, fConfiguration);
125  }
126 
127  ClassDef(TConfiguredAction,0); // A configured action
128  };
129 
130  typedef std::vector<TConfiguredAction> ActionContainer_t;
131  class TActionSequence : public TObject {
133  public:
134  TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata) : fStreamerInfo(info), fLoopConfig(0) { fActions.reserve(maxdata); };
136  delete fLoopConfig;
137  }
138 
139  template <typename action_t>
140  void AddAction( action_t action, TConfiguration *conf ) {
141  fActions.push_back( TConfiguredAction(action, conf) );
142  }
143  void AddAction(const TConfiguredAction &action ) {
144  fActions.push_back( action );
145  }
146 
147  TVirtualStreamerInfo *fStreamerInfo; ///< StreamerInfo used to derive these actions.
148  TLoopConfiguration *fLoopConfig; ///< If this is a bundle of memberwise streaming action, this configures the looping
149  ActionContainer_t fActions;
150 
151  void AddToOffset(Int_t delta);
152 
153  TActionSequence *CreateCopy();
154  static TActionSequence *CreateReadMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy);
155  static TActionSequence *CreateWriteMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy);
156  TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);
157 
158  void Print(Option_t * = "") const;
159 
161  };
162 
163 }
164 
165 #endif // ROOT_TStreamerInfoActions
166 
167 
std::vector< TConfiguredAction > ActionContainer_t
TVirtualStreamerInfo * fInfo
TStreamerInfo form which the action is derived.
TLoopConfiguration * fLoopConfig
If this is a bundle of memberwise streaming action, this configures the looping.
const char Option_t
Definition: RtypesCore.h:62
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
void AddAction(action_t action, TConfiguration *conf)
virtual void PrintDebug(TBuffer &buffer, void *object) const
Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const
TConfiguredAction(const TConfiguredAction &rval)
TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata)
TConfiguredAction(TStreamerInfoLoopAction_t action, TConfiguration *conf)
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
UInt_t fElemId
Identifier of the TStreamerElement.
int Int_t
Definition: RtypesCore.h:41
void AddAction(const TConfiguredAction &action)
Float_t delta
TVirtualCollectionProxy::Next_t Next_t
#define ClassDef(name, id)
Definition: Rtypes.h:297
TConfiguredAction(TStreamerInfoVecPtrLoopAction_t action, TConfiguration *conf)
Int_t(* TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf)
TConfiguredAction & operator=(const TConfiguredAction &rval)
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:250
Base class of the Configurations for the member wise looping routines.
Int_t(* TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf)
TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset)
TStreamerInfoVecPtrLoopAction_t fVecPtrLoopAction
TStreamerInfo::TCompInfo_t TCompInfo_t
Int_t fOffset
Offset within the object.
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t operator()(TBuffer &buffer, void *object) const
Int_t(* TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf)
Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const
Mother of all ROOT objects.
Definition: TObject.h:37
TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset, UInt_t length)
void *(* Next_t)(void *iter, const void *end)
Abstract Interface class describing Streamer information for one class.
TConfiguredAction(TStreamerInfoAction_t action, TConfiguration *conf)
Base class of the Configurations.
UInt_t fLength
Number of element in a fixed length array.
TVirtualStreamerInfo * fStreamerInfo
StreamerInfo used to derive these actions.
TCompInfo_t * fCompInfo
Access to compiled information (for legacy code)