diff --git a/Changes b/Changes index e6062f852c..86e334de31 100644 --- a/Changes +++ b/Changes @@ -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) ======== diff --git a/src/IECoreImage/OpenImageIOAlgo.cpp b/src/IECoreImage/OpenImageIOAlgo.cpp index 2642ed2ce9..fea731d7f5 100644 --- a/src/IECoreImage/OpenImageIOAlgo.cpp +++ b/src/IECoreImage/OpenImageIOAlgo.cpp @@ -49,6 +49,42 @@ using namespace OIIO; using namespace IECore; +namespace +{ + +template +OIIO::TypeDesc extractStringCharPointers( const std::vector &strings, std::vector &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 { @@ -501,30 +537,15 @@ DataView::DataView( const IECore::Data *d, bool createUStrings ) case StringVectorDataTypeId: { const auto &readableStrings = static_cast( 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( d )->readable(); + type = extractStringCharPointers( readableStrings, m_charPointers, createUStrings ); data = &m_charPointers[0]; }