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

#include "parametertypes.h"
#include "parametersetmanager.h"

VersionUnion::VersionUnion()
{
    Value = 0;
}

VersionUnion::VersionUnion(
    UINT64 const value)
{
    Value = value;
}

VersionUnion::VersionUnion(
    UINT16 const major,
    UINT16 const minor,
    UINT32 const patch)
{
    Version.Major = major;
    Version.Minor = minor;
    Version.Patch = patch;
}

bool VersionUnion::operator ==(const VersionUnion& rhs)
{
    return Compare(rhs) == 0;
}

bool VersionUnion::operator !=(const VersionUnion& rhs)
{
    return Compare(rhs) != 0;
}

bool VersionUnion::operator >(const VersionUnion& rhs)
{
    return Compare(rhs) > 0;
}

bool VersionUnion::operator >=(const VersionUnion& rhs)
{
    return Compare(rhs) >= 0;
}

bool VersionUnion::operator <(const VersionUnion& rhs)
{
    return Compare(rhs) < 0;
}

bool VersionUnion::operator <=(const VersionUnion& rhs)
{
    return Compare(rhs) <= 0;
}

INT32 VersionUnion::Compare(const VersionUnion& rhs) const
{
    INT32 result = 0;
    if (Version.Major > rhs.Version.Major)
    {
        result = 1;
    }
    else if (Version.Major < rhs.Version.Major)
    {
        result = -1;
    }
    else if (Version.Minor > rhs.Version.Minor)
    {
        result = 1;
    }
    else if (Version.Minor < rhs.Version.Minor)
    {
        result = -1;
    }
    else if (Version.Patch > rhs.Version.Patch)
    {
        result = 1;
    }
    else if (Version.Patch < rhs.Version.Patch)
    {
        result = -1;
    }

    return result;
}

ModeUnion::ModeUnion()
{
    Value = 0;
}

ModeUnion::ModeUnion(
    UINT64 const value)
{
    Value = value;
}

ModeUnion::ModeUnion(
    UINT16 const mode,
    UINT16 const subMode)
{
    Mode.Mode = mode;
    Mode.SubMode = subMode;
}

ModuleData::ModuleData(
    UINT32 const               id,
    UINT32 const               duplicateID,
    IModeTable* const          modeTable,
    const CHAR* const          type,
    UINT64 const               versionValue,
    UINT32                     modeId,
    ParameterSetManager* const setManager)
{
    CHAR path[MAX_MODE_PATH];
    SIZE_T len = type != nullptr ? PARAMETER_STRLEN(type) : 0;

    ID            = id;
    DuplicateID   = duplicateID;
    ModeId        = modeId;
    Version.Value = versionValue;
    SetManager    = setManager;
    SymbolTable   = setManager->SymbolTable;
    path[0]       = '\0';

    if (modeTable != nullptr)
    {
        Mode = modeTable->GetModeEntry(modeId);
        if (Mode != nullptr)
        {
            Mode->GetModePath(path, MAX_MODE_PATH);
        }
        else
        {
            // Create an empty mode and report the error
            Mode = PARAMETER_NEW ModeEntry(false, false);
            PARAMETER_LOG_ERROR(SetManager, "Failed to find ModeID %d in mode table when creating ModuleData\n", modeId);
        }
    }
    else
    {
        Mode = nullptr;
        PARAMETER_LOG_ERROR(SetManager, "ModuleData called with nullptr modeTable parameter\n");
    }

    Type = PARAMETER_NEW CHAR[len + 1];
    Type[0] = '\0';
    if (type != nullptr)
    {
        PARAMETER_STRCPY(Type, len + 1, type);
    }
    else
    {
        PARAMETER_LOG_ERROR(SetManager, "ModuleData called with nullptr type parameter\n");
    }

    len      = PARAMETER_STRLEN(path);
    ModePath = PARAMETER_NEW CHAR[len + 1];
    PARAMETER_STRCPY(ModePath, len + 1, path);
}

ModuleData::~ModuleData()
{
    PARAMETER_DELETE[] Type;
    PARAMETER_DELETE[] ModePath;
    Type = nullptr;
    ModePath = nullptr;
}

CHAR* ModuleData::GetType(
    CHAR* const outputType,
    const CHAR* const moduleName)
{
    constexpr INT32 PREFIX_COUNT   = 2;
    constexpr CHAR  TYPE_SEPARATOR = '-';
    constexpr INT32 TYPE_START_LEN = TYPE_LEN / 4;
    constexpr INT32 TYPE_END_LEN   = TYPE_LEN - TYPE_START_LEN - 1;
    constexpr const CHAR* const prefixes[] = { "chromatix_", "chromatix" };
    const CHAR* type = moduleName;

    for (INT32 i = 0; i < PREFIX_COUNT; i++)
    {
        const SIZE_T len = PARAMETER_STRLEN(prefixes[i]);
        if ((PARAMETER_STRNICMP(moduleName, prefixes[i], len) == 0) &&
            (len < PARAMETER_STRLEN(moduleName)))
        {
            type = &moduleName[len];
            break;
        }
    }

    const SIZE_T typeLen = PARAMETER_STRLEN(type);
    if (typeLen > TYPE_LEN)
    {
        for (INT32 i = 0; i < TYPE_START_LEN; i++)
        {
            outputType[i] = type[i];
        }
        outputType[TYPE_START_LEN] = TYPE_SEPARATOR;
        SIZE_T typePos = PARAMETER_STRLEN(type) - TYPE_END_LEN;
        INT32  index   = TYPE_START_LEN + 1;
        while (typePos < typeLen)
        {
            outputType[index++] = type[typePos++];
        }
    }
    else
    {
        PARAMETER_STRCPY(outputType, PARAMETER_MIN(TYPE_LEN + 1, typeLen + 1), type);
    }

    return outputType;
}
