Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:02:17

0001 #ifndef DTBufferTree_H
0002 #define DTBufferTree_H
0003 /** \class DTBufferTree
0004  *
0005  *  Description:
0006  *
0007  *  \author Paolo Ronchese INFN Padova
0008  *
0009  */
0010 
0011 #include <map>
0012 #include <memory>
0013 #include <vector>
0014 
0015 // This trait template defines the type of the output argument
0016 // in the find function.  Usually the output type is just the
0017 // content type, but in the special case where the content is
0018 // a unique_ptr the the output type is a bare pointer. The
0019 // functions in the trait template make that output type work
0020 // in both cases.
0021 template <typename T>
0022 class DTBufferTreeTrait {
0023 public:
0024   typedef T outputTypeOfConstFind;
0025   typedef T outputTypeOfNonConstFind;
0026 
0027   static T getOutputValue(T const& t) { return t; }
0028   static T getDefault() { return 0; }
0029 };
0030 
0031 template <typename T>
0032 class DTBufferTreeTrait<std::unique_ptr<T> > {
0033 public:
0034   typedef T const* outputTypeOfConstFind;
0035   typedef T* outputTypeOfNonConstFind;
0036 
0037   static T* getOutputValue(std::unique_ptr<T> const& t) { return t.get(); }
0038   static T* getDefault() { return nullptr; }
0039 };
0040 
0041 template <class Key, class Content>
0042 class DTBufferTree {
0043 public:
0044   typedef typename std::vector<Key>::const_iterator ElementKey;
0045 
0046   DTBufferTree();
0047   DTBufferTree(DTBufferTree const&) = delete;
0048   DTBufferTree& operator=(DTBufferTree const&) = delete;
0049   virtual ~DTBufferTree();
0050 
0051   void clear();
0052 
0053   int insert(ElementKey fKey, ElementKey lKey, Content cont);
0054   int insert(const Key& k, Content cont);
0055   int find(ElementKey fKey, ElementKey lKey, typename DTBufferTreeTrait<Content>::outputTypeOfConstFind& cont) const;
0056   int find(const Key& k, typename DTBufferTreeTrait<Content>::outputTypeOfConstFind& cont) const;
0057   int find(ElementKey fKey, ElementKey lKey, typename DTBufferTreeTrait<Content>::outputTypeOfNonConstFind& cont);
0058   int find(const Key& k, typename DTBufferTreeTrait<Content>::outputTypeOfNonConstFind& cont);
0059 
0060 private:
0061   typedef DTBufferTree<Key, Content> map_node;
0062   typedef typename std::map<Key, DTBufferTree<Key, Content>*> map_cont;
0063   typedef typename std::map<Key, DTBufferTree<Key, Content>*>::const_iterator map_iter;
0064 
0065   Content bufferContent;
0066   map_cont bufferMap;
0067 };
0068 
0069 #include "CondFormats/DTObjects/interface/DTBufferTree.icc"
0070 
0071 // This class is defined because it is easier to forward declare
0072 // it than the template. Then unique_ptr is not exposed. When
0073 // we stop using GCCXML (which does not recognize C++11's unique_ptr)
0074 // this will not be as important, although it will still keep
0075 // #include <memory> out of the header file of the class using
0076 // DTBufferTree.
0077 class DTBufferTreeUniquePtr : public DTBufferTree<int, std::unique_ptr<std::vector<int> > > {};
0078 
0079 #endif  // DTBufferTree_H