OpenBarnyard
 
Loading...
Searching...
No Matches
PTRBSymbols Class Reference

#include <PTRB.h>

Public Member Functions

 PTRBSymbols ()
 
void Reset ()
 
TBOOL Is (TUINT index, const TCHAR *name)
 
TINT FindIndex (PTRBSections &sect, const TCHAR *name)
 
TINT FindIndex (PTRBSections *sect, const TCHAR *name)
 
template<class T>
PTRBSections::MemoryStream::Ptr< T > Get (PTRBSections &sect, TINT index)
 
template<class T>
PTRBSections::MemoryStream::Ptr< T > Find (PTRBSections &sect, const TCHAR *name)
 
template<class T>
PTRBSections::MemoryStream::Ptr< T > Find (PTRBSections *sect, const TCHAR *name)
 
PTRBSections::MemoryStreamFindStack (PTRBSections &sect, const TCHAR *name)
 
PTRBSections::MemoryStreamFindStack (PTRBSections *sect, const TCHAR *name)
 
template<class T>
PTRBSections::MemoryStream::Ptr< T > GetByIndex (PTRBSections &sect, TUINT index)
 
template<class T>
PTRBSections::MemoryStream::Ptr< T > GetByIndex (PTRBSections *sect, TUINT index)
 
PTRBSections::MemoryStreamGetStack (PTRBSections &sect, TUINT index)
 
PTRBSections::MemoryStreamGetStack (PTRBSections *sect, TUINT index)
 
Toshi::T2StringView GetName (TUINT index)
 
TUINT GetCount ()
 
void Add (PTRBSections::MemoryStream *pStream, const TCHAR *name, void *ptr)
 
void UpdateSymbolsIndexes (PTRBSections::MemoryStream *pStream, TUINT32 newIndex)
 
void Remove (TUINT index)
 
void RemoveAllWithStackIndex (TINT stackIndex)
 
void Write (Toshi::TTSFO &ttsfo, Endianess eEndianess)
 
void Read (Toshi::TTSFI &ttsfi, PTRBSections &sect, Endianess eEndianess)
 
std::vector< Toshi::TString8 >::iterator begin ()
 
std::vector< Toshi::TString8 >::iterator end ()
 

Detailed Description

Definition at line 337 of file PTRB.h.

Constructor & Destructor Documentation

◆ PTRBSymbols()

PTRBSymbols::PTRBSymbols ( )
inline

Definition at line 340 of file PTRB.h.

341 {
342 Reset();
343 }
void Reset()
Definition PTRB.h:345

Member Function Documentation

◆ Add()

void PTRBSymbols::Add ( PTRBSections::MemoryStream * pStream,
const TCHAR * name,
void * ptr )
inline

Definition at line 480 of file PTRB.h.

481 {
482 m_Symbols.emplace_back( pStream->GetIndex(), 0, 0, 0, pStream->GetOffset( ptr ) );
483 m_SymbolNames.push_back( name );
484 }
TUINT32 GetIndex() const
Definition PTRB.h:203
TUINT GetOffset(const void *ptr) const
Definition PTRB.h:215

◆ begin()

std::vector< Toshi::TString8 >::iterator PTRBSymbols::begin ( )
inline

Definition at line 586 of file PTRB.h.

586{ return m_SymbolNames.begin(); }

◆ end()

std::vector< Toshi::TString8 >::iterator PTRBSymbols::end ( )
inline

Definition at line 587 of file PTRB.h.

587{ return m_SymbolNames.end(); }

◆ Find() [1/2]

template<class T>
PTRBSections::MemoryStream::Ptr< T > PTRBSymbols::Find ( PTRBSections & sect,
const TCHAR * name )
inline

Definition at line 405 of file PTRB.h.

406 {
407 TINT index = FindIndex( sect, name );
408
409 if ( index != -1 )
410 {
411 auto stack = sect.GetStack( m_Symbols[ index ].HDRX );
412 return { stack, m_Symbols[ index ].DataOffset };
413 }
414
415 return { TNULL, (TUINT)0 };
416 }
unsigned int TUINT
Definition Typedefs.h:8
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
PTRBSections::MemoryStream * GetStack(TUINT index)
Definition PTRB.h:1052
TINT FindIndex(PTRBSections &sect, const TCHAR *name)
Definition PTRB.h:369

◆ Find() [2/2]

template<class T>
PTRBSections::MemoryStream::Ptr< T > PTRBSymbols::Find ( PTRBSections * sect,
const TCHAR * name )
inline

Definition at line 419 of file PTRB.h.

420 {
421 return Find<T>( *sect, name );
422 }
PTRBSections::MemoryStream::Ptr< T > Find(PTRBSections &sect, const TCHAR *name)
Definition PTRB.h:405

◆ FindIndex() [1/2]

TINT PTRBSymbols::FindIndex ( PTRBSections & sect,
const TCHAR * name )
inline

Definition at line 369 of file PTRB.h.

370 {
371 auto hash = Toshi::TTRB::HashString( name );
372
373 for ( TUINT i = 0; i < m_Symbols.size(); i++ )
374 {
375 if ( m_Symbols[ i ].NameHash == hash )
376 {
377 if ( m_SymbolNames[ i ] == name )
378 {
379 return i;
380 }
381 }
382 }
383
384 return -1;
385 }

◆ FindIndex() [2/2]

TINT PTRBSymbols::FindIndex ( PTRBSections * sect,
const TCHAR * name )
inline

Definition at line 387 of file PTRB.h.

388 {
389 return FindIndex( *sect, name );
390 }

◆ FindStack() [1/2]

PTRBSections::MemoryStream * PTRBSymbols::FindStack ( PTRBSections & sect,
const TCHAR * name )
inline

Definition at line 424 of file PTRB.h.

425 {
426 TINT index = FindIndex( sect, name );
427
428 if ( index != -1 )
429 {
430 auto stack = sect.GetStack( m_Symbols[ index ].HDRX );
431 return stack;
432 }
433
434 return TNULL;
435 }

◆ FindStack() [2/2]

PTRBSections::MemoryStream * PTRBSymbols::FindStack ( PTRBSections * sect,
const TCHAR * name )
inline

Definition at line 437 of file PTRB.h.

438 {
439 return FindStack( *sect, name );
440 }
PTRBSections::MemoryStream * FindStack(PTRBSections &sect, const TCHAR *name)
Definition PTRB.h:424

◆ Get()

template<class T>
PTRBSections::MemoryStream::Ptr< T > PTRBSymbols::Get ( PTRBSections & sect,
TINT index )
inline

Definition at line 393 of file PTRB.h.

394 {
395 if ( index != -1 && (TINT)m_Symbols.size() > index )
396 {
397 auto stack = sect.GetStack( m_Symbols[ index ].HDRX );
398 return { stack, m_Symbols[ index ].DataOffset };
399 }
400
401 return { TNULL, (TUINT)0 };
402 }

◆ GetByIndex() [1/2]

template<class T>
PTRBSections::MemoryStream::Ptr< T > PTRBSymbols::GetByIndex ( PTRBSections & sect,
TUINT index )
inline

Definition at line 443 of file PTRB.h.

444 {
445 TASSERT( index < m_Symbols.size() );
446
447 return {
448 sect.GetStack( m_Symbols[ index ].HDRX ),
449 m_Symbols[ index ].DataOffset
450 };
451 }
#define TASSERT(X,...)
Definition Defines.h:138

◆ GetByIndex() [2/2]

template<class T>
PTRBSections::MemoryStream::Ptr< T > PTRBSymbols::GetByIndex ( PTRBSections * sect,
TUINT index )
inline

Definition at line 454 of file PTRB.h.

455 {
456 return GetByIndex<T>( *sect, index );
457 }
PTRBSections::MemoryStream::Ptr< T > GetByIndex(PTRBSections &sect, TUINT index)
Definition PTRB.h:443

◆ GetCount()

TUINT PTRBSymbols::GetCount ( )
inline

Definition at line 475 of file PTRB.h.

476 {
477 return m_Symbols.size();
478 }

◆ GetName()

Toshi::T2StringView PTRBSymbols::GetName ( TUINT index)
inline

Definition at line 470 of file PTRB.h.

471 {
472 return m_SymbolNames[ index ].GetString();
473 }

◆ GetStack() [1/2]

PTRBSections::MemoryStream * PTRBSymbols::GetStack ( PTRBSections & sect,
TUINT index )
inline

Definition at line 459 of file PTRB.h.

460 {
461 TASSERT( index < m_Symbols.size() );
462 return sect.GetStack( m_Symbols[ index ].HDRX );
463 }

◆ GetStack() [2/2]

PTRBSections::MemoryStream * PTRBSymbols::GetStack ( PTRBSections * sect,
TUINT index )
inline

Definition at line 465 of file PTRB.h.

466 {
467 return GetStack( *sect, index );
468 }
PTRBSections::MemoryStream * GetStack(PTRBSections &sect, TUINT index)
Definition PTRB.h:459

◆ Is()

TBOOL PTRBSymbols::Is ( TUINT index,
const TCHAR * name )
inline

Definition at line 353 of file PTRB.h.

354 {
355 TASSERT( index >= 0 && index < m_Symbols.size() );
356 auto hash = Toshi::TTRB::HashString( name );
357
358 if ( m_Symbols[ index ].NameHash == hash )
359 {
360 if ( m_SymbolNames[ index ] == name )
361 {
362 return TTRUE;
363 }
364 }
365
366 return TFALSE;
367 }
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25

◆ Read()

void PTRBSymbols::Read ( Toshi::TTSFI & ttsfi,
PTRBSections & sect,
Endianess eEndianess )
inline

Definition at line 554 of file PTRB.h.

555 {
556 TUINT32 symbolCount = 0;
557 ttsfi.Read( &symbolCount );
558 symbolCount = CONVERTENDIANESS( eEndianess, symbolCount );
559
560 // Read symbols
561 TUINT symbolsSize = sizeof( Toshi::TTRB::TTRBSymbol ) * symbolCount;
562 m_Symbols.resize( symbolCount );
563 ttsfi.ReadRaw( m_Symbols.data(), symbolsSize );
564
565 // Read symbol names
566 TUINT namesSize = ttsfi.GetCurrentHunk().Size - symbolsSize;
567 m_SymbolNames.reserve( symbolCount );
568 TCHAR* namesBuffer = new TCHAR[ namesSize ];
569 ttsfi.ReadRaw( namesBuffer, namesSize );
570
571 for ( auto& symbol : m_Symbols )
572 {
573 symbol.HDRX = CONVERTENDIANESS( eEndianess, symbol.HDRX );
574 symbol.NameHash = CONVERTENDIANESS( eEndianess, symbol.NameHash );
575 symbol.NameOffset = CONVERTENDIANESS( eEndianess, symbol.NameOffset );
576 symbol.Padding = CONVERTENDIANESS( eEndianess, symbol.Padding );
577 symbol.DataOffset = CONVERTENDIANESS( eEndianess, symbol.DataOffset );
578
579 const TCHAR* symbolName = &namesBuffer[ symbol.NameOffset ];
580 m_SymbolNames.push_back( symbolName );
581 }
582
583 delete[] namesBuffer;
584 }
char TCHAR
Definition Typedefs.h:20
uint32_t TUINT32
Definition Typedefs.h:13

◆ Remove()

void PTRBSymbols::Remove ( TUINT index)
inline

Definition at line 501 of file PTRB.h.

502 {
503 TASSERT( index >= 0 && index < m_Symbols.size() );
504
505 m_Symbols.erase( m_Symbols.begin() + index );
506 m_SymbolNames.erase( m_SymbolNames.begin() + index );
507 }

◆ RemoveAllWithStackIndex()

void PTRBSymbols::RemoveAllWithStackIndex ( TINT stackIndex)
inline

Definition at line 509 of file PTRB.h.

510 {
511 for ( TUINT i = 0; i < m_Symbols.size(); )
512 {
513 if ( m_Symbols[ i ].HDRX == stackIndex )
514 {
515 Remove( i );
516 }
517 else
518 {
519 i++;
520 }
521 }
522 }
void Remove(TUINT index)
Definition PTRB.h:501

◆ Reset()

void PTRBSymbols::Reset ( )
inline

Definition at line 345 of file PTRB.h.

346 {
347 m_Symbols.clear();
348 m_SymbolNames.clear();
349 m_Symbols.reserve( 5 );
350 m_SymbolNames.reserve( 5 );
351 }

◆ UpdateSymbolsIndexes()

void PTRBSymbols::UpdateSymbolsIndexes ( PTRBSections::MemoryStream * pStream,
TUINT32 newIndex )
inline

Definition at line 486 of file PTRB.h.

487 {
488 auto stackIndex = pStream->GetIndex();
489
490 for ( TUINT i = 0; i < m_Symbols.size(); i++ )
491 {
492 if ( m_Symbols[ i ].HDRX == stackIndex )
493 {
494 m_Symbols[ i ].HDRX = newIndex;
495 }
496 }
497
498 pStream->SetIndex( newIndex );
499 }
TUINT32 SetIndex(TUINT32 index)
Definition PTRB.h:192

◆ Write()

void PTRBSymbols::Write ( Toshi::TTSFO & ttsfo,
Endianess eEndianess )
inline

Definition at line 524 of file PTRB.h.

525 {
526 TASSERT( m_Symbols.size() == m_SymbolNames.size(), "" );
527
528 TUINT32 nameOffset = 0;
529 TUINT32 symbolCount = m_Symbols.size();
530 ttsfo.Write( CONVERTENDIANESS( eEndianess, symbolCount ) );
531
532 for ( TUINT i = 0; i < m_Symbols.size(); i++ )
533 {
534 m_Symbols[ i ].NameHash = Toshi::TTRB::HashString( m_SymbolNames[ i ] );
535 m_Symbols[ i ].NameOffset = nameOffset;
536 nameOffset += m_SymbolNames[ i ].Length() + 1;
537
538 Toshi::TTRB::TTRBSymbol oFixedSymbol;
539 oFixedSymbol.HDRX = CONVERTENDIANESS( eEndianess, m_Symbols[ i ].HDRX );
540 oFixedSymbol.NameHash = CONVERTENDIANESS( eEndianess, m_Symbols[ i ].NameHash );
541 oFixedSymbol.NameOffset = CONVERTENDIANESS( eEndianess, m_Symbols[ i ].NameOffset );
542 oFixedSymbol.Padding = CONVERTENDIANESS( eEndianess, m_Symbols[ i ].Padding );
543 oFixedSymbol.DataOffset = CONVERTENDIANESS( eEndianess, m_Symbols[ i ].DataOffset );
544 ttsfo.Write( oFixedSymbol );
545 }
546
547 for ( auto& name : m_SymbolNames )
548 {
549 ttsfo.WriteRaw( name, name.Length() );
550 ttsfo.Write( (TUINT8)0 );
551 }
552 }
uint8_t TUINT8
Definition Typedefs.h:17

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