Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:55

0001 #ifndef DETECTOR_DESCRIPTION_CORE_DDI_REP_TYPE_H
0002 #define DETECTOR_DESCRIPTION_CORE_DDI_REP_TYPE_H
0003 
0004 #include <memory>
0005 
0006 namespace DDI {
0007 
0008   template <class N, class I>
0009   struct rep_traits {
0010     using name_type = N;
0011     using pointer = typename I::pointer;
0012     using reference = typename I::reference;
0013   };
0014 
0015   template <class N, class I>
0016   struct rep_traits<N, I*> {
0017     using name_type = N;
0018     using pointer = I*;
0019     using reference = I&;
0020   };
0021 
0022   template <class N, class I>
0023   struct rep_traits<N, std::unique_ptr<I>> {
0024     using name_type = N;
0025     using pointer = I*;
0026     using reference = I&;
0027   };
0028 
0029   template <class N, class I>
0030   struct rep_type {
0031     rep_type() : second(nullptr), init_(false) {}
0032     rep_type(const N& n, I i) : first(n), second(std::move(i)), init_(false) {
0033       if (i)
0034         init_ = true;
0035     }
0036     N first;
0037     I second;
0038 
0039     const typename rep_traits<N, I>::name_type& name() const { return first; }
0040     const typename rep_traits<N, I>::reference rep() const { return *second; }
0041 
0042     I swap(I i) {
0043       I tmp(second);
0044       second = i;
0045       init_ = false;
0046       if (i)
0047         init_ = true;
0048       return tmp;
0049     }
0050     operator bool() const { return init_; }
0051 
0052   private:
0053     bool init_;
0054   };
0055 }  // namespace DDI
0056 
0057 #endif