Skip to content

Commit

Permalink
OpenImageIOAlgo : InternedStringVectorData
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Oct 26, 2023
1 parent 2795c41 commit 3353bb0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
10.5.x.x (relative to 10.5.2.1)
========

Improvements
------------

- OpenImageIOAlgo : Added support for `InternedStringVectorData` to `DataView`.

10.5.2.1 (relative to 10.5.2.0)
========

Expand Down
67 changes: 44 additions & 23 deletions src/IECoreImage/OpenImageIOAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@
using namespace OIIO;
using namespace IECore;

namespace
{

template<typename T>
OIIO::TypeDesc extractStringCharPointers( const std::vector<T> &strings, std::vector<const char *> &charPointers, bool createUStrings )
{
size_t numStrings = strings.size();
OIIO::TypeDesc type = TypeDesc(
TypeDesc::STRING,
TypeDesc::SCALAR,
TypeDesc::NOSEMANTICS,
numStrings
);

charPointers.resize( numStrings );

if ( createUStrings )
{
for(size_t i = 0; i < numStrings; ++i)
{
charPointers[i] = ustring( strings[i].c_str() ).c_str();
}
}
else
{
for(size_t i = 0; i < numStrings; ++i)
{
charPointers[i] = strings[i].c_str();
}
}

return type;
}

} // namespace

namespace IECoreImage
{

Expand Down Expand Up @@ -501,30 +537,15 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
case StringVectorDataTypeId:
{
const auto &readableStrings = static_cast<const StringVectorData *>( d )->readable();
size_t numStrings = readableStrings.size();
type = TypeDesc(
TypeDesc::STRING,
TypeDesc::SCALAR,
TypeDesc::NOSEMANTICS,
numStrings
);

m_charPointers.resize( numStrings );
type = extractStringCharPointers( readableStrings, m_charPointers, createUStrings );

if ( createUStrings )
{
for(size_t i = 0; i < numStrings; ++i)
{
m_charPointers[i] = ustring( readableStrings[i].c_str() ).c_str();
}
}
else
{
for(size_t i = 0; i < numStrings; ++i)
{
m_charPointers[i] = readableStrings[i].c_str();
}
}
data = &m_charPointers[0];
}
break;
case InternedStringVectorDataTypeId:
{
const auto &readableStrings = static_cast<const InternedStringVectorData *>( d )->readable();
type = extractStringCharPointers( readableStrings, m_charPointers, createUStrings );

data = &m_charPointers[0];
}
Expand Down

0 comments on commit 3353bb0

Please sign in to comment.