File indexing completed on 2024-04-21 14:46:40

0001 /*
0002     SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "typedef.h"
0010 
0011 class DeepStarComponent;
0012 class StarBlock;
0013 
0014 /**
0015  * @class StarBlockList
0016  * Maintains a list of StarBlocks that contain the stars lying in a single trixel.
0017  * Takes care of the dynamic loading of stars
0018  *
0019  * @author Akarsh Simha
0020  * @version 0.1
0021  */
0022 class StarBlockList
0023 {
0024   public:
0025     /**
0026      * Constructor for deep star catalogs.
0027      * @param trixel The trixel ID
0028      * @param parent Pointer to the parent DeepStarComponent
0029      */
0030     explicit StarBlockList(const Trixel &trixel, DeepStarComponent *parent = nullptr);
0031 
0032     /**
0033      * @short Ensures that the list is loaded with stars to given magnitude limit
0034      *
0035      * @param maglim Magnitude limit to load stars upto
0036      * @return true on success, false on failure (data file not found, bad seek etc)
0037      */
0038     bool fillToMag(float maglim);
0039 
0040     /**
0041      * @short Sets the first StarBlock in the list to point to the given StarBlock
0042      *
0043      * This function must ideally be used only once. Also, it does not make a copy
0044      * of the StarBlock supplied, but uses the pointer directly. StarBlockList will
0045      * take care of deleting the StarBlock when it is destroyed
0046      *
0047      * @param block Pointer to the StarBlock
0048      */
0049     void setStaticBlock(std::shared_ptr<StarBlock> &block);
0050 
0051     /**
0052      * @short  Drops the StarBlock with the given pointer from the list
0053      * @param  block Pointer to the StarBlock to remove
0054      * @return Number of entries removed from the QList
0055      */
0056     int releaseBlock(StarBlock *block);
0057 
0058     /**
0059      * @short  Returns the i-th block in this StarBlockList
0060      *
0061      * @param  i Index of the required block
0062      * @return The StarBlock requested for, nullptr if index out of bounds
0063      */
0064     inline std::shared_ptr<StarBlock> block(unsigned int i) { return ((i < nBlocks) ? blocks[i] : std::shared_ptr<StarBlock>()); }
0065 
0066     /**
0067      * @return a const reference to the contents of this StarBlockList
0068      */
0069     inline const QList<std::shared_ptr<StarBlock>> &contents() const { return blocks; }
0070 
0071     /**
0072      * @short  Returns the total number of stars in this StarBlockList
0073      * @return Total number of stars in this StarBlockList
0074      */
0075     inline long getStarCount() const { return nStars; }
0076 
0077     /**
0078      * @short  Returns the total number of blocks in theis StarBlockList
0079      * @return Number of blocks in this StarBlockList
0080      */
0081     inline int getBlockCount() const { return nBlocks; }
0082 
0083     /**
0084      * @short  Returns the magnitude of the faintest star currently stored
0085      * @return Magnitude of faintest star stored in this StarBlockList
0086      */
0087     inline float getFaintMag() const { return faintMag; }
0088 
0089     /**
0090      * @short  Returns the trixel that this SBL is meant for
0091      * @return The value of trixel
0092      */
0093     inline Trixel getTrixel() const { return trixel; }
0094 
0095   private:
0096     Trixel trixel;
0097     unsigned long nStars { 0 };
0098     long readOffset { 0 };
0099     float faintMag { -5 };
0100     QList<std::shared_ptr<StarBlock>> blocks;
0101     unsigned int nBlocks { 0 };
0102     bool staticStars { false };
0103     DeepStarComponent *parent { nullptr };
0104 };