Hot Door CORE Forum
Changes in pointers, ArtVector iterator - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: General discussion (http://hotdoorcore.com/forum/forumdisplay.php?fid=3)
+--- Thread: Changes in pointers, ArtVector iterator (/showthread.php?tid=301)



Changes in pointers, ArtVector iterator - Rick Johnson - 01-21-2022

This once-reliable code no longer works, no doubt due to the change in auto_pointers, etc.

Code:
hdi::core::Art::ArtVector vMatches;
hdi::core::CurrentDocument::MatchArtSpecVector vSpec;
hdi::core::MatchArtSpec selectedPaths(hdi::core::MatchArtTypePath,
            hdi::core::MatchArtAttrSelected,
            hdi::core::MatchArtSearchIncludes);
vSpec.push_back(selectedPaths);

vMatches = HDI_CORE_ILLUSTRATOR->currentDocument()->matchingArt(vSpec);
for (std::vector<hdi::core::Art*>::iterator iter = vMatches.begin(); iter != vMatches.end(); ++iter) {
    // do something with (*iter), e.g. get (*iter)->artType()
}

hdi::core::cleanupVector(vMatches);

I get errors in the for statement that I don't understand and can't get past. The docs online and in the download still give an example using an ArtAP with an Art::Iterator.

Is there a preferred format for iterating an ArtVector?

Also, is there a general guideline for when to use a unique_pointer and when to use a shared_pointer as relates to CORE vectors and Art objects? I've been studying them online, but it's a bit complex for me to really grasp.


RE: Changes in pointers, ArtVector iterator - garrett - 01-21-2022

Use std::unique_ptr when only one reference to some object exists (or is allowed to exist) simultaneously.

Use std::shared_ptr when multiple references exist (or are allowed to exist) simultaneously.

That's pretty much it.

Most/all of our containers (like vectors) now contain std::shared_ptr, which means that you must update all code from e.g. std::vector<hdi::core::Art*> to std::vector<std::shared_ptr<hdi::core::Art>>

Beyond that, you won't necessarily notice many differences in most cases. The advantages here are big - std::unique_ptr "compilationally" enforces only one reference to exist; containers of std::shared_ptr do not need to be manually emptied/cleaned up to ensure no memory leaks.


RE: Changes in pointers, ArtVector iterator - Rick Johnson - 01-21-2022

Ah, that works! Do I understand correctly that these vectors no longer need to be sent to cleanupVector?

If a variable tempArt is defined an ArtSP and I use it as a prep_ object in Art.duplicate, is it OK to pass tempArt.get() as an Art*? I see that I need to be mindful that Art.duplicate returns a unique pointer, not a shared pointer.

I'm getting close to a successful Mac build, but am stumped by a few surprises. I started with the Panel sample project, and replaced the sources and headers with my 0.7.8 project files. The plugin I'm updating uses the SDK, so I've added those paths and defined HDI_CORE_DONT_DECLARE_AI_TYPES. That might affect these errors, but removing this flag and/or including headers with AI or HDI_CORE types doesn't seem to help.

hdicorePlugin.h:93:13: Unknown type name 'SPPluginRef'
hdicoreArt.h:327:15: Unknown type name 'AIArtHandle'
hdicoreArt.h:336:15: Unknown type name 'AISafeArtHandle'

Any suggestions on things to check would be much appreciated!


RE: Changes in pointers, ArtVector iterator - garrett - 01-22-2022

(01-21-2022, 05:28 PM)Rick Johnson Wrote: Ah, that works! Do I understand correctly that these vectors no longer need to be sent to cleanupVector?

Correct

(01-21-2022, 05:28 PM)Rick Johnson Wrote: If a variable tempArt is defined an ArtSP and I use it as a prep_ object in Art.duplicate, is it OK to pass tempArt.get() as an Art*? I see that I need to be mindful that Art.duplicate returns a unique pointer, not a shared pointer.

It should be, yes.

(01-21-2022, 05:28 PM)Rick Johnson Wrote: I'm getting close to a successful Mac build, but am stumped by a few surprises. I started with the Panel sample project, and replaced the sources and headers with my 0.7.8 project files. The plugin I'm updating uses the SDK, so I've added those paths and defined HDI_CORE_DONT_DECLARE_AI_TYPES. That might affect these errors, but removing this flag and/or including headers with AI or HDI_CORE types doesn't seem to help.

hdicorePlugin.h:93:13: Unknown type name 'SPPluginRef'
hdicoreArt.h:327:15: Unknown type name 'AIArtHandle'
hdicoreArt.h:336:15: Unknown type name 'AISafeArtHandle'

You just need to #include the proper headers from the Adobe SDK that define/declare these things before you #include e.g. hdicoreArt.h


RE: Changes in pointers, ArtVector iterator - Rick Johnson - 01-23-2022

Got it. Everything's moving along well now. Thanks, Garrett!