Changeset 944 in Sophya for trunk/SophyaLib/BaseTools/ndatablock.h
- Timestamp:
- Apr 16, 2000, 1:49:13 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ndatablock.h
r802 r944 12 12 namespace SOPHYA { 13 13 14 //////////////////////////////////////////////////////////////// 15 //// ------------------- Class Bridge ----------------------- // 16 //////////////////////////////////////////////////////////////// 17 /*! 18 \class Bridge 19 \ingroup SysTools 20 This class is use by NDataBlock. It allows sharing of datas 21 with external structures : by example, if you want to connect 22 a Blitz data structure with a NDataBlock or a TMatrix or ... 23 \sa NDataBlock 24 */ 25 14 26 // Classe pour permettre de partager des donnees avec 15 27 // un autre systeme de gestion de references (ex avec Blitz) 28 //! Empty class which allows data sharing with external structures (for NDataBlock) 16 29 class Bridge { 17 30 public: … … 20 33 }; 21 34 35 //////////////////////////////////////////////////////////////// 36 //// ----------------- Class NDataBlock --------------------- // 37 //////////////////////////////////////////////////////////////// 38 22 39 // classe de container avec partage de reference 40 //! Container of data with reference sharing 23 41 template <class T> 24 42 class NDataBlock : public AnyDataObj { 25 43 26 44 public: 45 46 // Methodes statiques pour debug. 47 static void SetPrintDebug(int prtdbglevel=1); 48 static void ResetDebug(size_t nallocdata=0, size_t nallocsref=0); 49 static void PrintDebug(); 27 50 28 51 // Creation / destruction … … 35 58 36 59 // Temporaire? 60 //! Return true if data block is temporay 37 61 inline bool IsTemp(void) const {return mIsTemp;} 62 //! Set temporary caracter of data block 38 63 inline void SetTemp(bool temp=false) const {mIsTemp = temp;} 39 64 … … 43 68 void Share(const NDataBlock<T>& a); 44 69 void FillFrom(size_t n,T* data); 70 //! Re-set all data values to \b v 45 71 inline void Reset(T v=0) 46 72 {if(mSz==0) return; T *p=Begin(),*pe=End(); while(p<pe) *p++=v;} … … 50 76 // et le nouveau tableau mis a zero. La nouvelle structure de 51 77 // donnees n'a qu'une reference (celle de cette classe). 78 //! Re-size the data structure 79 /*! Old datas are lost (for this class). The new values are set to zero. 80 The new data structure has only one reference (itself!). */ 52 81 inline void ReSize(size_t n) {Alloc(n);} 53 82 … … 55 84 56 85 // Informations pointeur/data 86 //! Return pointer on data structure. 57 87 inline T* Data() 58 88 {if(mSRef) return mSRef->data; else return NULL;} 89 //! Return pointer on data structure. 59 90 inline T* Data() const 60 91 {if(mSRef) return mSRef->data; else return NULL;} 92 //! Return the size of the data structure 61 93 inline size_t Size() const {return mSz;} 94 //! Return the \b i th element of the data structure 62 95 inline T& operator()(size_t i) {return *(mSRef->data+i);} 96 //! Return the \b i th element of the data structure 63 97 inline T operator()(size_t i) const {return *(mSRef->data+i);} 98 //! Return pointer to the beginning of the data structure. 64 99 inline T* Begin() {return mSRef->data;} 100 //! Return pointer to the beginning of the data structure. 65 101 inline T const* Begin() const {return mSRef->data;} 102 //! Return pointer to the end of the data structure. 66 103 inline T* End() {return mSRef->data+mSz;} 104 //! Return pointer to the end of the data structure. 67 105 inline T const* End() const {return mSRef->data+mSz;} 106 //! Return the number of references to the data structure 68 107 inline size_t NRef() const {if(mSRef) return 0; else return mSRef->nref;} 69 108 70 109 // Impression 71 110 void Print(ostream& os, size_t i1=0,size_t n=10) const; 111 //! print infos and datas (from \b i1 to \b i2) on stdout. 72 112 inline void Print(size_t i1=0,size_t n=0) const {Print(cout,i1,n);} 73 113 … … 106 146 107 147 protected: 108 typedef struct {size_t nref; T* data; Bridge* bridge; } NDREF; 148 //! NDREF structure for reference management 149 typedef struct { 150 size_t nref; //!< Number of references to the data structure 151 T* data; //!< Pointer to data structure itself 152 Bridge* bridge; //!< Pointer to a bridge for the data structure 153 } NDREF; 109 154 110 155 void Alloc(size_t n,T* data=NULL,Bridge* br=NULL, bool zero=true); 111 156 void Delete(void); 112 157 113 size_t mSz; 114 NDREF* mSRef; 115 mutable bool mIsTemp; 158 static int Debug_NDataBlock; //!< DEBUG: set debug level (all type<T> classes) 159 static size_t NallocData; //!< DEBUG: number of allocations (all type<T> classes) 160 static size_t NallocSRef; //!< DEBUG: number of references (all type<T> classes) 161 162 size_t mSz; //!< size of data structure 163 NDREF* mSRef; //!< NDREF structure for reference management 164 mutable bool mIsTemp; //!< true if class is temporary 116 165 }; 117 166 118 167 //! Define operator \<\< for printing 119 168 template<class T> 120 169 inline ostream& operator << (ostream& os, const NDataBlock<T>& a) 121 170 {a.Print(os); return(os);} 171 172 //! Add a constant to datas and return NDataBlock : ND = NDa + b 122 173 template<class T> 123 174 inline NDataBlock<T> operator + (const NDataBlock<T>& a,T b) 124 175 {return a.Add(b);} 176 //! Add a constant to datas and return NDataBlock : ND = b + NDa 125 177 template<class T> 126 178 inline NDataBlock<T> operator + (T b,const NDataBlock<T>& a) 127 179 {return a.Add(b);} 180 //! Substract a constant to datas and return NDataBlock : ND = NDa - b 128 181 template<class T> 129 182 inline NDataBlock<T> operator - (const NDataBlock<T>& a,T b) 130 183 {return a.Sub(b);} 184 //! Substract a constant to datas and return NDataBlock : ND = b - NDa 131 185 template<class T> 132 186 inline NDataBlock<T> operator - (T b,const NDataBlock<T>& a) 133 187 {return a.SubInv(b);} 188 //! Multiply datas by a constant and return NDataBlock : ND = NDa * b 134 189 template<class T> 135 190 inline NDataBlock<T> operator * (const NDataBlock<T>& a,T b) 136 191 {return a.Mul(b);} 192 //! Multiply datas by a constant and return NDataBlock : ND = b * NDa 137 193 template<class T> 138 194 inline NDataBlock<T> operator * (T b,const NDataBlock<T>& a) 139 195 {return a.Mul(b);} 196 //! Divide datas by a constant and return NDataBlock : ND = NDa / b 140 197 template<class T> 141 198 inline NDataBlock<T> operator / (const NDataBlock<T>& a,T b) 142 199 {return a.Div(b);} 200 //! Divide a constant by datas and return NDataBlock : ND = b / NDa 143 201 template<class T> 144 202 inline NDataBlock<T> operator / (T b,const NDataBlock<T>& a) 145 203 {return a.DivInv(b);} 146 204 205 //! Add datas of two data blocks and return NDataBlock : ND = NDa + NDb 147 206 template<class T> 148 207 inline NDataBlock<T> operator + (const NDataBlock<T>& a,const NDataBlock<T>& b) 149 208 {return a.Add(b);} 209 //! Substract datas of two data blocks and return NDataBlock : ND = NDa - NDb 150 210 template<class T> 151 211 inline NDataBlock<T> operator - (const NDataBlock<T>& a,const NDataBlock<T>& b) 152 212 {return a.Sub(b);} 213 //! Multiply datas of two data blocks and return NDataBlock : ND = NDa * NDb 153 214 template<class T> 154 215 inline NDataBlock<T> operator * (const NDataBlock<T>& a,const NDataBlock<T>& b) 155 216 {return a.Mul(b);} 217 //! Divide datas of two data blocks and return NDataBlock : ND = NDa / NDb 156 218 template<class T> 157 219 inline NDataBlock<T> operator / (const NDataBlock<T>& a,const NDataBlock<T>& b) 158 220 {return a.Div(b);} 159 221 160 161 162 222 } // Fin du namespace 163 223
Note:
See TracChangeset
for help on using the changeset viewer.