Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:33

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_LINKMANAGER_H
0012 #define GAUDIKERNEL_LINKMANAGER_H
0013 
0014 // STL includes
0015 #include <memory>
0016 #include <string>
0017 #include <vector>
0018 // Gaudi
0019 #include "GaudiKernel/Kernel.h"
0020 
0021 class DataObject;
0022 class IOpaqueAddress;
0023 
0024 /** @class LinkManager LinkManager.h GaudiKernel/LinkManager.h
0025  *
0026  *  A LinkManager is the object aggregated into a DataObject,
0027  *  which is responsible for the handling of non-tree like links.
0028  *
0029  *  @author M.Frank
0030  */
0031 class GAUDI_API LinkManager final {
0032 
0033 public:
0034   /// Directory link types
0035   enum DirLinkType { INVALID, VALID };
0036 
0037   /** Embedded class defining a symbolic link
0038    * Note: No explicit copy constructor; implicit compiler generated one
0039    *       is just fine.
0040    */
0041   class Link final {
0042     /// String containing path of symbolic link
0043     std::string m_path;
0044     /// Pointer to object behind the link
0045     DataObject* m_pObject = nullptr;
0046     /// Link ID
0047     long m_id = INVALID;
0048 
0049   public:
0050     /// Standard constructor
0051     Link( long id, std::string path, DataObject* pObject = nullptr )
0052         : m_path( std::move( path ) ), m_pObject( pObject ), m_id( id ) {}
0053     /// Standard constructor for Root I/O
0054     Link() = default;
0055     /// Equality operator: check paths only
0056     bool operator==( const Link& link ) const { return link.m_path == m_path; }
0057     /// Update object pointer
0058     void setObject( const DataObject* pObject ) { m_pObject = const_cast<DataObject*>( pObject ); }
0059     /// Const access to data object
0060     const DataObject* object() const { return m_pObject; }
0061     DataObject*       object() { return m_pObject; }
0062     /// Access to path of object
0063     const std::string& path() const { return m_path; }
0064     /// Link identifier
0065     long ID() const { return m_id; }
0066     /// Access to the object's address
0067     IOpaqueAddress* address();
0068   };
0069 
0070 private:
0071   ///@ TODO: replace by std::vector<std::unique_ptr<Link>> once
0072   ///        ROOT does 'automatic' schema conversion from T* to
0073   ///        std::unique_ptr<T>...
0074   ///        Or, even better, just std::vector<Link>, given that
0075   ///        Link is barely larger than a pointer (40 vs. 8 bytes)
0076   ///        -- but that requires more invasive schema evolution.
0077   ///
0078   /// The vector containing all links which are non-tree like
0079   std::vector<Link*> m_linkVector;
0080 
0081 public:
0082   /// Standard Constructor
0083   LinkManager()                                = default;
0084   LinkManager( LinkManager&& )                 = default;
0085   LinkManager& operator=( LinkManager&& )      = default;
0086   LinkManager( LinkManager const& )            = delete;
0087   LinkManager& operator=( LinkManager const& ) = delete;
0088   /// Standard Destructor
0089   ~LinkManager();
0090   /// Retrieve number of link present
0091   long size() const { return m_linkVector.size(); }
0092   bool empty() const { return m_linkVector.empty(); }
0093   /// Retrieve symbolic link identified by ID
0094   const Link* link( long id ) const;
0095   Link*       link( long id );
0096   /// Retrieve symbolic link identified by object
0097   const Link* link( const DataObject* pObject ) const;
0098   Link*       link( const DataObject* pObject );
0099   /// Retrieve symbolic link identified by path
0100   const Link* link( std::string_view path ) const;
0101   Link*       link( std::string_view path );
0102   /// Add link by object reference and path
0103   long addLink( const std::string& path, const DataObject* pObject );
0104 
0105   struct Sentinel {};
0106   Sentinel end() const { return {}; }
0107   auto     begin() const {
0108     class Iterator {
0109       int                i;
0110       LinkManager const* parent;
0111 
0112     public:
0113       Iterator( LinkManager const* p, int i ) : i{ i }, parent{ p } {}
0114       bool      operator==( Sentinel ) const { return i == parent->size(); }
0115       bool      operator!=( Sentinel ) const { return !( *this == Sentinel{} ); }
0116       Iterator& operator++() {
0117         ++i;
0118         return *this;
0119       }
0120       const Link& operator*() const { return *parent->link( i ); }
0121     };
0122     return Iterator{ this, 0 };
0123   }
0124 };
0125 #endif // GAUDIKERNEL_LINKMANAGER_H