From e0d7dfad8fc32a9879eeafc0dda27266445ca283 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 28 May 2022 17:54:16 +0300 Subject: Autocommit at 28.05.2022 @ 17:54 --- src/Generic/List/List.hpp | 11 +++++++++++ src/Models/Table.cpp | 4 +--- src/Models/Table.h | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') 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::List(const T* elements, unsigned elementsCount) { this->elements[i] = elements[i]; } +template +List::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>(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> constantsCells; + List> cells; + List> constantsCells; public: Table(unsigned rows, unsigned cols); -- cgit v1.3.1-26-gb76a