1 /*
2     SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "typedef.h"
10 
11 class DeepStarComponent;
12 class StarBlock;
13 
14 /**
15  * @class StarBlockList
16  * Maintains a list of StarBlocks that contain the stars lying in a single trixel.
17  * Takes care of the dynamic loading of stars
18  *
19  * @author Akarsh Simha
20  * @version 0.1
21  */
22 class StarBlockList
23 {
24   public:
25     /**
26      * Constructor for deep star catalogs.
27      * @param trixel The trixel ID
28      * @param parent Pointer to the parent DeepStarComponent
29      */
30     explicit StarBlockList(const Trixel &trixel, DeepStarComponent *parent = nullptr);
31 
32     /**
33      * @short Ensures that the list is loaded with stars to given magnitude limit
34      *
35      * @param maglim Magnitude limit to load stars upto
36      * @return true on success, false on failure (data file not found, bad seek etc)
37      */
38     bool fillToMag(float maglim);
39 
40     /**
41      * @short Sets the first StarBlock in the list to point to the given StarBlock
42      *
43      * This function must ideally be used only once. Also, it does not make a copy
44      * of the StarBlock supplied, but uses the pointer directly. StarBlockList will
45      * take care of deleting the StarBlock when it is destroyed
46      *
47      * @param block Pointer to the StarBlock
48      */
49     void setStaticBlock(std::shared_ptr<StarBlock> &block);
50 
51     /**
52      * @short  Drops the StarBlock with the given pointer from the list
53      * @param  block Pointer to the StarBlock to remove
54      * @return Number of entries removed from the QList
55      */
56     int releaseBlock(StarBlock *block);
57 
58     /**
59      * @short  Returns the i-th block in this StarBlockList
60      *
61      * @param  i Index of the required block
62      * @return The StarBlock requested for, nullptr if index out of bounds
63      */
block(unsigned int i)64     inline std::shared_ptr<StarBlock> block(unsigned int i) { return ((i < nBlocks) ? blocks[i] : std::shared_ptr<StarBlock>()); }
65 
66     /**
67      * @return a const reference to the contents of this StarBlockList
68      */
contents()69     inline const QList<std::shared_ptr<StarBlock>> &contents() const { return blocks; }
70 
71     /**
72      * @short  Returns the total number of stars in this StarBlockList
73      * @return Total number of stars in this StarBlockList
74      */
getStarCount()75     inline long getStarCount() const { return nStars; }
76 
77     /**
78      * @short  Returns the total number of blocks in theis StarBlockList
79      * @return Number of blocks in this StarBlockList
80      */
getBlockCount()81     inline int getBlockCount() const { return nBlocks; }
82 
83     /**
84      * @short  Returns the magnitude of the faintest star currently stored
85      * @return Magnitude of faintest star stored in this StarBlockList
86      */
getFaintMag()87     inline float getFaintMag() const { return faintMag; }
88 
89     /**
90      * @short  Returns the trixel that this SBL is meant for
91      * @return The value of trixel
92      */
getTrixel()93     inline Trixel getTrixel() const { return trixel; }
94 
95   private:
96     Trixel trixel;
97     unsigned long nStars { 0 };
98     long readOffset { 0 };
99     float faintMag { -5 };
100     QList<std::shared_ptr<StarBlock>> blocks;
101     unsigned int nBlocks { 0 };
102     bool staticStars { false };
103     DeepStarComponent *parent { nullptr };
104 };
105