Kstars

starblock.h
1 /*
2  SPDX-FileCopyrightText: 2008 Akarsh Simha <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "typedef.h"
10 #include "starblocklist.h"
11 
12 #include <QVector>
13 
14 class StarObject;
15 class StarBlockList;
16 class PointSourceNode;
17 struct StarData;
18 struct DeepStarData;
19 
20 #ifdef KSTARS_LITE
21 #include "starobject.h"
22 
23 struct StarNode
24 {
25  StarNode();
26  ~StarNode();
27 
28  StarObject star;
29  PointSourceNode *starNode;
30 };
31 #endif
32 
33 /**
34  * @class StarBlock
35  *
36  * Holds a block of stars and various peripheral variables to mark its place in data structures
37  *
38  * @author Akarsh Simha
39  * @version 1.0
40  */
41 
42 class StarBlock
43 {
44  public:
45 // StarBlockEntry is the data type held by the StarBlock's QVector
46 #ifdef KSTARS_LITE
47  typedef StarNode StarBlockEntry;
48 #else
49  typedef StarObject StarBlockEntry;
50 #endif
51 
52  /**
53  * Constructor
54  *
55  * Initializes values of various parameters and creates nstars number of stars
56  *
57  * @param nstars Number of stars to hold in this StarBlock
58  */
59  explicit StarBlock(int nstars = 100);
60 
61  ~StarBlock() = default;
62 
63  /**
64  * @short Initialize another star with data.
65  *
66  * FIXME: StarObject::init doesn't reset object name(s). It
67  * shouldn't be issue since stars which are swapped in/out do not
68  * have names.
69  *
70  * @param data data to initialize star with.
71  * @return pointer to star initialized with data. nullptr if block is full.
72  */
73  StarBlockEntry *addStar(const StarData &data);
74  StarBlockEntry *addStar(const DeepStarData &data);
75 
76  /**
77  * @short Returns true if the StarBlock is full
78  *
79  * @return true if full, false if not full
80  */
81  inline bool isFull() const { return nStars == size(); }
82 
83  /**
84  * @short Return the capacity of this StarBlock
85  *
86  * This is different from nStars. While nStars indicates the number of stars that this StarBlock
87  * actually holds, this method returns the number of stars for which we have allocated memory.
88  * Thus, this method should return a number >= nStars.
89  *
90  * @return The number of stars that this StarBlock can hold
91  */
92  inline int size() const { return stars.size(); }
93 
94  /**
95  * @short Return the i-th star in this StarBlock
96  *
97  * @param i Index of StarBlock to return
98  * @return A pointer to the i-th StarObject
99  */
100  inline StarBlockEntry *star(int i) { return &stars[i]; }
101 
102  /**
103  * @return a reference to the internal container of this
104  * @note This is bad -- is there a way of providing non-const access to the list's elements
105  * without allowing altering of the list alone?
106  */
107 
108  inline QVector<StarBlockEntry> &contents() { return stars; }
109 
110  // These methods are there because we might want to make faintMag and brightMag private at some point
111  /**
112  * @short Return the magnitude of the brightest star in this StarBlock
113  *
114  * @return Magnitude of the brightest star
115  */
116  inline float getBrightMag() const { return brightMag; }
117 
118  /**
119  * @short Return the magnitude of the faintest star in this StarBlock
120  *
121  * @return Magnitude of the faintest star
122  */
123  inline float getFaintMag() const { return faintMag; }
124 
125  /**
126  * @short Return the number of stars currently filled in this StarBlock
127  *
128  * @return Number of stars filled in this StarBlock
129  */
130  inline int getStarCount() const { return nStars; }
131 
132  /** @short Reset this StarBlock's data, for reuse of the StarBlock */
133  void reset();
134 
135  float faintMag { 0 };
136  float brightMag { 0 };
137  StarBlockList *parent;
138  std::shared_ptr<StarBlock> prev;
139  std::shared_ptr<StarBlock> next;
140  quint32 drawID { 0 };
141 
142  private:
143  // Disallow copying and assignment. Just in case.
144  StarBlock(const StarBlock &);
145  StarBlock &operator=(const StarBlock &);
146 
147  /** Number of initialized stars in StarBlock. */
148  int nStars { 0 };
149  /** Array of stars. */
151 };
float getFaintMag() const
Return the magnitude of the faintest star in this StarBlock.
Definition: starblock.h:123
A 32-byte Structure that holds star data.
Definition: stardata.h:17
void reset()
Reset this StarBlock's data, for reuse of the StarBlock.
Definition: starblock.cpp:43
int size() const
Return the capacity of this StarBlock.
Definition: starblock.h:92
bool isFull() const
Returns true if the StarBlock is full.
Definition: starblock.h:81
float getBrightMag() const
Return the magnitude of the brightest star in this StarBlock.
Definition: starblock.h:116
StarBlockEntry * addStar(const StarData &data)
Initialize another star with data.
Definition: starblock.cpp:85
subclass of SkyObject specialized for stars.
Definition: starobject.h:32
A SkyNode derived class that represents stars and objects that are drawn as stars.
StarBlockEntry * star(int i)
Return the i-th star in this StarBlock.
Definition: starblock.h:100
A 16-byte structure that holds star data for really faint stars.
int getStarCount() const
Return the number of stars currently filled in this StarBlock.
Definition: starblock.h:130
StarBlock(int nstars=100)
Constructor.
Definition: starblock.cpp:33
QVector< StarBlockEntry > & contents()
Definition: starblock.h:108
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:02:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.