Website Summary Files Commits Branches @commit @diff @stats
path: root / Utills / si_14.06 / task1 / Optional
diff options
context:
space:
mode:
Commit8cf1283a4ffb9fe1901c29c087fa376de82726af (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Filesabdfe6bf526100dcce87a88563100e02adf7605e /Utills/si_14.06/task1/Optional
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar.gz
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.zip
Parentd73a7ec225516657dec74472a0491330e9999217 (diff)
clean up
1 files changed, 0 insertions, 109 deletions
-rw-r--r--Utills/si_14.06/task1/Optional/Optional.hpp109
diff --git a/Utills/si_14.06/task1/Optional/Optional.hpp b/Utills/si_14.06/task1/Optional/Optional.hpp
deleted file mode 100644
index cf1ec0d..0000000
--- a/Utills/si_14.06/task1/Optional/Optional.hpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#include <iostream>
-
-template <typename T>
-class Optional
-{
- T* objPtr;
-
- void copyFrom(const Optional<T>& other);
- void free();
-
-public:
- Optional();
- Optional(const T& obj);
-
- Optional(const Optional& other);
- Optional<T>& operator=(const Optional<T>& other);
-
- ~Optional();
-
- void setValue(const T& obj);
- T getValue() const;
-
- bool containsValue() const;
-
- bool operator==(const Optional<T>& other) const;
- bool operator!=(const Optional<T>& other) const;
-};
-
-template <typename T>
-Optional<T>::Optional() : objPtr(nullptr)
-{};
-
-template <typename T>
-Optional<T>::Optional(const T& obj)
-{
- objPtr = new T(obj);
-}
-
-template <typename T>
-void Optional<T>::setValue(const T& obj)
-{
- delete objPtr;
- objPtr = new T(obj);
-}
-
-template <typename T>
-T Optional<T>::getValue() const
-{
- if (!obj)
- throw std::exception("No value assigned!");
- return *objPtr;
-}
-
-template <typename T>
-bool Optional<T>::containsValue() const
-{
- return objPtr != nullptr;
-}
-
-template <typename T>
-void Optional<T>::copyFrom(const Optional<T>& other)
-{
- if (!other.obj)
- objPtr = nullptr;
- else
- objPtr = new T(*other.obj);
-}
-
-template <typename T>
-void Optional<T>::free()
-{
- delete objPtr;
-}
-
-template <typename T>
-Optional<T>::Optional(const Optional<T>& other)
-{
- copyFrom(other);
-}
-
-template <typename T>
-Optional<T>& Optional<T>::operator=(const Optional<T>& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
-
- return *this;
-}
-
-template <typename T>
-Optional<T>::~Optional()
-{
- free();
-}
-
-template <typename T>
-bool Optional<T>::operator==(const Optional<T>& other) const
-{
- return (!objPtr && !other.objPtr) || (objPtr && other.objPtr && *objPtr == *other.objPtr);
-}
-
-template <typename T>
-bool Optional<T>::operator!=(const Optional<T>& other) const
-{
- return !operator==(other);
-}