Commit 3e5a8fd7a6eb14d24a0a974a2e03c58371835fbb

Authored by knodlseder
1 parent 2131cf36

add print() method

include/GFitsTableCol.hpp
@@ -67,6 +67,7 @@ public: @@ -67,6 +67,7 @@ public:
67 int number(void) const; 67 int number(void) const;
68 int length(void) const; 68 int length(void) const;
69 int anynul(void) const; 69 int anynul(void) const;
  70 + std::string print(void) const;
70 71
71 protected: 72 protected:
72 // Protected data area 73 // Protected data area
@@ -97,14 +98,13 @@ protected: @@ -97,14 +98,13 @@ protected:
97 virtual void* ptr_nulval(void) = 0; 98 virtual void* ptr_nulval(void) = 0;
98 99
99 // Protected methods 100 // Protected methods
100 - virtual void save(void);  
101 - virtual void fetch_data(void);  
102 - virtual void load_column(void);  
103 - virtual void save_column(void);  
104 - virtual std::ostream& dump_column(std::ostream& os) const;  
105 - virtual GLog& dump_column(GLog& log) const;  
106 - virtual void dump_buffer(char* buffer) const;  
107 - virtual int offset(const int& row, const int& inx) const; 101 + virtual void save(void);
  102 + virtual void fetch_data(void);
  103 + virtual void load_column(void);
  104 + virtual void save_column(void);
  105 + virtual std::ostream& dump_column(std::ostream& os) const;
  106 + virtual GLog& dump_column(GLog& log) const;
  107 + virtual int offset(const int& row, const int& inx) const;
108 108
109 private: 109 private:
110 // Private methods 110 // Private methods
src/fits/GFitsTableCol.cpp
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 #include "GException.hpp" 19 #include "GException.hpp"
20 #include "GFitsCfitsio.hpp" 20 #include "GFitsCfitsio.hpp"
21 #include "GFitsTableCol.hpp" 21 #include "GFitsTableCol.hpp"
  22 +#include "GTools.hpp"
22 23
23 /* __ Method name definitions ____________________________________________ */ 24 /* __ Method name definitions ____________________________________________ */
24 #define G_LOAD_COLUMN "GFitsTableCol::load_column()" 25 #define G_LOAD_COLUMN "GFitsTableCol::load_column()"
@@ -266,6 +267,48 @@ int GFitsTableCol::anynul(void) const @@ -266,6 +267,48 @@ int GFitsTableCol::anynul(void) const
266 } 267 }
267 268
268 269
  270 +/***********************************************************************//**
  271 + * @brief Print column information
  272 + *
  273 + * @todo Format and cfitsio information is mainly for debugging. This could
  274 + * be vanish in a more stable version of the code, or it could be compiled
  275 + * in conditionally using a debug option.
  276 + ***************************************************************************/
  277 +std::string GFitsTableCol::print(void) const
  278 +{
  279 + // Initialise result string
  280 + std::string result;
  281 +
  282 + // Append formatted column name
  283 + result.append(parformat(m_name));
  284 +
  285 + // Append column number
  286 + if (m_colnum > 0)
  287 + result.append(right(str(m_colnum),4)+" ");
  288 + else
  289 + result.append(right("[-]",4)+" ");
  290 +
  291 + // Append loading information
  292 + if (((GFitsTableCol*)this)->ptr_data() == NULL)
  293 + result.append("[not loaded] ");
  294 + else
  295 + result.append("[loaded] ");
  296 +
  297 + // Append format information
  298 + result.append("["+binary_format()+","+ascii_format()+"]");
  299 +
  300 + // Append cfitsio information
  301 + result.append(" repeat="+str(m_repeat));
  302 + result.append(" width="+str(m_width));
  303 + result.append(" number="+str(m_number));
  304 + result.append(" length="+str(m_length));
  305 + result.append(" size="+str(m_size));
  306 +
  307 + // Return result
  308 + return result;
  309 +}
  310 +
  311 +
269 /*========================================================================== 312 /*==========================================================================
270 = = 313 = =
271 = Protected methods = 314 = Protected methods =
@@ -418,19 +461,11 @@ void GFitsTableCol::save_column(void) @@ -418,19 +461,11 @@ void GFitsTableCol::save_column(void)
418 * 461 *
419 * @param[in] os Output stream. 462 * @param[in] os Output stream.
420 * @param[in] column Column. 463 * @param[in] column Column.
421 - *  
422 - * @todo Use a stream buffer instead of a character buffer to circumvent  
423 - * any size limitations and return a std::string or a stream buffer.  
424 ***************************************************************************/ 464 ***************************************************************************/
425 std::ostream& GFitsTableCol::dump_column(std::ostream& os) const 465 std::ostream& GFitsTableCol::dump_column(std::ostream& os) const
426 { 466 {
427 - char buffer[1024];  
428 -  
429 - // Dump column into buffer  
430 - dump_buffer(buffer);  
431 -  
432 - // Write buffer into logger  
433 - os << buffer; 467 + // Write column in output stream
  468 + os << print();
434 469
435 // Return stream 470 // Return stream
436 return os; 471 return os;
@@ -442,20 +477,11 @@ std::ostream&amp; GFitsTableCol::dump_column(std::ostream&amp; os) const @@ -442,20 +477,11 @@ std::ostream&amp; GFitsTableCol::dump_column(std::ostream&amp; os) const
442 * 477 *
443 * @param[in] log Logger. 478 * @param[in] log Logger.
444 * @param[in] column Column. 479 * @param[in] column Column.
445 - *  
446 - * @todo Use a stream buffer instead of a character buffer to circumvent  
447 - * any size limitations and return a std::string or a stream buffer.  
448 ***************************************************************************/ 480 ***************************************************************************/
449 GLog& GFitsTableCol::dump_column(GLog& log) const 481 GLog& GFitsTableCol::dump_column(GLog& log) const
450 { 482 {
451 - // Allocate buffer  
452 - char buffer[1024];  
453 -  
454 - // Dump column into buffer  
455 - dump_buffer(buffer);  
456 -  
457 - // Write buffer into logger  
458 - log << buffer; 483 + // Write column in logger
  484 + log << print();
459 485
460 // Return logger 486 // Return logger
461 return log; 487 return log;
@@ -463,51 +489,6 @@ GLog&amp; GFitsTableCol::dump_column(GLog&amp; log) const @@ -463,51 +489,6 @@ GLog&amp; GFitsTableCol::dump_column(GLog&amp; log) const
463 489
464 490
465 /***********************************************************************//** 491 /***********************************************************************//**
466 - * @brief Write column into character buffer  
467 - *  
468 - * @param[in] buffer C string character buffer.  
469 - *  
470 - * Write column information in a formatted way into a C string buffer.  
471 - *  
472 - * @todo Use a stream buffer instead of a character buffer to circumvent  
473 - * any size limitations and return a std::string or a stream buffer.  
474 - ***************************************************************************/  
475 -void GFitsTableCol::dump_buffer(char* buffer) const  
476 -{  
477 - // Allocate buffers  
478 - char name[256];  
479 - char fmt[100];  
480 - char load[100];  
481 - char fits[256];  
482 -  
483 - // Put column number and name in buffer  
484 - if (m_colnum > 0)  
485 - sprintf(name, "Column %5d ..............: %20s", m_colnum, m_name.c_str());  
486 - else  
487 - sprintf(name, "Column [not linked] .......: %20s", m_name.c_str());  
488 -  
489 - // Put column format in buffer  
490 - sprintf(fmt, "[%5s,%5s]", binary_format().c_str(), ascii_format().c_str());  
491 -  
492 - // Put loading information in buffer  
493 - if (((GFitsTableCol*)this)->ptr_data() == NULL)  
494 - sprintf(load, "[not loaded] ");  
495 - else  
496 - sprintf(load, "[loaded in memory]");  
497 -  
498 - // Put cfitsio information in buffer  
499 - sprintf(fits, "repeat=%d width=%d number=%d length=%d size=%d", m_repeat,  
500 - m_width, m_number, m_length, m_size);  
501 -  
502 - // Assemble buffer  
503 - sprintf(buffer, "%s %s %s %s", name, fmt, load, fits);  
504 -  
505 - // Return  
506 - return;  
507 -}  
508 -  
509 -  
510 -/***********************************************************************//**  
511 * @brief Convert row and vector index into column offset 492 * @brief Convert row and vector index into column offset
512 * 493 *
513 * @param[in] row Row of column. 494 * @param[in] row Row of column.