Website Summary Files Commits Branches @commit @diff @stats
path: root / Week09 / Exercise05 / StringArray.h
diff options
context:
space:
mode:
Commitb38346eebca9a007971af02fb3bb9472c5e16d0c (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-04-26 21:43:31 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-04-26 21:43:31 +0300
Files575a64089a17be271aec84683f426252d8f5d1f9 /Week09/Exercise05/StringArray.h
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.tar
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.tar.gz
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.zip
Parent7d98b664c9e459a08f2e6e6fa5b636686dfed554 (diff)
feat(Week09): Add solutions
1 files changed, 80 insertions, 0 deletions
-rw-r--r--Week09/Exercise05/StringArray.h80
diff --git a/Week09/Exercise05/StringArray.h b/Week09/Exercise05/StringArray.h
new file mode 100644
index 0000000..4b15ba0
--- /dev/null
+++ b/Week09/Exercise05/StringArray.h
@@ -0,0 +1,80 @@
+#ifndef _STRINGARRAY
+#define _STRINGARRAY
+
+#include "String.h"
+#include <ostream>
+
+// Декларация на класа, за да може в StringArray
+// да си го използваме преди пълната дефиниция
+class Z;
+
+class StringArray {
+ String* strings;
+ unsigned stringsCount;
+ unsigned stringsAlloc;
+
+ unsigned stringsAssigned;
+
+ void free();
+ void copyFrom(const StringArray& other);
+ void resize();
+
+public:
+ StringArray();
+ ~StringArray();
+ StringArray(const StringArray& other);
+ StringArray& operator=(const StringArray& other);
+
+ StringArray(StringArray&& other);
+ StringArray& operator=(StringArray&& other);
+
+ void PushLength(unsigned length);
+ void PushString(const char* str);
+
+ StringArray& operator[](const Z& expectedNumbers);
+
+ // Можем да създадем помощен клас "PassedStrings".
+ // Обаче нямаме ограничение което задължава StringArray и
+ // PassedStrings да са различни класове.
+ // Можем и просто да се възползваме от StringArray,
+ // и да си спестим писане на код.
+ StringArray& operator()(const StringArray& strings);
+ StringArray& operator()(const char* str);
+ StringArray(const char* str);
+
+ // Оператор "|" е ляво асоциативен
+ StringArray& operator|(const char* str);
+
+ // Това не е нужно по условие, но ще ни е
+ // полезно за тестване.
+ friend std::ostream& operator<<(std::ostream& ostr, const StringArray& sa);
+};
+
+class Z {
+ unsigned* numbers;
+ unsigned numbersCount;
+ unsigned numbersAlloc;
+
+ void free();
+ void copyFrom(const Z& other);
+ void resize();
+
+public:
+ Z();
+ ~Z();
+ Z(const Z& other);
+ Z& operator=(const Z& other);
+
+ Z(Z&& other);
+ Z& operator=(Z&& other);
+
+ Z(unsigned num);
+
+ Z& operator++(int);
+ Z& operator+(const Z& rhs);
+
+ friend StringArray;
+};
+
+
+#endif /* _STRINGARRAY */