Changeset 895 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Apr 12, 2000, 7:49:54 PM (25 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/anydataobj.h
r552 r895 10 10 namespace SOPHYA { 11 11 12 //! Ancestor class for all data objects (for RTTI). 13 12 14 class AnyDataObj { 13 15 public: -
trunk/SophyaLib/BaseTools/dvlist.cc
r827 r895 12 12 //++ 13 13 // Class DVList 14 // Lib Outils++14 // Lib SysTools 15 15 // include dvlist.h 16 16 // … … 42 42 static MuTyV ddvdum(-9.e19); 43 43 44 /*! 45 \class SOPHYA::DVList 46 This class can be used to construct list of values associated with names. 47 Variables names should not contain space characters and is limited to 64 48 characters. The DVList class uses \b SOPHYA::MuTyV objects to hold values 49 of type string, integer (\b int_8) or float (\b r_8). A comment string 50 can be associated with each variable name. A global comment string 51 can be attached to the DVList object. DVList objects can conveniently be 52 used to represent FITS headers. The class \b SOPHYA::ObjFileIO<DVList> 53 handles serialisation for DVList. (See SOPHYA::PPersist ). 54 An 55 \code 56 // ------- Using MuTyV objects ------- 57 MuTyV mvu; // MuTyV variable declaration 58 mvu = 60; // mvu contains the integer value 60 59 mvu = 66.6; // and now the double value 66.6 60 string ds = mvu; // ds contains the string "66.6" 61 MuTyV mvi(14); // New MuTyV variable containing integer value 14 62 r_4 x = mvi; // x has the value 14.0 63 MuTyV mvs("Bonjour !"); // mvs contains the string "Bonjour !" 64 string s = mvs; // s vaut "Bonjour, Ca va ?" 65 // ------- Using DVList objects ------ 66 DVList dvl; 67 dvl("toto") = 14; // Integer type value (=14) named toto 68 dvl("titi") = 25.5; // float type value (=25.5) named titi 69 dvl("tata") = "Bonjour !"; // string type value (="Bonjour !") named tata 70 // Upper and lower case letters are distinguished 71 dvl("hello") = 88; 72 dvl("Hello") = 77.77; 73 dvl.Comment() = "DVList test object, with values named hello, Hello "; 74 // Saving the dvl object into a PPF file 75 POutStream os("dvl.ppf"); 76 os << dvl; 77 // later on ... 78 DVList dvlr; 79 PInStream is("dvl.ppf"); 80 is << dvlr; 81 int k = dvlr["toto"] ; // k = 14 82 r_8 b = dvlr["titi"] ; // b = 25.5 83 string s = dvlr["tata"] ; // s = "Bonjour !" 84 int m = dvlr["hello"] ; // m = 88 85 86 \endcode 87 */ 44 88 45 89 //++ … … 58 102 59 103 /* --Methode-- */ 104 /*! Default constructor */ 60 105 DVList::DVList() 61 106 { … … 64 109 65 110 /* --Methode-- */ 111 /*! copy constructor */ 66 112 DVList::DVList(const DVList& dvl) 67 113 { … … 70 116 71 117 /* --Methode-- */ 118 /*! Copy constructor - Object initialized using the PPF file \b flnm */ 72 119 DVList::DVList(char *flnm) 73 120 { … … 97 144 98 145 /* --Methode-- */ 146 /*! Copy operator - Replaces the variables list with the list from \b dvl */ 99 147 DVList& DVList::operator= (const DVList& dvl) 100 148 { … … 105 153 106 154 /* --Methode-- */ 155 /*! Resets the object and clears the variable list and global comment */ 107 156 void DVList::Clear() 108 157 { … … 112 161 113 162 /* --Methode-- */ 163 /*! Appends the values from the object \b dvl to the objects list */ 114 164 DVList& DVList::Merge(const DVList& dvl) 115 165 { … … 149 199 150 200 /* --Methode-- */ 201 /*! Returns the value corresponding to name \b key, converted to integer 202 Default value \b def is returned if name \b key not found */ 151 203 int_8 DVList::GetI(string const& key, int_8 def) 152 204 { … … 158 210 159 211 /* --Methode-- */ 212 /*! Returns the value corresponding to name \b key, converted to double 213 Default value \b def is returned if name \b key not found */ 160 214 r_8 DVList::GetD(string const& key, r_8 def) 161 215 { … … 167 221 168 222 /* --Methode-- */ 223 /*! Returns the value corresponding to name \b key, converted to string 224 Default value \b def is returned if name \b key not found */ 169 225 string DVList::GetS(string const& key, char* def) 170 226 { … … 176 232 177 233 /* --Methode-- */ 234 /*! Returns the comment associated with name \b key */ 178 235 string DVList::GetComment(string const& key) 179 236 { … … 200 257 201 258 /* --Methode-- */ 259 /*! Appends or sets the integer value \b val in the list with name \b key */ 202 260 void DVList::SetI(string const& key, int_8 val) 203 261 { … … 207 265 /* --Methode-- */ 208 266 void DVList::SetD(string const& key, r_8 val) 267 /*! Appends or sets the double value \b val in the list with name \b key */ 209 268 { 210 269 Get(key) = (r_8)val; … … 212 271 213 272 /* --Methode-- */ 273 /*! Appends or sets the string value \b val in the list with name \b key */ 214 274 void DVList::SetS(string const& key, char const* val) 215 275 { … … 219 279 220 280 /* --Methode-- */ 281 /*! Appends or sets the string value \b val in the list with name \b key */ 221 282 void DVList::SetS(string const& key, string val) 222 283 { … … 226 287 227 288 /* --Methode-- */ 289 /*! Assigns the comment \b comm with the name \b key . 290 Does nothing if the entry with name is not present in the list */ 228 291 void DVList::SetComment(string const& key, string const& comm) 229 292 { … … 246 309 247 310 /* --Methode-- */ 311 /*! Return the MuTyV value associated with name \b key . 312 Adds an entry of type integer in the list if \b key is not present in the list */ 248 313 MuTyV& DVList::Get(string const& key) 249 314 { … … 272 337 //-- 273 338 274 275 /* --Methode-- */ 339 /* --Methode-- */ 340 /*! Prints a brief description of object on on the output stream \b os */ 341 void DVList::Show(ostream& os) const 342 { 343 os << "DVList::Show() - NVar= " << (int)mvlist.size() << "\n"; 344 os << comment << endl; 345 } 346 347 /* --Methode-- */ 348 /*! Prints the list of variables on the output stream \b os */ 276 349 void DVList::Print(ostream& os) const 277 350 { -
trunk/SophyaLib/BaseTools/dvlist.h
r827 r895 70 70 // Classe liste de variables Dynamic Variable List 71 71 72 //! Dynamic Variable List class. 72 73 class DVList : public AnyDataObj { 73 74 public: … … 97 98 98 99 MuTyV& Get(string const& key); 100 /*! Returns the value associated with the name \b key */ 99 101 inline MuTyV& operator() (string const& key) { return Get(key); } 102 /*! Returns the value associated with the name \b key */ 100 103 inline MuTyV& operator[] (string const& key) { return Get(key); } 104 /*! Returns the global comment string associated with the object */ 101 105 inline string& Comment() { return(comment); } 102 106 103 inline void Print() const { Print(cout); } 107 /*! Prints a brief description of object on \b cout */ 108 inline void Show() const { Show(cout); } 109 virtual void Show(ostream& os) const; 110 /*! Prints the list of variables on \b cout */ 111 inline void Print() const { Print(cout); } 104 112 virtual void Print(ostream& os) const; 105 113 … … 111 119 struct dvlElement {MuTyV elval; string elcomm; } ; 112 120 typedef map<string, dvlElement, less<string> > ValList; 121 /*! Returns an iterator pointing on the first variable in the list */ 113 122 inline ValList::const_iterator Begin() { return(mvlist.begin()); } 123 /*! Returns the iterator end value */ 114 124 inline ValList::const_iterator End() { return(mvlist.end()); } 115 125 … … 121 131 }; 122 132 133 /*! operator << overloading - Prints the list on the stream \b s */ 123 134 inline ostream& operator << (ostream& s, DVList const & dvl) 124 135 { dvl.Print(s); return(s); } 125 136 137 /*! Writes the object in the POutPersist stream \b os */ 126 138 inline POutPersist& operator << (POutPersist& os, DVList & obj) 127 139 { ObjFileIO<DVList> fio(&obj); fio.Write(os); return(os); } 140 /*! Reads the object from the PInPersist stream \b is */ 128 141 inline PInPersist& operator >> (PInPersist& is, DVList & obj) 129 142 { ObjFileIO<DVList> fio(&obj); fio.Read(is); return(is); } -
trunk/SophyaLib/BaseTools/pexceptions.h
r773 r895 14 14 namespace SOPHYA { 15 15 16 // Utiliatire pour accoler un nom de fichier et numero de ligne aumessage16 //! Utility function for appending a file name and line number to a message 17 17 string BuildLongExceptionMessage(const char * s, const char *file, int line); 18 18 19 // Ancestor for PError and PException 20 // It has a message, and an id to give more 21 // information on the exception. 19 //! Base exception class in Sophya. 20 /*! Ancestor for PError and PException 21 It has a message, and an id to give more 22 information on the exception. 23 */ 22 24 class PThrowable { 23 25 public: 26 //! Constructor with the message and error-id (optional) specification 24 27 explicit PThrowable(const string& m, int ident=0) 25 28 : msg(m), id(ident) {} 26 29 virtual ~PThrowable() { } 30 //! Returns the associated message string 27 31 virtual string const& Msg() const {return msg;} 32 //! Returns the associated error-id 33 virtual int Id() const {return id; } 28 34 private: 29 35 string msg; 30 36 int id; 31 37 }; 32 33 // A PError is a serious logic error. Usually not caught... 38 39 // PThrowable 40 // PError 41 // PException 42 43 //! A PError is a serious logic error. Usually not caught... 34 44 class PError : public PThrowable { 35 45 public: … … 37 47 }; 38 48 39 //A PException is not as serious... Can be caught.49 //! A PException is not as serious... Can be caught. 40 50 class PException : public PThrowable { 41 51 public: … … 43 53 }; 44 54 45 // Errors 46 // Memory allocation failure 55 // ---- Errors ---- 56 // PError 57 // AllocationError 58 // NullPtrError 59 // ForbiddenError 60 // AssertionFailedError 61 62 //! Memory allocation failure 47 63 class AllocationError : public PError { 48 64 public: … … 50 66 }; 51 67 52 //Null pointer error68 //! Null pointer error 53 69 class NullPtrError : public PError { 54 70 public: … … 56 72 }; 57 73 58 // Size mismatch between objects 59 class SzMismatchError : public PError { 60 public: 61 explicit SzMismatchError(const string& m, int id=0) : PError(m,id) {} 62 }; 63 64 // Out of bounds for array, matrix, etc. 65 class RangeCheckError : public PError { 66 public: 67 explicit RangeCheckError(const string& m, int id=0) : PError(m,id) {} 68 }; 69 70 // Invalid parameter to method/constructor... 71 class ParmError : public PError { 72 public: 73 explicit ParmError(const string& m, int id=0) : PError(m,id) {} 74 }; 75 76 // Calling a forbidden method, trying a forbidden operation 74 75 //! Calling a forbidden method, trying a forbidden operation 77 76 class ForbiddenError : public PError { 78 77 public: … … 80 79 }; 81 80 82 // Calling a non available / not implemented method 83 class NotAvailableOperation : public PException { 84 public: 85 explicit NotAvailableOperation(const string& m, int id=0) : PException(m,id) {} 86 }; 87 88 // ASSERT macro failure. The message is the assertion... 81 82 //! ASSERT macro failure. The message is the assertion... 89 83 class AssertionFailedError : public PError { 90 84 public: … … 97 91 // IOExc 98 92 // FileFormatExc 93 // SzMismatchError 94 // RangeCheckError 95 // ParmError 99 96 // TypeMismatchExc 97 // MathExc 98 // SingMatxExc 100 99 // DuplicateIdExc 101 100 // NotFoundExc 102 // MathExc 103 // SingMatxExc 104 105 // generic IO Exception 101 // CaughtSignalExc 102 103 //! Generic IO Exception. 106 104 class IOExc : public PException { 107 105 public: … … 109 107 }; 110 108 111 // Bad type -> keep ? 109 //! Bad file format. 110 class FileFormatExc : public IOExc { 111 public: 112 explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {} 113 }; 114 115 //! Size mismatch between objects. 116 class SzMismatchError : public PException { 117 public: 118 explicit SzMismatchError(const string& m, int id=0) : PException(m,id) {} 119 }; 120 121 //! Out of bounds for array, matrix, etc. 122 class RangeCheckError : public PException { 123 public: 124 explicit RangeCheckError(const string& m, int id=0) : PException(m,id) {} 125 }; 126 127 //! Invalid parameter to method/constructor... 128 class ParmError : public PException { 129 public: 130 explicit ParmError(const string& m, int id=0) : PException(m,id) {} 131 }; 132 133 //! Calling a non available / not implemented method 134 class NotAvailableOperation : public PException { 135 public: 136 explicit NotAvailableOperation(const string& m, int id=0) : PException(m,id) {} 137 }; 138 139 //! Bad data type -> keep ? 112 140 class TypeMismatchExc : public PException { 113 141 public: 114 142 explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {} 115 143 }; 116 144 145 //! Math operation exception 117 146 class MathExc : public PException { 118 147 public: … … 120 149 }; 121 150 151 //! Singular matrix 152 class SingMatrixExc : public MathExc { 153 public: 154 explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {} 155 }; 156 157 //! Duplicate identifier during registration 122 158 class DuplicateIdExc : public PException { 123 159 public: … … 125 161 }; 126 162 163 //! Not found identifier 127 164 class NotFoundExc : public PException { 128 165 public: … … 130 167 }; 131 168 169 //! Generated exception when processing a signal 132 170 class CaughtSignalExc : public PException { 133 171 public: 134 172 explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {} 135 173 }; 136 137 // Bad file format 138 class FileFormatExc : public IOExc { 139 public: 140 explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {} 141 }; 142 143 class SingMatrixExc : public MathExc { 144 public: 145 explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {} 146 }; 147 148 149 } 174 175 } // namespace SOPHYA 150 176 151 177 -
trunk/SophyaLib/BaseTools/ppersist.h
r821 r895 34 34 class PPersist; 35 35 36 /* Persistant (delegate or mixin) object */ 37 36 //! Persistent (delegate or mixin) base class 38 37 class PPersist { 39 38 public: … … 69 68 70 69 71 // Ancestor for PInPersist and POutPersist 72 70 //! Ancestor for PInPersist and POutPersist PPF streams. 71 // Handles (statically) the registration of classes. 73 72 74 73 class PIOPersist { … … 137 136 // TBD : use hash tables instead of maps. Check hashtbl status in STL. 138 137 138 //! Input stream for PPersit objects. 139 139 class PInPersist : public PIOPersist { 140 140 public: … … 236 236 }; 237 237 238 //! Output stream for PPersit objects. 238 239 class POutPersist : public PIOPersist { 239 240 public: … … 370 371 // - compute the class ID from a MD5 hash of the class name 371 372 // - register classes with PIOPersist, through PPRegister macro 372 373 374 //! template class for handling the PPersist registration mechanism. 373 375 template <class T> 374 376 class PPersistRegistrar {
Note:
See TracChangeset
for help on using the changeset viewer.