@@ -140,16 +140,17 @@ CiffDirectory::~CiffDirectory() {
140140 }
141141}
142142
143- void CiffComponent::add (UniquePtr component) {
144- doAdd (std::move (component));
143+ CiffComponent* CiffComponent::add (UniquePtr component) {
144+ return doAdd (std::move (component));
145145}
146146
147- void CiffEntry::doAdd (UniquePtr /* component*/ ) {
147+ CiffComponent* CiffEntry::doAdd (UniquePtr /* component*/ ) {
148148 throw Error (ErrorCode::kerFunctionNotSupported, " CiffEntry::add" );
149149} // CiffEntry::doAdd
150150
151- void CiffDirectory::doAdd (UniquePtr component) {
151+ CiffComponent* CiffDirectory::doAdd (UniquePtr component) {
152152 components_.push_back (component.release ());
153+ return components_.back ();
153154} // CiffDirectory::doAdd
154155
155156void CiffHeader::read (const byte* pData, size_t size) {
@@ -542,39 +543,30 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
542543 if not found, create it
543544 set value
544545 */
545- CiffComponent* cc = nullptr ;
546546 if (!crwDirs.empty ()) {
547547 auto dir = crwDirs.top ();
548548 crwDirs.pop ();
549549 // Find the directory
550550 for (const auto & c : components_)
551551 if (c->tag () == dir.dir ) {
552- cc = c;
553- break ;
552+ // Recursive call to next lower level directory
553+ return c-> add (crwDirs, crwTagId) ;
554554 }
555- if (!cc) {
556- // Directory doesn't exist yet, add it
557- auto m = std::make_unique<CiffDirectory>(dir.dir , dir.parent );
558- add (std::move (m));
559- cc = components_.back ();
560- }
561- // Recursive call to next lower level directory
562- return cc->add (crwDirs, crwTagId);
555+
556+ // Directory doesn't exist yet, add it
557+ auto m = std::make_unique<CiffDirectory>(dir.dir , dir.parent );
558+ return add (std::move (m))->add (crwDirs, crwTagId);
563559 }
564560
565561 // Find the tag
566562 for (const auto & c : components_)
567563 if (c->tagId () == crwTagId) {
568- cc = c;
569- break ;
564+ return c;
570565 }
571- if (!cc) {
572- // Tag doesn't exist yet, add it
573- auto m = std::make_unique<CiffEntry>(crwTagId, tag ());
574- add (std::move (m));
575- cc = components_.back ();
576- }
577- return cc;
566+
567+ // Tag doesn't exist yet, add it
568+ auto m = std::make_unique<CiffEntry>(crwTagId, tag ());
569+ return add (std::move (m));
578570} // CiffDirectory::doAdd
579571
580572void CiffHeader::remove (uint16_t crwTagId, uint16_t crwDir) const {
0 commit comments