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.cc

    r802 r944  
    1010#include "ndatablock.h"
    1111
    12 // define DEBUG_NDATABLOCK
    13 
    14 #ifdef DEBUG_NDATABLOCK
    15   static size_t NallocData = 0;
    16   static size_t NallocSRef = 0;
    17 #endif
    18 
    19 ////////////////////////////////////////////////////////////////
    20 //************ Createur, Destructeur
    21 
     12/*!
     13  \class SOPHYA::NDataBlock
     14  \ingroup SysTools
     15  Management of data blocks
     16*/
     17
     18//////////////////////////////////
     19// Fonctionnement en mode debug //
     20//////////////////////////////////
     21
     22template <class T> int    NDataBlock<T>::Debug_NDataBlock = 0;
     23template <class T> size_t NDataBlock<T>::NallocData       = 0;
     24template <class T> size_t NDataBlock<T>::NallocSRef       = 0;
     25
     26//! Set debug (and level print) for allocation and references debug.
     27/*!
     28  \param prtlevel : activate/des-activate debug mode
     29                    and select print level
     30
     31  \arg prtlevel <= 0 : no debug
     32  \arg prtlevel == 1 : debug activated, no print
     33  \arg prtlevel >=2  : debug activated,
     34       print infos in all routines that have something to do with
     35       allocations or des-allocation of datas or references.
     36 */
     37template <class T>
     38void NDataBlock<T>::SetPrintDebug(int prtdbglevel)
     39{
     40  Debug_NDataBlock = prtdbglevel;
     41}
     42
     43//! Reset debug counter values.
     44/*!
     45  \param nallocdata : reset number of allocated data structures to \b nallocdata
     46  \param nallocsref : reset number of allocated references to \b nallocsref
     47  \warning In principle this routine should not be use (only experts)
     48 */
     49template <class T>
     50void NDataBlock<T>::ResetDebug(size_t nallocdata, size_t nallocsref)
     51{
     52NallocData = nallocdata;
     53NallocSRef = nallocsref;
     54}
     55
     56//! Print debug current status.
     57/*!
     58  Print debug current status for number of allocated
     59  data structures and number of allocated references.
     60 */
     61template <class T>
     62void NDataBlock<T>::PrintDebug()
     63{
     64cout<<"... ... ... NallocData = "<<NallocData
     65    <<"  ,  NallocSRef = "<<NallocSRef
     66    <<" ... ... ..."<<endl;
     67}
     68
     69///////////////////////////
     70// Createur, Destructeur //
     71///////////////////////////
     72
     73//! Constructor for \b n datas
    2274template <class T>
    2375NDataBlock<T>::NDataBlock(size_t n)
     
    2577: mSz(0), mSRef(NULL), mIsTemp(false)
    2678{
    27 #ifdef DEBUG_NDATABLOCK
    28 cout<<"?_NDataBlock::NDataBlock("<<this<<",n="<<n<<")"<<endl;
    29 #endif
     79if(Debug_NDataBlock>1)
     80  cout<<"?_NDataBlock::NDataBlock("<<this<<",n="<<n<<")"<<endl;
    3081
    3182Alloc(n, NULL, NULL, true);   // allocation et mise a zero
    3283}
    3384
     85//! Constructor for \b n datas shared with external
     86/*!
     87  Datas are previously allocated by an other external source.
     88  \warning This require particular care (see Alloc)
     89  \sa Alloc
     90 */
    3491template <class T>
    3592NDataBlock<T>::NDataBlock(size_t n, T* data, Bridge* br)
     
    3895: mSz(0), mSRef(NULL), mIsTemp(false)
    3996{
    40 #ifdef DEBUG_NDATABLOCK
    41 cout<<"?_NDataBlock::NDataBlock("<<this
    42     <<",data="<<data<<",br="<<br<<")"<<endl;
    43 #endif
     97if(Debug_NDataBlock>1)
     98  cout<<"?_NDataBlock::NDataBlock("<<this
     99      <<",data="<<data<<",br="<<br<<")"<<endl;
    44100
    45101Alloc(n,data,br);
    46102}
    47103
     104//! Default constructor
    48105template <class T>
    49106NDataBlock<T>::NDataBlock()
     
    51108: mSz(0), mSRef(NULL), mIsTemp(false)
    52109{
    53 #ifdef DEBUG_NDATABLOCK
    54 cout<<"?_NDataBlock::NDataBlock("<<this<<") default"<<endl;
    55 #endif
    56 }
    57 
     110if(Debug_NDataBlock>1)
     111  cout<<"?_NDataBlock::NDataBlock("<<this<<") default"<<endl;
     112}
     113
     114//! Copy constructor
     115/*!
     116  \warning datas are shared if \b a is temporary, cloned if not.
     117 */
    58118template <class T>
    59119NDataBlock<T>::NDataBlock(const NDataBlock<T>& a)
     
    61121: mSz(0), mSRef(NULL), mIsTemp(false)
    62122{
    63 #ifdef DEBUG_NDATABLOCK
    64 cout<<"?_NDataBlock::NDataBlock("<<this<<",&a="<<&a<<")"<<endl;
    65 #endif
     123if(Debug_NDataBlock>1)
     124  cout<<"?_NDataBlock::NDataBlock("<<this<<",&a="<<&a<<")"<<endl;
    66125
    67126CloneOrShare(a);
    68127}
    69128
     129//! Copy constructor with \b share option
     130/*!
     131  \warning datas are shared if \b share is \b true, cloned if not.
     132 */
    70133template <class T>
    71134NDataBlock<T>::NDataBlock(const NDataBlock<T>& a,bool share)
     
    73136: mSz(0), mSRef(NULL), mIsTemp(false)
    74137{
    75 #ifdef DEBUG_NDATABLOCK
    76 cout<<"?_NDataBlock::NDataBlock("<<this<<",&a="<<&a<<",sh=<<"<<share<<")"<<endl;
    77 #endif
     138if(Debug_NDataBlock>1)
     139  cout<<"?_NDataBlock::NDataBlock("<<this<<",&a="<<&a<<",sh=<<"<<share<<")"<<endl;
    78140
    79141if(share) Share(a); else Clone(a);
    80142}
    81143
     144//! Destructor
    82145template <class T>
    83146NDataBlock<T>::~NDataBlock()
    84147// Destructeur
    85148{
    86 #ifdef DEBUG_NDATABLOCK
    87 cout<<"?_NDataBlock::~NDataBlock("<<this<<")"<<endl;
    88 #endif
     149if(Debug_NDataBlock>1)
     150  cout<<"?_NDataBlock::~NDataBlock("<<this<<")"<<endl;
    89151
    90152Delete();
    91153}
    92154
    93 ////////////////////////////////////////////////////////////////
    94 //************ Gestion de donnees
    95 
     155////////////////////////
     156// Gestion de donnees //
     157////////////////////////
     158
     159//! Clone datas from \b a
     160template <class T>
     161void NDataBlock<T>::Clone(const NDataBlock<T>& a)
     162// Clone: copie de donnees a partir de "a"
     163{
     164if(Debug_NDataBlock>1)
     165  cout<<"?_NDataBlock::Clone("<<this<<","<<&a<<") a.(mSz="
     166      <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()
     167      <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
     168
     169if(&a==NULL) throw(NullPtrError("NDataBlock::Clone  &a==NULL\n"));
     170if(!a.mSRef || a.mSz==0) throw(SzMismatchError("NDataBlock::Clone a.mSz==0\n"));
     171Alloc(a.mSz, NULL, NULL, false);  // pas de mise a zero
     172memcpy(Data(),a.Data(),mSz*sizeof(T));
     173}
     174
     175//! Share datas with \b a
     176template <class T>
     177void NDataBlock<T>::Share(const NDataBlock<T>& a)
     178// Share: Partage les donnees avec "a"
     179{
     180if(Debug_NDataBlock>1) {
     181  cout<<"?_NDataBlock::Share("<<this<<","<<&a<<")";
     182  if(&a!=NULL) cout<<" a.(mSz="<<a.mSz<<" mSRef="<<a.mSRef
     183                   <<" IsTemp="<<a.IsTemp()<<")";
     184  cout<<", mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
     185}
     186
     187if(&a==NULL) throw(NullPtrError("NDataBlock::Share  &a==NULL\n"));
     188if(!a.mSRef || a.mSz==0) throw(NullPtrError("NDataBlock::Share a.mSz=0\n"));
     189if(mSRef) Delete();
     190mSz = a.mSz; mSRef = a.mSRef; mSRef->nref++;
     191
     192if(Debug_NDataBlock>1)
     193  cout<<"...?_NDataBlock::Share mSz="<<mSz<<" mSRef="<<mSRef
     194      <<" mSRef->nref="<<mSRef->nref<<" mSRef->data="<< mSRef->data
     195      <<" mSRef->bridge="<<mSRef->bridge<<" IsTemp="<<mIsTemp<<endl;
     196}
     197
     198//! \b Share with \b a if \b temporary, \b clone from \b a if not.
     199template <class T>
     200void NDataBlock<T>::CloneOrShare(const NDataBlock<T>& a)
     201// CloneOrShare: Share si "a" temporaire, Clone sinon.
     202{
     203if(Debug_NDataBlock>1)
     204  cout<<"?_NDataBlock::CloneOrShare("<<this<<","<<&a<<")"<<endl;
     205
     206if(&a==NULL) throw(NullPtrError("NDataBlock::CloneOrShare  &a==NULL\n"));
     207if(a.IsTemp()) Share(a); else Clone(a);
     208}
     209
     210////////////////////////////////////////////////////////////
     211// Allocation , destruction , remplissage et reallocation //
     212////////////////////////////////////////////////////////////
     213
     214//! Allocation management
     215/*!
     216   Allocation d'un NOUVEL espace de stoquage de "n" donnees
     217   \verbatim
     218   Si data==NULL : allocation de l'espace memoire
     219      si zero == true , l'espace est remplis de zeros
     220      data!=NULL : partage des donnees avec l'adresse data
     221   Si br==NULL   : les donnees nous appartiennent
     222      br!=NULL   : les donnees ne nous appartiennent pas (ex: Blitz)
     223 
     224   Exemple: on veut connecter a un tableau de T*
     225   > float *x = new float[5]; ... remplissage de x[] ...;
     226   1- On veut que NDataBlock NE DESALLOUE PAS le tableau "x[]"
     227      a- Premiere solution
     228         > NDataBlock A(5,x,new Bridge);
     229         ......
     230         > delete [] x;
     231            - Il faut deleter x[] explicitement.
     232            - Le destructeur de "A" ne detruit pas x[].
     233            ATTENTION: Une fois x[] detruit, "A" ne peut
     234                       plus acceder les donnees!
     235            - Bridge est detruit par le destructeur de "A"
     236      b- Autre solution:
     237         > NDataBlock A(5); A.FillFrom(5,x);
     238         > delete [] x;
     239         ......
     240            - Il faut deleter x[] explicitement.
     241            - "A" possede une copie en local de x[].
     242            - Le destructeur de "A" ne detruit pas x[] mais la copie locale.
     243   2- On veut que NDataBlock desalloue le tableau
     244         > NDataBlock A(5,x);
     245            - Ne Pas Faire "delete [] x;"
     246            - "A" partage les donnees avec x[].
     247            - Le destructeur de "A" detruit x[].
     248 
     249   --- REMARQUE SUR LE DANGER DE CERTAINES SITUATIONS (CMV):
     250   1-/ x = new float[n1]; NDataBlock A(n2,x);
     251       1er danger: si n2>n1 depassement de tableaux (core dump)
     252       2sd danger: celui qui alloue x[] ne doit pas faire le "delete"
     253                   en desaccord avec toutes les regles de bonne conduite.
     254   2-/ float x[5]={1,2,3,4,5}; {NDataBlock A(n2,&x[0]);} cout<<x[2];
     255       Ici, a la sortie du bloc {}, le destructeur de "A" va detruire
     256       l'adresse de &x[0]: je n'ose imaginer que ca se fasse sans probleme
     257       et de toute facon, cout<<x[2]; va surement faire des etincelles.
     258   3-/ x = new float[n1]; NDataBlock A(n2,x,new Bridge);
     259       1er danger: si n2>n1 depassement de tableaux (core dump)
     260       2sd danger: si la methode bridgee (blitz?) detruit x[]
     261                   "A" n'a plus de donnees connectees!
     262   --- CONCLUSION
     263   Cette classe est franchement merdique.
     264   - On peut accepter la prise de risque liee a NDataBlock(n2,x,new Bridge);
     265     car je ne vois pas comment on pourrait faire autrement pour connecter
     266     un tableau de type blitz par exemple.
     267   - Par contre le createur NDataBlock(n2,x); doit etre interdit
     268     dans sa forme actelle car trop dangereux et il me semble inutile.
     269   - Dans cette nouvelle optique:
     270     NDataBlock(n2,x,new Bridge) et NDataBlock(n2,x) disparaissent
     271     On remplace par NDataBlock(n2,x) {Alloc(n2,x,new Bridge);}
     272        qui force le Bridge dans tout les cas puisque NDataBlock
     273        ne possede pas les donnees.
     274     Mais puis-je encore le faire vu que NDataBlock est a la base
     275     de TVector,TMatrix et qu'il faut donc reprendre tout le code DPC
     276   - Quoiqu'il arrive Alloc est une methode privee et peut donc rester
     277     sous sa forme actuelle.
     278             
     279   \endverbatim
     280 */
    96281template <class T>
    97282void NDataBlock<T>::Alloc(size_t n,T* data,Bridge* br,bool zero)
    98 // Allocation d'un NOUVEL espace de stoquage de "n" donnees
    99 // Si data==NULL : allocation de l'espace memoire
    100 //    si zero == true , l'espace est remplis de zeros
    101 //    data!=NULL : partage des donnees avec l'adresse data
    102 // Si br==NULL   : les donnees nous appartiennent
    103 //    br!=NULL   : les donnees ne nous appartiennent pas (ex: Blitz)
    104 //
    105 // Exemple: on veut connecter a un tableau de T*
    106 // > float *x = new float[5]; ... remplissage de x[] ...;
    107 // 1- On veut que NDataBlock NE DESALLOUE PAS le tableau "x[]"
    108 //    a- Premiere solution
    109 //       > NDataBlock A(5,x,new Bridge);
    110 //       ......
    111 //       > delete [] x;
    112 //          - Il faut deleter x[] explicitement.
    113 //          - Le destructeur de "A" ne detruit pas x[].
    114 //          ATTENTION: Une fois x[] detruit, "A" ne peut
    115 //                     plus acceder les donnees!
    116 //          - Bridge est detruit par le destructeur de "A"
    117 //    b- Autre solution:
    118 //       > NDataBlock A(5); A.FillFrom(5,x);
    119 //       > delete [] x;
    120 //       ......
    121 //          - Il faut deleter x[] explicitement.
    122 //          - "A" possede une copie en local de x[].
    123 //          - Le destructeur de "A" ne detruit pas x[] mais la copie locale.
    124 // 2- On veut que NDataBlock desalloue le tableau
    125 //       > NDataBlock A(5,x);
    126 //          - Ne Pas Faire "delete [] x;"
    127 //          - "A" partage les donnees avec x[].
    128 //          - Le destructeur de "A" detruit x[].
    129 //
    130 // --- REMARQUE SUR LE DANGER DE CERTAINES SITUATIONS (CMV):
    131 // 1-/ x = new float[n1]; NDataBlock A(n2,x);
    132 //     1er danger: si n2>n1 depassement de tableaux (core dump)
    133 //     2sd danger: celui qui alloue x[] ne doit pas faire le "delete"
    134 //                 en desaccord avec toutes les regles de bonne conduite.
    135 // 2-/ float x[5]={1,2,3,4,5}; {NDataBlock A(n2,&x[0]);} cout<<x[2];
    136 //     Ici, a la sortie du bloc {}, le destructeur de "A" va detruire
    137 //     l'adresse de &x[0]: je n'ose imaginer que ca se fasse sans probleme
    138 //     et de toute facon, cout<<x[2]; va surement faire des etincelles.
    139 // 3-/ x = new float[n1]; NDataBlock A(n2,x,new Bridge);
    140 //     1er danger: si n2>n1 depassement de tableaux (core dump)
    141 //     2sd danger: si la methode bridgee (blitz?) detruit x[]
    142 //                 "A" n'a plus de donnees connectees!
    143 // --- CONCLUSION
    144 // Cette classe est franchement merdique.
    145 // - On peut accepter la prise de risque liee a NDataBlock(n2,x,new Bridge);
    146 //   car je ne vois pas comment on pourrait faire autrement pour connecter
    147 //   un tableau de type blitz par exemple.
    148 // - Par contre le createur NDataBlock(n2,x); doit etre interdit
    149 //   dans sa forme actelle car trop dangereux et il me semble inutile.
    150 // - Dans cette nouvelle optique:
    151 //   NDataBlock(n2,x,new Bridge) et NDataBlock(n2,x) disparaissent
    152 //   On remplace par NDataBlock(n2,x) {Alloc(n2,x,new Bridge);}
    153 //      qui force le Bridge dans tout les cas puisque NDataBlock
    154 //      ne possede pas les donnees.
    155 //   Mais puis-je encore le faire vu que NDataBlock est a la base
    156 //   de TVector,TMatrix et qu'il faut donc reprendre tout le code DPC
    157 // - Quoiqu'il arrive Alloc est une methode privee et peut donc rester
    158 //   sous sa forme actuelle.
    159 //           
    160 {
    161 #ifdef DEBUG_NDATABLOCK
    162 cout<<"?_NDataBlock::Alloc("<<this<<","
    163     <<n<<","<<data<<","<<br<<") mSz="<<mSz
    164     <<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    165 #endif
     283{
     284if(Debug_NDataBlock>1)
     285  cout<<"?_NDataBlock::Alloc("<<this<<","
     286      <<n<<","<<data<<","<<br<<") mSz="<<mSz
     287      <<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    166288
    167289if(br && !data)
     
    176298mSRef->bridge = br;
    177299
    178 #ifdef DEBUG_NDATABLOCK
    179 // Meme dans le cas data!=0 et br==0 (connexion d'un tableau
    180 // avec destruction geree par ~NDataBlock (cas 2-) on compte
    181 // comme si on avait fait une allocation du tableau (ce qui a ete
    182 // fait au niveau du dessus!).
    183 if(!br) NallocData++; NallocSRef++;
    184 cout<<"...?_NDataBlock::Alloc mSz="<<mSz<<" mSRef="<<mSRef
    185     <<" mSRef->nref="<<mSRef->nref<<" mSRef->data="<< mSRef->data
    186     <<" mSRef->bridge="<<mSRef->bridge<<" IsTemp="<<mIsTemp
    187     <<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
    188 #endif
    189 }
    190 
    191 template <class T>
    192 void NDataBlock<T>::Clone(const NDataBlock<T>& a)
    193 // Clone: copie de donnees a partir de "a"
    194 {
    195 #ifdef DEBUG_NDATABLOCK
    196 cout<<"?_NDataBlock::Clone("<<this<<","<<&a<<") a.(mSz="
    197     <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()
    198     <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    199 #endif
    200 
    201 if(&a==NULL) throw(NullPtrError("NDataBlock::Clone  &a==NULL\n"));
    202 if(!a.mSRef || a.mSz==0) throw(SzMismatchError("NDataBlock::Clone a.mSz==0\n"));
    203 Alloc(a.mSz, NULL, NULL, false);  // pas de mise a zero
    204 memcpy(Data(),a.Data(),mSz*sizeof(T));
    205 }
    206 
    207 template <class T>
    208 void NDataBlock<T>::CloneOrShare(const NDataBlock<T>& a)
    209 // CloneOrShare: Share si "a" temporaire, Clone sinon.
    210 {
    211 #ifdef DEBUG_NDATABLOCK
    212 cout<<"?_NDataBlock::CloneOrShare("<<this<<","<<&a<<")"<<endl;
    213 #endif
    214 
    215 if(&a==NULL) throw(NullPtrError("NDataBlock::CloneOrShare  &a==NULL\n"));
    216 if(a.IsTemp()) Share(a); else Clone(a);
    217 }
    218 
    219 template <class T>
    220 void NDataBlock<T>::Share(const NDataBlock<T>& a)
    221 // Share: Partage les donnees avec "a"
    222 {
    223 #ifdef DEBUG_NDATABLOCK
    224 cout<<"?_NDataBlock::Share("<<this<<","<<&a<<")";
    225 if(&a!=NULL) cout<<" a.(mSz="<<a.mSz<<" mSRef="<<a.mSRef
    226                  <<" IsTemp="<<a.IsTemp()<<")";
    227 cout<<", mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    228 #endif
    229 
    230 if(&a==NULL) throw(NullPtrError("NDataBlock::Share  &a==NULL\n"));
    231 if(!a.mSRef || a.mSz==0) throw(NullPtrError("NDataBlock::Share a.mSz=0\n"));
    232 if(mSRef) Delete();
    233 mSz = a.mSz; mSRef = a.mSRef; mSRef->nref++;
    234 
    235 #ifdef DEBUG_NDATABLOCK
    236 cout<<"...?_NDataBlock::Share mSz="<<mSz<<" mSRef="<<mSRef
    237     <<" mSRef->nref="<<mSRef->nref<<" mSRef->data="<< mSRef->data
    238     <<" mSRef->bridge="<<mSRef->bridge<<" IsTemp="<<mIsTemp<<endl;
    239 #endif
    240 }
    241 
     300if(Debug_NDataBlock>0) {
     301  // Meme dans le cas data!=0 et br==0 (connexion d'un tableau
     302  // avec destruction geree par ~NDataBlock (cas 2-) on compte
     303  // comme si on avait fait une allocation du tableau (ce qui a ete
     304  // fait au niveau du dessus!).
     305  if(!br) NallocData++; NallocSRef++;
     306  if(Debug_NDataBlock>1)
     307    cout<<"...?_NDataBlock::Alloc mSz="<<mSz<<" mSRef="<<mSRef
     308        <<" mSRef->nref="<<mSRef->nref<<" mSRef->data="<< mSRef->data
     309        <<" mSRef->bridge="<<mSRef->bridge<<" IsTemp="<<mIsTemp
     310        <<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
     311}
     312}
     313
     314//! Management of de-allocation
    242315template <class T>
    243316void NDataBlock<T>::Delete(void)
    244317// Pour detruire les pointeurs en tenant compte des references
    245318{
    246 #ifdef DEBUG_NDATABLOCK
    247 cout<<"?_NDataBlock::Delete("<<this<<") mSz="<<mSz
    248     <<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp;
    249 if(mSRef)
    250   cout<<" mSRef->nref="<<mSRef->nref<<" mSRef->data="
    251       <<mSRef->data<<" mSRef->bridge="<<mSRef->bridge;
    252 cout<<endl;
    253 #endif
     319if(Debug_NDataBlock>1) {
     320  cout<<"?_NDataBlock::Delete("<<this<<") mSz="<<mSz
     321      <<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp;
     322  if(mSRef)
     323    cout<<" mSRef->nref="<<mSRef->nref<<" mSRef->data="
     324        <<mSRef->data<<" mSRef->bridge="<<mSRef->bridge;
     325  cout<<endl;
     326}
    254327
    255328if(mSRef==NULL) return;
     
    257330if(mSRef->nref != 0) {
    258331
    259 #ifdef DEBUG_NDATABLOCK
     332if(Debug_NDataBlock>1)
    260333  cout<<"...?_NDataBlock::Delete() pas de desallocation il reste nref="
    261334      <<mSRef->nref<<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
    262 #endif
    263335
    264336  mSz = 0; mSRef=NULL;
     
    266338}
    267339
    268 #ifdef DEBUG_NDATABLOCK
    269 if(!mSRef->bridge) NallocData--; NallocSRef--;
    270 cout<<"...?_NDataBlock::Delete() desallocation complete il reste nref="
    271     <<mSRef->nref<<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
    272 #endif
     340if(Debug_NDataBlock>0) {
     341  if(!mSRef->bridge) NallocData--; NallocSRef--;
     342  if(Debug_NDataBlock>1)
     343    cout<<"...?_NDataBlock::Delete() desallocation complete il reste nref="
     344        <<mSRef->nref<<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
     345}
    273346
    274347// Si il y a un Bridge les donnees ne n'appartiennent pas, on detruit le Bridge
     
    279352}
    280353
     354//! Fill dats of this NDataBlock with the \b n datas pointed by \b data
     355/*!
     356  \warning If class empty : allocate space in memory
     357  \warning If class already connected : overwrite with minimum size
     358           (\b n or \b mSz)
     359 */
    281360template <class T>
    282361void NDataBlock<T>::FillFrom(size_t n,T* data)
     
    293372}
    294373
     374//! Re-allocate space for \b nnew datas
     375/*!
     376  \param nnnew : new size
     377  \param force : to manage the way re-allocation will be done (see after).
     378  \verbatim
     379  Re-allocation de "nnew" place memoire pour les donnees
     380  avec conservation des "nold" donnees precedentes si possible.
     381  "force" gere la re-allocation de la place memoire pour les donnees.
     382  Divers cas se presentent:
     383  a-/ *** nnew>nold force=quelconque ***
     384      place re-allouee, donnees [0,nold[ copiees, surplus [nold,new[ mis a zero
     385  b-/ *** nnew<=nold force=true ***
     386      place re-allouee, donnees [0,nnew[ copiees, pas de surplus
     387  c-/ *** nnew<=nold force=false ***
     388      place non re-allouee, seule la valeur de la taille est diminuee
     389  - On tient compte du partage des donnees dans tous les cas.
     390  - Si il n'y a pas de donnees connectees a la classe, on re-alloue
     391    dans tous les cas
     392  \endverbatim
     393 */
    295394template <class T>
    296395void NDataBlock<T>::Realloc(size_t nnew,bool force)
    297 // Re-allocation de "nnew" place memoire pour les donnees
    298 // avec conservation des "nold" donnees precedentes si possible.
    299 // "force" gere la re-allocation de la place memoire pour les donnees.
    300 // Divers cas se presentent:
    301 // a-/ *** nnew>nold force=quelconque ***
    302 //     place re-allouee, donnees [0,nold[ copiees, surplus [nold,new[ mis a zero
    303 // b-/ *** nnew<=nold force=true ***
    304 //     place re-allouee, donnees [0,nnew[ copiees, pas de surplus
    305 // c-/ *** nnew<=nold force=false ***
    306 //     place non re-allouee, seule la valeur de la taille est diminuee
    307 // - On tient compte du partage des donnees dans tous les cas.
    308 // - Si il n'y a pas de donnees connectees a la classe, on re-alloue
    309 //   dans tous les cas
    310396{
    311397if(nnew==0) throw(ParmError("NDataBlock::Realloc  n<=0\n"));
     
    323409}
    324410
    325 ////////////////////////////////////////////////////////////////
    326 //**** Impression
    327 
     411////////////////
     412// Impression //
     413////////////////
     414
     415//! Give infos and print \b n datas beginning at \b i1 on stream \b os.
    328416template <class T>
    329417void NDataBlock<T>::Print(ostream& os,size_t i1,size_t n) const
     
    347435}
    348436
    349 ////////////////////////////////////////////////////////////////
    350 
     437//////////////////////////////////////////////
     438// Calcul de la somme / produit des donnees //
     439//////////////////////////////////////////////
     440
     441//! Return sum of \b n datas beginning at data \b i1.
    351442template <class T>
    352443T NDataBlock<T>::Sum(size_t i1,size_t n) const
     
    361452}
    362453
     454//! Return product of \b n datas beginning at data \b i1.
    363455template <class T>
    364456T NDataBlock<T>::Product(size_t i1,size_t n) const
     
    373465}
    374466
    375 ////////////////////////////////////////////////////////////////
    376 //**** Surcharge de = : NDataBlock=NDataBlock; NDataBlock=<T> b;
    377 
     467///////////////////////////////////////////////////////////////
     468// Surcharge de = : NDataBlock=NDataBlock; NDataBlock=<T> b; //
     469///////////////////////////////////////////////////////////////
     470
     471//! Operator = : ND = ND1
     472/*! \warning share if \b a is temporary, clone if not */
    378473template <class T>
    379474NDataBlock<T>& NDataBlock<T>::operator = (const NDataBlock<T>& a)
    380475// Affectation: partage des donnees si "a" temporaire, clone sinon.
    381476{
    382 #ifdef DEBUG_NDATABLOCK
    383 cout<<"?_NDataBlock::operator=("<<this<<","<<&a<<") a.(mSz="
    384     <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()
    385     <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    386 #endif
     477if(Debug_NDataBlock>1)
     478  cout<<"?_NDataBlock::operator=("<<this<<","<<&a<<") a.(mSz="
     479      <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()
     480      <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    387481
    388482if(this == &a) return *this;
     
    393487}
    394488
     489//! Operator = : ND = \b v (at dats set to \b v).
    395490template <class T>
    396491NDataBlock<T>& NDataBlock<T>::operator = (T v)
    397492// Affectation de tous les elements a une constante "v"
    398493{
    399 #ifdef DEBUG_NDATABLOCK
    400 cout<<"?_NDataBlock::operator=("<<this<<","<<v<<")"
    401     <<" mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
    402 #endif
     494if(Debug_NDataBlock>1)
     495  cout<<"?_NDataBlock::operator=("<<this<<","<<v<<")"
     496      <<" mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
     497
    403498
    404499if(mSz==0) throw(SzMismatchError("NDataBlock::operator=v null size\n"));
     
    408503}
    409504
    410 ////////////////////////////////////////////////////////////////
    411 //**** Surcharge de +=,-=,*=,/= (INPLACE): NDataBlock += <T> b;
    412 
     505//////////////////////////////////////////////////////////////
     506// Surcharge de +=,-=,*=,/= (INPLACE): NDataBlock += <T> b; //
     507//////////////////////////////////////////////////////////////
     508
     509//! Add a constant : ND += b
    413510template <class T>
    414511NDataBlock<T>& NDataBlock<T>::operator += (T b)
     
    420517}
    421518
     519//! Substract a constant : ND -= b
    422520template <class T>
    423521NDataBlock<T>& NDataBlock<T>::operator -= (T b)
     
    429527}
    430528
     529//! Multiply by a constant : ND *= b
    431530template <class T>
    432531NDataBlock<T>& NDataBlock<T>::operator *= (T b)
     
    438537}
    439538
     539//! Divide by a constant : ND *= b
    440540template <class T>
    441541NDataBlock<T>& NDataBlock<T>::operator /= (T b)
     
    448548}
    449549
    450 ////////////////////////////////////////////////////////////////
    451 //**** Surcharge de +=,-=,*=,/= (INPLACE): NDataBlock += NDataBlock;
    452 
     550////////////////////////////////////////////////////////////////////
     551// Surcharge de +=,-=,*=,/= (INPLACE): NDataBlock += NDataBlock1; //
     552////////////////////////////////////////////////////////////////////
     553
     554//! Add a NDataBlock : ND += ND1
    453555template <class T>
    454556NDataBlock<T>& NDataBlock<T>::operator += (const NDataBlock<T>& a)
     
    462564}
    463565
     566//! Substract a NDataBlock : ND -= ND1
    464567template <class T>
    465568NDataBlock<T>& NDataBlock<T>::operator -= (const NDataBlock<T>& a)
     
    473576}
    474577
     578//! Multiply by a NDataBlock : ND *= ND1
    475579template <class T>
    476580NDataBlock<T>& NDataBlock<T>::operator *= (const NDataBlock<T>& a)
     
    484588}
    485589
     590//! Divide by a NDataBlock : ND *= ND1
    486591template <class T>
    487592NDataBlock<T>& NDataBlock<T>::operator /= (const NDataBlock<T>& a)
     
    497602
    498603////////////////////////////////////////////////////////////////
    499 //**** Surcharge de +,-,*,/ : NDataBlock = NDataBlock+<T>b;
    500 //                            NDataBlock = <T>b+NDataBlock;
    501 
     604// Pour surcharge de +,-,*,/ : NDataBlock = NDataBlock1+<T>b; //
     605//                             NDataBlock = <T>b+NDataBlock1; //
     606////////////////////////////////////////////////////////////////
     607
     608//! Add a constant and return NDataBlock : NDret = ND + b
    502609template <class T>
    503610NDataBlock<T> NDataBlock<T>::Add(T b) const
     
    509616}
    510617
     618//! Substract a constant and return NDataBlock : NDret = ND - b
    511619template <class T>
    512620NDataBlock<T> NDataBlock<T>::Sub(T b) const
     
    517625}
    518626
     627//! Substract from a constant and return NDataBlock : NDret = b - ND
    519628template <class T>
    520629NDataBlock<T> NDataBlock<T>::SubInv(T b) const
     
    528637}
    529638
     639//! Multiply by a constant and return NDataBlock : NDret = ND * b
    530640template <class T>
    531641NDataBlock<T> NDataBlock<T>::Mul(T b) const
     
    536646}
    537647
     648//! Divide by a constant and return NDataBlock : NDret = ND / b
    538649template <class T>
    539650NDataBlock<T> NDataBlock<T>::Div(T b) const
     
    544655}
    545656
     657//! Divide from a constant and return NDataBlock : NDret = b / ND
    546658template <class T>
    547659NDataBlock<T> NDataBlock<T>::DivInv(T b) const
     
    555667}
    556668
    557 ////////////////////////////////////////////////////////////////
    558 //**** Surcharge de +,-,*,/ : NDataBlock = NDataBlock+NDataBlock;
    559 
     669///////////////////////////////////////////////////////////////////////
     670// Pour surcharge de +,-,*,/ : NDataBlock = NDataBlock1+NDataBlock2; //
     671///////////////////////////////////////////////////////////////////////
     672
     673//! Add a NDataBlock and return a NDataBlock: ND = NDthis + NDb
    560674template <class T>
    561675NDataBlock<T> NDataBlock<T>::Add(const NDataBlock<T>& b) const
     
    570684}
    571685
     686//! Multiply by a NDataBlock and return a NDataBlock: ND = NDthis * NDb
    572687template <class T>
    573688NDataBlock<T> NDataBlock<T>::Mul(const NDataBlock<T>& b) const
     
    582697}
    583698
     699//! Substract a NDataBlock and return a NDataBlock: ND = NDthis - NDb
    584700template <class T>
    585701NDataBlock<T> NDataBlock<T>::Sub(const NDataBlock<T>& b) const
     
    597713}
    598714
     715//! Divide by a NDataBlock and return a NDataBlock: ND = NDthis / NDb
    599716template <class T>
    600717NDataBlock<T> NDataBlock<T>::Div(const NDataBlock<T>& b) const
Note: See TracChangeset for help on using the changeset viewer.