Website Summary Files Commits Branches @commit @diff @stats
path: root / Utills / si_14.06 / task2 / Values
diff options
context:
space:
mode:
Commitb4e603d6018a0b43ad3ce9d3a1900ce784a2d07b (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-06-16 16:56:02 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-06-16 16:56:02 +0300
Files10cdb0ce4b62990ff27d418d29c659b7cf748fed /Utills/si_14.06/task2/Values
Object-oriented_programming_FMI-b4e603d6018a0b43ad3ce9d3a1900ce784a2d07b.tar
Object-oriented_programming_FMI-b4e603d6018a0b43ad3ce9d3a1900ce784a2d07b.tar.gz
Object-oriented_programming_FMI-b4e603d6018a0b43ad3ce9d3a1900ce784a2d07b.zip
Parent9a86536fb579b244b29aa03fbefcce54746546dc (diff)
utills
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