Skip to content

Commit

Permalink
Some fixed to PPropertyReader
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Sep 6, 2024
1 parent 83bf1fd commit afff703
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Toshi/Plugins/Include/PPropertyParser/PProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ class PPROPERTYPARSER_EXPORTS PProperties : Toshi::TObject

PProperties *m_pParentProps; // 0x8
Toshi::TQList<PProperty> m_oPropSet; // 0xC
TINT m_iPropCount; //0x14
TINT m_iPropCount; // 0x14
};
2 changes: 1 addition & 1 deletion Toshi/Plugins/Include/PPropertyParser/PPropertyReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ class PPROPERTYPARSER_EXPORTS PPropertyReader : public Toshi::TObject
Toshi::TFileLexerUTF8 *m_pLexer; // 0x10
TBOOL m_bLoadComments; // 0x24
TBOOL m_bAssertOnError; // 0x25
Toshi::TArray<PProperties> m_oPropertyBlocks; // 0x28
Toshi::TArray<PProperties> m_oPropertyBlock; // 0x28
};
14 changes: 8 additions & 6 deletions Toshi/Plugins/Include/PPropertyParser/PPropertyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,19 @@ class PPROPERTYPARSER_EXPORTS PPropertyValue
}

protected:
Toshi::TManagedPtr<PProperties> &GetPropertiesMP()
// Toshi::TManagedPtr<PProperties>
PProperties *GetPropertiesMP()
{
TASSERT(TYPE_PROPS == m_type);
Toshi::TManagedPtr<PProperties> value(m_valueProps);
return value;
//Toshi::TManagedPtr<PProperties> value(m_valueProps);
return m_valueProps;
}
Toshi::TManagedPtr<PPropertyValueArray> &GetPropArrayMP()
// Toshi::TManagedPtr<PPropertyValueArray>
PPropertyValueArray *GetPropArrayMP()
{
TASSERT(TYPE_ARRAY == m_type);
Toshi::TManagedPtr<PPropertyValueArray> value(m_valueArray);
return value;
//Toshi::TManagedPtr<PPropertyValueArray> value(m_valueArray);
return m_valueArray;
}

public:
Expand Down
32 changes: 15 additions & 17 deletions Toshi/Plugins/Source/PPropertyParser/PPropertyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ TBOOL PPropertyReader::GetValue(PPropertyValue &a_rValue)
if (token.GetType() == Toshi::TFileLexer::TOKEN_OPENBRACE) {
PPropertyValueArray *values = new PPropertyValueArray(3);
m_pLexer->GetNextToken();
Toshi::TFileLexer::Token token2;
PPropertyValue *val;
do {
if (m_pLexer->PeekNextToken(0).GetType() == Toshi::TFileLexer::TOKEN_CLOSEBRACE) {
m_pLexer->GetNextToken();
break;
a_rValue = values;
return TTRUE;
}
values->m_oValues.Push(PPropertyValue());
if (!GetValue(values->m_oValues[values->m_oValues.GetNumElements()])) {
if (!GetValue(values->m_oValues[values->m_oValues.GetNumElements()-1])) {
return TFALSE;
}
} while (token2 = m_pLexer->GetNextToken(), token2.GetType() == Toshi::TFileLexer::TOKEN_COMMA);
if (token2.GetType() != Toshi::TFileLexer::TOKEN_CLOSEBRACE) {
} while (token = m_pLexer->GetNextToken(), token.GetType() == Toshi::TFileLexer::TOKEN_COMMA);
if (token.GetType() != Toshi::TFileLexer::TOKEN_CLOSEBRACE) {
Error("Expected a comma or close brace inside a list");
return TFALSE;
}
Expand Down Expand Up @@ -136,17 +135,17 @@ TBOOL PPropertyReader::LoadProperty(PProperties *a_pProperty)
Toshi::TFileLexer::Token token = m_pLexer->PeekNextToken(0);
Toshi::TFileLexer::TokenType type = token.GetType();
if (type == Toshi::TFileLexer::TOKEN_CLOSEBRACE) {
if (m_oPropertyBlocks.GetNumElements() > 0) {
m_oPropertyBlocks.Pop();
if (m_oPropertyBlock.GetNumElements() > 0) {
m_oPropertyBlock.Pop();
}
m_pLexer->GetNextToken();
return TTRUE;
}
if (type == Toshi::TFileLexer::TOKEN_EOF && m_oPropertyBlocks.GetNumElements() != 0) {
PProperties propBlock = m_oPropertyBlocks.Pop();
if (type == Toshi::TFileLexer::TOKEN_EOF && m_oPropertyBlock.GetNumElements() != 0) {
PProperties propBlock = m_oPropertyBlock.End().Get();
Error(Toshi::TCString().Format("Unexpected end of file in middle of property block (started at line %d)"));
if (m_oPropertyBlocks.GetNumElements() > 0) {
m_oPropertyBlocks.Pop();
if (m_oPropertyBlock.GetNumElements() > 0) {
m_oPropertyBlock.Pop();
}
return TFALSE;
}
Expand All @@ -171,7 +170,7 @@ TBOOL PPropertyReader::LoadProperty(PProperties *a_pProperty)
Toshi::TFileLexer::Token nextToken = m_pLexer->GetNextToken();
PProperties *prop;
if (nextToken.GetType() == Toshi::TFileLexer::TOKEN_OPENBRACE) {
prop = m_oPropertyBlocks.Push(new PProperties());
prop = m_oPropertyBlock.Push(new PProperties());
prop->PutProperty(propertyName, PPropertyValue(prop), comment);
if (!LoadProperty(prop)) {
return TFALSE;
Expand Down Expand Up @@ -211,18 +210,17 @@ TBOOL PPropertyReader::LoadProperty(PProperties *a_pProperty)
TBOOL PPropertyReader::LoadPropertyBlock(PProperties &a_rProperty)
{
TASSERT(m_pLexer != TNULL);
Toshi::TFileLexer::Token token = m_pLexer->PeekNextToken(0);
if (token.GetType() == Toshi::TFileLexer::TOKEN_EOF) {
if (m_pLexer->PeekNextToken(0).GetType() == Toshi::TFileLexer::TOKEN_EOF) {
return TFALSE;
}
m_oPropertyBlock.Clear();
return LoadProperty(&a_rProperty);
}

PProperties *PPropertyReader::LoadPropertyBlock()
{
TASSERT(m_pLexer != TNULL);
Toshi::TFileLexer::Token token = m_pLexer->PeekNextToken(0);
if (token.GetType() == Toshi::TFileLexer::TOKEN_EOF) {
if (m_pLexer->PeekNextToken(0).GetType() == Toshi::TFileLexer::TOKEN_EOF) {
return TNULL;
}
PProperties *propertyBlock = new PProperties();
Expand Down
18 changes: 12 additions & 6 deletions Toshi/Plugins/Source/PPropertyParser/PPropertyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ PPropertyValue::PPropertyValue(PProperties *props)
{
m_type = TYPE_PROPS;
m_valueProps = TNULL;
GetPropertiesMP() = props;
m_valueProps = props;
}

PPropertyValue::PPropertyValue(const PPropertyValue &a_rOther)
Expand All @@ -66,6 +66,12 @@ PPropertyValue::PPropertyValue(const PPropertyValue &a_rOther)

PPropertyValue::~PPropertyValue()
{
if (m_type == TYPE_TPCSTRING) {
GetTPCString().~TPCString();
}
else if (m_type == TYPE_PROPS) {
delete GetPropertiesMP();
}
}

void PPropertyValue::Assign(const PPropertyValue &a_rValue)
Expand All @@ -87,7 +93,7 @@ void PPropertyValue::Assign(const PPropertyValue &a_rValue)
m_valueBool = a_rValue.GetBoolean();
}
else if (m_type == TYPE_PROPS) {
TManagedPtr<PProperties> props = GetPropertiesMP();
PProperties *props = GetPropertiesMP();
PProperties *otherProps = a_rValue.m_type == TYPE_PROPS ? a_rValue.m_valueProps : TNULL;
if (props != otherProps) {
if (props) {
Expand All @@ -103,7 +109,7 @@ void PPropertyValue::Assign(const PPropertyValue &a_rValue)
m_valueName = new PPropertyName(a_rValue.GetPropertyName());
}
else if (m_type == TYPE_ARRAY) {
TManagedPtr<PPropertyValueArray> arr = GetPropArrayMP();
PPropertyValueArray *arr = GetPropArrayMP();
PPropertyValueArray *otherArr = a_rValue.GetArray();
if (arr != otherArr) {
if (arr) {
Expand All @@ -126,10 +132,10 @@ TBOOL PPropertyValue::ChangeType(const TClass *a_pType)
GetTPCString().~TPCString();
}
else if (m_type == TYPE_PROPS) {
GetPropertiesMP().~TManagedPtr();
delete GetPropertiesMP();
}
else if (m_type == TYPE_ARRAY) {
GetPropArrayMP().~TManagedPtr();
delete GetPropArrayMP();
}
else if (m_type == TYPE_PROPNAME) {
delete m_valueName;
Expand Down Expand Up @@ -271,7 +277,7 @@ const PPropertyName &PPropertyValue::GetPropertyName() const
void PPropertyValue::SetArray(PPropertyValueArray *a_pArray)
{
ChangeType(TYPE_ARRAY);
GetPropArrayMP() = a_pArray;
m_valueArray = a_pArray;
}

PPropertyValueArray::PPropertyValueArray()
Expand Down

0 comments on commit afff703

Please sign in to comment.