Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

at_pointers.h

Go to the documentation of this file.
00001 //
00002 // The Austria library is copyright (c) Gianni Mariani 2004.
00003 // 
00004 // Grant Of License.  Grants to LICENSEE the non-exclusive right to use the Austria
00005 // library subject to the terms of the LGPL.
00006 // 
00007 // A copy of the license is available in this directory or one may be found at this URL:
00008 //      http://www.gnu.org/copyleft/lesser.txt
00009 // 
00021 #ifndef x_at_pointers_h_x
00022 #define x_at_pointers_h_x 1
00023 
00024 
00025 #include "at_os.h"
00026 #include "at_assert.h"
00027 
00028 // Austria namespace
00029 namespace at
00030 {
00031 
00032 // ======== PointerRange ===========================================
00038 enum PointerRange
00039 {
00045         Null,
00046         
00052         Invalid,
00053         
00058         Valid
00059         
00060 };
00061 
00062 
00063 
00064 
00065 // ======== IteratorWrapper ========================================
00071 template <typename w_T, typename w_value_type, bool w_debug_code>
00072 class IteratorWrapper
00073 {
00074         public:
00075 
00076         enum {
00081                 e_debug_code = ( w_debug_code && OSTraitsBase::DebugBuild ) ? 1 : 0
00082         };
00083 
00084 
00090         typedef w_value_type            value_type;
00091 
00097         IteratorWrapper()
00098                 : m_range( Null )
00099         {
00100         }
00101 
00112         IteratorWrapper( const w_T & i_value )
00113           : m_value( i_value ),
00114                 m_range( Valid )
00115         {
00116         }
00117         
00118 
00119         // ======== Assign ================================================
00128         inline IteratorWrapper Assign( w_T & i_in )
00129         {
00130                 IteratorWrapper retval( * this );
00131 
00132                 m_range = Valid;
00133 
00134                 m_value = i_in;
00135 
00136                 return retval;
00137 
00138         } // end Assign
00139 
00140         // ======== AssignNull ============================================
00147         inline void AssignNull()
00148         {
00149                 m_range = Null;
00150 
00151         } // end AssignNull
00152 
00153         // ======== AssignInvalid =========================================
00160         inline void AssignInvalid()
00161         {
00162                 m_range = Invalid;
00163 
00164         } // end AssignInvalid
00165 
00166 
00167         // ======== IsNull ================================================
00174         inline bool IsNull() const
00175         {
00176 
00177                 if ( e_debug_code )
00178                 {
00179                         AT_Assert( m_range != Invalid );                        
00180                 }
00181 
00182                 return m_range == Null;
00183 
00184         } // end IsNull
00185 
00186         
00187         // ======== IsValid ===============================================
00194         inline bool IsValid() const
00195         {
00196                 return m_range == IsValid;
00197 
00198         } // end IsValid
00199 
00200 
00201         // ======== Get ===================================================
00209         inline const w_T & Get() const
00210         {
00211 
00212                 return m_value;
00213 
00214         } // end GetPtr
00215 
00216         
00217         protected:
00218         
00219         w_T                                                     m_value;
00220         PointerRange                            m_range;
00221                 
00222 };
00223 
00224 
00225 
00226 // ======== PointerWrapper =========================================
00240 template <typename w_TD, bool w_debug_code>
00241 class PointerWrapper
00242 {
00243 
00244         enum {
00249                 e_debug_code = ( w_debug_code && OSTraitsBase::DebugBuild ) ? 1 : 0
00250         };
00251 
00257         w_TD                            * m_value;
00258         
00259         public:
00260 
00266         typedef w_TD            value_type;
00267 
00278         PointerWrapper( w_TD * i_value = 0 )
00279           : m_value( i_value )
00280         {
00281         }
00282         
00283 
00284         // ======== Assign ================================================
00292         inline void Assign( w_TD * i_in )
00293         {
00294                 m_value = i_in;
00295 
00296         } // end Assign
00297 
00298         // ======== AssignNull ============================================
00305         inline void AssignNull()
00306         {
00307                 m_value = 0;
00308 
00309         } // end AssignNull
00310 
00311         // ======== AssignInvalid =========================================
00318         inline void AssignInvalid()
00319         {
00320                 m_value = e_debug_code ? ( reinterpret_cast<w_TD *>( -1 ) ) : 0;
00321 
00322         } // end AssignInvalid
00323 
00324 
00325         // ======== IsNull ================================================
00333         inline bool IsNull() const
00334         {
00335                 if ( e_debug_code )
00336                 {
00337                         AT_Assert( m_value != ( reinterpret_cast<w_TD *>( -1 ) ) );
00338                 }
00339                 
00340                 return m_value == 0;
00341                 
00342         } // end IsNull
00343 
00344         
00345         // ======== IsValid ===============================================
00354         inline bool IsValid() const
00355         {
00356 
00357                 if ( e_debug_code )
00358                 {
00359                         if ( m_value == ( reinterpret_cast<w_TD *>( -1 ) ) )
00360                         {
00361                                 return false;
00362                         }
00363                 }
00364 
00365                 return m_value != 0;
00366 
00367         } // end IsValid
00368 
00369 
00370         // ======== Get ===================================================
00378         inline const w_TD * Get() const
00379         {
00380                 // don't worry about assertion silliness.
00381                 if ( e_debug_code )
00382                 {
00383                         AT_Assert( m_value != ( reinterpret_cast<w_TD *>( -1 ) ) );
00384                 }
00385                 
00386                 return m_value;
00387 
00388         } // end GetPtr
00389 
00390         // ======== GetInnerAddr ============================================
00399         inline w_TD ** GetInnerAddr()
00400         {
00401                 return & m_value;
00402 
00403         } // end GetPtr
00404 
00405 };
00406 
00407 
00408 // ======== PointerTo ==============================================
00415 template <typename w_T>
00416 class PointerTo
00417 {
00418     public:
00419 
00425     typedef typename w_T::value_type value_type;
00426 
00432         typedef IteratorWrapper< w_T, value_type, true >                t_pointer_traits_debug;
00433         typedef IteratorWrapper< w_T, value_type, false >       t_pointer_traits_nodebug;
00434 };
00435 
00436 
00437 
00438 // ======== PointerTo ==============================================
00448 template <typename w_TD>
00449 class PointerTo<w_TD *>
00450 {
00451     public:
00452 
00458     typedef w_TD value_type;
00459 
00465         typedef PointerWrapper< w_TD, true >            t_pointer_traits_debug;
00466         
00471         typedef PointerWrapper< w_TD, false >   t_pointer_traits_nondebug;
00472 };
00473 
00474 
00481 typedef char MPT_False;
00482 
00483 
00490 struct MPT_True { int m[2]; };
00491 
00502 template <typename w_D, typename w_TD>
00503 struct MPT_Finder
00504 {
00505     template <typename w_T>
00506     static MPT_True finder( const w_T *, typename w_T::PtrTargetMarker * );
00507         
00508     static MPT_False finder( const w_D *, w_TD * );
00509 
00510 };
00511 
00525 template <typename w_D, typename w_TD = int >
00526 struct MPT_ContainsMember
00527 {
00534     struct DerivedClass : w_D
00535     {
00536     };
00537 
00543     typedef DerivedClass  * DerivedClassp;
00544 
00548     typedef w_TD  * t_TDp;
00549 
00550     enum {
00556         value = (
00557             sizeof( MPT_Finder<w_D,w_TD>::finder( DerivedClassp(), t_TDp() ) )
00558             == sizeof( MPT_True )
00559         )
00560     };
00561     
00562 };
00563 
00564 template <int w_select, typename w_T0, typename w_T1>
00565 struct MPT_Select_Def
00566 {
00567 };
00568 
00569 template <typename w_T0, typename w_T1>
00570 struct MPT_Select_Def<0, w_T0, w_T1>
00571 {
00572     typedef     w_T0    type;
00573 };
00574 
00575 template <typename w_T0, typename w_T1>
00576 struct MPT_Select_Def<1, w_T0, w_T1>
00577 {
00578     typedef     w_T1    type;
00579 };
00580 
00581 
00582 
00583 // ======== MPT_Select ================================================
00596 template <typename w_ValueT, typename w_T0, typename w_T1>
00597 struct MPT_Select
00598 {
00599     typedef typename MPT_Select_Def<
00600         w_ValueT::value,
00601         w_T0,
00602         w_T1
00603     >::type                     type;
00604     
00605 };
00606 
00607 
00608 
00609 }; // namespace
00610 
00611 #endif // x_at_pointers_h_x
00612 

Generated for Austria by doxygen and MakeXS at Sun Oct 24 17:35:34 PDT 2004