[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>
|
---|
[2322] | 11 | #include <iostream>
|
---|
[754] | 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 |
|
---|
[1310] | 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 |
|
---|
[1157] | 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;
|
---|
[754] | 46 |
|
---|
[1157] | 47 | bool DeleteKey(string const& key);
|
---|
| 48 | bool HasKey(string const& key) const;
|
---|
| 49 |
|
---|
[754] | 50 | void SetI(string const& key, int_8 val);
|
---|
| 51 | void SetD(string const& key, r_8 val);
|
---|
[1080] | 52 | void SetZ(string const& key, complex<r_8> val);
|
---|
[754] | 53 | void SetS(string const& key, char const* val);
|
---|
[1080] | 54 | void SetS(string const& key, string const& val);
|
---|
[754] | 55 | void SetComment(string const& key, string const& comm);
|
---|
| 56 |
|
---|
[1157] | 57 | MuTyV Get(string const& key) const ;
|
---|
[754] | 58 | MuTyV& Get(string const& key);
|
---|
[895] | 59 | /*! Returns the value associated with the name \b key */
|
---|
[1157] | 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 */
|
---|
[754] | 66 | inline MuTyV& operator() (string const& key) { return Get(key); }
|
---|
[895] | 67 | /*! Returns the value associated with the name \b key */
|
---|
[754] | 68 | inline MuTyV& operator[] (string const& key) { return Get(key); }
|
---|
[895] | 69 | /*! Returns the global comment string associated with the object */
|
---|
[754] | 70 | inline string& Comment() { return(comment); }
|
---|
| 71 |
|
---|
[895] | 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); }
|
---|
[754] | 77 | virtual void Print(ostream& os) const;
|
---|
| 78 |
|
---|
[2805] | 79 | //! \cond
|
---|
[754] | 80 | // Chaque element dans un DVList est constitue desormais d'un MuTyV
|
---|
| 81 | // et d'une chaine de caracteres (commentaire) regroupe dans la structure
|
---|
| 82 | // dvlElement. Ces elements sont associes aux noms de variables dans un
|
---|
| 83 | // map<...> ValList. Reza 02/2000
|
---|
| 84 | struct dvlElement {MuTyV elval; string elcomm; } ;
|
---|
| 85 | typedef map<string, dvlElement, less<string> > ValList;
|
---|
[2805] | 86 | //! \endcond
|
---|
[895] | 87 | /*! Returns an iterator pointing on the first variable in the list */
|
---|
[2823] | 88 | inline ValList::const_iterator Begin() const { return(mvlist.begin()); }
|
---|
[895] | 89 | /*! Returns the iterator end value */
|
---|
[2823] | 90 | inline ValList::const_iterator End() const { return(mvlist.end()); }
|
---|
[754] | 91 |
|
---|
| 92 |
|
---|
| 93 | private:
|
---|
| 94 |
|
---|
| 95 | ValList mvlist;
|
---|
| 96 | string comment;
|
---|
| 97 | };
|
---|
| 98 |
|
---|
[895] | 99 | /*! operator << overloading - Prints the list on the stream \b s */
|
---|
[754] | 100 | inline ostream& operator << (ostream& s, DVList const & dvl)
|
---|
| 101 | { dvl.Print(s); return(s); }
|
---|
| 102 |
|
---|
[895] | 103 | /*! Writes the object in the POutPersist stream \b os */
|
---|
[754] | 104 | inline POutPersist& operator << (POutPersist& os, DVList & obj)
|
---|
| 105 | { ObjFileIO<DVList> fio(&obj); fio.Write(os); return(os); }
|
---|
[895] | 106 | /*! Reads the object from the PInPersist stream \b is */
|
---|
[754] | 107 | inline PInPersist& operator >> (PInPersist& is, DVList & obj)
|
---|
[2477] | 108 | { ObjFileIO<DVList> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
[754] | 109 |
|
---|
| 110 | // Classe pour la gestion de persistance
|
---|
| 111 | // ObjFileIO<DVList>
|
---|
| 112 |
|
---|
| 113 | } // namespace SOPHYA
|
---|
| 114 |
|
---|
| 115 | #endif /* DVLIST_H__SEEN */
|
---|
| 116 |
|
---|
| 117 |
|
---|