| 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.h> | 
|---|
| 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              SetComment(string const& key, string const& comm); | 
|---|
| 56 |  | 
|---|
| 57 | MuTyV             Get(string const& key) const ; | 
|---|
| 58 | MuTyV&            Get(string const& key); | 
|---|
| 59 | /*! Returns the value associated with the name \b key */ | 
|---|
| 60 | inline MuTyV      operator()  (string const& key) const { return Get(key); } | 
|---|
| 61 | /*! Returns the value associated with the name \b key */ | 
|---|
| 62 | inline MuTyV      operator[]  (string const& key) const { return Get(key); } | 
|---|
| 63 | /*! Returns the global comment string associated with the object */ | 
|---|
| 64 | inline string     Comment() const { return(comment); } | 
|---|
| 65 | /*! Returns the value associated with the name \b key */ | 
|---|
| 66 | inline MuTyV&     operator()  (string const& key)  { return Get(key); } | 
|---|
| 67 | /*! Returns the value associated with the name \b key */ | 
|---|
| 68 | inline MuTyV&     operator[]  (string const& key)  { return Get(key); } | 
|---|
| 69 | /*! Returns the global comment string associated with the object */ | 
|---|
| 70 | inline string&    Comment() { return(comment); } | 
|---|
| 71 |  | 
|---|
| 72 | /*! Prints a brief description of object on \b cout */ | 
|---|
| 73 | inline  void      Show() const { Show(cout); } | 
|---|
| 74 | virtual void      Show(ostream& os)  const; | 
|---|
| 75 | /*! Prints the list of variables on \b cout */ | 
|---|
| 76 | inline  void      Print() const  { Print(cout); } | 
|---|
| 77 | virtual void      Print(ostream& os)  const; | 
|---|
| 78 |  | 
|---|
| 79 | // Chaque element dans un DVList est constitue desormais d'un MuTyV | 
|---|
| 80 | // et d'une chaine de caracteres (commentaire) regroupe dans la structure | 
|---|
| 81 | // dvlElement. Ces elements sont associes aux noms de variables dans un | 
|---|
| 82 | // map<...> ValList.            Reza 02/2000 | 
|---|
| 83 |  | 
|---|
| 84 | struct dvlElement {MuTyV elval; string elcomm; } ; | 
|---|
| 85 | typedef map<string, dvlElement, less<string> >  ValList; | 
|---|
| 86 | /*! Returns an iterator pointing on the first variable in the list */ | 
|---|
| 87 | inline ValList::const_iterator Begin() { return(mvlist.begin()); } | 
|---|
| 88 | /*! Returns the iterator end value */ | 
|---|
| 89 | inline ValList::const_iterator End() { return(mvlist.end()); } | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | private: | 
|---|
| 93 |  | 
|---|
| 94 | ValList mvlist; | 
|---|
| 95 | string comment; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | /*! operator << overloading - Prints the list on the stream \b s */ | 
|---|
| 99 | inline ostream& operator << (ostream& s, DVList const & dvl) | 
|---|
| 100 | {  dvl.Print(s);  return(s);  } | 
|---|
| 101 |  | 
|---|
| 102 | /*! Writes the object in the POutPersist stream \b os */ | 
|---|
| 103 | inline POutPersist& operator << (POutPersist& os, DVList & obj) | 
|---|
| 104 | { ObjFileIO<DVList> fio(&obj);  fio.Write(os);  return(os); } | 
|---|
| 105 | /*! Reads the object from the PInPersist stream \b is */ | 
|---|
| 106 | inline PInPersist& operator >> (PInPersist& is, DVList & obj) | 
|---|
| 107 | { ObjFileIO<DVList> fio(&obj);  fio.Read(is);  return(is); } | 
|---|
| 108 |  | 
|---|
| 109 | // Classe pour la gestion de persistance | 
|---|
| 110 | // ObjFileIO<DVList> | 
|---|
| 111 |  | 
|---|
| 112 | } // namespace SOPHYA | 
|---|
| 113 |  | 
|---|
| 114 | #endif /* DVLIST_H__SEEN */ | 
|---|
| 115 |  | 
|---|
| 116 |  | 
|---|