|
49 | 49 | using namespace OIIO;
|
50 | 50 | using namespace IECore;
|
51 | 51 |
|
| 52 | +namespace |
| 53 | +{ |
| 54 | + |
| 55 | +template<typename T> |
| 56 | +OIIO::TypeDesc extractStringCharPointers( const std::vector<T> &strings, std::vector<const char *> &charPointers, bool createUStrings ) |
| 57 | +{ |
| 58 | + size_t numStrings = strings.size(); |
| 59 | + OIIO::TypeDesc type = TypeDesc( |
| 60 | + TypeDesc::STRING, |
| 61 | + TypeDesc::SCALAR, |
| 62 | + TypeDesc::NOSEMANTICS, |
| 63 | + numStrings |
| 64 | + ); |
| 65 | + |
| 66 | + charPointers.resize( numStrings ); |
| 67 | + |
| 68 | + if ( createUStrings ) |
| 69 | + { |
| 70 | + for(size_t i = 0; i < numStrings; ++i) |
| 71 | + { |
| 72 | + charPointers[i] = ustring( strings[i].c_str() ).c_str(); |
| 73 | + } |
| 74 | + } |
| 75 | + else |
| 76 | + { |
| 77 | + for(size_t i = 0; i < numStrings; ++i) |
| 78 | + { |
| 79 | + charPointers[i] = strings[i].c_str(); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + return type; |
| 84 | +} |
| 85 | + |
| 86 | +} // namespace |
| 87 | + |
52 | 88 | namespace IECoreImage
|
53 | 89 | {
|
54 | 90 |
|
@@ -501,30 +537,15 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
|
501 | 537 | case StringVectorDataTypeId:
|
502 | 538 | {
|
503 | 539 | const auto &readableStrings = static_cast<const StringVectorData *>( d )->readable();
|
504 |
| - size_t numStrings = readableStrings.size(); |
505 |
| - type = TypeDesc( |
506 |
| - TypeDesc::STRING, |
507 |
| - TypeDesc::SCALAR, |
508 |
| - TypeDesc::NOSEMANTICS, |
509 |
| - numStrings |
510 |
| - ); |
511 |
| - |
512 |
| - m_charPointers.resize( numStrings ); |
| 540 | + type = extractStringCharPointers( readableStrings, m_charPointers, createUStrings ); |
513 | 541 |
|
514 |
| - if ( createUStrings ) |
515 |
| - { |
516 |
| - for(size_t i = 0; i < numStrings; ++i) |
517 |
| - { |
518 |
| - m_charPointers[i] = ustring( readableStrings[i].c_str() ).c_str(); |
519 |
| - } |
520 |
| - } |
521 |
| - else |
522 |
| - { |
523 |
| - for(size_t i = 0; i < numStrings; ++i) |
524 |
| - { |
525 |
| - m_charPointers[i] = readableStrings[i].c_str(); |
526 |
| - } |
527 |
| - } |
| 542 | + data = &m_charPointers[0]; |
| 543 | + } |
| 544 | + break; |
| 545 | + case InternedStringVectorDataTypeId: |
| 546 | + { |
| 547 | + const auto &readableStrings = static_cast<const InternedStringVectorData *>( d )->readable(); |
| 548 | + type = extractStringCharPointers( readableStrings, m_charPointers, createUStrings ); |
528 | 549 |
|
529 | 550 | data = &m_charPointers[0];
|
530 | 551 | }
|
|
0 commit comments