KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SCRATCH_DOC< DOC > Struct Template Reference

Move-only RAII wrapper for "load a KiCad document into a non-active scratch PROJECT and clean up after. More...

#include <scratch_doc.h>

Public Types

using CLEAR_FN = std::function<void( DOC* )>
 

Public Member Functions

 SCRATCH_DOC ()=default
 
 SCRATCH_DOC (const SCRATCH_DOC &)=delete
 
SCRATCH_DOCoperator= (const SCRATCH_DOC &)=delete
 
 SCRATCH_DOC (SCRATCH_DOC &&aOther) noexcept
 
SCRATCH_DOCoperator= (SCRATCH_DOC &&aOther) noexcept
 
 ~SCRATCH_DOC ()
 

Public Attributes

SETTINGS_MANAGERmgr = nullptr
 
std::unique_ptr< DOC > doc
 
PROJECTproject = nullptr
 
CLEAR_FN clearProject
 
bool ownsProject = false
 True when this load created the project (LoadScratchDoc found the path not yet in the SettingsManager).
 

Private Member Functions

void release ()
 

Detailed Description

template<typename DOC>
struct SCRATCH_DOC< DOC >

Move-only RAII wrapper for "load a KiCad document into a non-active scratch PROJECT and clean up after.

" Pattern used by the diff/merge JOB handlers so they can load ancestor/ours/theirs documents without disturbing the active editor's project settings.

The destructor sequences cleanup in the only safe order:

  1. clearProject(doc) — severs the document's raw m_project pointer (BOARD::ClearProject / SCHEMATIC::SetProject(nullptr)).
  2. doc.reset() — destroys the document while its project is still attached to the SETTINGS_MANAGER.
  3. mgr->UnloadProject(project, false) — releases the scratch project, but only if it isn't the active Prj() (the user might have asked us to load a path that happens to be the live project).

Construct via the factory LoadScratchDoc() so the call site doesn't have to spell the LoadProject/GetProject dance.

Definition at line 164 of file scratch_doc.h.

Member Typedef Documentation

◆ CLEAR_FN

template<typename DOC>
using SCRATCH_DOC< DOC >::CLEAR_FN = std::function<void( DOC* )>

Definition at line 166 of file scratch_doc.h.

Constructor & Destructor Documentation

◆ SCRATCH_DOC() [1/3]

template<typename DOC>
SCRATCH_DOC< DOC >::SCRATCH_DOC ( )
default

◆ SCRATCH_DOC() [2/3]

template<typename DOC>
SCRATCH_DOC< DOC >::SCRATCH_DOC ( const SCRATCH_DOC< DOC > & )
delete

References SCRATCH_DOC().

◆ SCRATCH_DOC() [3/3]

template<typename DOC>
SCRATCH_DOC< DOC >::SCRATCH_DOC ( SCRATCH_DOC< DOC > && aOther)
inlinenoexcept

Definition at line 186 of file scratch_doc.h.

References SCRATCH_DOC().

◆ ~SCRATCH_DOC()

template<typename DOC>
SCRATCH_DOC< DOC >::~SCRATCH_DOC ( )
inline

Definition at line 204 of file scratch_doc.h.

References release().

Member Function Documentation

◆ operator=() [1/2]

template<typename DOC>
SCRATCH_DOC & SCRATCH_DOC< DOC >::operator= ( const SCRATCH_DOC< DOC > & )
delete

References SCRATCH_DOC().

◆ operator=() [2/2]

template<typename DOC>
SCRATCH_DOC & SCRATCH_DOC< DOC >::operator= ( SCRATCH_DOC< DOC > && aOther)
inlinenoexcept

Definition at line 188 of file scratch_doc.h.

References clearProject, doc, mgr, ownsProject, project, release(), and SCRATCH_DOC().

◆ release()

template<typename DOC>
void SCRATCH_DOC< DOC >::release ( )
inlineprivate

Definition at line 207 of file scratch_doc.h.

References clearProject, doc, mgr, ownsProject, and project.

Referenced by operator=(), and ~SCRATCH_DOC().

Member Data Documentation

◆ clearProject

template<typename DOC>
CLEAR_FN SCRATCH_DOC< DOC >::clearProject

Definition at line 171 of file scratch_doc.h.

Referenced by LoadScratchDoc(), operator=(), and release().

◆ doc

◆ mgr

template<typename DOC>
SETTINGS_MANAGER* SCRATCH_DOC< DOC >::mgr = nullptr

Definition at line 168 of file scratch_doc.h.

Referenced by LoadScratchDoc(), operator=(), and release().

◆ ownsProject

template<typename DOC>
bool SCRATCH_DOC< DOC >::ownsProject = false

True when this load created the project (LoadScratchDoc found the path not yet in the SettingsManager).

False when the project was already loaded by a previous call (e.g. ancestor and ours share a path, or the caller is diffing against the active editor's project). Only owners unload — otherwise two SCRATCH_DOCs holding the same PROJECT* would double-unload it and the second would dangle.

Definition at line 179 of file scratch_doc.h.

Referenced by LoadScratchDoc(), operator=(), and release().

◆ project

template<typename DOC>
PROJECT* SCRATCH_DOC< DOC >::project = nullptr

The documentation for this struct was generated from the following file: