SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
10 #ifndef smtk_operation_Operation_h
11 #define smtk_operation_Operation_h
13 #include "smtk/resource/Lock.h"
17 #include "smtk/common/Deprecation.h"
40 class ImportPythonOperation;
44 using Handler = std::function<void(Operation&,
const std::shared_ptr<smtk::attribute::Attribute>&)>;
48 std::weak_ptr<smtk::resource::Resource>,
49 smtk::resource::LockType,
50 std::owner_less<std::weak_ptr<smtk::resource::Resource>>>;
70 typedef std::size_t Index;
73 typedef std::shared_ptr<smtk::attribute::Attribute> Parameters;
76 typedef std::shared_ptr<smtk::attribute::Attribute> Result;
80 typedef std::shared_ptr<smtk::attribute::Resource> Specification;
82 typedef std::shared_ptr<smtk::attribute::Definition> Definition;
103 virtual Index index()
const {
return std::type_index(
typeid(*
this)).hash_code(); }
127 virtual bool configure(
134 virtual bool ableToOperate();
154 Outcome safeOperate();
155 Outcome safeOperate(Handler handler);
165 virtual bool releaseResult(Result& result);
176 Specification specification();
181 Parameters parameters();
182 Parameters parameters()
const;
186 Result createResult(Outcome);
192 bool restoreTrace(
const std::string& trace);
195 void setManagers(
const std::shared_ptr<smtk::common::Managers>& m) { m_managers = m; }
196 std::shared_ptr<smtk::common::Managers> managers()
const {
return m_managers; }
243 virtual Result operateInternal() = 0;
248 virtual void postProcessResult(Result&) {}
253 virtual void markModifiedResources(Result&);
256 virtual bool unmanageResources(Result&);
260 virtual void generateSummary(Result&);
264 Specification createBaseSpecification()
const;
266 int m_debugLevel{ 0 };
267 std::weak_ptr<Manager> m_manager;
268 std::shared_ptr<smtk::common::Managers> m_managers;
284 , m_lockOption(lockOption)
285 , m_observerOption(observerOption)
286 , m_paramsOption(paramsOption)
291 LockOption m_lockOption{ LockOption::SkipLocks };
296 struct SMTK_DEPRECATED_IN_24_11(
297 "Use this->childKey(
ObserverOption::SkipObservers, LockOption::SkipLocks, "
298 "ParametersOption::SkipValidation) instead.") Key :
BaseKey
310 ObserverOption observerOption = ObserverOption::SkipObservers,
311 LockOption lockOption = LockOption::LockAll,
312 ParametersOption paramsOption = ParametersOption::Validate)
const;
316 Result operate(
const BaseKey& key);
323 virtual Specification createSpecification() = 0;
327 Specification m_specification;
328 Parameters m_parameters;
329 Definition m_resultDefinition;
330 std::vector<std::weak_ptr<smtk::attribute::Attribute>> m_results;
345 #endif // smtk_operation_Operation_h
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
An operation Manager is responsible for creating new operations and filtering operations based on inp...
Definition: Manager.h:42
Outcome
Definition: Operation.h:85
const ResourceAccessMap & lockedResources() const
Returns the set of resources that are currently locked by this operation.
Definition: Operation.h:240
A class for adding python operations to the current session.
Definition: ImportPythonOperation.h:27
ObserverOption
When running a nested operation, specify whether observers should be invoked.
Definition: Operation.h:216
Operation::Outcome outcome(const Operation::Result &result)
Return the outcome of an operation given its result object.
Definition: Operation.cxx:752
@ Validate
Ensure the nested operation's parameters are valid.
Definition: Operation.h:226
Log messages for later presentation to a user or a file.
Definition: Logger.h:94
#define smtkEnableSharedPtr(...)
An abbreviation for enabling shared pointers.
Definition: SharedFromThis.h:234
smtk::shared_ptr< smtk::operation::Manager > ManagerPtr
Definition: PublicPointerDefs.h:355
std::map< std::weak_ptr< smtk::resource::Resource >, smtk::resource::LockType, std::owner_less< std::weak_ptr< smtk::resource::Resource > >> ResourceAccessMap
Hold a set of resources to be locked for an operation along with the type of lock to acquire.
Definition: Operation.h:50
@ ParentLocksOnly
Use only the locks already held by this (the parent's) operation.
Definition: Operation.h:208
A key used to run operations nested from within this operation.
Definition: Operation.h:275
LockOption
When running a nested operation, specify how resource locks should be handled.
Definition: Operation.h:205
Operation is a base class for all SMTK operations.
Definition: Operation.h:62
smtk::shared_ptr< smtk::attribute::Attribute > AttributePtr
Definition: PublicPointerDefs.h:463
A helper for dealing with serialization/deserialization done within an operation.
Definition: Helper.h:25
smtk::common::Singleton< detail::Manager > Manager
The Manager is a singleton interface for registering available plugins to manager instances.
Definition: Manager.h:92
@ InvokeObservers
Do not invoke observers for the internal/nested operation.
Definition: Operation.h:218
void setManagers(const std::shared_ptr< smtk::common::Managers > &m)
Operations may be passed application state in the form of a Managers type-container.
Definition: Operation.h:195
ManagerPtr manager() const
Operations that are managed have a non-null pointer to their manager.
Definition: Operation.h:189
@ LockAll
Lock all resources mentioned in the nested operation's parameters.
Definition: Operation.h:207
ParametersOption
When running a nested operation, specify whether to call the operation's ableToOperate() method or sk...
Definition: Operation.h:224
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:474
Macros for dealing with shared-pointer classes.
#define smtkTypeMacroBase(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:151
smtk::shared_ptr< smtk::resource::Manager > ManagerPtr
Definition: PublicPointerDefs.h:288
virtual bool threadSafe() const
Is this type of operation safe to launch in a thread?
Definition: Operation.h:199