Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:51

0001 #ifndef DataFormats_Common_fillPtrVector_h
0002 #define DataFormats_Common_fillPtrVector_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Common
0006 // Class  :     fillPtrVector
0007 //
0008 /**\class fillPtrVector fillPtrVector.h DataFormats/Common/interface/fillPtrVector.h
0009 
0010  Description: Helper function used to implement the edm::Ptr class
0011 
0012  Usage:
0013     This is an internal detail of edm::Ptr interaction with edm::Wrapper and should not be used by others
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Sat Oct 20 11:45:38 CEST 2007
0019 //
0020 
0021 // system include files
0022 
0023 // user include files
0024 #include "DataFormats/Common/interface/FillView.h"
0025 #include "FWCore/Utilities/interface/EDMException.h"
0026 #include "FWCore/Utilities/interface/OffsetToBase.h"
0027 
0028 #include "DataFormats/Common/interface/fwd_fillPtrVector.h"
0029 
0030 #include <typeinfo>
0031 #include <vector>
0032 
0033 // forward declarations
0034 namespace edm {
0035   namespace detail {
0036     template <typename COLLECTION>
0037     void reallyfillPtrVector(COLLECTION const& coll,
0038                              std::type_info const& iToType,
0039                              std::vector<unsigned long> const& iIndicies,
0040                              std::vector<void const*>& oPtr) {
0041       typedef COLLECTION product_type;
0042       typedef typename GetProduct<product_type>::element_type element_type;
0043       typedef typename product_type::const_iterator iter;
0044 
0045       oPtr.reserve(iIndicies.size());
0046       if (iToType == typeid(element_type)) {
0047         for (std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(), itEnd = iIndicies.end();
0048              itIndex != itEnd;
0049              ++itIndex) {
0050           iter it = coll.begin();
0051           std::advance(it, *itIndex);
0052           element_type const* address = GetProduct<product_type>::address(it);
0053           oPtr.push_back(address);
0054         }
0055       } else {
0056         for (std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(), itEnd = iIndicies.end();
0057              itIndex != itEnd;
0058              ++itIndex) {
0059           iter it = coll.begin();
0060           std::advance(it, *itIndex);
0061           element_type const* address = GetProduct<product_type>::address(it);
0062           void const* ptr = pointerToBase(iToType, address);
0063           if (nullptr != ptr) {
0064             oPtr.push_back(ptr);
0065           } else {
0066             Exception::throwThis(errors::LogicError,
0067                                  "TypeConversionError "
0068                                  "edm::PtrVector<> : unable to convert type ",
0069                                  typeid(element_type).name(),
0070                                  " to ",
0071                                  iToType.name(),
0072                                  "\n");
0073           }
0074         }
0075       }
0076     }
0077   }  // namespace detail
0078 
0079   template <typename T, typename A>
0080   void fillPtrVector(std::vector<T, A> const& obj,
0081                      std::type_info const& iToType,
0082                      std::vector<unsigned long> const& iIndicies,
0083                      std::vector<void const*>& oPtr) {
0084     detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
0085   }
0086 
0087   template <typename T, typename A>
0088   void fillPtrVector(std::list<T, A> const& obj,
0089                      std::type_info const& iToType,
0090                      std::vector<unsigned long> const& iIndicies,
0091                      std::vector<void const*>& oPtr) {
0092     detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
0093   }
0094 
0095   template <typename T, typename A>
0096   void fillPtrVector(std::deque<T, A> const& obj,
0097                      std::type_info const& iToType,
0098                      std::vector<unsigned long> const& iIndicies,
0099                      std::vector<void const*>& oPtr) {
0100     detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
0101   }
0102 
0103   template <typename T, typename A, typename Comp>
0104   void fillPtrVector(std::set<T, A, Comp> const& obj,
0105                      std::type_info const& iToType,
0106                      std::vector<unsigned long> const& iIndicies,
0107                      std::vector<void const*>& oPtr) {
0108     detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
0109   }
0110 }  // namespace edm
0111 
0112 #endif