DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectExtensions.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_GEOMETRY_OBJECTEXTENSIONS_H
14 #define DD4HEP_GEOMETRY_OBJECTEXTENSIONS_H
15 
16 // C/C++ include files
17 #include <typeinfo>
18 #include <map>
19 
21 namespace DD4hep {
22 
24 
32  public:
34  typedef std::map<const std::type_info*, void*> Extensions;
36  typedef void* (*copy_t)(const void*, void* arg);
38  typedef void (*destruct_t)(void*);
40  struct Entry {
43  int id;
44  };
45  typedef std::map<const std::type_info*, Entry> ExtensionMap;
46 
51 
53  static void _noDelete(void*) {}
54 
56  template <typename T> static void _delete(void* ptr) {
57  delete (T*) (ptr);
58  }
59 
60  public:
62  ObjectExtensions(const std::type_info& parent_type);
64  ObjectExtensions(const ObjectExtensions& copy) = delete;
66  virtual ~ObjectExtensions();
70  void move(ObjectExtensions& copy);
72  void clear(bool destroy=true);
74  void copyFrom(const Extensions& ext, void* arg);
76  void* addExtension(void* ptr, const std::type_info& info, copy_t ctor, destruct_t dtor);
78  void* addExtension(void* ptr, const std::type_info& info, destruct_t dtor);
80  void* removeExtension(const std::type_info& info, bool destroy);
82  void* extension(const std::type_info& info, bool alert) const;
84  void* extension(const std::type_info& info) const;
85  };
86 
87 } /* End namespace DD4hep */
88 #endif /* DD4HEP_GEOMETRY_OBJECTEXTENSIONS_H */
Defintiion of the extension entry.
void move(ObjectExtensions &copy)
Move extensions to target object.
int id
std::map< const std::type_info *, void * > Extensions
Definition of the extension type.
std::map< const std::type_info *, Entry > ExtensionMap
Extensions extensions
The extensions object.
void copyFrom(const Extensions &ext, void *arg)
Copy object extensions from another object. Hosting type must be identical!
copy_t copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
ObjectExtensions(const std::type_info &parent_type)
Default constructor.
static void _delete(void *ptr)
Templated destructor function.
ObjectExtensions & operator=(const ObjectExtensions &copy)=delete
Assignment operator.
destruct_t destruct
void clear(bool destroy=true)
Clear all extensions.
void *(* copy_t)(const void *, void *arg)
Extensions copy constructor type.
virtual ~ObjectExtensions()
Default destructor.
void * extension(const std::type_info &info, bool alert) const
Access an existing extension object from the detector element.
void * addExtension(void *ptr, const std::type_info &info, copy_t ctor, destruct_t dtor)
Add an extension object to the detector element.
void(* destruct_t)(void *)
Extensions destructor type.
static void _noDelete(void *)
Function to be passed as dtor if object should NOT be deleted!
void * removeExtension(const std::type_info &info, bool destroy)
Remove an existing extension object from the instance.
Implementation of an object supporting arbitrary user extensions.
ExtensionMap * extensionMap
Pointer to the extension map.