///////////////////////////////////////////////////////////////
//
// CClientPerfStatManagerImpl::CClientPerfStatManagerImpl
//
//
//
///////////////////////////////////////////////////////////////
CClientPerfStatManagerImpl::~CClientPerfStatManagerImpl()
{
    for (uint i = 0; i < GetModuleCount(); i++)
    {
        CClientPerfStatModule* pModule = GetModuleByIndex(i);
        delete pModule;
    }
}
///////////////////////////////////////////////////////////////
//
// CClientPerfStatManagerImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CClientPerfStatManagerImpl::DoPulse()
{
    for (uint i = 0; i < GetModuleCount(); i++)
    {
        CClientPerfStatModule* pModule = GetModuleByIndex(i);
        pModule->DoPulse();
    }
}
///////////////////////////////////////////////////////////////
//
// CClientPerfStatManagerImpl::GetModuleByCategoryName
//
//
//
///////////////////////////////////////////////////////////////
CClientPerfStatModule* CClientPerfStatManagerImpl::GetModuleByCategoryName(const SString& strCategory)
{
    for (uint i = 0; i < GetModuleCount(); i++)
    {
        CClientPerfStatModule* pModule = GetModuleByIndex(i);
        if (pModule->GetCategoryName() == strCategory)
            return pModule;
    }
    return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: activates a module by name
//-----------------------------------------------------------------------------
bool CVGuiSystemModuleLoader::ActivateModule(const char *moduleName)
{
	for (int i = 0; i < GetModuleCount(); i++)
	{
		if (!stricmp(GetModuleLabel(i), moduleName) || !stricmp(m_Modules[i].data->GetName(), moduleName))
		{
			ActivateModule(i);
			return true;
		}
	}

	return false;
}
///////////////////////////////////////////////////////////////
//
// CClientPerfStatManagerImpl::GetStats
//
//
//
///////////////////////////////////////////////////////////////
void CClientPerfStatManagerImpl::GetStats(CClientPerfStatResult* pResult, const SString& strCategory, const SString& strOptions, const SString& strFilter)
{
    pResult->Clear();

    if (strCategory == "")
    {
        // List all modules
        pResult->AddColumn("Categories");
        for (uint i = 0; i < GetModuleCount(); i++)
        {
            CClientPerfStatModule* pModule = GetModuleByIndex(i);
            pResult->AddRow()[0] = pModule->GetCategoryName();
        }
        pResult->AddRow()[0] = "Help";
        return;
    }

    // Handle help
    if (strCategory == "Help")
    {
        pResult->AddColumn("Help");
        pResult->AddRow()[0] = "Comma separate multiple options";
        pResult->AddRow()[0] = "Type h in options and select a category to see help for that category";
        return;
    }

    // Put options in a map
    std::map<SString, int> strOptionMap;
    {
        std::vector<SString> strParts;
        strOptions.Split(",", strParts);
        for (unsigned int i = 0; i < strParts.size(); i++)
            MapSet(strOptionMap, strParts[i], 1);
    }

    // Find module
    CClientPerfStatModule* pModule = GetModuleByCategoryName(strCategory);
    if (!pModule)
    {
        pResult->AddColumn("Error");
        pResult->AddRow()[0] = "Error: Unknown category '" + strCategory + "'";
        return;
    }

    // Get stats from module
    pModule->GetStats(pResult, strOptionMap, strFilter);
}