File indexing completed on 2024-04-21 03:44:38

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 #include "starblocklist.h"
0011 
0012 #include <QVector>
0013 
0014 class StarObject;
0015 class StarBlockList;
0016 class PointSourceNode;
0017 struct StarData;
0018 struct DeepStarData;
0019 
0020 #ifdef KSTARS_LITE
0021 #include "starobject.h"
0022 
0023 struct StarNode
0024 {
0025     StarNode();
0026     ~StarNode();
0027 
0028     StarObject star;
0029     PointSourceNode *starNode;
0030 };
0031 #endif
0032 
0033 /**
0034  * @class StarBlock
0035  *
0036  * Holds a block of stars and various peripheral variables to mark its place in data structures
0037  *
0038  * @author  Akarsh Simha
0039  * @version 1.0
0040  */
0041 
0042 class StarBlock
0043 {
0044   public:
0045 // StarBlockEntry is the data type held by the StarBlock's QVector
0046 #ifdef KSTARS_LITE
0047     typedef StarNode StarBlockEntry;
0048 #else
0049     typedef StarObject StarBlockEntry;
0050 #endif
0051 
0052     /**
0053      * Constructor
0054      *
0055      * Initializes values of various parameters and creates nstars number of stars
0056      *
0057      * @param nstars   Number of stars to hold in this StarBlock
0058      */
0059     explicit StarBlock(int nstars = 100);
0060 
0061     ~StarBlock() = default;
0062 
0063     /**
0064      * @short Initialize another star with data.
0065      *
0066      * FIXME: StarObject::init doesn't reset object name(s). It
0067      * shouldn't be issue since stars which are swapped in/out do not
0068      * have names.
0069      *
0070      * @param  data    data to initialize star with.
0071      * @return pointer to star initialized with data. nullptr if block is full.
0072      */
0073     StarBlockEntry *addStar(const StarData &data);
0074     StarBlockEntry *addStar(const DeepStarData &data);
0075 
0076     /**
0077      * @short Returns true if the StarBlock is full
0078      *
0079      * @return true if full, false if not full
0080      */
0081     inline bool isFull() const { return nStars == size(); }
0082 
0083     /**
0084      * @short  Return the capacity of this StarBlock
0085      *
0086      * This is different from nStars. While nStars indicates the number of stars that this StarBlock
0087      * actually holds, this method returns the number of stars for which we have allocated memory.
0088      * Thus, this method should return a number >= nStars.
0089      *
0090      * @return The number of stars that this StarBlock can hold
0091      */
0092     inline int size() const { return stars.size(); }
0093 
0094     /**
0095      * @short  Return the i-th star in this StarBlock
0096      *
0097      * @param  i Index of StarBlock to return
0098      * @return A pointer to the i-th StarObject
0099      */
0100     inline StarBlockEntry *star(int i) { return &stars[i]; }
0101 
0102     /**
0103      * @return a reference to the internal container of this
0104      * @note This is bad -- is there a way of providing non-const access to the list's elements
0105      * without allowing altering of the list alone?
0106      */
0107 
0108     inline QVector<StarBlockEntry> &contents() { return stars; }
0109 
0110     // These methods are there because we might want to make faintMag and brightMag private at some point
0111     /**
0112      * @short  Return the magnitude of the brightest star in this StarBlock
0113      *
0114      * @return Magnitude of the brightest star
0115      */
0116     inline float getBrightMag() const { return brightMag; }
0117 
0118     /**
0119      * @short  Return the magnitude of the faintest star in this StarBlock
0120      *
0121      * @return Magnitude of the faintest star
0122      */
0123     inline float getFaintMag() const { return faintMag; }
0124 
0125     /**
0126      * @short  Return the number of stars currently filled in this StarBlock
0127      *
0128      * @return Number of stars filled in this StarBlock
0129      */
0130     inline int getStarCount() const { return nStars; }
0131 
0132     /** @short  Reset this StarBlock's data, for reuse of the StarBlock */
0133     void reset();
0134 
0135     float faintMag { 0 };
0136     float brightMag { 0 };
0137     StarBlockList *parent;
0138     std::shared_ptr<StarBlock> prev;
0139     std::shared_ptr<StarBlock> next;
0140     quint32 drawID { 0 };
0141 
0142   private:
0143     // Disallow copying and assignment. Just in case.
0144     StarBlock(const StarBlock &);
0145     StarBlock &operator=(const StarBlock &);
0146 
0147     /** Number of initialized stars in StarBlock. */
0148     int nStars { 0 };
0149     /** Array of stars. */
0150     QVector<StarBlockEntry> stars;
0151 };