00001 #ifndef MN_SH_DATA_H 00002 #define MN_SH_DATA_H 00003 00004 #include "SHRPtr.h" 00005 #include "MNValid.h" 00006 00007 class MNRTPPacket; 00008 00009 namespace SH 00010 { 00011 class SHPlainData; 00012 class SHOrderedData; 00013 class DummyData; 00014 class OrderedDummyData; 00015 class SHRTPData; 00016 00028 class Data 00029 { 00030 DECLARE_VALID 00031 private: 00032 size_t _ref; 00033 // no memory leak trouble right now with this class 00034 // static size_t _total_cnt; ///< look for memory leaks 00035 // static void inc_total_cnt( ); 00036 // static void dec_total_cnt( ); 00037 public: 00038 Data( ) 00039 : _ref( 0 ) 00040 { 00041 MAKE_VALID 00042 // inc_total_cnt(); 00043 } 00044 00047 virtual ~Data() 00048 { 00049 CHECK_VALID 00050 // dec_total_cnt(); 00051 assert( _ref == 0 ); 00052 MAKE_INVALID 00053 } 00054 00060 virtual RPtr<Data> clone() = 0; 00061 00066 virtual size_t getByteSize( ) const = 0; 00067 00072 virtual bool isPlainData( ) const = 0; 00073 00075 virtual bool isOrderedData( ) const = 0; 00076 00078 virtual bool isRTPData( ) const = 0; 00079 00081 virtual bool isDummyData( ) const = 0; 00082 00084 virtual bool isSHRTPData( ) const = 0; 00085 00086 void ref( ) 00087 { 00088 CHECK_VALID 00089 _ref += 1; 00090 } 00091 00097 void unref() 00098 { 00099 CHECK_VALID 00100 _ref -= 1; 00101 if( _ref == 0 ) 00102 { 00103 delete this; 00104 } 00105 } 00106 00112 inline SHPlainData* asPlainData( ); 00113 00114 inline SHOrderedData* asOrderedData( ); 00115 inline MNRTPPacket* asRTPData( ); 00116 inline DummyData* asDummyData( ); 00117 inline OrderedDummyData* asOrderedDummyData( ); 00118 inline SHRTPData* asSHRTPData( ); 00120 private: 00121 Data( const Data& orig ); 00122 Data& operator=( const Data& orig ); 00123 }; 00124 00125 typedef RPtr<Data> DataPtr; 00126 00127 inline SHPlainData* Data::asPlainData( ) 00128 { 00129 if( isPlainData() ) return (SHPlainData*)this; 00130 return NULL; 00131 } 00132 00133 inline SHOrderedData* Data::asOrderedData( ) 00134 { 00135 if( isOrderedData() && !isDummyData() ) return (SHOrderedData*)this; 00136 return NULL; 00137 } 00138 00139 inline MNRTPPacket* Data::asRTPData( ) 00140 { 00141 if( isRTPData() ) return (MNRTPPacket*)this; 00142 return NULL; 00143 } 00144 00145 inline DummyData* Data::asDummyData( ) 00146 { 00147 if( isDummyData() ) return (DummyData*)this; 00148 return NULL; 00149 } 00150 00151 inline OrderedDummyData* Data::asOrderedDummyData( ) 00152 { 00153 if( isDummyData() && isOrderedData() ) return (OrderedDummyData*)this; 00154 return NULL; 00155 } 00156 00157 inline SHRTPData* Data::asSHRTPData( ) 00158 { 00159 if ( isSHRTPData() ) return (SHRTPData*) this; 00160 return NULL; 00161 } 00162 00164 00165 }; // namespace SH 00166 00167 #endif /* MN_SH_DATA_H */ 00168