37#include <unordered_set>
58template <ALLEGRO_BLOCK_DATA BLK_T>
62 if constexpr( std::is_same_v<BLK_T, BLK_0x15_16_17_SEGMENT> )
63 return aType == 0x15 || aType == 0x16 || aType == 0x17;
65 return aType == BLK_T::BLOCK_TYPE_CODE;
73template <ALLEGRO_BLOCK_DATA BLK_T>
77 return static_cast<const BLOCK<BLK_T>&
>( aBlock ).GetData();
87template <ALLEGRO_BLOCK_DATA BLK_T>
105 explicit operator bool()
const {
return m_block !=
nullptr; }
109 wxASSERT(
m_block !=
nullptr );
115 wxASSERT(
m_block !=
nullptr );
195 m_current = ( *m_nextFunc )( *m_currBlock );
302template <ALLEGRO_BLOCK_DATA T>
349 const auto blockTypeDesc = []() -> wxString
351 if constexpr( std::is_same_v<T, BLK_0x15_16_17_SEGMENT> )
352 return wxS(
"0x15/0x16/0x17 (segment)" );
354 return wxString::Format( wxS(
"%#04x" ), T::BLOCK_TYPE_CODE );
361 wxString::Format(
"Expected block type %s, got %#04x", blockTypeDesc(), blockType ) );
363 wxLogTrace(
traceAllegroUtils,
"Expected block type %s, got %#04x, skipping", blockTypeDesc(),
368 ( *m_reporter )( blockType, *block );
434 uint16_t aFieldCode );
440 uint16_t aFieldCode );
The base class for all blocks in the main body of an Allegro file.
uint8_t GetBlockType() const
This is the actual type code as read from the file.
const BLOCK_BASE * m_block
const BLK_T & operator*() const
BLOCK_REF(const BLOCK_BASE *aBlock)
const BLK_T * operator->() const
const BLOCK_BASE * Block() const
An Allegro board database representing the contents of a .brd (and presumably .dra) file.
const BLOCK_BASE * operator*() const
std::unordered_set< uint32_t > m_visited
friend bool operator==(const ITERATOR &aLhs, const ITERATOR &aRhs)
ITERATOR()
Usually constructed as an end-of-list sentinel.
const BLOCK_BASE * m_currBlock
const NEXT_FUNC_T * m_nextFunc
ITERATOR(uint32_t aCurrent, uint32_t aTail, const BRD_DB &aBoard, const NEXT_FUNC_T &aNextFunc)
Actual object ITERATOR.
Range-for-compatible walker over a linked list of BLOCK_BASE objects in a BRD_DB.
LL_WALKER(const FILE_HEADER::LINKED_LIST &aList, const BRD_DB &aBoard, NEXT_FUNC_T aNextFunc=GetPrimaryNext)
Convenience constructor for linked lists in the file header.
NEXT_FUNC_T m_nextFunction
std::function< uint32_t(const BLOCK_BASE &)> NEXT_FUNC_T
LL_WALKER(uint32_t aHead, uint32_t aTail, const BRD_DB &aBoard, NEXT_FUNC_T aNextFunc=GetPrimaryNext)
General constructor for walking any linked list given head/tail keys, a database, and a next-function...
const MISMATCH_REPORTER * m_reporter
const T * operator->() const
size_t GetBlockOffset() const
File offset of the current underlying block (for diagnostics).
const T & operator*() const
friend bool operator==(const ITERATOR &aLhs, const ITERATOR &aRhs)
LL_WALKER::ITERATOR m_baseIter
ITERATOR()=default
End sentinel.
ITERATOR(LL_WALKER::ITERATOR aCurrent, MISMATCH_POLICY aPolicy, const MISMATCH_REPORTER *aReporter)
TYPED_LL_WALKER(const FILE_HEADER::LINKED_LIST &aList, const BRD_DB &aBoard, MISMATCH_POLICY aPolicy=MISMATCH_POLICY::SKIP, LL_WALKER::NEXT_FUNC_T aNextFunc=GetPrimaryNext)
void SetMismatchReporter(MISMATCH_REPORTER aReporter)
TYPED_LL_WALKER(uint32_t aHead, uint32_t aTail, const BRD_DB &aBoard, MISMATCH_POLICY aPolicy=MISMATCH_POLICY::SKIP, LL_WALKER::NEXT_FUNC_T aNextFunc=GetPrimaryNext)
MISMATCH_REPORTER m_mismatchReporter
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
constexpr bool BlockTypeMatches(uint8_t aType)
Check whether a runtime block type code matches the expected type for T.
MISMATCH_POLICY
Policy for TYPED_LL_WALKER when a block with an unexpected type code is encountered.
@ THROW
THROW_IO_ERROR on mismatch.
@ LOG_TRACE
wxLogTrace the mismatch and skip
@ SKIP
silently skip blocks with the wrong type
@ REPORT
invoke a user-supplied callback, then skip
std::optional< FIELD_VALUE > GetFirstFieldOfType(const BRD_DB &aDb, uint32_t aFieldsPtr, uint32_t aEndKey, uint16_t aFieldCode)
Look up the first 0x03 FIELD value of a given type in a linked field chain.
std::optional< int > GetFirstFieldOfTypeInt(const BRD_DB &aDb, uint32_t aFieldsPtr, uint32_t aEndKey, uint16_t aFieldCode)
Convenience wrapper around GetFirstFieldOfType() for integer-valued fields.
uint32_t GetPrimaryNext(const BLOCK_BASE &aBlock)
Get the next block key in the linked list for a given block.
const wxChar *const traceAllegroUtils
std::function< void(uint8_t aGotType, const BLOCK_BASE &aBlock)> MISMATCH_REPORTER
Callback signature for MISMATCH_POLICY::REPORT.
const BLK_T & BlockDataAs(const BLOCK_BASE &aBlock)
Cast a BLOCK_BASE to a typed BLOCK<T> and return the data.
std::variant< wxString, uint32_t > FIELD_VALUE
Some value stored in an 0x03 FIELD block.