Go to the documentation of this file.00001 #ifndef DDI_rep_type_h
00002 #define DDI_rep_type_h
00003
00004 namespace DDI {
00005
00006 template <class N, class I>
00007 struct rep_traits
00008 {
00009 typedef N name_type;
00010 typedef typename I::value_type value_type;
00011 typedef typename I::pointer pointer;
00012 typedef typename I::reference reference;
00013 };
00014
00015 template <class N, class I>
00016 struct rep_traits<N,I*>
00017 {
00018 typedef N name_type;
00019 typedef I value_type;
00020 typedef I* pointer;
00021 typedef I& reference;
00022 };
00023
00024
00025 template <class N, class I>
00026 struct rep_type
00027 {
00028 rep_type() : second(0), init_(false) {}
00029 rep_type(const N & n, I i) : first(n), second(i), init_(false)
00030 { if (i) init_=true; }
00031 virtual ~rep_type(){}
00032 N first;
00033 I second;
00034 bool init_;
00035 const typename rep_traits<N,I>::name_type & name() const { return first; }
00036 const typename rep_traits<N,I>::reference rep() const { return *second; }
00037 typename rep_traits<N,I>::reference rep() { return *second; }
00038 I swap(I i) { I tmp(second);
00039 second = i;
00040 init_ = false;
00041 if (i) init_ = true;
00042 return tmp;
00043 }
00044 operator bool() const { return init_; }
00045 };
00046
00047 }
00048 #endif