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

#include "camxpdafconfig.h"
#include "parametersetmanager.h"

CAMX_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// SetValue/GetValue Functions
/// Gets or sets the requested value
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_PDAFPixelShieldInformation(
    ParameterFileSymbolTableEntry* const entry,
    PDAFPixelShieldInformation& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(PDAFPixelShieldInformation::LEFTDIODE):
            enumValue = PDAFPixelShieldInformation::LEFTDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::RIGHTDIODE):
            enumValue = PDAFPixelShieldInformation::RIGHTDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::LEFTSHIELDED):
            enumValue = PDAFPixelShieldInformation::LEFTSHIELDED;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::RIGHTSHIELDED):
            enumValue = PDAFPixelShieldInformation::RIGHTSHIELDED;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::UPDIODE):
            enumValue = PDAFPixelShieldInformation::UPDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::DOWNDIODE):
            enumValue = PDAFPixelShieldInformation::DOWNDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::UPSHIELDED):
            enumValue = PDAFPixelShieldInformation::UPSHIELDED;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::DOWNSHIELDED):
            enumValue = PDAFPixelShieldInformation::DOWNSHIELDED;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::TOPLEFTDIODE):
            enumValue = PDAFPixelShieldInformation::TOPLEFTDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::TOPRIGHTDIODE):
            enumValue = PDAFPixelShieldInformation::TOPRIGHTDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::BOTTOMLEFTDIODE):
            enumValue = PDAFPixelShieldInformation::BOTTOMLEFTDIODE;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelShieldInformation::BOTTOMRIGHTDIODE):
            enumValue = PDAFPixelShieldInformation::BOTTOMRIGHTDIODE;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to PDAFPixelShieldInformation", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_PDAFOrientation(
    ParameterFileSymbolTableEntry* const entry,
    PDAFOrientation& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(PDAFOrientation::DEFAULT):
            enumValue = PDAFOrientation::DEFAULT;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFOrientation::MIRROR):
            enumValue = PDAFOrientation::MIRROR;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFOrientation::FLIP):
            enumValue = PDAFOrientation::FLIP;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFOrientation::MIRRORANDFLIP):
            enumValue = PDAFOrientation::MIRRORANDFLIP;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to PDAFOrientation", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_PDAFBufferDataFormat(
    ParameterFileSymbolTableEntry* const entry,
    PDAFBufferDataFormat& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(PDAFBufferDataFormat::MIPI8):
            enumValue = PDAFBufferDataFormat::MIPI8;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFBufferDataFormat::MIPI10):
            enumValue = PDAFBufferDataFormat::MIPI10;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFBufferDataFormat::PACKED10):
            enumValue = PDAFBufferDataFormat::PACKED10;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFBufferDataFormat::UNPACKED16):
            enumValue = PDAFBufferDataFormat::UNPACKED16;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFBufferDataFormat::MIPI12):
            enumValue = PDAFBufferDataFormat::MIPI12;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to PDAFBufferDataFormat", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_PDAFPixelOrderType(
    ParameterFileSymbolTableEntry* const entry,
    PDAFPixelOrderType& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(PDAFPixelOrderType::DEFAULT):
            enumValue = PDAFPixelOrderType::DEFAULT;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelOrderType::LEFTTORIGHT):
            enumValue = PDAFPixelOrderType::LEFTTORIGHT;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFPixelOrderType::RIGHTTOLEFT):
            enumValue = PDAFPixelOrderType::RIGHTTOLEFT;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to PDAFPixelOrderType", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_PDAFType(
    ParameterFileSymbolTableEntry* const entry,
    PDAFType& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(PDAFType::PDTypeUnknown):
            enumValue = PDAFType::PDTypeUnknown;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFType::PDType1):
            enumValue = PDAFType::PDType1;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFType::PDType2):
            enumValue = PDAFType::PDType2;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFType::PDType3):
            enumValue = PDAFType::PDType3;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFType::PDType2PD):
            enumValue = PDAFType::PDType2PD;
            result    = true;
            break;
        case static_cast<UINT32>(PDAFType::PDTypeQPD):
            enumValue = PDAFType::PDTypeQPD;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to PDAFType", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_SensorPDStatsFormat(
    ParameterFileSymbolTableEntry* const entry,
    SensorPDStatsFormat& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(SensorPDStatsFormat::SensorPDStatsCustom):
            enumValue = SensorPDStatsFormat::SensorPDStatsCustom;
            result    = true;
            break;
        case static_cast<UINT32>(SensorPDStatsFormat::SensorPDStatsRaw10Conf8BitPd10Bit):
            enumValue = SensorPDStatsFormat::SensorPDStatsRaw10Conf8BitPd10Bit;
            result    = true;
            break;
        case static_cast<UINT32>(SensorPDStatsFormat::SensorPDStatsRaw10Conf11BitPd11Bit):
            enumValue = SensorPDStatsFormat::SensorPDStatsRaw10Conf11BitPd11Bit;
            result    = true;
            break;
        case static_cast<UINT32>(SensorPDStatsFormat::SensorPDStatsRaw10Conf11BitPd10Bit):
            enumValue = SensorPDStatsFormat::SensorPDStatsRaw10Conf11BitPd10Bit;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to SensorPDStatsFormat", uintValue);
            break;
        }
    }
    return result;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PDAFConfigurationDataClass::PDAFConfigurationDataClass(
    const CHAR* const name)
    : ParameterModule(name, MAJOR, MINOR, PATCH, nullptr)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(PDCommonInfo);
    PARAMETER_INITIALIZE(PDModeInfoCount);
    PARAMETER_INITIALIZE(PDModeInfo);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PDAFConfigurationDataClass::PDAFConfigurationDataClass(
    const CHAR* const name,
    ModuleData* const moduleData)
    : ParameterModule(name, MAJOR, MINOR, PATCH, moduleData)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(PDCommonInfo);
    PARAMETER_INITIALIZE(PDModeInfo);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PDAFConfigurationDataClass::~PDAFConfigurationDataClass()
{
    if (Loaded)
    {
        UnloadModule();
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// GetName
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CHAR* PDAFConfigurationDataClass::GetName(
    const CHAR* const type)
{
    const CHAR* name = type;
    CHAR temp[ParameterFileSymbolTableEntry::TYPE_LEN + 1];
    if (PARAMETER_STRCMP(type, ModuleData::GetType(temp, "PDConfigData")) == 0)
    {
        name = "PDConfigData";
    }
    return name;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFInformation::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(PDAFName);
    PARAMETER_INITIALIZE(PDOrientation);
    PARAMETER_INITIALIZE(PDDefocusConfidenceThreshold);
    PARAMETER_INITIALIZE(PDBlackLevelExists);
    PARAMETER_INITIALIZE(PDBlackLevel);


    // Reading String PDAFName from symbol table
    {
        UINT32 count = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, count, alignment)
        ParameterFileSymbolTableEntry stringPointerEntryCls;
        ParameterFileSymbolTableEntry* const stringPointerEntry = &stringPointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(stringPointerEntryCls, entry, alignment);
        }
        SYMBOL_TABLE_ENTRY_READ_STRING(stringPointerEntry, result, PDAFName, count, alignment)
    }
    if (result)
    {
        result = ReadEnum_PDAFOrientation(entry, PDOrientation, alignment);
    }
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDDefocusConfidenceThreshold, alignment)

    // Reading Optional parameter PDBlackLevel from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDBlackLevelExists, alignment)
        PDBlackLevelID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDBlackLevelExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, PDBlackLevel, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(PDBlackLevel);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFPixelCoordinates
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFPixelCoordinates::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(PDXCoordinate);
    PARAMETER_INITIALIZE(PDYCoordinate);
    PARAMETER_INITIALIZE(PDPixelShieldInformation);
    PARAMETER_INITIALIZE(PDExposureTypeExists);
    PARAMETER_INITIALIZE(PDExposureType);

    SYMBOL_TABLE_ENTRY_READ(entry, result, PDXCoordinate, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDYCoordinate, alignment)
    if (result)
    {
        result = ReadEnum_PDAFPixelShieldInformation(entry, PDPixelShieldInformation, alignment);
    }

    // Reading Optional parameter PDExposureType from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDExposureTypeExists, alignment)
        PDExposureTypeID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDExposureTypeExists)
        {
            if (result)
            {
                result = ReadEnum_ExposureType(pointerEntry, PDExposureType, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDExposureType);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFBlockPattern
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFBlockPattern::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(PDPixelCount);
    PARAMETER_INITIALIZE(PDPixelCoordinates);
    PARAMETER_INITIALIZE(PDBlockDimensions);
    PARAMETER_INITIALIZE(PDOffsetHorizontal);
    PARAMETER_INITIALIZE(PDOffsetVertical);

    SYMBOL_TABLE_ENTRY_READ(entry, result, PDPixelCount, alignment)

    // Reading Array PDPixelCoordinates from symbol table
    // Do not check result value here because the count value needs to be initialized in this block
    {
        PDPixelCoordinatesCount = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDPixelCoordinatesCount, alignment)
        constexpr const CHAR* const file {__FILE__};
        constexpr INT32 line {LINE_CONST};
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }

        if (result)
        {
            PDPixelCoordinatesID = pointerEntry->ID;
            DupObjInfo* PDPixelCoordinatesDupInfo = pointerEntry->GetDupObject(PDPixelCoordinatesCount, file, line);
            if (PDPixelCoordinatesDupInfo != nullptr && PDPixelCoordinatesDupInfo->Object != nullptr)
            {
                PDPixelCoordinates = (PDAFPixelCoordinates*)PDPixelCoordinatesDupInfo->Object;
                if (PDPixelCoordinates == nullptr)
                {
                    if (PDPixelCoordinatesDupInfo->File != nullptr)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "PDPixelCoordinates duplicate found but object is nullptr: %s:%d, RefCount: %d\n",
                            PDPixelCoordinatesDupInfo->File, PDPixelCoordinatesDupInfo->Line, PDPixelCoordinatesDupInfo->RefCount);
                    }
                    else
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "PDPixelCoordinates duplicate found but Object is nullptr: <nullptr file ptr>:%d, RefCount: %d\n",
                            PDPixelCoordinatesDupInfo->Line, PDPixelCoordinatesDupInfo->RefCount);
                    }
                }
            }

            if (PDPixelCoordinates == nullptr)
            {
                if (result && PDPixelCoordinatesCount > 0)
                {
                    PDPixelCoordinates = PARAMETER_NEW PDAFPixelCoordinates[PDPixelCoordinatesCount];
                    (void)pointerEntry->SetDupObject(PDPixelCoordinates, PDPixelCoordinatesCount, file, line);
                }
                if (!result || PDPixelCoordinates == nullptr)
                {
                    if (PDPixelCoordinatesCount > 0)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "Failed to allocate PDPixelCoordinates\n");
                    }
                    PDPixelCoordinatesCount = 0;
                }
                for (UINT32 i = 0; result && i < PDPixelCoordinatesCount; i++)
                {
                    result = PDPixelCoordinates[i].Load(pointerEntry, alignment);
                }
            }
        }
        if (PDPixelCoordinates == nullptr)
        {
            PDPixelCoordinatesCount = 0;
        }
    }
    if (result)
    {
        result = PDBlockDimensions.Load(entry, alignment);
    }
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDOffsetHorizontal, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDOffsetVertical, alignment)

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFSensorNativePatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFSensorNativePatternInformation::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(PDBlockCountHorizontal);
    PARAMETER_INITIALIZE(PDBlockCountVertical);
    PARAMETER_INITIALIZE(PDBlockPatternExists);
    PARAMETER_INITIALIZE(PDBlockPattern);
    PARAMETER_INITIALIZE(PDCropRegion);
    PARAMETER_INITIALIZE(PDDownscaleFactorHorizontal);
    PARAMETER_INITIALIZE(PDDownscaleFactorVertical);
    PARAMETER_INITIALIZE(PDNativeBufferFormat);

    SYMBOL_TABLE_ENTRY_READ(entry, result, PDBlockCountHorizontal, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDBlockCountVertical, alignment)

    // Reading Optional parameter PDBlockPattern from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDBlockPatternExists, alignment)
        PDBlockPatternID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDBlockPatternExists)
        {
            if (result)
            {
                result = PDBlockPattern.Load(pointerEntry, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDBlockPattern);
        }
    }
    if (result)
    {
        result = PDCropRegion.Load(entry, alignment);
    }
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDDownscaleFactorHorizontal, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, PDDownscaleFactorVertical, alignment)
    if (result)
    {
        result = ReadEnum_PDAFBufferDataFormat(entry, PDNativeBufferFormat, alignment);
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFBlockPatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFBlockPatternInformation::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(PDStride);
    PARAMETER_INITIALIZE(PDBufferFormat);
    PARAMETER_INITIALIZE(PDBlockPatternExists);
    PARAMETER_INITIALIZE(PDBlockPattern);

    SYMBOL_TABLE_ENTRY_READ(entry, result, PDStride, alignment)
    if (result)
    {
        result = ReadEnum_PDAFBufferDataFormat(entry, PDBufferFormat, alignment);
    }

    // Reading Optional parameter PDBlockPattern from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDBlockPatternExists, alignment)
        PDBlockPatternID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDBlockPatternExists)
        {
            if (result)
            {
                result = PDBlockPattern.Load(pointerEntry, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDBlockPattern);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFModeInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFModeInformation::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(PDSensorNativePatternInfoExists);
    PARAMETER_INITIALIZE(PDSensorNativePatternInfo);
    PARAMETER_INITIALIZE(PDBufferBlockPatternInfoExists);
    PARAMETER_INITIALIZE(PDBufferBlockPatternInfo);
    PARAMETER_INITIALIZE(PDType);
    PARAMETER_INITIALIZE(PDSensorModeExists);
    PARAMETER_INITIALIZE(PDSensorMode);
    PARAMETER_INITIALIZE(PDModeKeyExists);
    PARAMETER_INITIALIZE(PDModeKey);
    PARAMETER_INITIALIZE(PDAFLibraryName);
    PARAMETER_INITIALIZE(PDSensorPDStatsFormatExists);
    PARAMETER_INITIALIZE(PDSensorPDStatsFormat);
    PARAMETER_INITIALIZE(PDSensorOutputFormatExists);
    PARAMETER_INITIALIZE(PDSensorOutputFormat);
    PARAMETER_INITIALIZE(lcrPDOffsetCorrectionExists);
    PARAMETER_INITIALIZE(lcrPDOffsetCorrection);
    PARAMETER_INITIALIZE(PDPixelOrderTypeExists);
    PARAMETER_INITIALIZE(PDPixelOrderType);
    PARAMETER_INITIALIZE(PDoffsetmapIDExists);
    PARAMETER_INITIALIZE(PDoffsetmapID);
    PARAMETER_INITIALIZE(PDOffsetCorrectionExists);
    PARAMETER_INITIALIZE(PDOffsetCorrection);


    // Reading Optional parameter PDSensorNativePatternInfo from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDSensorNativePatternInfoExists, alignment)
        PDSensorNativePatternInfoID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDSensorNativePatternInfoExists)
        {
            result = PDSensorNativePatternInfo.Load(pointerEntry, alignment);
        }
        else
        {
            PARAMETER_INITIALIZE(PDSensorNativePatternInfo);
        }
    }

    // Reading Optional parameter PDBufferBlockPatternInfo from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDBufferBlockPatternInfoExists, alignment)
        PDBufferBlockPatternInfoID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDBufferBlockPatternInfoExists)
        {
            if (result)
            {
                result = PDBufferBlockPatternInfo.Load(pointerEntry, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDBufferBlockPatternInfo);
        }
    }
    if (result)
    {
        result = ReadEnum_PDAFType(entry, PDType, alignment);
    }

    // Reading Optional parameter PDSensorMode from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDSensorModeExists, alignment)
        PDSensorModeID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDSensorModeExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, PDSensorMode, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(PDSensorMode);
        }
    }

    // Reading Optional parameter PDModeKey from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDModeKeyExists, alignment)
        PDModeKeyID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDModeKeyExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, PDModeKey, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(PDModeKey);
        }
    }

    // Reading String PDAFLibraryName from symbol table
    {
        UINT32 count = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, count, alignment)
        ParameterFileSymbolTableEntry stringPointerEntryCls;
        ParameterFileSymbolTableEntry* const stringPointerEntry = &stringPointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(stringPointerEntryCls, entry, alignment);
        }
        SYMBOL_TABLE_ENTRY_READ_STRING(stringPointerEntry, result, PDAFLibraryName, count, alignment)
    }

    // Reading Optional parameter PDSensorPDStatsFormat from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDSensorPDStatsFormatExists, alignment)
        PDSensorPDStatsFormatID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDSensorPDStatsFormatExists)
        {
            if (result)
            {
                result = ReadEnum_SensorPDStatsFormat(pointerEntry, PDSensorPDStatsFormat, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDSensorPDStatsFormat);
        }
    }

    // Reading Optional parameter PDSensorOutputFormat from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDSensorOutputFormatExists, alignment)
        PDSensorOutputFormatID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDSensorOutputFormatExists)
        {
            if (result)
            {
                result = ReadEnum_PDAFBufferDataFormat(pointerEntry, PDSensorOutputFormat, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDSensorOutputFormat);
        }
    }

    // Reading Optional parameter lcrPDOffsetCorrection from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, lcrPDOffsetCorrectionExists, alignment)
        lcrPDOffsetCorrectionID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && lcrPDOffsetCorrectionExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, lcrPDOffsetCorrection, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(lcrPDOffsetCorrection);
        }
    }

    // Reading Optional parameter PDPixelOrderType from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDPixelOrderTypeExists, alignment)
        PDPixelOrderTypeID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDPixelOrderTypeExists)
        {
            if (result)
            {
                result = ReadEnum_PDAFPixelOrderType(pointerEntry, PDPixelOrderType, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(PDPixelOrderType);
        }
    }

    // Reading Optional parameter PDoffsetmapID from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDoffsetmapIDExists, alignment)
        PDoffsetmapIDID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDoffsetmapIDExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, PDoffsetmapID, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(PDoffsetmapID);
        }
    }

    // Reading Optional parameter PDOffsetCorrection from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDOffsetCorrectionExists, alignment)
        PDOffsetCorrectionID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && PDOffsetCorrectionExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, PDOffsetCorrection, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(PDOffsetCorrection);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFConfigurationData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFConfigurationData::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(PDCommonInfo);
    PARAMETER_INITIALIZE(PDModeInfo);

    result = module_version.Load(entry, alignment);
    if (result)
    {
        result = PDCommonInfo.Load(entry, alignment);
    }

    // Reading Array PDModeInfo from symbol table
    // Do not check result value here because the count value needs to be initialized in this block
    {
        PDModeInfoCount = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, PDModeInfoCount, alignment)
        constexpr const CHAR* const file {__FILE__};
        constexpr INT32 line {LINE_CONST};
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }

        if (result)
        {
            PDModeInfoID = pointerEntry->ID;
            DupObjInfo* PDModeInfoDupInfo = pointerEntry->GetDupObject(PDModeInfoCount, file, line);
            if (PDModeInfoDupInfo != nullptr && PDModeInfoDupInfo->Object != nullptr)
            {
                PDModeInfo = (PDAFModeInformation*)PDModeInfoDupInfo->Object;
                if (PDModeInfo == nullptr)
                {
                    if (PDModeInfoDupInfo->File != nullptr)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "PDModeInfo duplicate found but object is nullptr: %s:%d, RefCount: %d\n",
                            PDModeInfoDupInfo->File, PDModeInfoDupInfo->Line, PDModeInfoDupInfo->RefCount);
                    }
                    else
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "PDModeInfo duplicate found but Object is nullptr: <nullptr file ptr>:%d, RefCount: %d\n",
                            PDModeInfoDupInfo->Line, PDModeInfoDupInfo->RefCount);
                    }
                }
            }

            if (PDModeInfo == nullptr)
            {
                if (result && PDModeInfoCount > 0)
                {
                    PDModeInfo = PARAMETER_NEW PDAFModeInformation[PDModeInfoCount];
                    (void)pointerEntry->SetDupObject(PDModeInfo, PDModeInfoCount, file, line);
                }
                if (!result || PDModeInfo == nullptr)
                {
                    if (PDModeInfoCount > 0)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "Failed to allocate PDModeInfo\n");
                    }
                    PDModeInfoCount = 0;
                }
                for (UINT32 i = 0; result && i < PDModeInfoCount; i++)
                {
                    result = PDModeInfo[i].Load(pointerEntry, alignment);
                }
            }
        }
        if (PDModeInfo == nullptr)
        {
            PDModeInfoCount = 0;
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load module_versionStruct
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFConfigurationData::module_versionStruct::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(major_revision);
    PARAMETER_INITIALIZE(minor_revision);
    PARAMETER_INITIALIZE(incr_revision);

    SYMBOL_TABLE_ENTRY_READ(entry, result, major_revision, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, minor_revision, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, incr_revision, alignment)

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFInformation::Unload(ParameterFileSymbolTable* const __table)
{
    if (__table != nullptr && __table->ReleaseDupObject(PDAFName))
    {
        PARAMETER_DELETE[] PDAFName;
    }
    PDAFName = nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFBlockPattern
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFBlockPattern::Unload(ParameterFileSymbolTable* const __table)
{
    if (__table != nullptr && __table->ReleaseDupObject(PDPixelCoordinates))
    {
        PARAMETER_DELETE[] PDPixelCoordinates;
    }
    PDPixelCoordinates = nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFSensorNativePatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFSensorNativePatternInformation::Unload(ParameterFileSymbolTable* const __table)
{
    PDBlockPattern.Unload(__table);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFBlockPatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFBlockPatternInformation::Unload(ParameterFileSymbolTable* const __table)
{
    PDBlockPattern.Unload(__table);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFModeInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFModeInformation::Unload(ParameterFileSymbolTable* const __table)
{
    PDSensorNativePatternInfo.Unload(__table);
    PDBufferBlockPatternInfo.Unload(__table);
    if (__table != nullptr && __table->ReleaseDupObject(PDAFLibraryName))
    {
        PARAMETER_DELETE[] PDAFLibraryName;
    }
    PDAFLibraryName = nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFConfigurationData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationData::Unload(ParameterFileSymbolTable* const __table)
{
    PDCommonInfo.Unload(__table);
    for (UINT32 i = 0; i < PDModeInfoCount; i++)
    {
        PDModeInfo[i].Unload(__table);
    }
    if (__table != nullptr && __table->ReleaseDupObject(PDModeInfo))
    {
        PARAMETER_DELETE[] PDModeInfo;
    }
    PDModeInfo = nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Release the ParameterModule object
/// Requires that this object was created via a ParameterSetManager::GetModule call
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationData::Release()
{
    ((PDAFConfigurationDataClass*)this)->Release();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns the ParameterModule::Modified value
/// The Modified value is incremented when the module's data or pointer values change
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
UINT32 PDAFConfigurationData::GetModified()
{
    return ((PDAFConfigurationDataClass*)this)->Modified;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Create module, and return a new object
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ParameterModule* PDAFConfigurationDataClass::Create(
    ModuleData*    moduleData,
    DefaultModule* const defModule) const
{
    PDAFConfigurationDataClass* cls = nullptr;

    if (PARAMETER_STRCMP(Type, moduleData->Type) == 0 && Version.Value == moduleData->Version.Value)
    {
        const UINT32 id = moduleData->DuplicateID > 0 ? moduleData->DuplicateID : moduleData->ID;

        ParameterModule* const module = defModule->Find(id);
        if (module != nullptr)
        {
            cls = (PDAFConfigurationDataClass*)module;
        }
        else
        {
            cls = PARAMETER_NEW PDAFConfigurationDataClass(GetName(moduleData->Type), moduleData);
            cls->SymbolTableID = id;
            defModule->AddModule((ParameterModule*)cls);
        }
    }
    else if (Version.Value != moduleData->Version.Value)
    {
        PARAMETER_LOG_ERROR(moduleData->SetManager, "Unable to create PDAFConfigurationDataClass, binary version (%lld) does not match source version (%lld)\n",
            moduleData->Version.Value, Version.Value);
    }
    else
    {
        PARAMETER_LOG_ERROR(moduleData->SetManager, "Unable to create PDAFConfigurationDataClass, binary name (%s) does not match source name (%s)\n",
            moduleData->Type, Type);
    }

    return (ParameterModule*)cls;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load module data, return true is successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PDAFConfigurationDataClass::LoadModule(
    ParameterFileSymbolTable* const table)
{
    bool result = true;

    if (!Loaded)
    {
        BYTE const alignment = table->Alignment;
        PDAFConfigurationDataClass* const cls = this;

        ParameterFileSymbolTableEntry  entryObj;
        ParameterFileSymbolTableEntry* const entry = &entryObj;
        result = table->Find(entryObj, SymbolTableID);

        if (!result)
        {
            PARAMETER_LOG_ERROR(entry->SetManager, "PDAFConfigurationDataClass::LoadModule Failed to find module ID (%d) in Symbol Table\n", SymbolTableID);
        }

        if (result)
        {
            result = cls->Load(entry, alignment);
        }
        Modified++;
        Loaded = true;
    }

    if (!result)
    {
        /// Module failed to fully load, unload it
        UnloadModule();
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload module data
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::UnloadModule()
{
    if (Loaded)
    {
        if (Data != nullptr && Data->SymbolTable != nullptr)
        {
            Unload(Data->SymbolTable);
        }
        else
        {
            PARAMETER_LOG_ERROR(Data != nullptr ? Data->SetManager : nullptr, "UnloadModule %s called with nullptr "
                "Data->SymbolTable object\n", Name);
            Unload(nullptr);
        }
        Loaded = false;
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// /// Release the ParameterModule object
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::Release()
{
    ParameterModule::Release();
}

CAMX_NAMESPACE_END
