////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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  parameterfilesymboltableentry.h
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef PARAMETERSYMBOLTABLEENTRY_H
#define PARAMETERSYMBOLTABLEENTRY_H

#include "parametertypes.h"
#include "parameterutils.h"

#define SYMBOL_TABLE_ENTRY_READ_STRING(entry, result, value, count, alignment)\
{\
    CHAR* readEntryTemp = nullptr;\
    if (result && entry != nullptr)\
    {\
        result = entry->ReadString(&readEntryTemp, count, alignment);\
    }\
    value = readEntryTemp;\
}

#define SYMBOL_TABLE_ENTRY_READ(entry, result, value, alignment)\
{\
    constexpr SIZE_T ENTRY_READ_SIZE = sizeof(value);\
    if (result && entry != nullptr && entry->Position + ENTRY_READ_SIZE <= entry->DataSize && entry->Data != nullptr)\
    {\
        PARAMETER_MEMCPY(&value, ENTRY_READ_SIZE, &entry->Data[entry->Position], ENTRY_READ_SIZE);\
        entry->Position += (UINT32)PARAMETER_MAX(ENTRY_READ_SIZE, alignment);\
        result = true;\
    }\
    else\
    {\
        PARAMETER_LOG_ERROR(entry != nullptr ? entry->SetManager : nullptr, "Failed to read symbol table entry\n");\
        result = false;\
    }\
}

/*******************************************************************************
* Forward declarations
*******************************************************************************/
class ParameterFileSymbolTable;
/* To prevent misaligned pointer access, make this value greater than TYPE_LEN
   and 8 byte aligned */
#define TYPE_CHAR_ARRAY_LEN 40

class ParameterFileSymbolTableEntry
{
public:
    // ID 0 is reserved for Parent ID to indicate the entry is a Module
    static constexpr UINT32 MODULE_PARENT_ID = 0U;
    static constexpr UINT32 START_ID         = 1U;
    static constexpr INT32  TYPE_LEN         = 32;

    // Symbol table entry size as defined in the Chromatix Data Access Design document
    static constexpr INT32  SYMBOL_ENTRY_SIZE_LEGACY =    4 +       // ID
                                                          TYPE_LEN +// Type
                                                          2 +       // Version: Major
                                                          2 +       // Version: Minor
                                                          4 +       // Version: Patch
                                                          2 +       // Mode
                                                          2 +       // Selector
                                                          4 +       // Selector Data
                                                          4 +       // Mode ID
                                                          4 +       // Data Offset
                                                          4;        // Data Size

    // Symbol table entry size as defined in the Chromatix Data Access Design document
    static constexpr INT32  SYMBOL_ENTRY_SIZE =           4 +       // ID
                                                          TYPE_LEN +// Type
                                                          2 +       // Version: Major
                                                          2 +       // Version: Minor
                                                          4 +       // Version: Patch
                                                          4 +       // Mode ID
                                                          4 +       // Data Offset
                                                          4 +       // Data Size
                                                          4;        // Duplicate ID

    static constexpr INT32  SYMBOL_ENTRY_ALIGNED_SIZE   = 8 +       // ID
                                                          TYPE_LEN +// Type
                                                          2 +       // Version: Major
                                                          2 +       // Version: Minor
                                                          8 +       // Version: Patch
                                                          8 +       // Mode ID
                                                          8 +       // Data Offset
                                                          8;        // Data Size

    static constexpr INT32  SYMBOL_ENTRY_UNALIGNED_SIZE = 4 +       // ID
                                                          TYPE_LEN +// Type
                                                          2 +       // Version: Major
                                                          2 +       // Version: Minor
                                                          4 +       // Version: Patch
                                                          4 +       // Mode ID
                                                          4 +       // Data Offset
                                                          4;        // Data Size

    static constexpr INT32  DATA_TABLE_ENTRY_SIZE =       4 +       // ID
                                                          4 +       // Data Offset
                                                          4 +       // Data Size
                                                          4;        // Duplicate ID

    static constexpr INT32  MODE_ENTRY_SIZE_LEGACY =      4 +       // ID
                                                          2 +       // Mode
                                                          2 +       // SubMode
                                                          4 +       // Group
                                                          4;        // Parent ID

    static constexpr INT32  MODE_ENTRY_SIZE_NOLINK =      8 +       // ID
                                                          2 +       // Mode
                                                          2 +       // SubMode
                                                          4 +       // Group
                                                          8;        // Parent ID

    static constexpr INT32  MODE_ENTRY_SIZE =             8 +       // ID
                                                          2 +       // Mode
                                                          2 +       // SubMode
                                                          4 +       // Group
                                                          8 +       // Parent ID
                                                          8;        // Link ID

    static constexpr INT32  MODE_ENTRY_UNALIGNED_SIZE  =  4 +       // ID
                                                          2 +       // Mode
                                                          2 +       // SubMode
                                                          4 +       // Group
                                                          4 +       // Parent ID
                                                          4;        // Link ID

    static constexpr INT32  MODE_ENTRY_FLAGS_SIZE      =  4 +       // ID
                                                          2 +       // Mode
                                                          2 +       // SubMode
                                                          4 +       // Group
                                                          4 +       // Parent ID
                                                          4 +       // Link ID
                                                          4;        // Flags

    ParameterFileSymbolTableEntry();

    ~ParameterFileSymbolTableEntry();

    void Init(
        ParameterFileSymbolTable* const table);

    bool Load(
        BYTE* const                buffer,
        const CHAR* const          fileName,
        ParameterBinaryFile* const file,
        UINT32 const               length,
        UINT32* const              pos,
        UINT32 const               dataOffset,
        IModeTable*                modeTable,
        bool const                 isModule,
        BYTE const                 alignment);

    static PARAMETER_INLINE bool CheckIsModule(UINT32 const modeId)
    {
        constexpr UINT32 NON_MODULE_PARENT_ID = 0xFFFFFFFFU;
        return modeId != NON_MODULE_PARENT_ID;
    }

    PARAMETER_INLINE bool IsModule() const
    {
        return Module != nullptr;
    }

    template<typename T> PARAMETER_INLINE bool Read(
        T*   value,
        BYTE const alignment)
    {
        if (Data != nullptr)
        {
            return ParameterUtils::Read(value, Data, DataSize, &Position, alignment, SetManager);
        }
        return false;
    }

    template<typename T> PARAMETER_INLINE T* ReadArray(
        UINT32 count,
        BYTE   alignment)
    {
        if (Data != nullptr)
        {
            return ParameterUtils::ReadArray<T>(Data, DataSize, &Position, count, alignment, SetManager);
        }
        return nullptr;
    }

    template<typename T> PARAMETER_INLINE bool ReadArray(
        T*     value,
        UINT32 count,
        BYTE   alignment)
    {
        if (Data != nullptr)
        {
            return ParameterUtils::ReadArray(value, Data, DataSize, &Position, count, alignment, SetManager);
        }
        return false;
    }

    bool ReadString(
        CHAR** const value,
        UINT32 const maxChars,
        BYTE   const alignment);

    UINT32 ReadEnum(
        bool* const result,
        BYTE const  alignment);

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

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

    ParameterFileSymbolTable* Table;
    ParameterSetManager*      SetManager;
    UINT32                    ID;
    UINT32                    DuplicateID;
    BYTE*                     Data;
    const CHAR*               File;
    UINT32                    Offset;
    UINT32                    Position;
    UINT32                    DataSize;
    ModuleData*               Module;
};

#endif
