Changeset 895 in Sophya
- Timestamp:
- Apr 12, 2000, 7:49:54 PM (25 years ago)
- Location:
- trunk/SophyaLib
- Files:
-
- 2 added
- 12 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 { -
trunk/SophyaLib/SUtils/datacards.cc
r754 r895 1 // $Id: datacards.cc,v 1. 1 2000-03-02 16:10:58ansari Exp $1 // $Id: datacards.cc,v 1.2 2000-04-12 17:49:42 ansari Exp $ 2 2 // 3 3 // Datacards, acquisition EROS II … … 18 18 //++ 19 19 // Class DataCards 20 // Lib Outils++20 // Lib SysTools 21 21 // include datacards.h 22 22 // … … 24 24 // de mot-cle (lecture d'un fichier par exemple) 25 25 //-- 26 26 27 27 28 //++ … … 35 36 //-- 36 37 38 /*! 39 \class SOPHYA::DataCards 40 This class can be used for decoding program parameters from an ascii 41 file. Each line of the ascii contains a keyword starting with \b @ . 42 Lines with any other character in the first column are treated as comments. 43 Keywords can be followed by 0 or more parameters. 44 Processing functions (\b ProcCard) can automatically be called for 45 keywords matching a given pattern. (see \b AddProcF ) 46 */ 47 48 /* Default constructor */ 37 49 DataCards::DataCards() 38 50 { 39 51 } 40 52 53 /*! constructor with the specification of a parameter file */ 41 54 DataCards::DataCards(string const& fn) 42 55 { … … 63 76 //-- 64 77 78 /*! 79 Adds a new processing function for all keywords matching the 80 specified pattern. 81 \param mtch : The pattern - can contain * 82 */ 65 83 void 66 84 DataCards::AddProcF(ProcCard f, string const& mtch) … … 85 103 } 86 104 87 void 88 DataCards::Clear()105 /*! Resets the objects - Suppresses all cards */ 106 void DataCards::Clear() 89 107 { 90 108 cards.erase(cards.begin(), cards.end()); 91 109 } 92 110 111 /*! Reads the file named \b fn. if fn=="" the value of \b SOPHYA_DATACARDS is used */ 93 112 void 94 113 DataCards::ReadFile(string const& fn) … … 96 115 string file = fn; 97 116 if (file == "") { 98 char * efn = getenv(" PEIDA_DATACARDS");117 char * efn = getenv("SOPHYA_DATACARDS"); 99 118 if (efn != NULL) file = efn; 100 119 } … … 104 123 DoReadFile(file); 105 124 } catch(...) { 106 char* wdp = getenv(" PEIDA_WORK");125 char* wdp = getenv("SOPHYA_WORK"); 107 126 if (wdp) { 108 cerr << "DataCards::ReadFile() Error reading file " << fn << " (Trying with PEIDA_WORK) \n";127 cerr << "DataCards::ReadFile() Error reading file " << fn << " (Trying with SOPHYA_WORK) \n"; 109 128 file = wdp + file; 110 129 DoReadFile(file); … … 115 134 } 116 135 136 /*! Appends a card, represented by the string \b crd to the list of cards */ 117 137 void 118 138 DataCards::AppendCard(string const& crd) … … 145 165 } 146 166 147 void148 DataCards::DoReadFile(string const& fn)149 {150 char line_buff[512];151 FILE *fip;152 153 if ( (fip = fopen(fn.c_str(),"r")) == NULL )154 throw IOExc("DataCards::DoReadFile() fopen Error ") ;155 while (fgets(line_buff,511,fip) != NULL)156 {157 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */158 string line(line_buff);159 AppendCard(line);160 }161 }162 163 int164 DataCards::ApplyPF(CrdPF & cpf, string const& key, string const& toks)165 {166 int l,lk;167 int rc = 0;168 // On verifie si le "pattern" correspond169 bool mtch = false;170 l = cpf.patt.length();171 if (cpf.patt == "*") mtch = true;172 else if (cpf.patt[0] == '*')173 {174 lk = key.length();175 if (cpf.patt[l-1] != '*')176 {177 if (strcmp(key.c_str()+(lk-l+1), cpf.patt.c_str()+1) == 0) mtch = true;178 }179 else if (key.find(cpf.patt.substr(1,l-2)) < lk) mtch = true;180 }181 else if (cpf.patt[l-1] == '*')182 {183 if ( strncmp(key.c_str(), cpf.patt.c_str(),l-1) == 0) mtch = true;184 }185 else if (key == cpf.patt) mtch = true;186 187 // Si oui, on appelle la fonction correspondante188 if (mtch) rc = cpf.pf(key, toks);189 190 return(rc);191 }192 193 194 int195 DataCards::ApplyPFL(string const& key, string const& toks)196 {197 int rc = 0;198 CrdPFList::iterator icf;199 for(icf = cpfs.begin(); icf != cpfs.end(); icf++)200 rc += ApplyPF((*icf), key, toks);201 return(rc);202 }203 204 void205 DataCards::RemoveCard(string const& key)206 {207 CardList::iterator i;208 for(i=cards.begin(); i != cards.end(); i++)209 if ((*i).kw == key) { cards.erase(i); break; }210 }211 212 DataCards::Card *213 DataCards::FindKey(string const& key)214 {215 /*216 CardList::iterator i = find_if(cards.begin(), cards.end(), bind2nd(KeyEq(),key));217 if (i == cards.end() ) return NULL;218 */219 CardList::iterator i;220 for(i=cards.begin(); i != cards.end(); i++)221 if ((*i).kw == key) return &*i;222 223 return NULL;224 }225 167 226 168 //++ … … 246 188 247 189 190 /*! Returns true if \b key is present in the list */ 248 191 bool 249 192 DataCards::HasKey(string const& key) … … 252 195 } 253 196 197 //! Returns the total number of cards 254 198 int 255 199 DataCards::NbCards() … … 258 202 } 259 203 204 /*! Returns the number of parameters for card \b key. (-1) if \b key not present */ 260 205 int 261 206 DataCards::NbParam(string const& key) … … 266 211 } 267 212 213 /*! Returns the parameter number \b numero for card \b key */ 268 214 string 269 215 DataCards::SParam(string const& key, int numero, string def) … … 275 221 } 276 222 223 /*! Returns the parameter number \b numero for card \b key, converted to type long */ 277 224 long 278 225 DataCards::IParam(string const& key, int numero, long def) … … 286 233 } 287 234 235 /*! Returns the parameter number \b numero for card \b key, converted to type double */ 288 236 double 289 237 DataCards::DParam(string const& key, int numero, double def) … … 298 246 299 247 300 ostream& operator << (ostream& s, DataCards c) 301 { 302 for (DataCards::CardList::iterator i = c.cards.begin(); i != c.cards.end(); i++) { 248 /*! Prints the list of cards on the output stream \b s */ 249 void 250 DataCards::Print(ostream& s) const 251 { 252 for (CardList::const_iterator i = cards.begin(); i != cards.end(); i++) { 303 253 s << setw(10) << (*i).kw << " "; 304 for (vector<string>:: iterator j = (*i).tokens.begin(); j != (*i).tokens.end(); j++)254 for (vector<string>::const_iterator j = (*i).tokens.begin(); j != (*i).tokens.end(); j++) 305 255 s << (*j) << " "; 306 256 s << endl; 307 257 } 308 return s; 309 } 310 311 312 258 } 259 260 /*! Reads the file named \b fn. */ 261 void 262 DataCards::DoReadFile(string const& fn) 263 { 264 char line_buff[512]; 265 FILE *fip; 266 267 if ( (fip = fopen(fn.c_str(),"r")) == NULL ) 268 throw IOExc("DataCards::DoReadFile() fopen Error ") ; 269 while (fgets(line_buff,511,fip) != NULL) 270 { 271 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */ 272 string line(line_buff); 273 AppendCard(line); 274 } 275 } 276 277 int 278 DataCards::ApplyPF(CrdPF & cpf, string const& key, string const& toks) 279 { 280 int l,lk; 281 int rc = 0; 282 // On verifie si le "pattern" correspond 283 bool mtch = false; 284 l = cpf.patt.length(); 285 if (cpf.patt == "*") mtch = true; 286 else if (cpf.patt[0] == '*') 287 { 288 lk = key.length(); 289 if (cpf.patt[l-1] != '*') 290 { 291 if (strcmp(key.c_str()+(lk-l+1), cpf.patt.c_str()+1) == 0) mtch = true; 292 } 293 else if (key.find(cpf.patt.substr(1,l-2)) < lk) mtch = true; 294 } 295 else if (cpf.patt[l-1] == '*') 296 { 297 if ( strncmp(key.c_str(), cpf.patt.c_str(),l-1) == 0) mtch = true; 298 } 299 else if (key == cpf.patt) mtch = true; 300 301 // Si oui, on appelle la fonction correspondante 302 if (mtch) rc = cpf.pf(key, toks); 303 304 return(rc); 305 } 306 307 308 int 309 DataCards::ApplyPFL(string const& key, string const& toks) 310 { 311 int rc = 0; 312 CrdPFList::iterator icf; 313 for(icf = cpfs.begin(); icf != cpfs.end(); icf++) 314 rc += ApplyPF((*icf), key, toks); 315 return(rc); 316 } 317 318 void 319 DataCards::RemoveCard(string const& key) 320 { 321 CardList::iterator i; 322 for(i=cards.begin(); i != cards.end(); i++) 323 if ((*i).kw == key) { cards.erase(i); break; } 324 } 325 326 DataCards::Card * 327 DataCards::FindKey(string const& key) 328 { 329 /* 330 CardList::iterator i = find_if(cards.begin(), cards.end(), bind2nd(KeyEq(),key)); 331 if (i == cards.end() ) return NULL; 332 */ 333 CardList::iterator i; 334 for(i=cards.begin(); i != cards.end(); i++) 335 if ((*i).kw == key) return &*i; 336 337 return NULL; 338 } 339 340 341 -
trunk/SophyaLib/SUtils/datacards.h
r754 r895 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: datacards.h,v 1. 1 2000-03-02 16:10:59ansari Exp $3 // $Id: datacards.h,v 1.2 2000-04-12 17:49:43 ansari Exp $ 4 4 // 5 5 // Datacards, acquisition EROS II … … 14 14 #define DATACARDS_SEEN 15 15 16 #include "machdefs.h" 16 17 #include <string.h> 17 18 #include <string> … … 19 20 #include <list> 20 21 #include <vector> 21 #include <string>22 22 23 #include "peida.h" 23 24 namespace SOPHYA { 24 25 25 26 typedef int (*ProcCard)(string const& key, string const& toks); 26 27 27 class DataCards EXC_AWARE { 28 //! Class for decoding parameters from an ascii file. 29 30 class DataCards { 28 31 public: 32 29 33 DataCards(); 30 34 DataCards(string const& fn); 31 35 32 // nom dans variable d'environnement PEIDA_DATACARDS33 // par defaut, peida.datacards36 // nom dans variable d'environnement SOPHYA_DATACARDS 37 // par defaut, sophya.datacards 34 38 // Si pas chemin complet, on tente dans repertoire 35 // en cours, puis dans PEIDA_WORK39 // en cours, puis dans SOPHYA_WORK 36 40 37 41 virtual ~DataCards() {} … … 50 54 double DParam(string const& key, int numero = 0, double def = 0); 51 55 52 friend ostream& operator << (ostream& s, DataCards c);56 void Print(ostream& s) const; 53 57 54 p ublic:58 protected: 55 59 struct Card { 56 60 string kw; 57 61 vector<string> tokens; 58 STRUCTCOMPF(Card,kw) 62 bool operator == (Card const & b) const { return(kw == b.kw); } 63 bool operator < (Card const & b) const { return(kw < b.kw); } 59 64 }; 60 typedef list<Card> CardList;61 65 struct CrdPF { 62 66 ProcCard pf; 63 67 string patt; 64 STRUCTCOMPF(CrdPF,pf) 68 bool operator == (CrdPF const & b) const { return(pf == b.pf); } 69 bool operator < (CrdPF const & b) const { return(pf == b.pf); } 65 70 }; 66 typedef list<CrdPF> CrdPFList;67 protected:68 CardList cards;69 CrdPFList cpfs;70 71 71 72 void DoReadFile(string const& fn); … … 77 78 78 79 Card* FindKey(string const& key); 80 81 typedef list<Card> CardList; 82 typedef list<CrdPF> CrdPFList; 83 CardList cards; 84 CrdPFList cpfs; 85 79 86 struct KeyEq : binary_function<Card, string, bool> { 80 87 bool operator()(const Card& x, const string& y) const { return x.kw == y; } 81 88 }; 82 89 }; 90 91 //! operator << overloading - calls Print() 92 inline ostream& operator << (ostream& s, DataCards c) 93 { c.Print(s); return s; } 94 95 } // namespace SOPHYA 96 83 97 #endif -
trunk/SophyaLib/SysTools/ctimer.cc
r241 r895 1 1 // 2 // $Id: ctimer.cc,v 1. 2 1999-04-21 13:11:59ansari Exp $2 // $Id: ctimer.cc,v 1.3 2000-04-12 17:49:40 ansari Exp $ 3 3 // 4 4 … … 8 8 //++ 9 9 // Class Timer 10 // Lib Outils++10 // Lib SysTools 11 11 // include ctimer.h 12 12 // … … 37 37 //-- 38 38 39 /*! 40 \class SOPHYA::Timer 41 This class implements a simple chronometer which can be used for 42 measuring the CPU and elapsed time in functions. The constructor 43 keeps the start time (and CPU time) and an optional message. 44 The \b Split method displays the partial time, and destructor 45 displays the total CPU and elapsed time since timer creation. 46 The macro \b TIMEF create a timer object with the function name. 47 The macro \b SPLITTIME calls the split methode for the timer created 48 by TIMEF. A named timer can be created using the macro \b TIMEN(nom) 49 */ 50 51 /*! Constructor with the specification of a optional name or message */ 39 52 Timer::Timer(const char* name) 40 53 : timerName(name) … … 53 66 //-- 54 67 55 68 /*! Method which displays the partial CPU and elapsed time 69 An optional message can be passed to be used instead of the 70 timer name 71 */ 56 72 void Timer::Split(const char* comm) 57 73 { … … 65 81 int etmt = elapse - elapse0; 66 82 67 cout << "***Timing " << (comm ? comm : timerName ) << endl;83 cout << "***Timing " << (comm ? comm : timerName.c_str()) << endl; 68 84 69 85 // Pour des formats comme ca, la syntaxe printf est plus agreable. -
trunk/SophyaLib/SysTools/ctimer.h
r241 r895 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: ctimer.h,v 1. 2 1999-04-21 13:12:00ansari Exp $3 // $Id: ctimer.h,v 1.3 2000-04-12 17:49:41 ansari Exp $ 4 4 // 5 5 … … 8 8 #define CTIMER_SEEN 9 9 10 #include "machdefs.h" 10 11 #include <sys/types.h> 11 12 #include <time.h> 12 13 #include <iostream.h> 13 14 #include <stdio.h> 14 #include "machdefs.h"15 #include <string> 15 16 16 17 // <summary> Permet de chronometrer des fonctions. </summary> … … 22 23 23 24 // La macro SPLITTIME lui permet d'afficher des temps partiels. 25 namespace SOPHYA { 26 27 //! Simple chronometer class 24 28 class Timer { 25 29 public: … … 35 39 36 40 // Sert a eviter que GNU ne pretende qu'on utilise pas l'objet... 41 /*! To avoid not used object compiler warnings */ 37 42 void Nop() {} 38 43 … … 40 45 clock_t cpu0, cpuSplit; 41 46 time_t elapse0, elapseSplit; 42 const char*timerName;47 string timerName; 43 48 }; 49 50 } // namespace SOPHYA 44 51 45 52 #define TIMEN(x) Timer timer(x); timer.Nop(); -
trunk/SophyaLib/SysTools/pdlmgr.cc
r480 r895 18 18 string* PDynLinkMgr::tmpDir = NULL; 19 19 20 /*! 21 \class SOPHYA::PDynLinkMgr 22 This classes handles the run-time operations related to using shared 23 libraries. The present version has been adapted for different Unix 24 flavours (Linux, Compaq/Digital Unix, SGI IRIX, IBM AIX, Sun Solaris). 25 */ 26 20 27 /* --Methode-Static-- */ 28 /*! Sets the path for a temporary space where shared libraries are copied. 29 The path is appended to \b LD_LIBRARY_PATH 30 */ 21 31 void PDynLinkMgr::SetTmpDir(string const & path) 22 32 { … … 63 73 64 74 /* --Methode-Static-- */ 75 /*! Returns the temporary space path */ 65 76 string& PDynLinkMgr::GetTmpDir() 66 77 { … … 68 79 tmpDir = new string(""); 69 80 char* varenv; 70 if ( (varenv=getenv(" PEIDA_TMP")) != NULL ) *tmpDir = varenv;81 if ( (varenv=getenv("SOPHYA_TMP")) != NULL ) *tmpDir = varenv; 71 82 else if ( (varenv=getenv("TMPDIR")) != NULL ) *tmpDir = varenv; 72 83 } … … 75 86 76 87 /* --Methode-Static-- */ 88 /*! Compiles the C source file named \b fname and creates the 89 corresponding shared library linking against the standard 90 C library (-lc) and the math library (-lm). 91 Returns a pointer to the created PDynLinkMgr object (by new). 92 Returns the NULL pointer in case of errors. 93 */ 77 94 PDynLinkMgr* PDynLinkMgr::BuildFromCFile(string const & fname) 78 95 { … … 131 148 132 149 /* --Methode-- */ 150 /*! The constructor. 151 \param soname : Name of the shared library. ".so" is appended 152 to the name if no dot "." is found in the name. 153 \param cp : if true, copies the shared library in the temporary space. 154 */ 133 155 PDynLinkMgr::PDynLinkMgr(string& soname, bool cp) 134 156 { … … 181 203 182 204 /* --Methode-- */ 205 /*! Destructor. Closes the shared library. Removes the file if it had been 206 copied in the temporary space, or generated by \b BuildFromCFile */ 183 207 PDynLinkMgr::~PDynLinkMgr() 184 208 { … … 196 220 197 221 /* --Methode-- */ 222 /*! Returns a handle to the function named \b funcname. 223 Returns the NULL pointer in case of error */ 198 224 DlFunction PDynLinkMgr::GetFunction(string const & funcname) 199 225 { -
trunk/SophyaLib/SysTools/pdlmgr.h
r480 r895 16 16 #endif 17 17 18 namespace SOPHYA { 19 18 20 typedef void (* DlFunction) (void); 19 21 22 //! Dynamic Link Manager. 20 23 class PDynLinkMgr { 21 24 public: … … 45 48 }; 46 49 50 } // namespace SOPHYA 51 47 52 #endif -
trunk/SophyaLib/SysTools/periodic.h
r480 r895 7 7 #include <list> 8 8 9 namespace SOPHYA { 10 9 11 class Periodic; 10 12 typedef list<Periodic*> PeriodicList; … … 12 14 typedef void (* UsPeriodicAction) (void *); 13 15 16 //! Class for the execution of a periodic action 14 17 class Periodic 15 18 { … … 23 26 virtual void SetIntervalms(int dtms); 24 27 28 /*! Returns the time interval in seconds >= 1 sec */ 25 29 inline int Interval() { return(mDt); } 30 /*! Returns the time interval in milli-second */ 26 31 inline int Intervalms() { return(mDtms); } 27 32 … … 41 46 }; 42 47 48 } // namespace SOPHYA 43 49 44 50 #endif
Note:
See TracChangeset
for help on using the changeset viewer.