Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for deleting attributes from a Variant and fixed bugs with outputs no wired #588

Merged
merged 4 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 47 additions & 36 deletions source/core/Variants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ VIREO_FUNCTION_SIGNATURET(VariantToData, VariantToDataParamBlock)
void* destData = _ParamImmediate(DestData)._pData;

if (inputType->Name().Compare(&TypeCommon::TypeVariant)) {
TypeRef variantInnerType = *(TypeRef *)_ParamImmediate(InputData._pData);
TypeRef variantInnerType = *reinterpret_cast<TypeRef *>_ParamImmediate(InputData._pData);
if (variantInnerType->IsA(destType)) {
variantInnerType->CopyData(variantInnerType->Begin(kPARead), destData);
} else if (errPtr) {
errPtr->SetErrorAndAppendCallChain(true, 91, "Variant To Data");
errPtr->SetErrorAndAppendCallChain(true, kVariantIncompatibleType, "Variant To Data");
}
} else {
if (inputType->IsA(destType)) {
inputType->CopyData(inputData, destData);
} else if (errPtr) {
errPtr->SetErrorAndAppendCallChain(true, 91, "Variant To Data");
errPtr->SetErrorAndAppendCallChain(true, kVariantIncompatibleType, "Variant To Data");
}
}
}
Expand All @@ -97,7 +97,7 @@ VIREO_FUNCTION_SIGNATURET(SetVariantAttribute, SetVariantAttributeParamBlock)
StringRef name = _Param(Name);
if (IsStringEmpty(name)) {
if (errPtr) {
errPtr->SetErrorAndAppendCallChain(true, 1, "Set Variant Attribute");
errPtr->SetErrorAndAppendCallChain(true, kVariantArgErr, "Set Variant Attribute");
}
} else {
TypeManagerRef tm = THREAD_TADM();
Expand Down Expand Up @@ -131,9 +131,8 @@ VIREO_FUNCTION_SIGNATURET(SetVariantAttribute, SetVariantAttributeParamBlock)
}
}
}
if (_ParamPointer(Replaced)) {
if (_ParamPointer(Replaced))
_Param(Replaced) = replaced;
}
return _NextInstruction();
}

Expand Down Expand Up @@ -167,16 +166,15 @@ VIREO_FUNCTION_SIGNATURET(GetVariantAttribute, GetVariantAttributeParamBlock)
found = true;
value->_paramType->CopyData(foundValue->Begin(kPARead), value->_pData);
} else {
if (errPtr) {
errPtr->SetErrorAndAppendCallChain(true, 91, "Get Variant Attribute"); // Incorrect type for default value for the attribute
if (errPtr) { // Incorrect type for default attribute value
cglzaguilar marked this conversation as resolved.
Show resolved Hide resolved
errPtr->SetErrorAndAppendCallChain(true, kVariantIncompatibleType, "Get Variant Attribute");
}
}
}
}
}
if (_ParamPointer(Found)) {
if (_ParamPointer(Found))
_Param(Found) = found;
}
return _NextInstruction();
}

Expand All @@ -192,10 +190,10 @@ struct GetVariantAttributesAllParamBlock : public InstructionCore
VIREO_FUNCTION_SIGNATURET(GetVariantAttributeAll, GetVariantAttributesAllParamBlock)
{
ErrorCluster *errPtr = _ParamPointer(ErrorClust);
TypedArrayCoreRef names = _Param(Names);
TypedArrayCoreRef values = _Param(Values);
TypedArrayCoreRef names = _ParamPointer(Names) ? _Param(Names) : nullptr;
TypedArrayCoreRef values = _ParamPointer(Values) ? _Param(Values) : nullptr;
bool bResetOutputArrays = true;
if (!errPtr || !errPtr->status) {
if ((!errPtr || !errPtr->status) && (names || values)) {
TypeRef inputVariant = _Param(InputVariant);
const VariantAttributeManager::VariantToAttributeMapType &variantToAttributeMap = VariantAttributeManager::Instance().GetVariantToAttributeMap();

Expand All @@ -205,35 +203,43 @@ VIREO_FUNCTION_SIGNATURET(GetVariantAttributeAll, GetVariantAttributesAllParamBl
const auto mapSize = attributeMap->size();
if (mapSize != 0) {
bResetOutputArrays = false;
names->Resize1D(mapSize);
values->Resize1D(mapSize);
AQBlock1* pNamesInsert = names->BeginAt(0);
AQBlock1* pValuesInsert = values->BeginAt(0);
TypeRef namesElementType = names->ElementType();
TypeRef valuesElementType = values->ElementType();
const Int32 namesAQSize = namesElementType->TopAQSize();
const Int32 valuesAQSize = valuesElementType->TopAQSize();
if (names)
names->Resize1D(mapSize);
if (values)
values->Resize1D(mapSize);
AQBlock1* pNamesInsert = names ? names->BeginAt(0) : nullptr;
TypeRef namesElementType = names ? names->ElementType() : nullptr;
Int32 namesAQSize = names ? namesElementType->TopAQSize() : 0;
AQBlock1* pValuesInsert = values ? values->BeginAt(0) : nullptr;
TypeRef valuesElementType = values ? values->ElementType() : nullptr;
Int32 valuesAQSize = values ? valuesElementType->TopAQSize() : 0;
TypeManagerRef tm = THREAD_TADM();
for (const auto attributePair : *attributeMap) {
String* const* attributeNameStr = &(attributePair.first);
TypeRef attributeValue = attributePair.second;
namesElementType->CopyData(attributeNameStr, pNamesInsert);
if (attributeValue->Name().Compare(&TypeCommon::TypeVariant)) {
attributeValue->CopyData(attributeValue->Begin(kPARead), pValuesInsert);
} else {
TypeRef variant = DefaultValueType::New(tm, attributeValue, true);
variant->CopyData(attributeValue->Begin(kPARead), variant->Begin(kPAWrite));
*reinterpret_cast<TypeRef *>(pValuesInsert) = variant;
if (names) {
namesElementType->CopyData(attributeNameStr, pNamesInsert);
pNamesInsert += namesAQSize;
}
if (values) {
if (attributeValue->Name().Compare(&TypeCommon::TypeVariant)) {
attributeValue->CopyData(attributeValue->Begin(kPARead), pValuesInsert);
} else {
TypeRef variant = DefaultValueType::New(tm, attributeValue, true);
variant->CopyData(attributeValue->Begin(kPARead), variant->Begin(kPAWrite));
*reinterpret_cast<TypeRef *>(pValuesInsert) = variant;
}
pValuesInsert += valuesAQSize;
}
pNamesInsert += namesAQSize;
pValuesInsert += valuesAQSize;
}
}
}
}
if (bResetOutputArrays) {
names->Resize1D(0);
values->Resize1D(0);
if (names)
names->Resize1D(0);
if (values)
values->Resize1D(0);
}
return _NextInstruction();
}
Expand All @@ -251,7 +257,8 @@ VIREO_FUNCTION_SIGNATURET(DeleteVariantAttribute, DeleteVariantAttributeParamBlo
{
ErrorCluster *errPtr = _ParamPointer(ErrorClust);
StringRef *name = _ParamPointer(Name);
_Param(Found) = false;
bool clearAllAttributes = (!name || (*name)->Length() == 0);
cglzaguilar marked this conversation as resolved.
Show resolved Hide resolved
Boolean found = false;
if (!errPtr || !errPtr->status) {
const TypeRef inputVariant = _Param(InputVariant);
VariantAttributeManager::VariantToAttributeMapType &variantToAttributeMap = VariantAttributeManager::Instance().GetVariantToAttributeMap();
Expand All @@ -261,25 +268,29 @@ VIREO_FUNCTION_SIGNATURET(DeleteVariantAttribute, DeleteVariantAttributeParamBlo
VariantAttributeManager::AttributeMapType *attributeMap = variantToAttributeMapIter->second;
const auto mapSize = attributeMap->size();
if (mapSize != 0) {
if (!name) {
if (clearAllAttributes) {
for (auto attribute : *attributeMap) {
attribute.first->Delete(attribute.first);
}
attributeMap->clear();
variantToAttributeMap.erase(variantToAttributeMapIter);
delete attributeMap;
_Param(Found) = true;
found = true;
} else {
const auto attributeMapIterator = attributeMap->find(*name);
if (attributeMapIterator != attributeMap->end()) {
_Param(Found) = true;
found = true;
attributeMapIterator->first->Delete(attributeMapIterator->first);
attributeMap->erase(attributeMapIterator);
}
}
}
} else if (clearAllAttributes) {
found = true;
}
}
if (_ParamPointer(Found))
_Param(Found) = found;
return _NextInstruction();
}

Expand Down
3 changes: 3 additions & 0 deletions source/include/Variants.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class VariantAttributeManager {
CleanUp();
}
};

enum { kVariantArgErr = 1, kVariantIncompatibleType = 91};
cglzaguilar marked this conversation as resolved.
Show resolved Hide resolved

} // namespace Vireo

#endif
8 changes: 8 additions & 0 deletions test-it/ExpectedResults/TestVI_VariantDeleteAttributes.vtr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dataItem_TestResult_AttributeDoesNotExist = true
dataItem_TestResult_DeleteAllAttributes = true
dataItem_TestResult_DeleteAllAttributesJustErrorOut = true
dataItem_TestResult_DeleteAllAttributesTwice = true
dataItem_TestResult_DeleteAllAttributesWithErrorIn = true
dataItem_TestResult_DeleteAttribute = true
dataItem_TestResult_ErrorInCorrectlyPropagated = true
dataItem_TestResult_GetAttributeUnwiredOutputs = true
Loading