So I have learned from David in some conversation that the TYPE_STRING
DX array is setup as a single array of characters, versus an array of
array of characters (array of strings). In other words, the array is of
type char[numStrings * shape], and to find the appropriate string, the
true index into the array needs to be calculated manually.
Relating to my original code snippet, I have changed it to look like:
array = DXAddArrayData(array, index, 1, 0); // Just perform allocation
of new element.
char* data_array_ptr = (char*)DXGetArrayData(array);
strcpy((data_array_ptr + index*256), str_value.c_str()); // Assuming
the shape of the array is 256 max str length when initially created.
This seems to work, as far as compiling and not segfaulting (which my
previous attempts did accomplish.)
HOWEVER, when I use DXExport on the entire DX group (which this array is
part of), I don't see any strings in the exported text file. Instead, I
just floating point numbers listed for that array; I would expect to see
strings listed. Is my expectation wrong? Does anyone have experience
with this? My goal here is to use the DX array to capture string values
in the same way I can capture positional integer or floating-point data.
Thanks,
Matt
--
David Thompson wrote:
You need to create the array and then strcpy(data_array_ptr[index],
str_value.c_str());
David
Hello,
Hopefully this is a question with a simple answer:
I'd like to have a DX Array of strings (TYPE_STRING). When I use
DXGetArrayData(...) to get the array, is the return type char*
(pointer to an array)? I'm not finding documentation on this.
My code looks something like:
char* data_array_ptr = (char*)DXGetArrayData(array);
data_array_ptr[index] = str_value.c_str();
// str_value is an object of the C++ STL string class, where the
c_str() method returns a null-terminated C-style string.
However, C++ errors out during compilation with the following message:
invalid conversion from `const char*' to `char'
I have also tried char** in place of "char*", as that makes more
sense, given I'm expecting to see an array of arrays. However, that
results in a similar compile error too:
invalid conversion from `const char*' to `char*'
Any ideas? I must be making an incorrect assumption here about what
is returned from the DXGetArrayData() function, but I don't see any
documentation that helps me figure it out.
Thanks,
Matt
--