diff options
| Commit | e0d7dfad8fc32a9879eeafc0dda27266445ca283 (patch) | |
|---|---|---|
| Author | 2022-05-28 17:54:16 +0300 | |
| Committer | 2022-05-28 17:54:16 +0300 | |
| Files | 6339bba35c6e3f7ed3377aba786f3bad4a46b129 /src | |
| FMI-OOP-P2_Tables-e0d7dfad8fc32a9879eeafc0dda27266445ca283.tar FMI-OOP-P2_Tables-e0d7dfad8fc32a9879eeafc0dda27266445ca283.tar.gz FMI-OOP-P2_Tables-e0d7dfad8fc32a9879eeafc0dda27266445ca283.zip | ||
| Parent | b0ab37392de9cc11a20206a8e7e388237013697e (diff) | |
Autocommit at 28.05.2022 @ 17:54
3 files changed, 14 insertions, 5 deletions
| -rw-r--r-- | src/Generic/List/List.hpp | 11 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 4 | ||||
| -rw-r--r-- | src/Models/Table.h | 4 |
diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index 0b53033..f1919b3 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -32,6 +32,8 @@ protected: public: //! Copies all elements in given array List(const T* elements, unsigned elementsCount); + //! Allocates memory for the given length + List(unsigned length); //! Adds an element void add(const T& element); //! Inserts element at given index @@ -112,6 +114,15 @@ List<T>::List(const T* elements, unsigned elementsCount) { this->elements[i] = elements[i]; } +template <typename T> +List<T>::List(unsigned length) { + this->length = length; + count = 0; + this->elements = new T[length]; + for (unsigned i = 0; i < count; i++) + this->elements[i] = elements[i]; +} + /*! * Resizes internal array if there is no space for additional elements. */ diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 6e367bc..232d066 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -1,7 +1,5 @@ #include "Table.h" Table::Table(unsigned rows, unsigned cols) { - cells = new Cell*[rows]; - for (unsigned i = 0; i < rows; i++) - cells[i] = new Cell[cols]; + cells = List<List<Cell*>>(rows); } diff --git a/src/Models/Table.h b/src/Models/Table.h index 5ed5dd9..9fea34a 100644 --- a/src/Models/Table.h +++ b/src/Models/Table.h @@ -5,8 +5,8 @@ #include "../Generic/List/List.hpp" class Table { - Cell** cells; - List<List<Cell>> constantsCells; + List<List<Cell*>> cells; + List<List<Cell*>> constantsCells; public: Table(unsigned rows, unsigned cols); |
