ATLAS Offline Software
Type.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 */
13 #ifndef ROOTUTILS_TYPE_H
14 #define ROOTUTILS_TYPE_H
15 
16 
18 
19 
20 #include "RootUtils/TSMethodCall.h"
21 #include "TClass.h"
22 #include "TDataType.h"
23 #include <typeinfo>
24 
25 
26 namespace RootUtils {
27 
28 
39 class Type
40 {
41 public:
48  Type();
49 
50 
55  Type (TClass* cls);
56 
57 
62  Type (EDataType type);
63 
64 
73  Type (const std::string& typname);
74 
75 
76 
81  Type (const RootUtils::Type& other);
82 
83 
89 
90 
94  ~Type();
95 
96 
107  void init (const std::string& typname);
108 
109 
116  void init (TClass* cls);
117 
118 
125  void init (EDataType type);
126 
127 
134  void* create() const;
135 
136 
141  void destroy (void* p) const;
142 
143 
147  std::string getTypeName() const;
148 
149 
155  const TClass* getClass() const;
156 
157 
163  EDataType getDataType() const;
164 
165 
169  const std::type_info* getTypeInfo() const;
170 
171 
175  size_t getSize() const;
176 
177 
186  void copyRange (void* dst, const void* src, size_t n) const;
187 
188 
198  void clearRange (void* dst, size_t n) const;
199 
200 
211  void clearRange (void* dst, size_t index, size_t n) const;
212 
213 
219  void clear (void* dst, size_t index) const;
220 
221 
226  void clear (void* dst) const;
227 
228 
238  void assign (void* dst, size_t dst_index,
239  const void* src, size_t src_index) const;
240 
241 
252  void assign (void* dst, const void* src) const;
253 
254 
264  void swap (void* a, size_t a_index,
265  void* b, size_t b_index) const;
266 
267 
273  void swap (void* a, void* b) const;
274 
275 
287  void swapRange (void* a, size_t a_index,
288  void* b, size_t b_index,
289  size_t n) const;
290 
291 
299  void fromString (void* p, const std::string& s) const;
300 
301 
305  class Deleter
306  {
307  public:
312 
313 
318  Deleter (const Type& t);
319 
320 
325  void operator() (void* p);
326 
327 
328  private:
330  const Type* m_t;
331  };
332 
333 
344  typedef std::unique_ptr<void, Deleter> unique_ptr;
345 
346 
347 private:
349  TClass* m_cls;
350 
352  EDataType m_type;
353 
355  const std::type_info* m_ti;
356 
358  size_t m_size;
359 
360  // Method call for assignment.
361  mutable TSMethodCall m_assign ATLAS_THREAD_SAFE;
362 
365  void* m_defElt;
366 };
367 
368 
369 } // namespace RootUtils
370 
371 
372 #include "RootUtils/Type.icc"
373 
374 
375 #endif // not ROOTUTILS_TYPE_H
TSMethodCall.h
Helper for thread-safe TMethodCall. Extracted from Type.
RootUtils
Definition: ILogger.h:20
RootUtils::Type::swapRange
void swapRange(void *a, size_t a_index, void *b, size_t b_index, size_t n) const
Swap a range of objects between vectors.
Definition: Type.cxx:567
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
RootUtils::Type::init
void init(const std::string &typname)
Initialize from a type name.
Definition: Type.cxx:154
RootUtils::Type::Deleter
Deleter object, compatible with std::unique_ptr.
Definition: Type.h:306
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
RootUtils::Type::m_cls
TClass * m_cls
The class of the derived type, or 0 if it's not a class type.
Definition: Type.h:349
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
RootUtils::Type::getClass
const TClass * getClass() const
Return the ROOT class for the described type.
Definition: Type.cxx:346
index
Definition: index.py:1
RootUtils::Type::swap
void swap(void *a, size_t a_index, void *b, size_t b_index) const
Swap an object between vectors.
Definition: Type.cxx:524
RootUtils::Type::getTypeInfo
const std::type_info * getTypeInfo() const
Return the type_info for the described type.
Definition: Type.cxx:366
RootUtils::Type::Deleter::m_t
const Type * m_t
The type describing this pointer.
Definition: Type.h:330
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
RootUtils::Type::Deleter::Deleter
Deleter()
Default constructor.
RootUtils::Type::Deleter::operator()
void operator()(void *p)
Delete an object.
RootUtils::Type::m_defElt
void * m_defElt
Pointer to a default-constructed instance of the payload object.
Definition: Type.h:365
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
RootUtils::Type::assign
void assign(void *dst, size_t dst_index, const void *src, size_t src_index) const
Copy an object within vectors.
Definition: Type.cxx:480
RootUtils::Type::m_type
EDataType m_type
The ROOT type code of the derived type, or kNoType_t for a class type.
Definition: Type.h:352
RootUtils::TSMethodCall
Helper for making a thread-safe function call.
Definition: TSMethodCall.h:33
RootUtils::Type::getSize
size_t getSize() const
Return the size in bytes of an instance of the described type.
Definition: Type.cxx:375
RootUtils::Type::clear
void clear(void *dst, size_t index) const
Clear an object in a vector.
Definition: Type.cxx:454
RootUtils::Type::destroy
void destroy(void *p) const
Destroy an instance of the object (and free memory).
Definition: Type.cxx:310
RootUtils::Type::clearRange
void clearRange(void *dst, size_t n) const
Clear a range of objects.
Definition: Type.cxx:420
beamspotman.n
n
Definition: beamspotman.py:731
xAODType
Definition: ObjectType.h:13
RootUtils::Type::fromString
void fromString(void *p, const std::string &s) const
Initialize an object from a string.
Definition: Type.cxx:601
RootUtils::Type::m_size
size_t m_size
The size in bytes of an instance of the described type.
Definition: Type.h:358
RootUtils::Type::getDataType
EDataType getDataType() const
Return the ROOT data type code for the described type.
Definition: Type.cxx:357
RootUtils::Type::m_ti
const std::type_info * m_ti
The type_info for the described type.
Definition: Type.h:355
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
RootUtils::Type::unique_ptr
std::unique_ptr< void, Deleter > unique_ptr
A std::unique_ptr type referencing a generic pointer.
Definition: Type.h:344
RootUtils::Type::ATLAS_THREAD_SAFE
TSMethodCall m_assign ATLAS_THREAD_SAFE
Definition: Type.h:361
RootUtils::Type::Type
Type()
Default constructor.
Definition: Type.cxx:35
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
RootUtils::Type::copyRange
void copyRange(void *dst, const void *src, size_t n) const
Copy a range of objects.
Definition: Type.cxx:389
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
RootUtils::Type::Deleter::Deleter
Deleter(const Type &t)
Constructor.
RootUtils::Type
Wrapper for ROOT types.
Definition: Type.h:40
RootUtils::Type::~Type
~Type()
Destructor.
Definition: Type.cxx:137
RootUtils::Type::create
void * create() const
Create an instance of the object.
Definition: Type.cxx:296
RootUtils::Type::getTypeName
std::string getTypeName() const
Return the name of this type.
Definition: Type.cxx:329
RootUtils::Type::operator=
Type & operator=(const RootUtils::Type &other)
Assignment.
Definition: Type.cxx:115
checker_macros.h
Define macros for attributes used to control the static checker.
Type.icc