Ignore:
Timestamp:
Apr 16, 2000, 1:49:13 PM (25 years ago)
Author:
ansari
Message:

doc + nouvelle gestion debug cmv 16/04/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/ndatablock.h

    r802 r944  
    1212namespace SOPHYA {
    1313
     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
    1426// Classe pour permettre de partager des donnees avec
    1527// un autre systeme de gestion de references (ex avec Blitz)
     28//! Empty class which allows data sharing with external structures (for NDataBlock)
    1629class Bridge {
    1730public:
     
    2033};
    2134
     35////////////////////////////////////////////////////////////////
     36//// ----------------- Class NDataBlock --------------------- //
     37////////////////////////////////////////////////////////////////
     38
    2239// classe de container avec partage de reference
     40//! Container of data with reference sharing
    2341template <class T>
    2442class NDataBlock : public AnyDataObj {
    2543
    2644public:
     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();
    2750
    2851  // Creation / destruction
     
    3558
    3659  // Temporaire?
     60  //! Return true if data block is temporay
    3761  inline bool IsTemp(void) const {return mIsTemp;}
     62  //! Set temporary caracter of data block
    3863  inline void SetTemp(bool temp=false) const {mIsTemp = temp;}
    3964
     
    4368  void Share(const NDataBlock<T>& a);
    4469  void FillFrom(size_t n,T* data);
     70  //! Re-set all data values to \b v
    4571  inline void Reset(T v=0)
    4672         {if(mSz==0) return; T *p=Begin(),*pe=End(); while(p<pe) *p++=v;}
     
    5076  // et le nouveau tableau mis a zero. La nouvelle structure de
    5177  // 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!). */
    5281  inline void ReSize(size_t n) {Alloc(n);}
    5382
     
    5584 
    5685  // Informations pointeur/data
     86  //! Return pointer on data structure.
    5787  inline T* Data()
    5888         {if(mSRef) return mSRef->data; else return NULL;}
     89  //! Return pointer on data structure.
    5990  inline T* Data() const
    6091         {if(mSRef) return mSRef->data; else return NULL;}
     92  //! Return the size of the data structure
    6193  inline size_t Size() const    {return mSz;}
     94  //! Return the \b i th element of  the data structure
    6295  inline T& operator()(size_t i)       {return *(mSRef->data+i);}
     96  //! Return the \b i th element of  the data structure
    6397  inline T  operator()(size_t i) const {return *(mSRef->data+i);}
     98  //! Return pointer to the beginning of the data structure.
    6499  inline T*        Begin()        {return mSRef->data;}
     100  //! Return pointer to the beginning of the data structure.
    65101  inline T const*  Begin() const  {return mSRef->data;}
     102  //! Return pointer to the end of the data structure.
    66103  inline T*        End()          {return mSRef->data+mSz;}
     104  //! Return pointer to the end of the data structure.
    67105  inline T const*  End() const    {return mSRef->data+mSz;}
     106  //! Return the number of references to the data structure
    68107  inline size_t NRef() const {if(mSRef) return 0; else return mSRef->nref;}
    69108
    70109  // Impression
    71110  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.
    72112  inline void Print(size_t i1=0,size_t n=0) const {Print(cout,i1,n);}
    73113
     
    106146
    107147protected:
    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;
    109154
    110155  void Alloc(size_t n,T* data=NULL,Bridge* br=NULL, bool zero=true);
    111156  void Delete(void);
    112157
    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
    116165};
    117166
    118 
     167//! Define operator \<\< for printing
    119168template<class T>
    120169inline ostream& operator << (ostream& os, const NDataBlock<T>& a)
    121170                      {a.Print(os); return(os);}
     171
     172//! Add a constant to datas and return NDataBlock : ND = NDa + b
    122173template<class T>
    123174inline NDataBlock<T> operator + (const NDataBlock<T>& a,T b)
    124175                      {return a.Add(b);}
     176//! Add a constant to datas and return NDataBlock : ND = b + NDa
    125177template<class T>
    126178inline NDataBlock<T> operator + (T b,const NDataBlock<T>& a)
    127179                      {return a.Add(b);}
     180//! Substract a constant to datas and return NDataBlock : ND = NDa - b
    128181template<class T>
    129182inline NDataBlock<T> operator - (const NDataBlock<T>& a,T b)
    130183                      {return a.Sub(b);}
     184//! Substract a constant to datas and return NDataBlock : ND = b - NDa
    131185template<class T>
    132186inline NDataBlock<T> operator - (T b,const NDataBlock<T>& a)
    133187                      {return a.SubInv(b);}
     188//! Multiply datas by a constant and return NDataBlock : ND = NDa * b
    134189template<class T>
    135190inline NDataBlock<T> operator * (const NDataBlock<T>& a,T b)
    136191                      {return a.Mul(b);}
     192//! Multiply datas by a constant and return NDataBlock : ND = b * NDa
    137193template<class T>
    138194inline NDataBlock<T> operator * (T b,const NDataBlock<T>& a)
    139195                      {return a.Mul(b);}
     196//! Divide datas by a constant and return NDataBlock : ND = NDa / b
    140197template<class T>
    141198inline NDataBlock<T> operator / (const NDataBlock<T>& a,T b)
    142199                      {return a.Div(b);}
     200//! Divide a constant by datas and return NDataBlock : ND = b / NDa
    143201template<class T>
    144202inline NDataBlock<T> operator / (T b,const NDataBlock<T>& a)
    145203                      {return a.DivInv(b);}
    146204
     205//! Add datas of two data blocks and return NDataBlock : ND = NDa + NDb
    147206template<class T>
    148207inline NDataBlock<T> operator + (const NDataBlock<T>& a,const NDataBlock<T>& b)
    149208                      {return a.Add(b);}
     209//! Substract datas of two data blocks and return NDataBlock : ND = NDa - NDb
    150210template<class T>
    151211inline NDataBlock<T> operator - (const NDataBlock<T>& a,const NDataBlock<T>& b)
    152212                      {return a.Sub(b);}
     213//! Multiply datas of two data blocks and return NDataBlock : ND = NDa * NDb
    153214template<class T>
    154215inline NDataBlock<T> operator * (const NDataBlock<T>& a,const NDataBlock<T>& b)
    155216                      {return a.Mul(b);}
     217//! Divide datas of two data blocks and return NDataBlock : ND = NDa / NDb
    156218template<class T>
    157219inline NDataBlock<T> operator / (const NDataBlock<T>& a,const NDataBlock<T>& b)
    158220                      {return a.Div(b);}
    159221
    160 
    161 
    162222} // Fin du namespace
    163223
Note: See TracChangeset for help on using the changeset viewer.