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

#include "statsroidifference.h"
#include "parametersetmanager.h"

STATSROIDIFFERENCE_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// SetValue/GetValue Functions
/// Gets or sets the requested value
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool modFaceRoiDiffTriggerDataType::GetValue(
    const CHAR* const __path,
    CHAR* const       __value,
    UINT32 const      __size)
{
    constexpr SIZE_T MAX_SIZE = 129;
    CHAR   __name[MAX_SIZE] = "";
    UINT32 __index          = MAX_UINT;
    bool   __result         = false;

    const UINT32 __pos = ParameterUtils::GetVariable(__path, __name, __index, MAX_SIZE);

    if (PARAMETER_STRCMP(__name, "triggerPt") == 0)
    {
        __result = triggerPt.GetValue(&__path[__pos], __value, __size);
    }
    else if (PARAMETER_STRCMP(__name, "triggerData") == 0)
    {
        if (__index < triggerDataCount)
        {
            __result = triggerData[__index].GetValue(&__path[__pos], __value, __size);
        }
    }

    return __result;
}

bool modFaceRoiDiffTriggerDataType::SetValue(
    const CHAR* const __path,
    const CHAR* const __value)
{
    constexpr SIZE_T MAX_SIZE = 129;
    CHAR   __name[MAX_SIZE] = "";
    UINT32 __index          = MAX_UINT;
    bool   __result         = false;

    const UINT32 __pos = ParameterUtils::GetVariable(__path, __name, __index, MAX_SIZE);

    if (PARAMETER_STRCMP(__name, "triggerPt") == 0)
    {
        __result = triggerPt.SetValue(&__path[__pos], __value);
    }
    else if (PARAMETER_STRCMP(__name, "triggerData") == 0)
    {
        if (__index < triggerDataCount)
        {
            __result = triggerData[__index].SetValue(&__path[__pos], __value);
        }
    }

    return __result;
}

bool modFaceRoiDiffTriggerDataType::GetInfo(
    const CHAR* const           __path,
    PList<ParameterParserInfo>& __info)
{
    constexpr SIZE_T MAX_SIZE = 129;
    CHAR   __name[MAX_SIZE] = "";
    UINT32 __index          = MAX_UINT;
    bool   __result         = false;

    const UINT32 __pos = ParameterUtils::GetVariable(__path, __name, __index, MAX_SIZE);

    // triggerPt
    if (__name[0] == '\0')
    {
        __result = true;
        __info.Add(ParameterParserInfo("triggerPt", ParameterParserDataType::Structure));
    }
    else if (PARAMETER_STRCMP(__name, "triggerPt") == 0)
    {
        __result = triggerPt.GetInfo(&__path[__pos], __info);
    }

    // triggerData
    if (__name[0] == '\0')
    {
        __result = true;
        __info.Add(ParameterParserInfo("triggerData", ParameterParserDataType::Structure, true, false, triggerDataCount));
    }
    else if (PARAMETER_STRCMP(__name, "triggerData") == 0)
    {
        if (__index < triggerDataCount)
        {
            __result = triggerData[__index].GetInfo(&__path[__pos], __info);
        }
        else
        {
            __result = true;
            __info.Add(ParameterParserInfo(nullptr, ParameterParserDataType::Structure, true, false, triggerDataCount));
        }
    }

    return __result;
}

bool chromatixStatsROIDifferenceType::GetValue(
    const CHAR* const __path,
    CHAR* const       __value,
    UINT32 const      __size)
{
    constexpr SIZE_T MAX_SIZE = 129;
    CHAR   __name[MAX_SIZE] = "";
    UINT32 __index          = MAX_UINT;
    bool   __result         = false;

    const UINT32 __pos = ParameterUtils::GetVariable(__path, __name, __index, MAX_SIZE);

    if (PARAMETER_STRCMP(__name, "statsROIDiffEnable") == 0)
    {
        ParameterUtils::DoubleToString((double)statsROIDiffEnable, __value, __size, 0);
        __result = true;
    }
    else if (PARAMETER_STRCMP(__name, "TriggerCtrlType") == 0)
    {
        ParameterUtils::DoubleToString((double)(UINT32)TriggerCtrlType, __value, __size, 0);
        __result = true;
    }
    else if (PARAMETER_STRCMP(__name, "statsROIDiffThreshold") == 0)
    {
        __result = statsROIDiffThreshold.GetValue(&__path[__pos], __value, __size);
    }

    return __result;
}

bool chromatixStatsROIDifferenceType::SetValue(
    const CHAR* const __path,
    const CHAR* const __value)
{
    constexpr SIZE_T MAX_SIZE = 129;
    CHAR   __name[MAX_SIZE] = "";
    UINT32 __index          = MAX_UINT;
    bool   __result         = false;

    const UINT32 __pos = ParameterUtils::GetVariable(__path, __name, __index, MAX_SIZE);

    if (PARAMETER_STRCMP(__name, "statsROIDiffEnable") == 0)
    {
        const double dblValue = ParameterUtils::StringToDouble(__value, __result);
        if (__result)
        {
            statsROIDiffEnable = (statsglobalelements::glbEnableFlagType)dblValue; 
        }
    }
    else if (PARAMETER_STRCMP(__name, "TriggerCtrlType") == 0)
    {
        const double dblValue = ParameterUtils::StringToDouble(__value, __result);
        if (__result)
        {
            TriggerCtrlType = (faceTriggerCtrlType)(UINT32)dblValue; 
        }
    }
    else if (PARAMETER_STRCMP(__name, "statsROIDiffThreshold") == 0)
    {
        __result = statsROIDiffThreshold.SetValue(&__path[__pos], __value);
    }

    return __result;
}

bool chromatixStatsROIDifferenceType::GetInfo(
    const CHAR* const           __path,
    PList<ParameterParserInfo>& __info)
{
    constexpr SIZE_T MAX_SIZE = 129;
    CHAR   __name[MAX_SIZE] = "";
    UINT32 __index          = MAX_UINT;
    bool   __result         = false;

    const UINT32 __pos = ParameterUtils::GetVariable(__path, __name, __index, MAX_SIZE);

    // statsROIDiffEnable
    if (__name[0] == '\0')
    {
        __result = true;
        __info.Add(ParameterParserInfo("statsROIDiffEnable", ParameterParserDataType::Int32, (double)statsROIDiffEnable, 0));
    }
    else if (PARAMETER_STRCMP(__name, "statsROIDiffEnable") == 0)
    {
        __result = true;
        __info.Add(ParameterParserInfo(nullptr, ParameterParserDataType::Int32, (double)statsROIDiffEnable, 0));
    }

    // TriggerCtrlType
    if (__name[0] == '\0')
    {
        __result = true;
        __info.Add(ParameterParserInfo("TriggerCtrlType", ParameterParserDataType::Enum, (double)(UINT32)TriggerCtrlType, 0));
    }
    else if (PARAMETER_STRCMP(__name, "TriggerCtrlType") == 0)
    {
        __result = true;
        __info.Add(ParameterParserInfo(nullptr, ParameterParserDataType::Enum, (double)(UINT32)TriggerCtrlType, 0));
    }

    // statsROIDiffThreshold
    if (__name[0] == '\0')
    {
        __result = true;
        __info.Add(ParameterParserInfo("statsROIDiffThreshold", ParameterParserDataType::Structure));
    }
    else if (PARAMETER_STRCMP(__name, "statsROIDiffThreshold") == 0)
    {
        __result = statsROIDiffThreshold.GetInfo(&__path[__pos], __info);
    }

    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_faceTriggerCtrlType(
    ParameterFileSymbolTableEntry* const entry,
    faceTriggerCtrlType& enumValue,
    BYTE const alignment)
{
    bool result {false};

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

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



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

    PARAMETER_INITIALIZE(triggerPt);
    PARAMETER_INITIALIZE(triggerData);

    result = triggerPt.Load(entry, alignment);

    // Reading Array triggerData from symbol table
    // Do not check result value here because the count value needs to be initialized in this block
    {
        triggerDataCount = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, triggerDataCount, 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)
        {
            triggerDataID = pointerEntry->ID;
            DupObjInfo* triggerDataDupInfo = pointerEntry->GetDupObject(triggerDataCount, file, line);
            if (triggerDataDupInfo != nullptr && triggerDataDupInfo->Object != nullptr)
            {
                triggerData = (statsglobalelements::FaceROIDiffThresholdType*)triggerDataDupInfo->Object;
                if (triggerData == nullptr)
                {
                    if (triggerDataDupInfo->File != nullptr)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "triggerData duplicate found but object is nullptr: %s:%d, RefCount: %d\n",
                            triggerDataDupInfo->File, triggerDataDupInfo->Line, triggerDataDupInfo->RefCount);
                    }
                    else
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "triggerData duplicate found but Object is nullptr: <nullptr file ptr>:%d, RefCount: %d\n",
                            triggerDataDupInfo->Line, triggerDataDupInfo->RefCount);
                    }
                }
            }

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

    return result;
}

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

    PARAMETER_INITIALIZE(statsROIDiffEnable);
    PARAMETER_INITIALIZE(TriggerCtrlType);
    PARAMETER_INITIALIZE(statsROIDiffThreshold);

    SYMBOL_TABLE_ENTRY_READ(entry, result, statsROIDiffEnable, alignment)
    if (result)
    {
        result = statsroidifference::ReadEnum_faceTriggerCtrlType(entry, TriggerCtrlType, alignment);
    }
    if (result)
    {
        result = statsROIDiffThreshold.Load(entry, alignment);
    }

    return result;
}

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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload chromatixStatsROIDifferenceType
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void chromatixStatsROIDifferenceType::Unload(ParameterFileSymbolTable* const __table)
{
    statsROIDiffThreshold.Unload(__table);
}
STATSROIDIFFERENCE_NAMESPACE_END
