From b4e603d6018a0b43ad3ce9d3a1900ce784a2d07b Mon Sep 17 00:00:00 2001 From: angeld55 Date: Wed, 16 Jun 2021 16:56:02 +0300 Subject: utills --- Utills/KN_exams_poll/poll.txt | 1 + Utills/KN_exams_poll/schedule.md | 8 ++ Utills/si_14.06/task1/Optional/Optional.hpp | 109 +++++++++++++++++++++ Utills/si_14.06/task1/Source.cpp | 17 ++++ Utills/si_14.06/task2/Source.cpp | 14 +++ Utills/si_14.06/task2/ValueArray/ValueArray.cpp | 72 ++++++++++++++ Utills/si_14.06/task2/ValueArray/ValueArray.h | 26 +++++ Utills/si_14.06/task2/Values/Date/Date.cpp | 19 ++++ Utills/si_14.06/task2/Values/Date/Date.h | 22 +++++ Utills/si_14.06/task2/Values/DateTime/DateTime.cpp | 14 +++ Utills/si_14.06/task2/Values/DateTime/DateTime.h | 14 +++ .../si_14.06/task2/Values/String/StringValue.cpp | 14 +++ Utills/si_14.06/task2/Values/String/StringValue.h | 15 +++ Utills/si_14.06/task2/Values/Time/Time.cpp | 19 ++++ Utills/si_14.06/task2/Values/Time/Time.h | 19 ++++ Utills/si_14.06/task2/Values/ValueBase/Value.cpp | 11 +++ Utills/si_14.06/task2/Values/ValueBase/Value.h | 18 ++++ 17 files changed, 412 insertions(+) create mode 100644 Utills/KN_exams_poll/poll.txt create mode 100644 Utills/KN_exams_poll/schedule.md create mode 100644 Utills/si_14.06/task1/Optional/Optional.hpp create mode 100644 Utills/si_14.06/task1/Source.cpp create mode 100644 Utills/si_14.06/task2/Source.cpp create mode 100644 Utills/si_14.06/task2/ValueArray/ValueArray.cpp create mode 100644 Utills/si_14.06/task2/ValueArray/ValueArray.h create mode 100644 Utills/si_14.06/task2/Values/Date/Date.cpp create mode 100644 Utills/si_14.06/task2/Values/Date/Date.h create mode 100644 Utills/si_14.06/task2/Values/DateTime/DateTime.cpp create mode 100644 Utills/si_14.06/task2/Values/DateTime/DateTime.h create mode 100644 Utills/si_14.06/task2/Values/String/StringValue.cpp create mode 100644 Utills/si_14.06/task2/Values/String/StringValue.h create mode 100644 Utills/si_14.06/task2/Values/Time/Time.cpp create mode 100644 Utills/si_14.06/task2/Values/Time/Time.h create mode 100644 Utills/si_14.06/task2/Values/ValueBase/Value.cpp create mode 100644 Utills/si_14.06/task2/Values/ValueBase/Value.h (limited to 'Utills') diff --git a/Utills/KN_exams_poll/poll.txt b/Utills/KN_exams_poll/poll.txt new file mode 100644 index 0000000..4ffc75f --- /dev/null +++ b/Utills/KN_exams_poll/poll.txt @@ -0,0 +1 @@ +https://forms.gle/2ciPStWkxz319C8k9 diff --git a/Utills/KN_exams_poll/schedule.md b/Utills/KN_exams_poll/schedule.md new file mode 100644 index 0000000..10f8757 --- /dev/null +++ b/Utills/KN_exams_poll/schedule.md @@ -0,0 +1,8 @@ +Дати: + + - 29.06 + - 01.07 + - 02.07 + +[Анкета за ден за събеседване](https://forms.gle/2ciPStWkxz319C8k9) + 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 + +template +class Optional +{ + T* objPtr; + + void copyFrom(const Optional& other); + void free(); + +public: + Optional(); + Optional(const T& obj); + + Optional(const Optional& other); + Optional& operator=(const Optional& other); + + ~Optional(); + + void setValue(const T& obj); + T getValue() const; + + bool containsValue() const; + + bool operator==(const Optional& other) const; + bool operator!=(const Optional& other) const; +}; + +template +Optional::Optional() : objPtr(nullptr) +{}; + +template +Optional::Optional(const T& obj) +{ + objPtr = new T(obj); +} + +template +void Optional::setValue(const T& obj) +{ + delete objPtr; + objPtr = new T(obj); +} + +template +T Optional::getValue() const +{ + if (!obj) + throw std::exception("No value assigned!"); + return *objPtr; +} + +template +bool Optional::containsValue() const +{ + return objPtr != nullptr; +} + +template +void Optional::copyFrom(const Optional& other) +{ + if (!other.obj) + objPtr = nullptr; + else + objPtr = new T(*other.obj); +} + +template +void Optional::free() +{ + delete objPtr; +} + +template +Optional::Optional(const Optional& other) +{ + copyFrom(other); +} + +template +Optional& Optional::operator=(const Optional& other) +{ + if (this != &other) + { + free(); + copyFrom(other); + } + + return *this; +} + +template +Optional::~Optional() +{ + free(); +} + +template +bool Optional::operator==(const Optional& other) const +{ + return (!objPtr && !other.objPtr) || (objPtr && other.objPtr && *objPtr == *other.objPtr); +} + +template +bool Optional::operator!=(const Optional& 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 +#include "Optional/Optional.hpp" + + + +int main() +{ + Optional o; + + std::cout << o.containsValue() << std::endl; + + o.setValue(12); + + Optional 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 +#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 +#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 +#include "../Values/ValueBase/Value.h" + +class ValueArray +{ + std::vector 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 + +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 -- cgit v1.3.1-23-gd82d