[754] | 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 |
|
---|
[1080] | 13 | #include "mutyv.h"
|
---|
[754] | 14 | #include <list>
|
---|
| 15 | #include <map>
|
---|
| 16 |
|
---|
| 17 | namespace SOPHYA {
|
---|
| 18 |
|
---|
| 19 | // Classe liste de variables Dynamic Variable List
|
---|
| 20 |
|
---|
[895] | 21 | //! Dynamic Variable List class.
|
---|
[754] | 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 |
|
---|
[1157] | 36 | int_8 GetI(string const& key, int_8 def=-1) const;
|
---|
| 37 | r_8 GetD(string const& key, r_8 def=-9.e19) const;
|
---|
| 38 | complex<r_8> GetZ(string const& key, complex<r_8> def=-9.e19) const;
|
---|
| 39 | string GetS(string const& key, char* def="") const;
|
---|
| 40 | string GetComment(string const& key) const;
|
---|
[754] | 41 |
|
---|
[1157] | 42 | bool DeleteKey(string const& key);
|
---|
| 43 | bool HasKey(string const& key) const;
|
---|
| 44 |
|
---|
[754] | 45 | void SetI(string const& key, int_8 val);
|
---|
| 46 | void SetD(string const& key, r_8 val);
|
---|
[1080] | 47 | void SetZ(string const& key, complex<r_8> val);
|
---|
[754] | 48 | void SetS(string const& key, char const* val);
|
---|
[1080] | 49 | void SetS(string const& key, string const& val);
|
---|
[754] | 50 | void SetComment(string const& key, string const& comm);
|
---|
| 51 |
|
---|
[1157] | 52 | MuTyV Get(string const& key) const ;
|
---|
[754] | 53 | MuTyV& Get(string const& key);
|
---|
[895] | 54 | /*! Returns the value associated with the name \b key */
|
---|
[1157] | 55 | inline MuTyV operator() (string const& key) const { return Get(key); }
|
---|
| 56 | /*! Returns the value associated with the name \b key */
|
---|
| 57 | inline MuTyV operator[] (string const& key) const { return Get(key); }
|
---|
| 58 | /*! Returns the global comment string associated with the object */
|
---|
| 59 | inline string Comment() const { return(comment); }
|
---|
| 60 | /*! Returns the value associated with the name \b key */
|
---|
[754] | 61 | inline MuTyV& operator() (string const& key) { return Get(key); }
|
---|
[895] | 62 | /*! Returns the value associated with the name \b key */
|
---|
[754] | 63 | inline MuTyV& operator[] (string const& key) { return Get(key); }
|
---|
[895] | 64 | /*! Returns the global comment string associated with the object */
|
---|
[754] | 65 | inline string& Comment() { return(comment); }
|
---|
| 66 |
|
---|
[895] | 67 | /*! Prints a brief description of object on \b cout */
|
---|
| 68 | inline void Show() const { Show(cout); }
|
---|
| 69 | virtual void Show(ostream& os) const;
|
---|
| 70 | /*! Prints the list of variables on \b cout */
|
---|
| 71 | inline void Print() const { Print(cout); }
|
---|
[754] | 72 | virtual void Print(ostream& os) const;
|
---|
| 73 |
|
---|
| 74 | // Chaque element dans un DVList est constitue desormais d'un MuTyV
|
---|
| 75 | // et d'une chaine de caracteres (commentaire) regroupe dans la structure
|
---|
| 76 | // dvlElement. Ces elements sont associes aux noms de variables dans un
|
---|
| 77 | // map<...> ValList. Reza 02/2000
|
---|
| 78 |
|
---|
| 79 | struct dvlElement {MuTyV elval; string elcomm; } ;
|
---|
| 80 | typedef map<string, dvlElement, less<string> > ValList;
|
---|
[895] | 81 | /*! Returns an iterator pointing on the first variable in the list */
|
---|
[754] | 82 | inline ValList::const_iterator Begin() { return(mvlist.begin()); }
|
---|
[895] | 83 | /*! Returns the iterator end value */
|
---|
[754] | 84 | inline ValList::const_iterator End() { return(mvlist.end()); }
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | private:
|
---|
| 88 |
|
---|
| 89 | ValList mvlist;
|
---|
| 90 | string comment;
|
---|
| 91 | };
|
---|
| 92 |
|
---|
[895] | 93 | /*! operator << overloading - Prints the list on the stream \b s */
|
---|
[754] | 94 | inline ostream& operator << (ostream& s, DVList const & dvl)
|
---|
| 95 | { dvl.Print(s); return(s); }
|
---|
| 96 |
|
---|
[895] | 97 | /*! Writes the object in the POutPersist stream \b os */
|
---|
[754] | 98 | inline POutPersist& operator << (POutPersist& os, DVList & obj)
|
---|
| 99 | { ObjFileIO<DVList> fio(&obj); fio.Write(os); return(os); }
|
---|
[895] | 100 | /*! Reads the object from the PInPersist stream \b is */
|
---|
[754] | 101 | inline PInPersist& operator >> (PInPersist& is, DVList & obj)
|
---|
| 102 | { ObjFileIO<DVList> fio(&obj); fio.Read(is); return(is); }
|
---|
| 103 |
|
---|
| 104 | // Classe pour la gestion de persistance
|
---|
| 105 | // ObjFileIO<DVList>
|
---|
| 106 |
|
---|
| 107 | } // namespace SOPHYA
|
---|
| 108 |
|
---|
| 109 | #endif /* DVLIST_H__SEEN */
|
---|
| 110 |
|
---|
| 111 |
|
---|