Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
diff --git a/Exams/poll.txt b/Utills/KN_exams_poll/poll.txt
index 4ffc75f..4ffc75f 100644
--- a/Exams/poll.txt
+++ b/Utills/KN_exams_poll/poll.txt
diff --git a/Exams/schedule.md b/Utills/KN_exams_poll/schedule.md
index 10f8757..10f8757 100644
--- a/Exams/schedule.md
+++ b/Utills/KN_exams_poll/schedule.md
diff --git a/Utills/si_14.06/task1/Optional/Optional.hpp b/Utills/si_14.06/task1/Optional/Optional.hpp
new file mode 100644
index 0000000..cf1ec0d
--- /dev/null
+++ b/Utills/si_14.06/task1/Optional/Optional.hpp
@@ -0,0 +1,109 @@
+#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);
+}
diff --git a/Utills/si_14.06/task1/Source.cpp b/Utills/si_14.06/task1/Source.cpp
new file mode 100644
index 0000000..d8397a0
--- /dev/null
+++ b/Utills/si_14.06/task1/Source.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+#include "Optional/Optional.hpp"
+
+
+
+int main()
+{
+ Optional<int> o;
+
+ std::cout << o.containsValue() << std::endl;
+
+ o.setValue(12);
+
+ Optional<int> o2(12);
+
+ std::cout << (o == o2) << std::endl;
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Source.cpp b/Utills/si_14.06/task2/Source.cpp
new file mode 100644
index 0000000..e8e1a2d
--- /dev/null
+++ b/Utills/si_14.06/task2/Source.cpp
@@ -0,0 +1,14 @@
+#include <iostream>
+#include "ValueArray/ValueArray.h"
+
+int main()
+{
+ ValueArray v;
+
+ v.addDate("First school day",15, 9, 2021);
+ v.addTime("Work day start", 10, 15);
+ v.addDateTime("Portugal - Germany", 19, 06, 2021, 19, 10);
+ v.addString("Name", "Test");
+
+ v.print();
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/ValueArray/ValueArray.cpp b/Utills/si_14.06/task2/ValueArray/ValueArray.cpp
new file mode 100644
index 0000000..8e06a95
--- /dev/null
+++ b/Utills/si_14.06/task2/ValueArray/ValueArray.cpp
@@ -0,0 +1,72 @@
+#include <iostream>
+#include "ValueArray.h"
+#include "../Values/Date/Date.h"
+#include "../Values/Time/Time.h"
+#include "../Values/String/StringValue.h"
+#include "../Values/DateTime/DateTime.h"
+
+void ValueArray::print() const
+{
+ std::cout << "[";
+ for (int i = 0; i < arr.size(); i++)
+ {
+ std::cout << arr[i]->toString();
+
+ if (i != arr.size() - 1)
+ std::cout << ", ";
+
+ }
+ std::cout << "]";
+}
+
+
+void ValueArray::free()
+{
+ for (int i = 0; i < arr.size(); i++)
+ delete arr[i];
+ arr.clear();
+}
+
+void ValueArray::copyFrom(const ValueArray& other)
+{
+ arr.resize(other.arr.size());
+
+ for (int i = 0; i < arr.size(); i++)
+ arr[i] = other.arr[i]->clone();
+}
+
+void ValueArray::addDate(const std::string& name, unsigned day, unsigned month, unsigned year)
+{
+ arr.push_back(new Date(name, day, month, year));
+}
+void ValueArray::addTime(const std::string& name, unsigned hours, unsigned mins)
+{
+ arr.push_back(new Time(name, hours, mins));
+}
+void ValueArray::addString(const std::string& name, const std::string& value)
+{
+ arr.push_back(new StringValue(name,value));
+}
+void ValueArray::addDateTime(const std::string& name, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned mins)
+{
+ arr.push_back(new DateTime(name, day, month, year, hours, mins));
+}
+
+ValueArray::ValueArray(const ValueArray& other)
+{
+ copyFrom(other);
+}
+ValueArray& ValueArray::operator= (const ValueArray& other)
+{
+ if (this != &other)
+ {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+
+ValueArray::~ValueArray()
+{
+ free();
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/ValueArray/ValueArray.h b/Utills/si_14.06/task2/ValueArray/ValueArray.h
new file mode 100644
index 0000000..39bdcbc
--- /dev/null
+++ b/Utills/si_14.06/task2/ValueArray/ValueArray.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <vector>
+#include "../Values/ValueBase/Value.h"
+
+class ValueArray
+{
+ std::vector<Value*> arr;
+
+ void copyFrom(const ValueArray& other);
+ void free();
+
+public:
+ void print() const;
+
+ ValueArray() = default;
+ ValueArray(const ValueArray& other);
+ ValueArray& operator=(const ValueArray& other);
+
+ //factory pattern ?
+ void addDate(const std::string& name, unsigned day, unsigned month, unsigned year);
+ void addTime(const std::string& name, unsigned hours, unsigned mins);
+ void addString(const std::string& name, const std::string& value);
+ void addDateTime(const std::string& name, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned mins);
+ ~ValueArray();
+}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Date/Date.cpp b/Utills/si_14.06/task2/Values/Date/Date.cpp
new file mode 100644
index 0000000..3d872d3
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/Date/Date.cpp
@@ -0,0 +1,19 @@
+#include "Date.h"
+
+//validation is needed for the date fields!
+Date::Date(const std::string& name, unsigned day, unsigned month, unsigned year) : Value(name), year(year), month(month), day(day)
+{}
+
+std::string Date::getDateString() const
+{
+ return std::to_string(day) + "." + std::to_string(month) + "." + std::to_string(year);;
+}
+std::string Date::toString() const
+{
+ return getPrefix() + getDateString() + "}";
+}
+
+Value* Date::clone() const
+{
+ return new Date(*this);
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Date/Date.h b/Utills/si_14.06/task2/Values/Date/Date.h
new file mode 100644
index 0000000..6194225
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/Date/Date.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "../ValueBase/Value.h"
+
+class Date : public virtual Value
+{
+ unsigned day;
+ unsigned month;
+ unsigned year;
+
+protected:
+
+ std::string getDateString() const;
+
+public:
+
+ Date(const std::string& name, unsigned day, unsigned month, unsigned year);
+
+ Value* clone() const;
+
+ std::string toString() const;
+}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/DateTime/DateTime.cpp b/Utills/si_14.06/task2/Values/DateTime/DateTime.cpp
new file mode 100644
index 0000000..b2e7e97
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/DateTime/DateTime.cpp
@@ -0,0 +1,14 @@
+#include "DateTime.h"
+
+DateTime::DateTime(const std::string& name, size_t day, size_t month, size_t year, size_t hours, size_t mins) : Value(name), Date(name, day, month, year), Time(name, hours,mins)
+{}
+
+std::string DateTime::toString() const
+{
+ return getPrefix() + getDateString() + ", " + getTimeString() + "}";
+}
+
+Value* DateTime::clone() const
+{
+ return new DateTime(*this);
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/DateTime/DateTime.h b/Utills/si_14.06/task2/Values/DateTime/DateTime.h
new file mode 100644
index 0000000..61d6a9a
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/DateTime/DateTime.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "../Date/Date.h"
+#include "../Time/Time.h"
+
+class DateTime : public Date, public Time
+{
+public:
+ DateTime(const std::string& name, size_t day, size_t month, size_t year, size_t hours, size_t mins);
+
+ std::string toString() const;
+
+ Value* clone() const;
+}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/String/StringValue.cpp b/Utills/si_14.06/task2/Values/String/StringValue.cpp
new file mode 100644
index 0000000..8d47f24
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/String/StringValue.cpp
@@ -0,0 +1,14 @@
+#include "StringValue.h"
+
+StringValue::StringValue(const std::string& name, const std::string& value) : Value(name), value(value)
+{}
+
+std::string StringValue::toString() const
+{
+ return getPrefix() + '\"' + value + '\"' + "}";
+}
+
+Value* StringValue::clone() const
+{
+ return new StringValue(*this);
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/String/StringValue.h b/Utills/si_14.06/task2/Values/String/StringValue.h
new file mode 100644
index 0000000..4e1500f
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/String/StringValue.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "../ValueBase/Value.h"
+
+class StringValue : public Value
+{
+ std::string value;
+public:
+
+ StringValue(const std::string& name, const std::string& value);
+
+ Value* clone() const;
+
+ std::string toString() const;
+}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Time/Time.cpp b/Utills/si_14.06/task2/Values/Time/Time.cpp
new file mode 100644
index 0000000..5b49e54
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/Time/Time.cpp
@@ -0,0 +1,19 @@
+#include "Time.h"
+
+//validation is needed for the time fields!
+Time::Time(const std::string& name, unsigned hours, unsigned mins) : Value(name), hours(hours), mins(mins)
+{}
+
+std::string Time::getTimeString() const
+{
+ return std::to_string(hours) + ":" + std::to_string(mins);
+}
+std::string Time::toString() const
+{
+ return getPrefix() + getTimeString() + "}";
+}
+
+Value* Time::clone() const
+{
+ return new Time(*this);
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Time/Time.h b/Utills/si_14.06/task2/Values/Time/Time.h
new file mode 100644
index 0000000..1d93d49
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/Time/Time.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "../ValueBase/Value.h"
+
+class Time : public virtual Value
+{
+ unsigned hours;
+ unsigned mins;
+
+protected:
+ std::string Time::getTimeString() const;
+
+public:
+ Time(const std::string& name, unsigned hours, unsigned mins);
+
+ Value* clone() const;
+
+ std::string toString() const;
+}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/ValueBase/Value.cpp b/Utills/si_14.06/task2/Values/ValueBase/Value.cpp
new file mode 100644
index 0000000..cd7c821
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/ValueBase/Value.cpp
@@ -0,0 +1,11 @@
+#include "Value.h"
+
+Value::Value(const std::string& valueName) : valueName(valueName)
+{
+
+}
+
+std::string Value::getPrefix() const
+{
+ return "{ " + valueName + " : ";
+} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/ValueBase/Value.h b/Utills/si_14.06/task2/Values/ValueBase/Value.h
new file mode 100644
index 0000000..e3320f3
--- /dev/null
+++ b/Utills/si_14.06/task2/Values/ValueBase/Value.h
@@ -0,0 +1,18 @@
+#pragma once
+#include <string>
+
+class Value
+{
+protected:
+ std::string valueName;
+public:
+ Value(const std::string& valueName);
+
+ std::string getPrefix() const;
+
+ virtual std::string toString() const = 0;
+
+ virtual Value* clone() const = 0;
+
+ virtual ~Value(){}
+}; \ No newline at end of file