Website Summary Files Commits Branches @commit @diff @stats
path: root / Week09 / Exercise05 / StringArray.h
blob: 34488ffba30eebbf344aa981f635c9fae9d263f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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 */