SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Public Types | Public Member Functions | Protected Attributes | List of all members
smtk::resource::CopyOptions Class Reference
Collaboration diagram for smtk::resource::CopyOptions:
[legend]

Public Types

enum  CopyType { None, Shallow, Deep }
 Control whether copies are omitted, by reference, or by value. More...
 
using ObjectMapType = std::unordered_map< smtk::common::UUID, smtk::resource::PersistentObject * >
 A type alias for the container holding the UUID translation table.
 

Public Member Functions

 CopyOptions (smtk::io::Logger &log)
 
bool setCopyLocation (bool copy)
 Should the resource location be copied? More...
 
bool copyLocation () const
 
bool setCopyComponents (bool copy)
 Should components be copied? More...
 
bool copyComponents () const
 
bool setCopyProperties (bool copy)
 Should property data be copied? More...
 
bool copyProperties () const
 
bool setCopyGeometry (bool copy)
 Should renderable geometry be copied? More...
 
bool copyGeometry () const
 
bool setCopyTemplateData (bool copy)
 Should the template type (and perhaps other template-related data) be copied? More...
 
bool copyTemplateData () const
 
bool setCopyTemplateVersion (bool copy)
 Copy the version number of the resource template. More...
 
bool copyTemplateVersion () const
 
bool setCopyUnitSystem (CopyType copy)
 Should the unit system of the source be copied by value, by reference, or omitted?
 
CopyType copyUnitSystem () const
 
bool setCopyLinks (bool copy)
 Set/get whether or not to copy link data. More...
 
bool copyLinks () const
 
bool clearLinkRolesToExclude ()
 Set/get which link data should not be copied. More...
 
bool addLinkRoleToExclude (smtk::resource::Links::RoleType linkRole)
 
bool removeLinkRoleToExclude (smtk::resource::Links::RoleType linkRole)
 
const std::set< smtk::resource::Links::RoleType > & linkRolesToExclude () const
 
bool shouldExcludeLinksInRole (smtk::resource::Links::RoleType role) const
 
ObjectMapTypeobjectMapping ()
 Provide a map from source-resource object-IDs to copied-resource object-pointers. More...
 
const ObjectMapTypeobjectMapping () const
 
template<typename ObjectType >
ObjectType * targetObjectFromSourceId (const smtk::common::UUID &sourceId) const
 A convenience to fetch an entry from objectMapping(), casting it to the given type. More...
 
const std::unordered_set< smtk::common::UUID > & omit () const
 Return a set of UUIDs to omit from copying. More...
 
std::unordered_set< smtk::common::UUID > & omit ()
 
bool shouldOmitId (const smtk::common::UUID &sourceId) const
 Return whether a sourceId should be omitted from the copy.
 
void omitComponents (const std::shared_ptr< const Resource > &resource)
 Insert a resource's component UUIDs into the omit() set. More...
 
const smtk::common::TypeContainersuboptions () const
 Provide a type-container to hold options specific to Resource subclasses. More...
 
smtk::common::TypeContainersuboptions ()
 
smtk::io::Loggerlog () const
 Return a logger to be used to provide feedback on copying.
 

Protected Attributes

bool m_copyTemplateData { true }
 
bool m_copyTemplateVersion { true }
 
CopyType m_copyUnitSystem { CopyType::Shallow }
 
bool m_copyLocation { false }
 
bool m_copyComponents { true }
 
bool m_copyProperties { true }
 
bool m_copyGeometry { true }
 
bool m_copyLinks { true }
 
std::set< smtk::resource::Links::RoleType > m_linkRolesToExclude
 
ObjectMapType m_objectMapping
 
std::unordered_set< smtk::common::UUIDm_omit
 
std::unordered_set< smtk::common::UUIDm_omitComponentsResources
 
smtk::common::TypeContainer m_suboptions
 
smtk::io::Loggerm_log { nullptr }
 
bool m_deleteLog
 

Member Enumeration Documentation

◆ CopyType

Control whether copies are omitted, by reference, or by value.

Enumerator
None 

Do not copy data at all; omit it.

Shallow 

Copy data by reference (the source and target will share access).

Deep 

Copy data by value (target and source will initially match; they may diverge).

Member Function Documentation

◆ clearLinkRolesToExclude()

bool smtk::resource::CopyOptions::clearLinkRolesToExclude ( )

Set/get which link data should not be copied.

By default, all link data will be copied; adding link roles here will omit them from duplication.

◆ objectMapping()

ObjectMapType& smtk::resource::CopyOptions::objectMapping ( )
inline

Provide a map from source-resource object-IDs to copied-resource object-pointers.

The Resource::copy() and Resource::resolveCopy() methods should populate and reference this map, respectively.

◆ omit()

const std::unordered_set<smtk::common::UUID>& smtk::resource::CopyOptions::omit ( ) const
inline

Return a set of UUIDs to omit from copying.

These UUIDs need not necessarily correspond to persistent objects, although typically this map is populated with component IDs (e.g., by smtk::resource::Resource::copyProperties() or other methods) when copyComponents() is false.

◆ omitComponents()

void smtk::resource::CopyOptions::omitComponents ( const std::shared_ptr< const Resource > &  resource)

Insert a resource's component UUIDs into the omit() set.

This is used by smtk::resource::Resource::copyProperties() and other helpers to prevent data related to components by UUID from being copied.

◆ setCopyComponents()

bool smtk::resource::CopyOptions::setCopyComponents ( bool  copy)

Should components be copied?

If true, each component in the source should have a matching component in the target resource and an entry in objectMapping() should be added.

◆ setCopyGeometry()

bool smtk::resource::CopyOptions::setCopyGeometry ( bool  copy)

Should renderable geometry be copied?

In general, copying geometry should not be required as backend providers should be able to regenerate the geometry on demand; however, copying this data can save significant effort since generating renderable data can be slow.

Note that if copyComponents() returns false, only geometry corresponding to the resource is copied. Otherwise, all geometry (resource and component) are copied if copyGeometry() returns true.

◆ setCopyLinks()

bool smtk::resource::CopyOptions::setCopyLinks ( bool  copy)

Set/get whether or not to copy link data.

If true (the default), then link data may be excluded by role using the addLinkRoleToExclude() method. If false, then linkRolesToExclude() is ignored.

◆ setCopyLocation()

bool smtk::resource::CopyOptions::setCopyLocation ( bool  copy)

Should the resource location be copied?

By default, the location of a clone should not be set; we do not want users to accidentally overwrite the original resource by saving the new one. When using clone() to produce an upgraded resource, this may be set to true.

◆ setCopyProperties()

bool smtk::resource::CopyOptions::setCopyProperties ( bool  copy)

Should property data be copied?

Note that if copyComponents() returns false, only properties corresponding to the resource are copied. Otherwise, all properties (resource and component) are copied if copyProperties() returns true.

◆ setCopyTemplateData()

bool smtk::resource::CopyOptions::setCopyTemplateData ( bool  copy)

Should the template type (and perhaps other template-related data) be copied?

At a minimum, if this is true, the source and target's templateType() should return the same value. If templates provide other data, such as an initial set of components or initialize other resource class-members, that data should be copied when copyTemplateData() is true.

◆ setCopyTemplateVersion()

bool smtk::resource::CopyOptions::setCopyTemplateVersion ( bool  copy)

Copy the version number of the resource template.

When copyTemplateData() is true, this value determines whether to copy the exact version number from the source resource or (if false) to use the most recent version number available.

◆ suboptions()

const smtk::common::TypeContainer& smtk::resource::CopyOptions::suboptions ( ) const
inline

Provide a type-container to hold options specific to Resource subclasses.

For example, you may insert an instance of smtk::attribute::CopyAssignmentOptions into this container to control how attribute resources are copied.

◆ targetObjectFromSourceId()

template<typename ObjectType >
ObjectType* smtk::resource::CopyOptions::targetObjectFromSourceId ( const smtk::common::UUID sourceId) const
inline

A convenience to fetch an entry from objectMapping(), casting it to the given type.

Be aware this method may return a null pointer if (a) there is no object that corresponds to the input sourceId or (b) the object cannot be cast to ObjectType.


The documentation for this class was generated from the following files: