| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | // Classe DVList : Liste dynamique de variables (valeurs) 
 | 
|---|
| 3 | // identifiees par un nom    Reza Ansari - Dec 96
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #ifndef DVLIST_H_SEEN
 | 
|---|
| 6 | #define DVLIST_H_SEEN
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "objfio.h"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include <stdio.h>
 | 
|---|
| 11 | #include <iostream>
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #include "mutyv.h"
 | 
|---|
| 14 | #include <list>
 | 
|---|
| 15 | #include <map>
 | 
|---|
| 16 | 
 | 
|---|
| 17 | namespace SOPHYA {
 | 
|---|
| 18 | 
 | 
|---|
| 19 | //  Classe liste de variables  Dynamic Variable List  
 | 
|---|
| 20 | 
 | 
|---|
| 21 | //! Dynamic Variable List class. 
 | 
|---|
| 22 | class DVList : public AnyDataObj {
 | 
|---|
| 23 | public:
 | 
|---|
| 24 | 
 | 
|---|
| 25 |                     DVList();
 | 
|---|
| 26 |                     DVList(const DVList&);
 | 
|---|
| 27 |                     DVList(char *flnm);
 | 
|---|
| 28 | 
 | 
|---|
| 29 |   virtual           ~DVList();
 | 
|---|
| 30 | 
 | 
|---|
| 31 |   DVList&           operator= (const DVList&);
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   void              Clear();
 | 
|---|
| 34 |   DVList&           Merge(const DVList&);
 | 
|---|
| 35 | 
 | 
|---|
| 36 |   //! Returns the number of elements (variables) in DVList object 
 | 
|---|
| 37 |   inline int        Size() { return(mvlist.size()); }
 | 
|---|
| 38 |   //! Returns the number of elements (variables) in DVList object 
 | 
|---|
| 39 |   inline int        NVar() { return(mvlist.size()); }
 | 
|---|
| 40 | 
 | 
|---|
| 41 |   int_8             GetI(string const& key, int_8 def=-1) const;
 | 
|---|
| 42 |   r_8               GetD(string const& key, r_8 def=-9.e19) const;
 | 
|---|
| 43 |   complex<r_8>      GetZ(string const& key, complex<r_8> def=-9.e19) const;
 | 
|---|
| 44 |   string            GetS(string const& key, char* def="") const;
 | 
|---|
| 45 |   string            GetComment(string const& key) const;
 | 
|---|
| 46 | 
 | 
|---|
| 47 |   bool              DeleteKey(string const& key);
 | 
|---|
| 48 |   bool              HasKey(string const& key) const;
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   void              SetI(string const& key, int_8 val);
 | 
|---|
| 51 |   void              SetD(string const& key, r_8 val);
 | 
|---|
| 52 |   void              SetZ(string const& key, complex<r_8> val);
 | 
|---|
| 53 |   void              SetS(string const& key, char const*  val);
 | 
|---|
| 54 |   void              SetS(string const& key, string const& val);
 | 
|---|
| 55 |   void              SetT(string const& key, TimeStamp const& val);
 | 
|---|
| 56 |   void              SetComment(string const& key, string const& comm);
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   MuTyV             Get(string const& key) const ;
 | 
|---|
| 59 |   MuTyV&            Get(string const& key);
 | 
|---|
| 60 | /*! Returns the value associated with the name \b key */
 | 
|---|
| 61 |   inline MuTyV      operator()  (string const& key) const { return Get(key); }
 | 
|---|
| 62 | /*! Returns the value associated with the name \b key */
 | 
|---|
| 63 |   inline MuTyV      operator[]  (string const& key) const { return Get(key); }
 | 
|---|
| 64 | /*! Returns the global comment string associated with the object */
 | 
|---|
| 65 |   inline string     Comment() const { return(comment); }
 | 
|---|
| 66 | /*! Returns the value associated with the name \b key */
 | 
|---|
| 67 |   inline MuTyV&     operator()  (string const& key)  { return Get(key); }
 | 
|---|
| 68 | /*! Returns the value associated with the name \b key */
 | 
|---|
| 69 |   inline MuTyV&     operator[]  (string const& key)  { return Get(key); }
 | 
|---|
| 70 | /*! Returns the global comment string associated with the object */
 | 
|---|
| 71 |   inline string&    Comment() { return(comment); }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | /*! Prints a brief description of object on \b cout */
 | 
|---|
| 74 |   inline  void      Show() const { Show(cout); }
 | 
|---|
| 75 |   virtual void      Show(ostream& os)  const;
 | 
|---|
| 76 | /*! Prints the list of variables on \b cout */
 | 
|---|
| 77 |   inline  void      Print() const  { Print(cout); }  
 | 
|---|
| 78 |   virtual void      Print(ostream& os)  const;
 | 
|---|
| 79 | 
 | 
|---|
| 80 | //!  \cond  
 | 
|---|
| 81 | // Chaque element dans un DVList est constitue desormais d'un MuTyV
 | 
|---|
| 82 | // et d'une chaine de caracteres (commentaire) regroupe dans la structure
 | 
|---|
| 83 | // dvlElement. Ces elements sont associes aux noms de variables dans un 
 | 
|---|
| 84 | // map<...> ValList.            Reza 02/2000
 | 
|---|
| 85 |   struct dvlElement {MuTyV elval; string elcomm; } ;
 | 
|---|
| 86 |   typedef map<string, dvlElement, less<string> >  ValList; 
 | 
|---|
| 87 | //!  \endcond
 | 
|---|
| 88 | /*! Returns an iterator pointing on the first variable in the list */
 | 
|---|
| 89 |   inline ValList::const_iterator Begin() const { return(mvlist.begin()); } 
 | 
|---|
| 90 | /*! Returns the iterator end value */
 | 
|---|
| 91 |   inline ValList::const_iterator End() const { return(mvlist.end()); } 
 | 
|---|
| 92 |   
 | 
|---|
| 93 | 
 | 
|---|
| 94 | private:
 | 
|---|
| 95 |   
 | 
|---|
| 96 |   ValList mvlist;
 | 
|---|
| 97 |   string comment;
 | 
|---|
| 98 | };
 | 
|---|
| 99 | 
 | 
|---|
| 100 | /*! operator << overloading - Prints the list on the stream \b s */
 | 
|---|
| 101 | inline ostream& operator << (ostream& s, DVList const & dvl)
 | 
|---|
| 102 |   {  dvl.Print(s);  return(s);  }
 | 
|---|
| 103 | 
 | 
|---|
| 104 | /*! Writes the object in the POutPersist stream \b os */
 | 
|---|
| 105 | inline POutPersist& operator << (POutPersist& os, DVList & obj)
 | 
|---|
| 106 | { ObjFileIO<DVList> fio(&obj);  fio.Write(os);  return(os); }
 | 
|---|
| 107 | /*! Reads the object from the PInPersist stream \b is */
 | 
|---|
| 108 | inline PInPersist& operator >> (PInPersist& is, DVList & obj)
 | 
|---|
| 109 | { ObjFileIO<DVList> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
 | 
|---|
| 110 | 
 | 
|---|
| 111 | // Classe pour la gestion de persistance
 | 
|---|
| 112 | // ObjFileIO<DVList>
 | 
|---|
| 113 | 
 | 
|---|
| 114 | } // namespace SOPHYA
 | 
|---|
| 115 | 
 | 
|---|
| 116 | #endif /* DVLIST_H__SEEN */
 | 
|---|
| 117 | 
 | 
|---|
| 118 | 
 | 
|---|