aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/common')
-rw-r--r--include/cru/common/auto_delete.hpp14
-rw-r--r--include/cru/common/endable.hpp21
2 files changed, 35 insertions, 0 deletions
diff --git a/include/cru/common/auto_delete.hpp b/include/cru/common/auto_delete.hpp
new file mode 100644
index 00000000..ae66f7bf
--- /dev/null
+++ b/include/cru/common/auto_delete.hpp
@@ -0,0 +1,14 @@
+#pragma once
+#include "base.hpp"
+
+namespace cru {
+// A instance of class implementing this interface is able to
+// delete itseft when program exits. Such as IGraphFactory,
+// IUiApplication.
+struct IAutoDelete : virtual Interface {
+ // Get whether it will delete itself when program exits.
+ virtual bool IsAutoDelete() const = 0;
+ // Set whether it will delete itself when program exits.
+ virtual void SetAutoDelete(bool value) = 0;
+};
+} // namespace cru
diff --git a/include/cru/common/endable.hpp b/include/cru/common/endable.hpp
new file mode 100644
index 00000000..4459b069
--- /dev/null
+++ b/include/cru/common/endable.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include "base.hpp"
+
+namespace cru {
+// Although c++ has destructor called automatically. But there is
+// occasion when an instance of class needs to end with a result
+// and release all internal resources.
+// eg. IGeometryBuild will end with building a Geometry and release
+// some resources. IPainter will end drawing and release some
+// resources and map the drawing result onto target.
+// note: You can't call End twice. And most methods on the object
+// is invalid to call after End is called. Get whether it is ended
+// by IsEnded.
+template<typename TResult>
+struct IEndable : virtual Interface {
+ // Get whether the object is ended.
+ virtual bool IsEnded() const = 0;
+ // End the object with a result.
+ virtual TResult End() = 0;
+};
+}