ini parser completed
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "SDL3/SDL_vulkan.h"
|
||||
#include "materialsystem/materialsystem.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#define VK_NO_PROTOTYPES
|
||||
#include "vulkan/vulkan_core.h"
|
||||
@@ -63,6 +64,7 @@ IIndexBuffer *CVkRenderContext::CreateIndexBuffer( uint32_t nSize )
|
||||
//-----------------------------------------------------------------------------
|
||||
IBuffer *CreateBuffer( uint32_t nSize, VkBufferUsageFlags2 eUsage )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -208,8 +210,16 @@ void CVkRenderContext::Frame( float fDeltaTime )
|
||||
|
||||
void CVkRenderContext::CreateSwapchain()
|
||||
{
|
||||
CUtlVector<VkSurfaceFormatKHR> surfaceFormats;
|
||||
|
||||
gamewindow->CreateVulkanSurface(g_vkInstance);
|
||||
|
||||
VkSwapchainCreateInfoKHR stSwapchainCreateInfo = {};
|
||||
stSwapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
stSwapchainCreateInfo.surface = (VkSurfaceKHR)gamewindow->GetVulkanSurface();
|
||||
|
||||
vkCreateSwapchainKHR(g_vkDevice, &stSwapchainCreateInfo, NULL, &g_vkSwapchain);
|
||||
|
||||
}
|
||||
|
||||
void CVkRenderContext::DestroySwapchain()
|
||||
|
||||
@@ -127,7 +127,7 @@ void CUtlVector<T>::AppendHead( const T &data )
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
||||
void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
||||
{
|
||||
size_t nOldSize = m_nSize;
|
||||
m_data.Resize(m_nSize+n);
|
||||
@@ -144,13 +144,13 @@ void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendTail( const T &data )
|
||||
void CUtlVector<T>::AppendTail( const T &data )
|
||||
{
|
||||
AppendTail(&data,1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||
{
|
||||
m_data.Resize(m_data.GetSize()+n);
|
||||
for ( size_t i = 0; i < n; i++ )
|
||||
@@ -159,13 +159,13 @@ void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T &data )
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T &data )
|
||||
{
|
||||
AppendAt(nIndex, &data, 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T *pData, size_t n )
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T *pData, size_t n )
|
||||
{
|
||||
size_t nOldSize = m_nSize;
|
||||
m_data.Resize(m_nSize+n);
|
||||
|
||||
@@ -24,6 +24,7 @@ abstract_class IINIManager
|
||||
{
|
||||
public:
|
||||
virtual IINIFile *ReadString( const char *psz ) = 0;
|
||||
virtual void ReleaseFile( IINIFile *pFile ) = 0;
|
||||
};
|
||||
|
||||
IINIManager *INIManager();
|
||||
|
||||
Binary file not shown.
@@ -45,5 +45,5 @@ int main( int argc, char **argv )
|
||||
if (!pTestValues)
|
||||
return 0;
|
||||
V_printf("%s\n",pTestValues->GetStringValue("abc3d"));
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -10,3 +10,4 @@ f = -890
|
||||
g = .34
|
||||
abc3d = "Hello world from the funny engine, you can use \" to add quotes"
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
enum ESectionType
|
||||
{
|
||||
SECTIONTYPE_String,
|
||||
SECTIONTYPE_Boolean,
|
||||
SECTIONTYPE_Float,
|
||||
SECTIONTYPE_STRING,
|
||||
SECTIONTYPE_BOOLEAN,
|
||||
SECTIONTYPE_FLOAT,
|
||||
};
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
virtual const char *GetStringValue( const char *szKeyName ) override;
|
||||
virtual CUtlString GetUTLStringValue( const char *szKeyName ) override;
|
||||
|
||||
CUtlVector<SectionData_t> m_values;
|
||||
CUtlVector<SectionData_t*> m_values;
|
||||
CUtlString m_szSectionName;
|
||||
};
|
||||
|
||||
@@ -47,6 +47,11 @@ int CINISection::GetIntValue( const char *szKeyName )
|
||||
|
||||
const char *CINISection::GetStringValue( const char *szKeyName )
|
||||
{
|
||||
for (auto &value: m_values)
|
||||
{
|
||||
if (value->m_szKey == szKeyName)
|
||||
return value->m_szData;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -68,7 +73,7 @@ IINISection *CINIFile::GetSection( const char *szSectionName )
|
||||
for ( auto §ion: m_sections )
|
||||
{
|
||||
if ( section->m_szSectionName == szSectionName )
|
||||
return (IINISection*)§ion;
|
||||
return (IINISection*)section;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -78,23 +83,24 @@ class CINIManager: public IINIManager
|
||||
{
|
||||
public:
|
||||
virtual IINIFile *ReadString( const char *psz ) override;
|
||||
virtual void ReleaseFile( IINIFile *pFile ) override;
|
||||
bool IsWordSymbol( char c );
|
||||
CUtlVector<CUtlString> TokenizeString();
|
||||
};
|
||||
|
||||
IINIFile *CINIManager::ReadString( const char *psz )
|
||||
{
|
||||
CINIFile *pFile = 0;
|
||||
CINIFile file = {};
|
||||
bool bIsQuoted;
|
||||
bool bIsSlash;
|
||||
CINIFile *pFile = new CINIFile;
|
||||
*pFile = {};
|
||||
bool bIsQuoted = false;
|
||||
bool bIsSlash = false;
|
||||
|
||||
bool bIsVarName;
|
||||
bool bIsVarValue;
|
||||
bool bIsSectionName;
|
||||
|
||||
CINISection currentSection;
|
||||
SectionData_t currentSectionData;
|
||||
CINISection *pCurrentSection = 0;
|
||||
SectionData_t *pCurrentSectionData = 0;
|
||||
size_t i = 0;
|
||||
|
||||
char c;
|
||||
@@ -183,14 +189,13 @@ IINIFile *CINIManager::ReadString( const char *psz )
|
||||
}
|
||||
};
|
||||
|
||||
currentSectionData.m_eSectionType = SECTIONTYPE_String;
|
||||
|
||||
for ( int i = 0; i < tokens.GetSize(); i++ )
|
||||
{
|
||||
if (tokens[i] == "]")
|
||||
{
|
||||
V_printf("Error: unexpected ]\n");
|
||||
return 0;
|
||||
return pFile;
|
||||
}
|
||||
if (tokens[i] == "[")
|
||||
{
|
||||
@@ -198,32 +203,45 @@ IINIFile *CINIManager::ReadString( const char *psz )
|
||||
if (i>=tokens.GetSize())
|
||||
{
|
||||
V_printf("Error: Trailing section start\n");
|
||||
return 0;
|
||||
return pFile;
|
||||
}
|
||||
currentSection = {};
|
||||
currentSection.m_szSectionName = tokens[i];
|
||||
V_printf("[%s]\n",currentSection.m_szSectionName.GetString());
|
||||
|
||||
pCurrentSection = (CINISection*)pFile->GetSection(tokens[i]);
|
||||
if (!pCurrentSection)
|
||||
{
|
||||
pCurrentSection = new CINISection;
|
||||
*pCurrentSection = {};
|
||||
pFile->m_sections.AppendTail(pCurrentSection);
|
||||
}
|
||||
pCurrentSection->m_szSectionName = tokens[i];
|
||||
|
||||
i++;
|
||||
if (i>=tokens.GetSize())
|
||||
{
|
||||
V_printf("Error: Trailing section name\n");
|
||||
return 0;
|
||||
return pFile;
|
||||
}
|
||||
if (tokens[i] != "]")
|
||||
{
|
||||
V_printf("Error: expected ]\n");
|
||||
return 0;
|
||||
return pFile;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!pCurrentSection)
|
||||
{
|
||||
V_printf("Error: section wasn't specified\n");
|
||||
return pFile;
|
||||
}
|
||||
if (tokens[i] == "=")
|
||||
{
|
||||
V_printf("Error: expected key\n");
|
||||
return 0;
|
||||
V_printf("Error: expected key\n");
|
||||
return pFile;
|
||||
}
|
||||
currentSectionData = {};
|
||||
currentSectionData.m_szKey = tokens[i];
|
||||
|
||||
pCurrentSectionData = new SectionData_t;
|
||||
pCurrentSectionData->m_eSectionType = SECTIONTYPE_STRING;
|
||||
pCurrentSectionData->m_szKey = tokens[i];
|
||||
|
||||
|
||||
|
||||
@@ -231,12 +249,14 @@ IINIFile *CINIManager::ReadString( const char *psz )
|
||||
if (i>=tokens.GetSize())
|
||||
{
|
||||
V_printf("Error: trailing key\n");
|
||||
return 0;
|
||||
delete pCurrentSectionData;
|
||||
return pFile;
|
||||
}
|
||||
if (tokens[i] != "=")
|
||||
{
|
||||
V_printf("Error: expected =\n");
|
||||
return 0;
|
||||
delete pCurrentSectionData;
|
||||
return pFile;
|
||||
}
|
||||
|
||||
i++;
|
||||
@@ -244,18 +264,21 @@ IINIFile *CINIManager::ReadString( const char *psz )
|
||||
if (i>=tokens.GetSize())
|
||||
{
|
||||
V_printf("Error: expected value\n");
|
||||
return 0;
|
||||
delete pCurrentSectionData;
|
||||
return pFile;
|
||||
}
|
||||
currentSectionData.m_szData = tokens[i];
|
||||
currentSection.m_values.AppendTail(currentSectionData);
|
||||
pCurrentSectionData->m_szData = tokens[i];
|
||||
|
||||
pCurrentSection->m_values.AppendTail(pCurrentSectionData);
|
||||
}
|
||||
|
||||
pFile = new CINIFile;
|
||||
*pFile = file;
|
||||
|
||||
return (IINIFile*)pFile;
|
||||
}
|
||||
|
||||
void CINIManager::ReleaseFile( IINIFile *pFile )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CINIManager::IsWordSymbol( char c )
|
||||
{
|
||||
if (V_isalnum(c))
|
||||
|
||||
Reference in New Issue
Block a user