300 | | |
301 | | /*! |
302 | | @brief Class for storing results (and semi-results) of an experiment |
303 | | |
304 | | This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed. |
305 | | */ |
306 | | class logger : public bdmroot { |
307 | | protected: |
308 | | //! RVs of all logged variables. |
309 | | Array<RV> entries; |
310 | | //! Names of logged quantities, e.g. names of algorithm variants |
311 | | Array<string> names; |
312 | | public: |
313 | | //!Default constructor |
314 | | logger ( ) : entries ( 0 ),names ( 0 ) {} |
315 | | |
316 | | //! returns an identifier which will be later needed for calling the log() function |
317 | | virtual int add ( const RV &rv, string name="" ) { |
318 | | int id=entries.length(); |
319 | | names=concat ( names, name ); // diff |
320 | | entries.set_length ( id+1,true ); |
321 | | entries ( id ) = rv; |
322 | | return id; // identifier of the last entry |
323 | | } |
324 | | |
325 | | //! log this vector |
326 | | virtual void logit ( int id, const vec &v ) =0; |
327 | | |
328 | | //! Shifts storage position for another time step. |
329 | | virtual void step() =0; |
330 | | |
331 | | //! Finalize storing information |
332 | | virtual void finalize() {}; |
333 | | |
334 | | //! Initialize the storage |
335 | | virtual void init() {}; |
336 | | |
337 | | //! for future use |
338 | | virtual ~logger() {}; |
339 | | }; |
340 | | |
| 379 | }; |
| 380 | |
| 381 | /*! |
| 382 | @brief Class for storing results (and semi-results) of an experiment |
| 383 | |
| 384 | This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed. |
| 385 | */ |
| 386 | class logger : public bdmroot { |
| 387 | protected: |
| 388 | //! RVs of all logged variables. |
| 389 | Array<RV> entries; |
| 390 | //! Names of logged quantities, e.g. names of algorithm variants |
| 391 | Array<string> names; |
| 392 | public: |
| 393 | //!Default constructor |
| 394 | logger ( ) : entries ( 0 ),names ( 0 ) {} |
| 395 | |
| 396 | //! returns an identifier which will be later needed for calling the log() function |
| 397 | virtual int add ( const RV &rv, string name="" ) { |
| 398 | int id=entries.length(); |
| 399 | names=concat ( names, name ); // diff |
| 400 | entries.set_length ( id+1,true ); |
| 401 | entries ( id ) = rv; |
| 402 | return id; // identifier of the last entry |
| 403 | } |
| 404 | |
| 405 | //! log this vector |
| 406 | virtual void logit ( int id, const vec &v ) =0; |
| 407 | |
| 408 | //! Shifts storage position for another time step. |
| 409 | virtual void step() =0; |
| 410 | |
| 411 | //! Finalize storing information |
| 412 | virtual void finalize() {}; |
| 413 | |
| 414 | //! Initialize the storage |
| 415 | virtual void init() {}; |
| 416 | |
| 417 | //! for future use |
| 418 | virtual ~logger() {}; |