-
Notifications
You must be signed in to change notification settings - Fork 44
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
Vireo EggShell Refactor for Supporting More Types #471
Changes from all commits
167e818
c4fbfd7
493d545
7fa3d60
ce1727c
e69710c
20c171c
56d5567
f303d55
d58340d
b7c830f
6db6834
5f812dc
cfd90b0
9d732e7
440a175
caa3ca8
3c6658e
7ec6613
6e61e37
89b024b
285aafa
c95bfdd
357a758
9978769
a500383
deefc47
3b526c1
8c3eee6
e200e3e
289aad2
38f6b95
4327ab0
7563590
93713db
e365f83
800ca42
129c512
17bffae
9524c9d
c761212
d9755cc
070a00c
6ccce6e
f816bcb
4282813
b324a8d
44724a8
a905e11
cc225b8
d59084d
b14bda8
5eb6d59
4f8a8e2
0e9519d
e9e9b21
7004589
72050a1
f391fd4
ae135ca
9db209f
e79f1e3
c01c7e2
558ff6f
32b5f73
48562fd
1eef26c
7754218
8498742
80c9e0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,67 +118,93 @@ VIREO_EXPORT Int32 EggShell_PokeMemory(TypeManagerRef tm, | |
} | ||
} | ||
//------------------------------------------------------------ | ||
//! Write a numeric value to a symbol. Value will be coerced as needed. | ||
VIREO_EXPORT void EggShell_WriteDouble(TypeManagerRef tm, const char* viName, const char* eltName, Double d) | ||
//! Get a reference to the type pointer and data for a symbol. | ||
VIREO_EXPORT EggShellResult EggShell_FindValue(TypeManagerRef tm, const char* viName, const char* eltName, TypeRef* typeRefLocation, void** dataRefLocation) | ||
{ | ||
void *pData = nullptr; | ||
|
||
TypeManagerScope scope(tm); | ||
SubString objectName(viName); | ||
SubString path(eltName); | ||
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true); | ||
if (actualType == nullptr) | ||
return; | ||
*typeRefLocation = tm->GetObjectElementAddressFromPath(&objectName, &path, dataRefLocation, true); | ||
if (*typeRefLocation == nullptr) | ||
return kEggShellResult_ObjectNotFoundAtPath; | ||
|
||
WriteDoubleToMemory(actualType, pData, d); | ||
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
//! Read a numeric value from a symbol. Value will be coerced as needed. | ||
VIREO_EXPORT Double EggShell_ReadDouble(TypeManagerRef tm, const char* viName, const char* eltName) | ||
//! Get a reference to the type pointer and data for a sub element | ||
VIREO_EXPORT EggShellResult EggShell_FindSubValue(TypeManagerRef tm, | ||
const TypeRef typeRef, void * pData, const char* eltName, TypeRef* typeRefLocation, void** dataRefLocation) | ||
{ | ||
void *pData = nullptr; | ||
SubString objectName(viName); | ||
if (typeRef == nullptr || !typeRef->IsValid()) | ||
return kEggShellResult_InvalidTypeRef; | ||
|
||
TypeManagerScope scope(tm); | ||
SubString path(eltName); | ||
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true); | ||
if (actualType == nullptr) | ||
return -1; | ||
*typeRefLocation = typeRef->GetSubElementAddressFromPath(&path, pData, dataRefLocation, true); | ||
if (*typeRefLocation == nullptr) | ||
return kEggShellResult_ObjectNotFoundAtPath; | ||
|
||
return ReadDoubleFromMemory(actualType, pData); | ||
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
// Write a string value to a symbol. Value will be parsed according to format designated. | ||
VIREO_EXPORT void EggShell_WriteValueString(TypeManagerRef tm, | ||
const char* viName, const char* eltName, const char* format, const char* value) | ||
//! Write a numeric value to a symbol. Value will be coerced as needed. | ||
VIREO_EXPORT EggShellResult EggShell_WriteDouble(TypeManagerRef tm, const TypeRef typeRef, void* pData, Double value) | ||
{ | ||
TypeManagerScope scope(tm); | ||
if (typeRef == nullptr || !typeRef->IsValid()) | ||
return kEggShellResult_InvalidTypeRef; | ||
|
||
void *pData = nullptr; | ||
NIError error = WriteDoubleToMemory(typeRef, pData, value); | ||
if (error) | ||
return kEggShellResult_UnexpectedObjectType; | ||
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
//! Read a numeric value from a symbol. Value will be coerced as needed. | ||
VIREO_EXPORT EggShellResult EggShell_ReadDouble(TypeManagerRef tm, const TypeRef typeRef, const void* pData, Double* result) | ||
{ | ||
TypeManagerScope scope(tm); | ||
if (typeRef == nullptr || !typeRef->IsValid()) | ||
return kEggShellResult_InvalidTypeRef; | ||
|
||
if (result == nullptr) | ||
return kEggShellResult_InvalidResultPointer; | ||
|
||
NIError error = kNIError_Success; | ||
*result = ReadDoubleFromMemory(typeRef, pData, &error); | ||
if (error) | ||
return kEggShellResult_UnexpectedObjectType; | ||
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
// Write a string value to a symbol. Value will be parsed according to format designated. | ||
VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, const char* value) | ||
{ | ||
TypeManagerScope scope(tm); | ||
|
||
SubString objectName(viName); | ||
SubString path(eltName); | ||
SubString valueString(value); | ||
|
||
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true); | ||
if (actualType == nullptr) | ||
return; | ||
if (typeRef == nullptr || !typeRef->IsValid()) | ||
return kEggShellResult_InvalidTypeRef; | ||
|
||
EventLog log(EventLog::DevNull); | ||
SubString formatss(format); | ||
TDViaParser parser(tm, &valueString, &log, 1, &formatss, true, true, true); | ||
parser.ParseData(actualType, pData); | ||
Int32 error = parser.ParseData(typeRef, pData); | ||
if (error) { | ||
return kEggShellResult_UnableToParseData; | ||
} | ||
|
||
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
//! Read a symbol's value as a string. Value will be formatted according to the format designated. | ||
VIREO_EXPORT const char* EggShell_ReadValueString(TypeManagerRef tm, | ||
const char* viName, const char* eltName, const char* format) | ||
//! Read a symbol's value as a string. Value will be formatted according to designated format. | ||
VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, UInt8** valueString) | ||
{ | ||
TypeManagerScope scope(tm); | ||
void *pData = nullptr; | ||
|
||
SubString objectName(viName); | ||
SubString path(eltName); | ||
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true); | ||
if (actualType == nullptr) | ||
return nullptr; | ||
if (typeRef == nullptr || !typeRef->IsValid()) | ||
return kEggShellResult_InvalidTypeRef; | ||
|
||
static StringRef returnBuffer = nullptr; | ||
if (returnBuffer == nullptr) { | ||
|
@@ -193,12 +219,14 @@ VIREO_EXPORT const char* EggShell_ReadValueString(TypeManagerRef tm, | |
if (returnBuffer) { | ||
SubString formatss(format); | ||
TDViaFormatter formatter(returnBuffer, true, 0, &formatss, kJSONEncodingEggShell); | ||
formatter.FormatData(actualType, pData); | ||
// Add an explicit nullptr terminator so it looks like a C string. | ||
formatter.FormatData(typeRef, pData); | ||
// Add an explicit null terminator so it looks like a C string. | ||
returnBuffer->Append((Utf8Char)'\0'); | ||
return (const char*) returnBuffer->Begin(); | ||
*valueString = returnBuffer->Begin(); | ||
return kEggShellResult_Success; | ||
} | ||
return ""; | ||
|
||
return kEggShellResult_UnableToCreateReturnBuffer; | ||
} | ||
void CopyArrayTypeNameStringToBuffer(StringRef arrayTypeNameBuffer, SubString arrayTypeName) | ||
{ | ||
|
@@ -257,20 +285,26 @@ VIREO_EXPORT Int32 EggShell_GetArrayDimLength(TypeManagerRef tm, const char* viN | |
} | ||
//------------------------------------------------------------ | ||
//! Resizes a variable size Array symbol to have new dimension lengths specified by newLengths, it also initializes cells for non-flat data. | ||
//! Returns -1 if the symbols is not found, -2 if was not possible to resize the array and 0 if resizing was successful. | ||
VIREO_EXPORT Int32 EggShell_ResizeArray(TypeManagerRef tm, const char* viName, const char* eltName, Int32 rank, Int32* newLengths) | ||
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef typeRef, const void* pData, | ||
Int32 rank, Int32 dimensionLengths[]) | ||
{ | ||
SubString objectName(viName); | ||
SubString path(eltName); | ||
void *pData = nullptr; | ||
TypeManagerScope scope(tm); | ||
if (typeRef == nullptr || !typeRef->IsValid()) | ||
return kEggShellResult_InvalidTypeRef; | ||
|
||
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true); | ||
if (actualType == nullptr || !actualType->IsArray()) { | ||
return kLVError_ArgError; | ||
} | ||
if (!typeRef->IsArray()) | ||
return kEggShellResult_UnexpectedObjectType; | ||
|
||
TypedArrayCoreRef actualArray = *(TypedArrayCoreRef*)pData; | ||
return Data_ResizeArray(tm, actualArray, rank, newLengths); | ||
if (typeRef->Rank() != rank) | ||
return kEggShellResult_MismatchedArrayRank; | ||
|
||
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData; | ||
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject)); | ||
|
||
if (!arrayObject->ResizeDimensions(rank, dimensionLengths, true, false)) { | ||
return kEggShellResult_UnableToCreateReturnBuffer; | ||
} | ||
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT void* Data_GetStringBegin(StringRef stringObject) | ||
|
@@ -329,6 +363,34 @@ VIREO_EXPORT EggShellResult Data_GetArrayMetadata(TypeManagerRef tm, | |
return kEggShellResult_Success; | ||
} | ||
//------------------------------------------------------------ | ||
//! Get the starting location of the first element of an Array / String type in memory | ||
// This function returns the start address of where elements would appear in memory (returns address even if length zero) | ||
VIREO_EXPORT void* Data_GetArrayBegin(const void* pData) | ||
{ | ||
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData; | ||
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject)); | ||
return arrayObject->BeginAt(0); | ||
} | ||
//------------------------------------------------------------ | ||
//! Get the values for dimensions of the array. Assumes dimensions target is of length equal to rank | ||
//! Caller is expected to allocate an array dimensions of size array rank for the duration of function invocation. | ||
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensionsLengths[]) | ||
{ | ||
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData; | ||
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject)); | ||
for (int i = 0; i < arrayObject->Rank(); i++) { | ||
dimensionsLengths[i] = arrayObject->GetLength(i); | ||
} | ||
} | ||
//------------------------------------------------------------ | ||
//! Get the total length for an array | ||
VIREO_EXPORT Int32 Data_GetArrayLength(const void* pData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name ArrayLength is good 👍 |
||
{ | ||
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData; | ||
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject)); | ||
return arrayObject->Length(); | ||
} | ||
//------------------------------------------------------------ | ||
//! Get the Length of a dimension in an Array Symbol. Returns -1 if the Symbol is not found or not | ||
//! an Array or dimension requested is out of the bounds of the rank. | ||
VIREO_EXPORT Int32 Data_GetArrayDimLength(TypeManagerRef tm, TypedArrayCoreRef arrayObject, Int32 dim) | ||
|
@@ -505,10 +567,54 @@ VIREO_EXPORT Int32 TypeRef_Alignment(TypeRef typeRef) | |
return typeRef->AQAlignment(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT void TypeRef_Name(TypeRef typeRef, Int32* bufferSize, char* buffer) | ||
VIREO_EXPORT const char* TypeRef_Name(TypeManagerRef tm, TypeRef typeRef) | ||
{ | ||
TypeManagerScope scope(tm); | ||
SubString name = typeRef->Name(); | ||
*bufferSize = name.CopyToBoundedBuffer(*bufferSize, reinterpret_cast<Utf8Char*>(buffer)); | ||
|
||
static StringRef returnBuffer = nullptr; | ||
if (returnBuffer == nullptr) { | ||
// Allocate a string the first time it is used. | ||
// After that it will be resized as needed. | ||
STACK_VAR(String, tempReturn); | ||
returnBuffer = tempReturn.DetachValue(); | ||
} else { | ||
returnBuffer->Resize1D(name.Length() + 1); | ||
} | ||
|
||
if (returnBuffer) { | ||
returnBuffer->CopyFromSubString(&name); | ||
// Add an explicit null terminator so it looks like a C string. | ||
returnBuffer->Append((Utf8Char)'\0'); | ||
return (const char*) returnBuffer->Begin(); | ||
} | ||
|
||
return ""; | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT const char* TypeRef_ElementName(TypeManagerRef tm, TypeRef typeRef) | ||
{ | ||
TypeManagerScope scope(tm); | ||
SubString name = typeRef->ElementName(); | ||
|
||
static StringRef returnBuffer = nullptr; | ||
if (returnBuffer == nullptr) { | ||
// Allocate a string the first time it is used. | ||
// After that it will be resized as needed. | ||
STACK_VAR(String, tempReturn); | ||
returnBuffer = tempReturn.DetachValue(); | ||
} else { | ||
returnBuffer->Resize1D(name.Length() + 1); | ||
} | ||
|
||
if (returnBuffer) { | ||
returnBuffer->CopyFromSubString(&name); | ||
// Add an explicit null terminator so it looks like a C string. | ||
returnBuffer->Append((Utf8Char)'\0'); | ||
return (const char*) returnBuffer->Begin(); | ||
} | ||
|
||
return ""; | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Int32 TypeRef_ElementOffset(TypeRef typeRef) | ||
|
@@ -546,6 +652,66 @@ VIREO_EXPORT TypeRef TypeRef_GetSubElementByIndex(TypeRef typeRef, Int32 index) | |
return typeRef->GetSubElement(index); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsCluster(TypeRef typeRef) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have the prefix of EggShell for all the new APIs that start with TypeRef as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are not exposing these functions to eggShell, I don't think they should be prefixed as eggshell. That's why we added the typeHelpers module. |
||
{ | ||
return typeRef->IsCluster(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsArray(TypeRef typeRef) | ||
{ | ||
return typeRef->IsArray(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsBoolean(TypeRef typeRef) | ||
{ | ||
return typeRef->IsBoolean(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsInteger(TypeRef typeRef) | ||
{ | ||
return typeRef->IsInteger(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsSigned(TypeRef typeRef) | ||
{ | ||
return typeRef->IsSignedInteger(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsEnum(TypeRef typeRef) | ||
{ | ||
return typeRef->IsEnum(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsFloat(TypeRef typeRef) | ||
{ | ||
return typeRef->IsFloat(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsString(TypeRef typeRef) | ||
{ | ||
return typeRef->IsString(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsPath(TypeRef typeRef) | ||
{ | ||
return typeRef->IsPath(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsTimestamp(TypeRef typeRef) | ||
{ | ||
return typeRef->IsTimestamp(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsComplex(TypeRef typeRef) | ||
{ | ||
return typeRef->IsComplex(); | ||
} | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Boolean TypeRef_IsAnalogWaveform(TypeRef typeRef) | ||
{ | ||
return typeRef->IsAnalogWaveform(); | ||
} | ||
//------------------------------------------------------------ | ||
//------------------------------------------------------------ | ||
VIREO_EXPORT Int32 Data_RawBlockSize(TypedBlock* object) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to designated format" instead of "to format designated"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it