aboutsummaryrefslogtreecommitdiff
path: root/CruUI/builder.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-18 01:38:02 +0800
committercrupest <crupest@outlook.com>2018-09-18 01:38:02 +0800
commit4710715102df3806479985679bd8048631ccaab5 (patch)
tree0f18f3c1d278aace11521a93abad97c97eb4ae54 /CruUI/builder.h
parent94c066a34900845297c41c134a9a910124a5833d (diff)
downloadcru-4710715102df3806479985679bd8048631ccaab5.tar.gz
cru-4710715102df3806479985679bd8048631ccaab5.tar.bz2
cru-4710715102df3806479985679bd8048631ccaab5.zip
I think I can't sleep well after this commit.
Still a lot of bugs!!!
Diffstat (limited to 'CruUI/builder.h')
-rw-r--r--CruUI/builder.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/CruUI/builder.h b/CruUI/builder.h
new file mode 100644
index 00000000..3ae8724e
--- /dev/null
+++ b/CruUI/builder.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include "base.h"
+
+namespace cru
+{
+ template<typename T>
+ class OneTimeBuilder : public Object
+ {
+ protected:
+ OneTimeBuilder() = default;
+
+ public:
+ OneTimeBuilder(const OneTimeBuilder& other) = delete;
+ OneTimeBuilder(OneTimeBuilder&& other) = delete;
+ OneTimeBuilder& operator=(const OneTimeBuilder& other) = delete;
+ OneTimeBuilder& operator=(OneTimeBuilder&& other) = delete;
+ virtual ~OneTimeBuilder() = default;
+
+ T* Create()
+ {
+ if (is_valid_)
+ {
+ is_valid_ = false;
+ return OnCreate();
+ }
+ else
+ throw std::runtime_error("OneTimeBuilder is invalid.");
+ }
+
+ bool IsValid() const
+ {
+ return is_valid_;
+ }
+
+ protected:
+ virtual T* OnCreate() = 0;
+
+ private:
+ bool is_valid_ = true;
+ };
+}