////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: Parameter Parser V5.5.1 (2411131018)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  parameterfilesymboltable.h
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef PARAMETERSYMBOLTABLE_H
#define PARAMETERSYMBOLTABLE_H

#include "parametertypes.h"
#include "parameterfilesymboltableentry.h"
#include "parametermodule.h"
#include <unordered_map>

class ParameterFileSymbolTable
{
public:

    ParameterFileSymbolTable(
        ParameterSetManager* const setManager,
        const VersionUnion&        version);

    ~ParameterFileSymbolTable();

    bool Load(
        BYTE* const                buffer,
        UINT32 const               bufLength,
        const CHAR* const          fileName,
        ParameterBinaryFile* const file,
        UINT32 const               fileLength,
        UINT32                     tableSize,
        UINT32                     tableOffset,
        UINT32                     dataTableSize,
        UINT32 const               dataTableOffset,
        UINT32 const               dataSize,
        UINT32 const               dataOffset,
        IModeTable* const          modeTable,
        BYTE const                 alignment);

    PARAMETER_INLINE ModuleData* GetModule(
        UINT32 const index)
    {
        if (index < m_modules.Count())
        {
            return m_modules[index];
        }
        else
        {
            return nullptr;
        }
    }

    PARAMETER_INLINE UINT32 Count()
    {
        return m_count;
    }

    PARAMETER_INLINE UINT32 DTCount()
    {
        return m_dtCount;
    }

    PARAMETER_INLINE UINT32 ModuleCount()
    {
        return m_modules.Count();
    }

    bool Find(
        ParameterFileSymbolTableEntry& entry,
        UINT32 id,
        bool const isModule = true);

    bool ReadPointerEntry(
        ParameterFileSymbolTableEntry& pointerEntry,
        ParameterFileSymbolTableEntry* const entry,
        BYTE const alignment);

    DupObjInfo* FindDupObject(
        void* const obj);

    DupObjInfo* GetDupObject(
        bool const        isModule,
        UINT32 const      id,
        UINT32 const      count,
        const CHAR* const file,
        UINT32 const      line);

    DupObjInfo* SetDupObject(
        bool const   isModule,
        UINT32 const id,
        void* const  obj,
        UINT32 const count,
        const CHAR*  file,
        UINT32       line);

    bool ReleaseDupObject(
        void* const obj);

    UINT32 GetSymbolEntrySize(
        BYTE const alignment);

    UINT32 GetDataTableEntrySize();

    UINT32 GetModeEntrySize(
        BYTE const alignment);

    void FreeEntryData();
    void FreeLookupData();

    void FileReference(INT32 adjust);

    ParameterSetManager*  SetManager;
    VersionUnion          Version;
    VersionUnion          AlignedEndVersion;
    VersionUnion          ModeFlagsVersion;
    VersionUnion          LinkVersion;
    VersionUnion          DataTableVersion;  // Mode Table Name and Data Table version
    const CHAR*           FileName;
    ParameterBinaryFile*  File;
    UINT32                FileLength;
    UINT32                SymbolTableSize;
    UINT32                SymbolTableOffset;
    UINT32                DataTableSize;
    UINT32                DataTableOffset;
    UINT32                DataOffset;
    UINT32                DataSize;
    UINT8*                Data;
    IModeTable*           ModeTable;
    BYTE                  Alignment;

private:
    class EntryData
    {
    public:
        EntryData()
        {
            Dup      = 0;
            Position = 0;
        }
        UINT32 Dup;
        UINT32 Position;
    };

    bool ReadTable(
        BYTE* const                    buffer,
        UINT32 const                   length,
        UINT32* const                  pos,
        UINT32                         count,
        ParameterFileSymbolTableEntry* entries,
        EntryData* const               entryLookup,
        UINT32&                        dupCount,
        PList<DupObjInfo*>*&           dupEntries,
        UINT32 const                   dataOffset,
        IModeTable* const              modeTable,
        const bool                     isModule,
        const BYTE                     alignment);

    UINT32                         m_count;
    UINT32                         m_dtCount;
    PList<ModuleData*>             m_modules;
    EntryData*                     m_entryLookup;
    EntryData*                     m_dtEntryLookup;
    PList<DupObjInfo*>*            m_dupEntries;
    PList<DupObjInfo*>*            m_dtDupEntries;
    UINT32                         m_dupCount;
    UINT32                         m_dtDupCount;
    INT32                          m_fileRef;     // Reference count file access
    ParameterFileSymbolTableEntry* m_entries;
    ParameterFileSymbolTableEntry* m_dtEntries;
    ParameterMutex                         m_dupInfoMutex; // Protect changes to m_dupInfoMap and DubObjInfo objects
    std::unordered_map<void*, DupObjInfo*> m_dupInfoMap;
};

#endif
