Changeset 278 in Sophya for trunk/SophyaLib/NTools


Ignore:
Timestamp:
Apr 28, 1999, 3:36:50 PM (26 years ago)
Author:
ansari
Message:

Implementation PPersist par deleguation pour DVList Reza 28/04/99

Location:
trunk/SophyaLib/NTools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/dvlist.cc

    r244 r278  
    3939
    4040
     41using namespace PlanckDPC;
     42
    4143char MuTyV::myStrBuf[64];   // Declare static ds le .h
    4244
     
    7476{
    7577PInPersist s(flnm);
    76 Read(s);
     78ObjFileIO<DVList> fiodvl(this);
     79fiodvl.Read(s);
    7780}
    7881
     
    279282}
    280283
    281 
    282 /* --Methode-- */
    283 void        DVList::WriteSelf(POutPersist& s) const
    284 {
    285 char buf[320];
    286 
    287 int lc = comment.length();
    288 if (lc > 319) lc = 319;
    289 if (lc > 0) {
    290   sprintf(buf,"Comment: ( %6d ) ", lc);
    291   s.PutLine(buf);
    292   s.PutBytes(comment.c_str(), lc);
    293   }
    294 s.PutLine("----Variable-List---------------");
    295 ValList::const_iterator it;
    296 for(it = mvlist.begin(); it != mvlist.end(); it++)  {
    297   switch ((*it).second.typ)
    298     {
    299     case 'I' :
    300       sprintf(buf,"I %s %d", (*it).first.substr(0,64).c_str(), (*it).second.mtv.iv );
    301       s.PutLine(buf);
    302       break;
    303     case 'D' :
    304       sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.mtv.dv );
    305       s.PutLine(buf);
    306       break;
    307     case 'S' :
    308       sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.mtv.strv );
    309       s.PutLine(buf);
    310       break;
    311     default :
    312       break;
    313     }
    314   }
    315 
    316 s.PutLine("ZZZZZ--End-of-Varible-List------");
    317 }
    318 
    319 /* --Methode-- */
    320 void        DVList::ReadSelf(PInPersist& s)
    321 {
    322 char buf[320];
    323 int_4 j,iv;
    324 double dv;
    325 bool ok=true;
    326 buf[0] = '\0';
    327 Clear();
    328 
    329 s.GetLine(buf, 319);  // Pour lire les "------- "
    330 if (buf[0] != '-') {  // Il y a un champ commentaire a lire
    331   buf[18] ='\0';
    332   int lc = atoi(buf+11);
    333   if (lc > 319)  {
    334     cerr << "DVList::ReadSelf() Pb/Bug ??  CommentLength= " << lc << endl;
    335     lc = 319;
    336     }
    337   s.GetBytes(buf, lc);
    338   buf[lc] ='\0';
    339   comment = buf;
    340   }
    341 
    342 while(ok) {
    343   s.GetLine(buf, 319);
    344   buf[319] = '\0';
    345   if (strncmp(buf,"ZZZZZ",5) == 0)  { ok=false; break; }
    346   j = posc(buf+2, ' ')+2;
    347   buf[j] = '\0';
    348   switch (buf[0])
    349     {
    350     case 'I' :
    351       iv = (int_4)atol(buf+j+1);
    352       SetI(buf+2, iv);
    353       break;
    354     case 'D' :
    355       dv = atof(buf+j+1);
    356       SetD(buf+2, dv);
    357       break;
    358     case 'S' :
    359       SetS(buf+2, buf+j+1);
    360       break;
    361     default :
    362       break;
    363     }
    364   }
    365 
    366 }
     284// Classe pour la gestion de persistance
     285// ObjFileIO<DVList>
     286
    367287
    368288//++
     
    397317//|     int m =  dvlr["hello"] ;   //  m = 88
    398318//--
     319
     320
     321
     322/* --Methode-- */
     323void        ObjFileIO<DVList>::WriteSelf(POutPersist& s) const
     324{
     325char buf[320];
     326
     327int lc = dobj->Comment().length();
     328if (lc > 319) lc = 319;
     329if (lc > 0) {
     330  sprintf(buf,"Comment: ( %6d ) ", lc);
     331  s.PutLine(buf);
     332  s.PutBytes(dobj->Comment().c_str(), lc);
     333  }
     334s.PutLine("----Variable-List---------------");
     335DVList::ValList::const_iterator it;
     336for(it = dobj->Begin(); it != dobj->End(); it++)  {
     337  switch ((*it).second.typ)
     338    {
     339    case 'I' :
     340      sprintf(buf,"I %s %d", (*it).first.substr(0,64).c_str(), (*it).second.mtv.iv );
     341      s.PutLine(buf);
     342      break;
     343    case 'D' :
     344      sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.mtv.dv );
     345      s.PutLine(buf);
     346      break;
     347    case 'S' :
     348      sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.mtv.strv );
     349      s.PutLine(buf);
     350      break;
     351    default :
     352      break;
     353    }
     354  }
     355
     356s.PutLine("ZZZZZ--End-of-Varible-List------");
     357}
     358
     359/* --Methode-- */
     360void        ObjFileIO<DVList>::ReadSelf(PInPersist& s)
     361{
     362char buf[320];
     363int_4 j,iv;
     364double dv;
     365bool ok=true;
     366buf[0] = '\0';
     367dobj->Clear();
     368
     369s.GetLine(buf, 319);  // Pour lire les "------- "
     370if (buf[0] != '-') {  // Il y a un champ commentaire a lire
     371  buf[18] ='\0';
     372  int lc = atoi(buf+11);
     373  if (lc > 319)  {
     374    cerr << "DVList::ReadSelf() Pb/Bug ??  CommentLength= " << lc << endl;
     375    lc = 319;
     376    }
     377  s.GetBytes(buf, lc);
     378  buf[lc] ='\0';
     379  dobj->Comment() = buf;
     380  }
     381
     382while(ok) {
     383  s.GetLine(buf, 319);
     384  buf[319] = '\0';
     385  if (strncmp(buf,"ZZZZZ",5) == 0)  { ok=false; break; }
     386  j = posc(buf+2, ' ')+2;
     387  buf[j] = '\0';
     388  switch (buf[0])
     389    {
     390    case 'I' :
     391      iv = (int_4)atol(buf+j+1);
     392      dobj->SetI(buf+2, iv);
     393      break;
     394    case 'D' :
     395      dv = atof(buf+j+1);
     396      dobj->SetD(buf+2, dv);
     397      break;
     398    case 'S' :
     399      dobj->SetS(buf+2, buf+j+1);
     400      break;
     401    default :
     402      break;
     403    }
     404  }
     405}
     406
     407#ifdef __CXX_PRAGMA_TEMPLATES__
     408#pragma define_template ObjFileIO<DVList>
     409#endif
     410
     411#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
     412template class ObjFileIO<DVList>;
     413#endif
  • trunk/SophyaLib/NTools/dvlist.h

    r220 r278  
    66#define DVLIST_H_SEEN
    77
    8 #include "ppersist.h"
     8#include "objfio.h"
    99
    1010#include <stdio.h>
     
    2121#include <map.h>
    2222#endif
     23
     24namespace PlanckDPC {
    2325
    2426// Classe utilitaire pour manipuler des variables typees
     
    6668//  Classe liste de variables  Dynamic Variable List 
    6769
    68 class DVList : public PPersist {
     70class DVList : public AnyDataObj {
    6971public:
    70   enum {classId = ClassId_DVList };
     72//  enum {classId = ClassId_DVList };
    7173
    7274                    DVList();
     
    9799  inline void       Print() const  { Print(cout); } 
    98100  virtual void      Print(ostream& os)  const;
     101
     102  typedef map<string, MuTyV, less<string> >  ValList;
     103  inline ValList::const_iterator Begin() { return(mvlist.begin()); }
     104  inline ValList::const_iterator End() { return(mvlist.end()); }
    99105 
    100   int_4             ClassId() const        { return classId; }
    101   static PPersist*  Create()               { return new DVList;}
     106//  int_4             ClassId() const        { return classId; }
     107//  static PPersist*  Create()               { return new DVList;}
    102108
    103   virtual void      WriteSelf(POutPersist&) const;
    104   virtual void      ReadSelf(PInPersist&);
     109//  virtual void      WriteSelf(POutPersist&) const;
     110//  virtual void      ReadSelf(PInPersist&);
    105111
    106112private:
    107   typedef map<string, MuTyV, less<string> >  ValList;
    108113 
    109114  ValList mvlist;
     
    114119  {  dvl.Print(s);  return(s);  }
    115120
     121inline POutPersist& operator << (POutPersist& os, DVList & obj)
     122{ ObjFileIO<DVList> fio(&obj);  fio.Write(os);  return(os); }
     123inline PInPersist& operator >> (PInPersist& is, DVList & obj)
     124{ ObjFileIO<DVList> fio(&obj);  fio.Read(is);  return(is); }
     125
     126// Classe pour la gestion de persistance
     127// ObjFileIO<DVList>
     128
     129} // namespace PlanckDPC
     130
    116131#endif /* DVLIST_H__SEEN */
    117132
  • trunk/SophyaLib/NTools/ntuple.cc

    r220 r278  
    311311s.PutI4(mBlk);
    312312s.PutI4(mNBlk);
    313 if (mInfo)  mInfo->Write(s);
     313if (mInfo)  s << (*mInfo);
    314314int jb;
    315315for(jb=0; jb<mNBlk; jb++)
     
    344344if (hadinfo) {    // Lecture eventuelle du DVList Info
    345345  if (mInfo == NULL)  mInfo = new DVList;
    346   mInfo->Read(s);
     346  s >> (*mInfo);
    347347  }
    348348
  • trunk/SophyaLib/NTools/outilsinit.cc

    r244 r278  
    3434  PPRegister(Poly);
    3535  PPRegister(Poly2);
    36   PPRegister(DVList);
     36  PPRegister(ObjFileIO<DVList>);
    3737  PPRegister(Histo);
    3838  PPRegister(Histo2D);
  • trunk/SophyaLib/NTools/rzimage.cc

    r270 r278  
    55// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
    66
    7 //  $Id: rzimage.cc,v 1.3 1999-04-27 15:03:02 ansari Exp $
     7//  $Id: rzimage.cc,v 1.4 1999-04-28 13:36:50 ansari Exp $
    88
    99#include "machdefs.h"
     
    602602}
    603603
    604 if (mInfo) mInfo->Write(s);
     604if (mInfo) s << (*mInfo);
    605605return;
    606606}
     
    667667if (itab[3])  // has info
    668668  { if (mInfo == NULL)  mInfo = new DVList;
    669   mInfo->Read(s); }
     669  s >> (*mInfo); }
    670670
    671671return;
Note: See TracChangeset for help on using the changeset viewer.