Implement poor-man's RTTI for use over KiWAY.

Fixes: lp:1777883
* https://bugs.launchpad.net/kicad/+bug/1777883
This commit is contained in:
Jeff Young 2018-09-15 12:05:54 +01:00
parent 872e1e6532
commit 02a3f83040
11 changed files with 26 additions and 6 deletions

View File

@ -30,6 +30,8 @@
class CACHE_WRAPPER : public S3D_CACHE, public PROJECT::_ELEM
{
public:
KICAD_T Type() override { return CACHE_WRAPPER_T; }
CACHE_WRAPPER();
virtual ~CACHE_WRAPPER();
};

View File

@ -401,7 +401,7 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs( KIWAY& aKiway )
FP_LIB_TABLE* tbl = (FP_LIB_TABLE*) GetElem( ELEM_FPTBL );
// its gotta be NULL or a FP_LIB_TABLE, or a bug.
wxASSERT( !tbl || dynamic_cast<FP_LIB_TABLE*>( tbl ) );
wxASSERT( !tbl || tbl->Type() == FP_LIB_TABLE_T );
if( !tbl )
{

View File

@ -189,8 +189,9 @@ typedef boost::ptr_vector< PART_LIB > PART_LIBS_BASE;
class PART_LIBS : public PART_LIBS_BASE, public PROJECT::_ELEM
{
public:
KICAD_T Type() override { return PART_LIBS_T; }
static int s_modify_generation; ///< helper for GetModifyHash()
static int s_modify_generation; ///< helper for GetModifyHash()
PART_LIBS()
{

View File

@ -641,7 +641,7 @@ SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
SYMBOL_LIB_TABLE* tbl = (SYMBOL_LIB_TABLE*) GetElem( ELEM_SYMBOL_LIB_TABLE );
// its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
wxASSERT( !tbl || dynamic_cast<SYMBOL_LIB_TABLE*>( tbl ) );
wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
if( !tbl )
{

View File

@ -154,9 +154,9 @@ SEARCH_STACK* PROJECT::SchSearchS()
PART_LIBS* PROJECT::SchLibs()
{
PART_LIBS* libs = (PART_LIBS*) GetElem( PROJECT::ELEM_SCH_PART_LIBS );
PART_LIBS* libs = (PART_LIBS*) GetElem( PROJECT::ELEM_SCH_PART_LIBS );
wxASSERT( !libs || dynamic_cast<PART_LIBS*>( libs ) );
wxASSERT( !libs || libs->Type() == PART_LIBS_T );
if( !libs )
{

View File

@ -107,6 +107,8 @@ class SYMBOL_LIB_TABLE : public LIB_TABLE
static int m_modifyHash; ///< helper for GetModifyHash()
public:
KICAD_T Type() override { return SYMBOL_LIB_TABLE_T; }
static const char* PropPowerSymsOnly;
static const char* PropNonPowerSymsOnly;

View File

@ -169,6 +169,15 @@ enum KICAD_T
*/
TYPE_PL_EDITOR_LAYOUT,
/*
* FOR PROJECT::_ELEMs
*/
SYMBOL_LIB_TABLE_T,
FP_LIB_TABLE_T,
PART_LIBS_T,
SEARCH_STACK_T,
CACHE_WRAPPER_T,
// End value
MAX_STRUCT_TYPE_ID
};

View File

@ -105,6 +105,7 @@ class FP_LIB_TABLE : public LIB_TABLE
friend class FP_LIB_TABLE_GRID;
public:
KICAD_T Type() override { return FP_LIB_TABLE_T; }
virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;

View File

@ -30,6 +30,7 @@
#include <vector>
#include <wx/string.h>
#include <wx/filename.h>
#include <core/typeinfo.h>
/// A variable name whose value holds the current project directory.
/// Currently an environment variable, eventually a project variable.
@ -67,6 +68,8 @@ public:
{
public:
virtual ~_ELEM() {}
virtual KICAD_T Type() = 0; // Sanity-checking for returned values.
};
PROJECT();

View File

@ -42,6 +42,8 @@ class SEARCH_STACK : public wxPathList, public PROJECT::_ELEM
{
public:
KICAD_T Type() override { return SEARCH_STACK_T; }
#if defined(DEBUG)
void Show( const wxString& aPrefix ) const;
#endif

View File

@ -172,7 +172,7 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs()
FP_LIB_TABLE* tbl = (FP_LIB_TABLE*) GetElem( ELEM_FPTBL );
// its gotta be NULL or a FP_LIB_TABLE, or a bug.
wxASSERT( !tbl || dynamic_cast<FP_LIB_TABLE*>( tbl ) );
wxASSERT( !tbl || tbl->Type() == FP_LIB_TABLE_T );
if( !tbl )
{