GFitsTableCol.hpp 15.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
/***************************************************************************
 *        GFitsTableCol.hpp - FITS table column abstract base class        *
 * ----------------------------------------------------------------------- *
 *  copyright (C) 2008-2017 by Juergen Knoedlseder                         *
 * ----------------------------------------------------------------------- *
 *                                                                         *
 *  This program is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation, either version 3 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 *                                                                         *
 ***************************************************************************/
/**
 * @file GFitsTableCol.hpp
 * @brief FITS table column abstract base class definition
 * @author Juergen Knoedlseder
 */

#ifndef GFITSTABLECOL_HPP
#define GFITSTABLECOL_HPP

/* __ Includes ___________________________________________________________ */
#include <string>
#include <vector>
#include "GBase.hpp"


/***********************************************************************//**
 * @class GFitsTableCol
 *
 * @brief Abstract interface for FITS table column
 *
 * This class provides an abstract base class for all FITS table columns.
 * The class supports both fixed-length and variable-length vector columns.
 ***************************************************************************/
class GFitsTableCol : public GBase {

    // Friend classes
    friend class GFitsTable;

public:
    // Constructors and destructors
    GFitsTableCol(void);
    GFitsTableCol(const std::string& name,
                  const int&         nrows,
                  const int&         number,
                  const int&         width);
    GFitsTableCol(const GFitsTableCol& column);
    virtual ~GFitsTableCol(void);

    // Operators
    GFitsTableCol& operator=(const GFitsTableCol& column);

    // Pure virtual methods
    virtual void            clear(void) = 0;
    virtual GFitsTableCol*  clone(void) const = 0;
    virtual std::string     classname(void) const = 0;
    virtual std::string     string(const int& row, const int& inx = 0) const = 0;
    virtual double          real(const int& row, const int& inx = 0) const = 0;
    virtual int             integer(const int& row, const int& inx = 0) const = 0;
    virtual void            insert(const int& row, const int& nrows) = 0;
    virtual void            remove(const int& row, const int& nrows) = 0;
    virtual bool            is_loaded(void) const = 0;

    // Other methods
    void                    name(const std::string& name);
    const std::string&      name(void) const;
    void                    unit(const std::string& unit);
    const std::string&      unit(void) const;
    void                    dim(const std::vector<int>& dim);
    const std::vector<int>& dim(void) const;
    void                    colnum(const int& colnum);
    const int&              colnum(void) const;
    void                    type(const int& type);
    const int&              type(void) const;
    void                    repeat(const int& repeat);
    const int&              repeat(void) const;
    void                    width(const int& width);
    const int&              width(void) const;
    void                    number(const int& number);
    const int&              number(void) const;
    void                    elements(const int& row, const int& elements);
    int                     elements(const int& row) const;
    void                    nrows(const int& nrows);
    const int&              nrows(void) const;
    void                    is_variable(const bool& variable);
    const bool&             is_variable(void) const;
    void                    anynul(const int& anynul);
    const int&              anynul(void) const;
    std::string             tform_binary(void) const;
    std::string             print(const GChatter& chatter = NORMAL) const;

protected:
    // Protected methods
    void        init_members(void);
    void        copy_members(const GFitsTableCol& column);
    void        free_members(void);
    void        connect(void* vptr);

    // Protected pure virtual methods
    virtual void        alloc_data(void) = 0;
    virtual void        init_data(void) = 0;
    virtual void        fetch_data(void) const = 0;
    virtual void        resize_data(const int& index, const int& number) = 0;
    virtual void        release_data(void) = 0;
    virtual void*       ptr_data(const int& index = 0) = 0;
    virtual void*       ptr_nulval(void) = 0;
    virtual std::string ascii_format(void) const = 0;

    // Protected virtual methods
    virtual void        save(void);
    virtual void        load_column(void);
    virtual void        load_column_fixed(void);
    virtual void        load_column_variable(void);
    virtual void        save_column(void);
    virtual void        save_column_fixed(void);
    virtual void        save_column_variable(void);
    virtual int         offset(const int& row, const int& inx) const;

    // Protected data area
    std::string      m_name;      //!< Column name
    std::string      m_unit;      //!< Column unit
    std::vector<int> m_dim;       //!< Column dimension
    int              m_colnum;    //!< @brief Column number (starting from 1).
                                  //!< This parameter is used to signal if a
                                  //!< table column corresponds to a FITS file
                                  //!< column. If it is set to 0 there is no
                                  //!< correspondence.
    int              m_type;      //!< Column type
    int              m_repeat;    //!< Repeat value of column
    int              m_width;     //!< Width of single column element
    int              m_number;    //!< @brief Number of elements in column.
                                  //!< m_number = m_repeat / m_width
    int              m_length;    //!< Length of column (number of rows)
    bool             m_variable;  //!< Signals if column is variable length
    int              m_varlen;    //!< Maximum number of elements in variable-length
    std::vector<int> m_rowstart;  //!< Start index of each row
    mutable int      m_size;      //!< Size of allocated data area (0 if not loaded)
    int              m_anynul;    //!< Number of NULLs encountered
    void*            m_fitsfile;  //!< FITS file pointer associated with column
};


/***********************************************************************//**
 * @brief Set column name
 *
 * @param[in] name Column name.
 ***************************************************************************/
inline
void GFitsTableCol::name(const std::string& name)
{
    // Set name
    m_name = name;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns column name
 *
 * @return Column name.
 ***************************************************************************/
inline
const std::string& GFitsTableCol::name(void) const
{
    // Return name
    return m_name;
}


/***********************************************************************//**
 * @brief Set column unit
 *
 * @param[in] unit Column unit.
 ***************************************************************************/
inline
void GFitsTableCol::unit(const std::string& unit)
{
    // Set unit
    m_unit = unit;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns column unit
 *
 * @return Column unit.
 ***************************************************************************/
inline
const std::string& GFitsTableCol::unit(void) const
{
    // Return column unit
    return m_unit;
}


/***********************************************************************//**
 * @brief Set column dimension
 *
 * @param[in] dim Vector of column dimensions.
 *
 * Sets the column dimension is a integer vector @p dim.
 *
 * @todo Implement dimension check.
 ***************************************************************************/
inline
void GFitsTableCol::dim(const std::vector<int>& dim)
{
    // Set dimension
    m_dim = dim;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns column dimension
 *
 * @return Column dimensions (specified by TDIM keyword).
 ***************************************************************************/
inline
const std::vector<int>& GFitsTableCol::dim(void) const
{
    // Return column dimension
    return m_dim;
}


/***********************************************************************//**
 * @brief Set column number
 *
 * @param[in] colnum Column number.
 ***************************************************************************/
inline
void GFitsTableCol::colnum(const int& colnum)
{
    // Set column number
    m_colnum = colnum;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns column number in FITS file (starting from 1)
 *
 * @return Column number in FITS file (starting from 1).
 ***************************************************************************/
inline
const int& GFitsTableCol::colnum(void) const
{
    // Return column number
    return m_colnum;
}


/***********************************************************************//**
 * @brief Set type code
 *
 * @param[in] type Type code.
 ***************************************************************************/
inline
void GFitsTableCol::type(const int& type)
{
    // Set type code
    m_type = type;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns CFITSIO column type
 *
 * Returns one of the following:
 *   1 (TBIT)
 *  11 (TBYTE)
 *  12 (TSBYTE)
 *  14 (TLOGICAL)
 *  16 (TSTRING)
 *  21 (TUSHORT)
 *  21 (TSHORT)
 *  31 (TUINT)
 *  31 (TINT)
 *  41 (TULONG)
 *  41 (TLONG)
 *  42 (TFLOAT)
 *  81 (TLONGLONG)
 *  82 (TDOUBLE)
 *  83 (TCOMPLEX)
 * 163 (TDBLCOMPLEX)
 *
 * If the type value is negative, the column is a variable-length column.
 ***************************************************************************/
inline
const int& GFitsTableCol::type(void) const
{
    // Return column type
    return m_type;
}


/***********************************************************************//**
 * @brief Set repeat value
 *
 * @param[in] repeat Repeat value.
 ***************************************************************************/
inline
void GFitsTableCol::repeat(const int& repeat)
{
    // Set repeat
    m_repeat = repeat;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns column repeat value (only used for binary tables)
 ***************************************************************************/
inline
const int& GFitsTableCol::repeat(void) const
{
    // Return column repeat value
    return m_repeat;
}


/***********************************************************************//**
 * @brief Set width value
 *
 * @param[in] width Width value.
 ***************************************************************************/
inline
void GFitsTableCol::width(const int& width)
{
    // Set width
    m_width = width;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns width of one column element
 *
 * @return Width of one column element.
 ***************************************************************************/
inline
const int& GFitsTableCol::width(void) const
{
    // Return width of one element in column
    return m_width;
}


/***********************************************************************//**
 * @brief Set number of elements in column
 *
 * @param[in] number Number of elements in column.
 ***************************************************************************/
inline
void GFitsTableCol::number(const int& number)
{
    // Set number of elements
    m_number = number;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns number of elements in column
 *
 * @return Number of elements in column.
 ***************************************************************************/
inline
const int& GFitsTableCol::number(void) const
{
    // Return number of elements in a column
    return m_number;
}


/***********************************************************************//**
 * @brief Set number of rows in column
 *
 * @param[in] nrows Number of rows in column.
 *
 * Sets the number of rows in column.
 ***************************************************************************/
inline
void GFitsTableCol::nrows(const int& nrows)
{
    // Set length
    m_length = nrows;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns number of rows in column
 *
 * @return Number of rows in column.
 ***************************************************************************/
inline
const int& GFitsTableCol::nrows(void) const
{
    // Return column length
    return m_length;
}


/***********************************************************************//**
 * @brief Set variable-length flag
 *
 * @param[in] variable Variable-length flag.
 ***************************************************************************/
inline
void GFitsTableCol::is_variable(const bool& variable)
{
    // Set variable-length flag
    m_variable = variable;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Signals if column is of variable length
 *
 * @return True if column is a variable length column
 ***************************************************************************/
inline
const bool& GFitsTableCol::is_variable(void) const
{
    // Return variable-length flag
    return m_variable;
}


/***********************************************************************//**
 * @brief Set number of NULLs encountered
 *
 * @param[in] anynul Number of NULLs encountered.
 ***************************************************************************/
inline
void GFitsTableCol::anynul(const int& anynul)
{
    // Set number of NULLs encountered
    m_anynul = anynul;

    // Return
    return;
}


/***********************************************************************//**
 * @brief Returns number of NULLs encountered
 ***************************************************************************/
inline
const int& GFitsTableCol::anynul(void) const
{
    // Return number of NULLs encountered
    return m_anynul;
}

#endif /* GFITSTABLECOL_HPP */