Kstars
            
 
    7#include "starblockfactory.h" 
   10#include "starobject.h" 
   12#include <kstars_debug.h> 
   15#define DEFAULT_NCACHE 12 
   22        pInstance = 
new StarBlockFactory();
 
   26StarBlockFactory::StarBlockFactory()
 
   32    nCache  = DEFAULT_NCACHE;
 
   37    deleteBlocks(nBlocks);
 
 
   44    std::shared_ptr<StarBlock> freeBlock;
 
   55    if (last && (last->drawID != drawID || last->drawID == 0))
 
   58        if (last->parent->block(last->parent->getBlockCount() - 1) != last)
 
   59            qCDebug(KSTARS) << 
"ERROR: Goof up here!";
 
   66        if (freeBlock == first)
 
   71        freeBlock->prev = 
nullptr;
 
   72        freeBlock->next = 
nullptr;
 
 
   92        first->prev = first->next = 
nullptr;
 
   93        first->drawID             = drawID;
 
   99        block->drawID = drawID;
 
  107        block->prev->next = block->next;
 
  110        block->next->prev = block->prev;
 
  114    block->prev = 
nullptr;
 
  117    block->drawID = drawID;
 
 
  125    if (!block.get() || !after.get())
 
  127        qCDebug(KSTARS) << 
"WARNING: markNext called with nullptr argument";
 
  133        qCDebug(KSTARS) << 
"WARNING: markNext called without an existing linked list";
 
  139        qCDebug(KSTARS) << 
"ERROR: Trying to mark a block after itself!";
 
  143    if (block->prev == after) 
 
  145        block->drawID = drawID;
 
  151        if (block->next == 
nullptr)
 
  153            qCDebug(KSTARS) << 
"ERROR: Trying to mark only block after some other block";
 
  159    if (after->getFaintMag() > block->getFaintMag() && block->getFaintMag() != -5)
 
  161        qCDebug(KSTARS) << 
"WARNING: Marking block with faint mag = " << block->getFaintMag() << 
" after block with faint mag " 
  162                 << after->getFaintMag() << 
"in trixel" << block->parent->getTrixel();
 
  169        block->prev->next = block->next;
 
  171        block->next->prev = block->prev;
 
  173    block->next = after->next;
 
  175        block->next->prev = block;
 
  182    block->drawID = drawID;
 
 
  234int StarBlockFactory::deleteBlocks(
int nblocks)
 
  237    std::shared_ptr<StarBlock> temp;
 
  239    while (last != 
nullptr && i != nblocks)
 
  247        last->next = 
nullptr;
 
  251    qCDebug(KSTARS) << nblocks << 
"StarBlocks freed from StarBlockFactory";
 
  259    std::shared_ptr<StarBlock> cur;
 
  260    Trixel curTrixel = 513; 
 
  267        if (curTrixel != cur->parent->getTrixel())
 
  269            qCDebug(KSTARS) << 
"Trixel" << cur->parent->getTrixel() << 
"starts at index" << index;
 
  270            curTrixel = cur->parent->getTrixel();
 
  272        if (cur->drawID == drawID && !draw)
 
  274            qCDebug(KSTARS) << 
"Blocks from index" << index << 
"are drawn";
 
  277        if (cur->drawID != drawID && draw)
 
  279            qCDebug(KSTARS) << 
"Blocks from index" << index << 
"are not drawn";
 
  284    } 
while (cur != last);
 
 
  290    std::shared_ptr<StarBlock> temp;
 
  292    while (last != 
nullptr && last->drawID < drawID && i != nBlocks)
 
  300        last->next = 
nullptr;
 
  304    qCDebug(KSTARS) << i << 
"StarBlocks freed from StarBlockFactory";
 
 
A factory that creates StarBlocks and recycles them in an LRU Cache.
 
~StarBlockFactory()
Destructor Deletes the linked list that maintains the Cache, sets the pointer to nullptr.
 
bool markNext(std::shared_ptr< StarBlock > &after, std::shared_ptr< StarBlock > &block)
Rank a given StarBlock after another given StarBlock in the LRU list and sync its drawID with the cur...
 
int freeUnused()
Frees all StarBlocks that are not used in this draw cycle.
 
std::shared_ptr< StarBlock > getBlock()
Return a StarBlock available for use.
 
void printStructure() const
Prints the structure of the cache, for debugging.
 
bool markFirst(std::shared_ptr< StarBlock > &block)
Mark a StarBlock as most recently used and sync its drawID with the current drawID.
 
Holds a block of stars and various peripheral variables to mark its place in data structures.
 
  
 
  This file is part of the KDE documentation.
  Documentation copyright © 1996-2025 The KDE developers.
  Generated on Fri May 2 2025 12:02:39 by
  
doxygen 1.13.2 written
  by 
Dimitri van Heesch, © 1997-2006
  
  KDE's Doxygen guidelines are available online.