From f1ca9056a0a0705496b180400502d363a7521a36 Mon Sep 17 00:00:00 2001 From: Sergei <31967497+SPetrenko17@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:09:16 +0300 Subject: [PATCH 1/5] Add files via upload --- CMakeLists.txt | 6 + ContainerView.cpp | 35 ++++++ ContainerView.h | 34 ++++++ Google_tests/CMakeLists.txt | 5 + Google_tests/page_tests.cpp | 87 +++++++++++++++ Google_tests/view_tests.cpp | 215 ++++++++++++++++++++++++++++++++++++ Page.cpp | 77 +++++++++++++ Page.h | 65 +++++++++++ View.cpp | 130 ++++++++++++++++++++++ View.h | 105 ++++++++++++++++++ main.cpp | 6 + 11 files changed, 765 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 ContainerView.cpp create mode 100644 ContainerView.h create mode 100644 Google_tests/CMakeLists.txt create mode 100644 Google_tests/page_tests.cpp create mode 100644 Google_tests/view_tests.cpp create mode 100644 Page.cpp create mode 100644 Page.h create mode 100644 View.cpp create mode 100644 View.h create mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9acc53f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.14) +project(CPProject) + +set(CMAKE_CXX_STANDARD 14) +add_subdirectory(Google_tests) +add_executable(CPProject main.cpp ContainerView.cpp ContainerView.h View.cpp View.h Page.cpp Page.h ) diff --git a/ContainerView.cpp b/ContainerView.cpp new file mode 100644 index 0000000..7e18e0a --- /dev/null +++ b/ContainerView.cpp @@ -0,0 +1,35 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#include "ContainerView.h" + +ContainerView::ContainerView() { + +} + +ContainerView *ContainerView::get_parent() { + return nullptr; +} + +void ContainerView::set_parent(ContainerView *containerView) { + +} + +string ContainerView::get_selector() { + return std::string(); +} + +string ContainerView::get_type() { + return std::string(); +} + +void ContainerView::set_type(string m_type) { + +} + +string ContainerView::get_path() { + return std::string(); +} + + diff --git a/ContainerView.h b/ContainerView.h new file mode 100644 index 0000000..f6a6e7e --- /dev/null +++ b/ContainerView.h @@ -0,0 +1,34 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#ifndef CPPROJECT_CONTAINERVIEW_H +#define CPPROJECT_CONTAINERVIEW_H +#include +#include +#include + + +using std::vector; +using std::string; +using std::map; + +class ContainerView { +private: + string path; + ContainerView *parent; + string selector; + string tag; + map attributes; +public: + ContainerView(); + ContainerView* get_parent(); + void set_parent(ContainerView *containerView); + string get_selector(); + string get_type(); + string get_path(); + void set_type(string m_type); +}; + + +#endif //CPPROJECT_CONTAINERVIEW_H diff --git a/Google_tests/CMakeLists.txt b/Google_tests/CMakeLists.txt new file mode 100644 index 0000000..e1060fd --- /dev/null +++ b/Google_tests/CMakeLists.txt @@ -0,0 +1,5 @@ +project(Google_tests) +add_subdirectory(googletest) +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) +add_executable(Google_Tests_run view_tests.cpp ../Page.h ../Page.cpp ../View.h ../View.cpp ../ContainerView.h ../ContainerView.cpp page_tests.cpp) +target_link_libraries(Google_Tests_run gtest gtest_main) \ No newline at end of file diff --git a/Google_tests/page_tests.cpp b/Google_tests/page_tests.cpp new file mode 100644 index 0000000..59dfc63 --- /dev/null +++ b/Google_tests/page_tests.cpp @@ -0,0 +1,87 @@ +// +// Created by Сергей Петренко on 2019-11-08. +// +#include "gtest/gtest.h" +#include "../ContainerView.h" +#include "../View.h" +#include "../Page.h" + +class TestPageData : public ::testing::Test +{ +protected: + void SetUp() override + { + page_data = new PageData(); + } + void TearDown() override + { + delete page_data; + } + PageData *page_data; +}; +TEST_F(TestPageData, test_get_static_data1) +{ + map current_pd = page_data->static_files; + page_data->get_static(); + ASSERT_NE(current_pd,page_data->static_files); +} + + +class TestPageViews : public ::testing::Test +{ +protected: + void SetUp() override + { + stringProperty = new StringProperty(); + view = new View(); + + } + View *view; + StringProperty *stringProperty; +}; + + + +class TestPageGenerator : public ::testing::Test +{ +protected: + void SetUp() override + { + page_generator = new PageGenerator(); + page_data = new PageData(); + } + PageGenerator *page_generator; + PageData *page_data; + +}; + +TEST_F(TestPageGenerator, test_generate_result_page) +{ + auto generated_page = page_generator->generate_result_page(*page_data); + ASSERT_EQ(generated_page.to_string(), "my_generated_page"); +} + + +class TestPageManager : public ::testing::Test +{ +protected: + void SetUp() override + { + page_manager = new PageManager(); + } + void TearDown() override + { + delete page_manager; + + } + PageManager *page_manager; +}; + +TEST_F(TestPageManager, test_get_from_server) +{ + + PageData page_data = page_manager->get_page_generator().get_page_data(); + // ASSERT_NE(page_data, page_manager->get_from_server()); +} + + diff --git a/Google_tests/view_tests.cpp b/Google_tests/view_tests.cpp new file mode 100644 index 0000000..223d57e --- /dev/null +++ b/Google_tests/view_tests.cpp @@ -0,0 +1,215 @@ +// +// Created by Сергей Петренко on 2019-11-08. +// +#include "gtest/gtest.h" +#include "../ContainerView.h" +#include "../View.h" + +class TestViews : public ::testing::Test +{ +protected: + void SetUp() override + { + string_property = new StringProperty(); + view = new View(); + + } + void TearDown() override + { + delete string_property; + delete view; + } + View *view; + StringProperty *string_property; +}; + +TEST_F(TestViews, test_set_get_template) +{ + view->set_view_template("p"); + ASSERT_EQ(view->get_view_template(), "p"); +} + +TEST_F(TestViews, test_set_get_name) +{ + view->set_name("string_view"); + ASSERT_EQ(view->get_view_template(), "string_view"); +} + +TEST_F(TestViews, test_to_string) +{ + view->set_view_template("

*name=*

"); + view->set_name("string_view"); + ASSERT_EQ(view->to_string(*string_property), + "

name=sting_view

"); +} + +TEST_F(TestViews, test_add_subview) +{ + view->set_view_template("

*name=*

"); + view->set_name("string_view"); + View *subview = new View(); + subview->set_view_template("

*name=*

"); + subview->set_name("substring_view"); + view->append_in_subview(*subview,view->get_path()); + + ASSERT_EQ(view->to_string(*string_property), + "

name=sting_view

name=substring_view

"); +} +TEST_F(TestViews, test_remove_subview) +{ + view->set_view_template("

*name=*

"); + view->set_name("string_view"); + View *subview = new View(); + subview->set_view_template("

*name=*

"); + subview->set_name("substring_view"); + view->append_in_subview(*subview,view->get_path()); + view->remove_subview(*view,subview->get_path()); + ASSERT_EQ(view->to_string(*string_property), + "

name=sting_view

"); +} +TEST_F(TestViews, test_remove_subview_by_name) +{ + view->set_view_template("

*name=*

"); + view->set_name("string_view"); + View *subview = new View(); + subview->set_view_template("

*name=*

"); + subview->set_name("substring_view"); + view->append_in_subview(*subview,view->get_path()); + view->remove_subview(*view, + view->get_subview_by_name(*view,"subsring_view").get_path()); + ASSERT_EQ(view->to_string(*string_property), + "

name=sting_view

"); +} + + +class TestTextViews : public ::testing::Test +{ +protected: + void SetUp() override + { + string_property = new StringProperty(); + tv = new TextView(); + + } + void TearDown() override + { + delete string_property; + delete tv; + } + TextView *tv; + StringProperty *string_property; +}; +TEST_F(TestTextViews, test_to_string) +{ + tv->set_view_template("

*name=**text*

"); + tv->set_name("text_view"); + tv->set_text("sample_text"); + ASSERT_EQ(tv->to_string(*string_property), "

name=sting_view sample_text

"); +} + +class TestImageViews : public ::testing::Test +{ +protected: + void SetUp() override + { + string_property = new StringProperty(); + iv = new ImageView(); + + } + void TearDown() override + { + delete string_property; + delete iv; + } + ImageView *iv; + StringProperty *string_property; +}; +TEST_F(TestImageViews, test_to_string) +{ + iv->set_view_template("

*name=**img=*

"); + iv->set_name("text_view"); + iv->set_image_path("image_path"); + ASSERT_EQ(iv->to_string(*string_property), "

name=sting_view sample_text

"); +} + +class TestButtons : public ::testing::Test +{ +protected: + void SetUp() override + { + string_property = new StringProperty(); + button = new Button(); + + } + void TearDown() override + { + delete string_property; + delete button; + } + Button* button; + StringProperty *string_property; +}; +TEST_F(TestButtons, test_to_string) +{ + button->TextView::set_view_template("template_for_button"); + button->TextView::set_name("button_name"); + button->ImageView::set_image_path("image_path"); + ASSERT_EQ(button->TextView::to_string(*string_property), + "template_for_button_with_params"); +} + +class TestTableViews : public ::testing::Test +{ +protected: + void SetUp() override + { + string_property = new StringProperty(); + tableView = new TableView(2,2); + columnView = new ColumnView(tableView->get_row_count()); + rowView = new RowView(); + } + void TearDown() override + { + delete string_property; + delete rowView; + delete columnView; + delete tableView; + } + RowView *rowView; + ColumnView *columnView; + TableView *tableView; + StringProperty *string_property; +}; + +TEST_F(TestTableViews, test_append) +{ + tableView->set_view_template("table_view_template"); + tableView->set_name("table_view_name"); + tableView->append_in_row(View(),"container/table/row"); + ASSERT_EQ( tableView->to_string(*string_property), + "template_for_tableview_with_params_and_new_row"); +} +TEST_F(TestTableViews, test_delete) +{ + tableView->set_view_template("table_view_template"); + tableView->set_name("table_view_name"); + tableView->remove_row(View(),"container/table/row"); + tableView->remove_column(View(),"container/table/row"); + ASSERT_EQ( tableView->to_string(*string_property), + "template_for_tableview_with_deleted_rows_and_columns"); +} + +TEST_F(TestTableViews, test_index_for_columns) +{ + tableView->set_view_template("table_view_template"); + tableView->set_name("table_view_name"); + tableView->remove_row(View(),"container/table/row"); + tableView->remove_column(View(),"container/table/column"); + ASSERT_THROW(tableView->remove_row(View(),"container/table/row"), std::out_of_range); +} + + + + + + diff --git a/Page.cpp b/Page.cpp new file mode 100644 index 0000000..3fe3bff --- /dev/null +++ b/Page.cpp @@ -0,0 +1,77 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#include "Page.h" + +PageGenerator::PageGenerator() { + +} + +Page PageGenerator::generate_start_page() { + return Page(); +} + +Page PageGenerator::generate_result_page(PageData m_data) { + return Page(); +} + +PageData PageGenerator::get_page_data() { + return PageData(); +} + +void PageManager::get_from_server() { + +} + +void PageManager::push_to_server() { + +} + +PageManager::PageManager() { + +} + +PageManager::PageManager(PageData m_data) { + +} + +PageGenerator PageManager::get_page_generator() { + return PageGenerator(); +} + +Page::Page() { + +} + +void Page::append_to_head(PageData page_data, string sv_path) { + +} + +void Page::append_in_view(PageData page_data, string sv_path) { + +} + +void Page::delete_view(string m_name) { + +} + +string Page::to_string() { + return std::string(); +} + +Page::Page(PageData page_data) { + +} + + +void PageData::get_static() { +} + +PageData::PageData(string response_from_server) { + +} + +PageData::PageData() { + +} diff --git a/Page.h b/Page.h new file mode 100644 index 0000000..5d6e78a --- /dev/null +++ b/Page.h @@ -0,0 +1,65 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#ifndef CPPROJECT_PAGE_H +#define CPPROJECT_PAGE_H + + +#include "View.h" +#include + +using std::string; +using std::vector; +class PageData{ +public: + PageData(); + PageData(string response_from_server); + vector image_urls; + vector user_urls; + map static_files; + void get_static(); +}; + + +class Page { +protected: + View view; +public: + Page(); + Page(PageData page_data); + void append_to_head(PageData page_data, string sv_path); + void append_in_view(PageData page_data, string sv_path); + void delete_view(string m_name); + string to_string(); +}; + +class PageGenerator{ +private: + string url; + PageData data; +protected: + Page page; +public: + PageGenerator(); + Page generate_start_page(); + Page generate_result_page(PageData m_data); + PageData get_page_data(); + +}; + +class PageManager{ +private: + PageData data; + PageGenerator pageGenerator; +public: + PageManager(); + PageManager(PageData m_data); + void get_from_server(); + void push_to_server(); + PageGenerator get_page_generator(); + +}; + + +#endif //CPPROJECT_PAGE_H diff --git a/View.cpp b/View.cpp new file mode 100644 index 0000000..86eece1 --- /dev/null +++ b/View.cpp @@ -0,0 +1,130 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#include "View.h" + +void View::append_in_subview(View m_view, string sv_path) { + +} + + + +View::View() { + +} + +View::View(string m_view_template) { + +} + +View View::get_subview_by_name(View m_view, string name) { + return View(); +} + +string View::to_string(StringProperty property) { + return std::string(); +} + +void View::set_name(string m_name) { + +} + +void View::set_view_template(string m_view_template) { + +} + +string View::get_view_template() { + return std::string(); +} + +string View::get_name() { + return std::string(); +} + +void View::remove_subview(View m_view, string sv_path) { + +} + +ImageView::ImageView() { + +} + +ImageView::ImageView(string m_image_path) : View(m_image_path) { + +} + +void ImageView::set_image_path(string m_image_path) { + +} + +string ImageView::get_image_path() { + return std::string(); +} + +StringProperty::StringProperty() { + +} + +TextView::TextView() { + +} + +TextView::TextView(string m_text) : View(m_text) { + +} + +void TextView::set_text(string m_text) { + +} + +string TextView::get_text() { + return std::string(); +} + +Button::Button() { + +} + +Button::Button(string path, string text) { + +} + +RowView::RowView() { + +} + +ColumnView::ColumnView() { + +} + +ColumnView::ColumnView(int rows_count) { + +} + +TableView::TableView() { + +} + +TableView::TableView(int rows, int columns) { + +} + +void TableView::append_in_row(View m_view, string path) { + +} + +int TableView::get_row_count() { + return 0; +} + +int TableView::get_colums_count() { + return 0; +} + +void TableView::remove_column(View m_view, string path) { + +} +void TableView::remove_row(View m_view, string path) { + +} \ No newline at end of file diff --git a/View.h b/View.h new file mode 100644 index 0000000..49a5269 --- /dev/null +++ b/View.h @@ -0,0 +1,105 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#ifndef CPPROJECT_VIEW_H +#define CPPROJECT_VIEW_H + + +#include "ContainerView.h" +#include +#include +#include +#include +using std::vector; +using std::string; +using std::map; + +class StringProperty{ +public: + bool is_new_line; + bool is_tag_close; + int indent; + StringProperty(); +}; + +class View: public ContainerView{ +protected: + string name; + string type; + string view_template; + vector subviews; + +public: + View(); + View(string m_view_template); + View get_subview_by_name(View m_view, string name); + + string to_string(StringProperty property); + void set_name(string m_name); + void set_view_template(string m_view_template); + void append_in_subview(View m_view,string sv_path); + void remove_subview(View m_view,string sv_path); + string get_view_template(); + string get_name(); +}; + +class ImageView: public View{ +private: + string image_path; +public: + ImageView(); + ImageView(string m_image_path); + void set_image_path(string m_image_path); + string get_image_path(); + +}; + +class TextView: public View{ +private: + string text; +public: + TextView(); + TextView(string m_text); + void set_text(string m_text); + string get_text(); + +}; + +class Button: public TextView, public ImageView{ +public: + Button(); + Button(string path,string text); +}; + +class RowView: protected View{ +public: + RowView(); +}; + +class ColumnView: public View{ +protected: + vector rows; +public: + ColumnView(); + ColumnView(int rows_count); +}; + +class TableView: public View{ +private: + int rows_count; + int columns_count; +protected: + vector rows; +public: + TableView(); + TableView(int rows, int columns); + void append_in_row(View m_row, string path); + void remove_column(View m_column, string path); + void remove_row(View m_row, string path); + int get_row_count(); + int get_colums_count(); + +}; + +#endif //CPPROJECT_VIEW_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..1cb17f6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + + return 0; +} \ No newline at end of file From fd0d20b740d36d31f647f97598cc966852dbe64b Mon Sep 17 00:00:00 2001 From: SPetrenko17 Date: Sat, 9 Nov 2019 14:25:10 +0300 Subject: [PATCH 2/5] add lib gtests --- .DS_Store | Bin 0 -> 6148 bytes Google_tests/.DS_Store | Bin 0 -> 6148 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store create mode 100644 Google_tests/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ab2bc947dbf22a184be64c1dfa407eab08760e56 GIT binary patch literal 6148 zcmeHK-D(p-6h70&bP}tLAhefzBX|)?LaeHj%*;76JKvm{*&!lUA9t!mB_iTT5_3glOGLKI zbWYYx%_fkkJ_33`A&n?OvSJyq4E*m5$h~`&4(K6y^n%j+cNe?(B_)TEIQ1jp!%iL& zpO9{TQv!|X8hi!Cu=TL>WArejV`u?QXqQfDK!e2|*mkCetzY)g%Xq)bcyH2uj4!B5 z5youeI|6X?4a|H$`-3PPC6&q-wzi(Tl;7aI$ctBs&s#k)X(e7V9@V|! zQ&~FllAdq$$3jFubrr0w%5`|RS%&`8@B=n*yP z9yJi2P4wTV&f>DFuStg^|4s18@JWx5PuXX`Mutq<7RA*P6E6JnYE8?|#xh_T_zMik z^T9!q=o*}BR7VFg^#lOsP^|>I{7sNPjzQPpTq9Z_OuGWLD>F|FrrlBR7(3VCT%&d; zW*#5RjLggng{jfezoX2Fxf*S58L$j2GO(_TC3*ihFMj_oI@ywCz%sB>46t0I)u>}i z=59SVIeFJQNGC{Aq}^PjazSRUW2MNecn3)d+8n6>U4wItsDaoY0Y!t&ECc_Pf$!)$ B;c5T? literal 0 HcmV?d00001 diff --git a/Google_tests/.DS_Store b/Google_tests/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..497cc6e4815b97acc287726a33b5ce607756c818 GIT binary patch literal 6148 zcmeHKJxc>Y5PhR5f9;Oq+YVc074Nlsv`~7r4hG8v5Tb{q_+~afw?z z;QRMaxQbUa=T*I!SM{8ED$)u4=p!2=U=Jl~{z_D2H*~JP%aOMY&Il{cRx09$F5b7e&s2Dcm!G+Eu)$?DEEEU@LV-{q6wotUZMbh3Whf8|gaTg*=>CxCiiKlq zn70lV`3XSOYjifodQDbNax5HML-x?bs6?ZRKQYAUY)_t7IJSmHhxp?|eCGAzMe^(% zKjm~tVHjm75DIh^*tP0d&;K+2WqKd^T}sqKfl%O|DIkN{)ojW|`PsU)JUwd@{f4fl qd94OC#+^$5E4q&y=1%KR8Z)nOYz=i3ZO?RKTm-TpQG^1&pui_umPph9 literal 0 HcmV?d00001 From 88c2294c63acd51e34a8e58ab7d641ed32117482 Mon Sep 17 00:00:00 2001 From: SPetrenko17 Date: Fri, 6 Dec 2019 18:14:46 +0300 Subject: [PATCH 3/5] Minimal functional without shared_ptr --- .DS_Store | Bin 6148 -> 6148 bytes CMakeLists.txt | 59 ++- ContainerView.cpp | 35 -- ContainerView.h | 34 -- Google_tests/.DS_Store | Bin 6148 -> 6148 bytes Google_tests/CMakeLists.txt | 2 +- Google_tests/page_tests.cpp | 136 +++--- Google_tests/view_tests.cpp | 403 +++++++++--------- Page.cpp | 77 ---- Page.h | 65 --- Sources/.DS_Store | Bin 0 -> 6148 bytes Sources/Page/Page.cpp | 43 ++ Sources/Page/Page.h | 60 +++ Sources/PageData/PageData.cpp | 16 + Sources/PageData/PageData.h | 43 ++ Sources/PageGenerator/PageGenerator.cpp | 72 ++++ Sources/PageGenerator/PageGenerator.h | 32 ++ Sources/PageManager/PageManager.cpp | 8 + Sources/PageManager/PageManager.h | 21 + Sources/Views/Button/Button.cpp | 6 + Sources/Views/Button/Button.h | 12 + Sources/Views/Cell/CellView.cpp | 94 ++++ Sources/Views/Cell/CellView.h | 37 ++ Sources/Views/Container/ContainerView.cpp | 24 ++ Sources/Views/Container/ContainerView.h | 177 ++++++++ Sources/Views/ImageView/ImageView.cpp | 43 ++ Sources/Views/ImageView/ImageView.h | 32 ++ Sources/Views/PersonView/PersonView.cpp | 85 ++++ Sources/Views/PersonView/PersonView.h | 31 ++ Sources/Views/Row/RowView.cpp | 79 ++++ Sources/Views/Row/RowView.h | 30 ++ Sources/Views/SecondaryView/SecondaryView.cpp | 44 ++ Sources/Views/SecondaryView/SecondaryView.h | 41 ++ Sources/Views/TableView/TableView.cpp | 111 +++++ Sources/Views/TableView/TableView.h | 37 ++ Sources/Views/TextView/TextView.cpp | 58 +++ Sources/Views/TextView/TextView.h | 30 ++ Sources/Views/UserData/UserData.cpp | 12 + Sources/Views/UserData/UserData.h | 21 + Sources/Views/View/View.cpp | 116 +++++ Sources/Views/View/View.h | 33 ++ Sources/main.cpp | 40 ++ View.cpp | 130 ------ View.h | 105 ----- main.cpp | 6 - 45 files changed, 1815 insertions(+), 725 deletions(-) delete mode 100644 ContainerView.cpp delete mode 100644 ContainerView.h delete mode 100644 Page.cpp delete mode 100644 Page.h create mode 100644 Sources/.DS_Store create mode 100644 Sources/Page/Page.cpp create mode 100644 Sources/Page/Page.h create mode 100644 Sources/PageData/PageData.cpp create mode 100644 Sources/PageData/PageData.h create mode 100644 Sources/PageGenerator/PageGenerator.cpp create mode 100644 Sources/PageGenerator/PageGenerator.h create mode 100644 Sources/PageManager/PageManager.cpp create mode 100644 Sources/PageManager/PageManager.h create mode 100644 Sources/Views/Button/Button.cpp create mode 100644 Sources/Views/Button/Button.h create mode 100644 Sources/Views/Cell/CellView.cpp create mode 100644 Sources/Views/Cell/CellView.h create mode 100644 Sources/Views/Container/ContainerView.cpp create mode 100644 Sources/Views/Container/ContainerView.h create mode 100644 Sources/Views/ImageView/ImageView.cpp create mode 100644 Sources/Views/ImageView/ImageView.h create mode 100644 Sources/Views/PersonView/PersonView.cpp create mode 100644 Sources/Views/PersonView/PersonView.h create mode 100644 Sources/Views/Row/RowView.cpp create mode 100644 Sources/Views/Row/RowView.h create mode 100644 Sources/Views/SecondaryView/SecondaryView.cpp create mode 100644 Sources/Views/SecondaryView/SecondaryView.h create mode 100644 Sources/Views/TableView/TableView.cpp create mode 100644 Sources/Views/TableView/TableView.h create mode 100644 Sources/Views/TextView/TextView.cpp create mode 100644 Sources/Views/TextView/TextView.h create mode 100644 Sources/Views/UserData/UserData.cpp create mode 100644 Sources/Views/UserData/UserData.h create mode 100644 Sources/Views/View/View.cpp create mode 100644 Sources/Views/View/View.h create mode 100644 Sources/main.cpp delete mode 100644 View.cpp delete mode 100644 View.h delete mode 100644 main.cpp diff --git a/.DS_Store b/.DS_Store index ab2bc947dbf22a184be64c1dfa407eab08760e56..8d58a1a26baff785a7b5e921fe1755bff6673161 100644 GIT binary patch delta 235 zcmZoMXfc@J&&aVcU^g=($7CKB`^l$SG$z-w2moox$ug|mj3*{*ur_FjS67=ES?VYl z8rJG4RGXU{=qQ*No7L8Ga)_%M+IlABR#sKl)Yi?Ie34b2apvTYtlE=Tuo>~QGXyi_ zGn6tEF(fmjG89ir2_KO3kK&B(IgqP(2^ymX)pl delta 431 zcmZoMXfc@J&&abeU^g=(&tx7J`$RzoXNG)+Jcbg6M21Wtoyt(e5C&wWGL$puF(fk- zFcf&^TPvOFbFU(Fp2|djsIW(WHB)C<24~;@*P(B$=)m)jGrgluxL!4!@|vY za`Fn622F|TYGYGV9R*`UgIXPhYIAb~9R(9(v)Wot4slgOThD~t%Bt#`+PayO16bu5 zXH70()vo7Y$c4HStJ@f?f$o`s -#include -#include - - -using std::vector; -using std::string; -using std::map; - -class ContainerView { -private: - string path; - ContainerView *parent; - string selector; - string tag; - map attributes; -public: - ContainerView(); - ContainerView* get_parent(); - void set_parent(ContainerView *containerView); - string get_selector(); - string get_type(); - string get_path(); - void set_type(string m_type); -}; - - -#endif //CPPROJECT_CONTAINERVIEW_H diff --git a/Google_tests/.DS_Store b/Google_tests/.DS_Store index 497cc6e4815b97acc287726a33b5ce607756c818..219a4f1ca620a08d24e3764f0d558d9fecca888a 100644 GIT binary patch delta 410 zcmZoMXfc=|#>B!ku~2NHo}wr_0|Nsi1A_nqLncEBLp%`bF%)cOWLnNF4U*yp3uQ9o zAxkqR?X z)aocyo0}WxD3}Ekq)zT&RGR#ZQE>8ZM(xQ~jDnlLGk#{=%+A5j0Ss|qsD5Xj X%r9ao0MrAv1V}J}Oy3+KvW6J|MzUit delta 163 zcmZoMXfc=|#>B`mu~2NHo}wrV0|Nsi1A_nqLn?z0LncEpLkUCi#KPr_ER&sB^e0be z5isOpNN30g!gPilprR5W1}gH*$xlwo$xi}m2kK?41JWA*!GM8b@=R7eCWe)hPqJD~ vKF%t*S&T!FWn;sC#?9;;{2V~5Hw$unXP(S2VhPj #include "gtest/gtest.h" -#include "../ContainerView.h" -#include "../View.h" -#include "../Page.h" +#include "UserData/UserData.h" +#include +#include +#include "View/View.h" +#include "Page.h" -class TestPageData : public ::testing::Test +class TestPage : public ::testing::Test { +public: + PageGenerator* pageGenerator; + //UserData* userData1 = new UserData("SLUG1","fname", "sname","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ); + //UserData* userData2 = new UserData("SLUG2","fname", "sname","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ); + //std::vector userData { + //PageData* pageData = new PageData(userData,PageType::TABLE_OF_USERS, Organize::ONE_LINE_VERTICAL); + std::string res; protected: void SetUp() override { - page_data = new PageData(); - } - void TearDown() override - { - delete page_data; - } - PageData *page_data; -}; -TEST_F(TestPageData, test_get_static_data1) -{ - map current_pd = page_data->static_files; - page_data->get_static(); - ASSERT_NE(current_pd,page_data->static_files); -} - + pageGenerator = new PageGenerator(); -class TestPageViews : public ::testing::Test -{ -protected: - void SetUp() override - { - stringProperty = new StringProperty(); - view = new View(); + //res = pageGenerator->generatePage()->toString(); } - View *view; - StringProperty *stringProperty; -}; - - - -class TestPageGenerator : public ::testing::Test -{ -protected: - void SetUp() override + void TearDown() override { - page_generator = new PageGenerator(); - page_data = new PageData(); + delete pageGenerator; } - PageGenerator *page_generator; - PageData *page_data; }; +TEST_F(TestPage, testTableCorrectOneLineVertical){ -TEST_F(TestPageGenerator, test_generate_result_page) -{ - auto generated_page = page_generator->generate_result_page(*page_data); - ASSERT_EQ(generated_page.to_string(), "my_generated_page"); + ASSERT_STREQ("hi","hi"); } - -class TestPageManager : public ::testing::Test -{ -protected: - void SetUp() override - { - page_manager = new PageManager(); - } - void TearDown() override - { - delete page_manager; - - } - PageManager *page_manager; -}; - -TEST_F(TestPageManager, test_get_from_server) -{ - - PageData page_data = page_manager->get_page_generator().get_page_data(); - // ASSERT_NE(page_data, page_manager->get_from_server()); -} +// +//class TestPageViews : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// stringProperty = new StringProperty(); +// view = new View(); +// +// } +// View *view; +// StringProperty *stringProperty; +//}; +// +// +// +//class TestPageGenerator : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// page_generator = new PageGenerator(); +// page_data = new PageData(); +// } +// PageGenerator *page_generator; +// PageData *page_data; +// +//}; +// +//TEST_F(TestPageGenerator, test_generate_result_page) +//{ +// auto generated_page = page_generator->generate_result_page(*page_data); +// ASSERT_EQ(generated_page.to_string(), "my_generated_page"); +//} +// +// +//class TestPageManager : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// page_manager = new PageManager(); +// } +// void TearDown() override +// { +// delete page_manager; +// +// } +// PageManager *page_manager; +//}; diff --git a/Google_tests/view_tests.cpp b/Google_tests/view_tests.cpp index 223d57e..a77ff1c 100644 --- a/Google_tests/view_tests.cpp +++ b/Google_tests/view_tests.cpp @@ -2,211 +2,204 @@ // Created by Сергей Петренко on 2019-11-08. // #include "gtest/gtest.h" -#include "../ContainerView.h" -#include "../View.h" - -class TestViews : public ::testing::Test -{ -protected: - void SetUp() override - { - string_property = new StringProperty(); - view = new View(); - - } - void TearDown() override - { - delete string_property; - delete view; - } - View *view; - StringProperty *string_property; -}; - -TEST_F(TestViews, test_set_get_template) -{ - view->set_view_template("p"); - ASSERT_EQ(view->get_view_template(), "p"); -} - -TEST_F(TestViews, test_set_get_name) -{ - view->set_name("string_view"); - ASSERT_EQ(view->get_view_template(), "string_view"); -} - -TEST_F(TestViews, test_to_string) -{ - view->set_view_template("

*name=*

"); - view->set_name("string_view"); - ASSERT_EQ(view->to_string(*string_property), - "

name=sting_view

"); -} - -TEST_F(TestViews, test_add_subview) -{ - view->set_view_template("

*name=*

"); - view->set_name("string_view"); - View *subview = new View(); - subview->set_view_template("

*name=*

"); - subview->set_name("substring_view"); - view->append_in_subview(*subview,view->get_path()); - - ASSERT_EQ(view->to_string(*string_property), - "

name=sting_view

name=substring_view

"); -} -TEST_F(TestViews, test_remove_subview) -{ - view->set_view_template("

*name=*

"); - view->set_name("string_view"); - View *subview = new View(); - subview->set_view_template("

*name=*

"); - subview->set_name("substring_view"); - view->append_in_subview(*subview,view->get_path()); - view->remove_subview(*view,subview->get_path()); - ASSERT_EQ(view->to_string(*string_property), - "

name=sting_view

"); -} -TEST_F(TestViews, test_remove_subview_by_name) -{ - view->set_view_template("

*name=*

"); - view->set_name("string_view"); - View *subview = new View(); - subview->set_view_template("

*name=*

"); - subview->set_name("substring_view"); - view->append_in_subview(*subview,view->get_path()); - view->remove_subview(*view, - view->get_subview_by_name(*view,"subsring_view").get_path()); - ASSERT_EQ(view->to_string(*string_property), - "

name=sting_view

"); -} - - -class TestTextViews : public ::testing::Test -{ -protected: - void SetUp() override - { - string_property = new StringProperty(); - tv = new TextView(); - - } - void TearDown() override - { - delete string_property; - delete tv; - } - TextView *tv; - StringProperty *string_property; -}; -TEST_F(TestTextViews, test_to_string) -{ - tv->set_view_template("

*name=**text*

"); - tv->set_name("text_view"); - tv->set_text("sample_text"); - ASSERT_EQ(tv->to_string(*string_property), "

name=sting_view sample_text

"); -} - -class TestImageViews : public ::testing::Test -{ -protected: - void SetUp() override - { - string_property = new StringProperty(); - iv = new ImageView(); - - } - void TearDown() override - { - delete string_property; - delete iv; - } - ImageView *iv; - StringProperty *string_property; -}; -TEST_F(TestImageViews, test_to_string) -{ - iv->set_view_template("

*name=**img=*

"); - iv->set_name("text_view"); - iv->set_image_path("image_path"); - ASSERT_EQ(iv->to_string(*string_property), "

name=sting_view sample_text

"); -} - -class TestButtons : public ::testing::Test -{ -protected: - void SetUp() override - { - string_property = new StringProperty(); - button = new Button(); - - } - void TearDown() override - { - delete string_property; - delete button; - } - Button* button; - StringProperty *string_property; -}; -TEST_F(TestButtons, test_to_string) -{ - button->TextView::set_view_template("template_for_button"); - button->TextView::set_name("button_name"); - button->ImageView::set_image_path("image_path"); - ASSERT_EQ(button->TextView::to_string(*string_property), - "template_for_button_with_params"); -} - -class TestTableViews : public ::testing::Test -{ -protected: - void SetUp() override - { - string_property = new StringProperty(); - tableView = new TableView(2,2); - columnView = new ColumnView(tableView->get_row_count()); - rowView = new RowView(); - } - void TearDown() override - { - delete string_property; - delete rowView; - delete columnView; - delete tableView; - } - RowView *rowView; - ColumnView *columnView; - TableView *tableView; - StringProperty *string_property; -}; - -TEST_F(TestTableViews, test_append) -{ - tableView->set_view_template("table_view_template"); - tableView->set_name("table_view_name"); - tableView->append_in_row(View(),"container/table/row"); - ASSERT_EQ( tableView->to_string(*string_property), - "template_for_tableview_with_params_and_new_row"); -} -TEST_F(TestTableViews, test_delete) -{ - tableView->set_view_template("table_view_template"); - tableView->set_name("table_view_name"); - tableView->remove_row(View(),"container/table/row"); - tableView->remove_column(View(),"container/table/row"); - ASSERT_EQ( tableView->to_string(*string_property), - "template_for_tableview_with_deleted_rows_and_columns"); -} - -TEST_F(TestTableViews, test_index_for_columns) -{ - tableView->set_view_template("table_view_template"); - tableView->set_name("table_view_name"); - tableView->remove_row(View(),"container/table/row"); - tableView->remove_column(View(),"container/table/column"); - ASSERT_THROW(tableView->remove_row(View(),"container/table/row"), std::out_of_range); -} +#include "Container/ContainerView.h" +#include "View/View.h" + +//class TestViews : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// string_property = new StringProperty(); +// view = new View(); +// +// } +// void TearDown() override +// { +// delete string_property; +// delete view; +// } +// View *view; +// StringProperty *string_property; +//}; +// +//TEST_F(TestViews, test_set_get_template) +//{ +// view->set_view_template("p"); +// ASSERT_EQ(view->get_view_template(), "p"); +//} +// +//TEST_F(TestViews, test_set_get_name) +//{ +// view->set_name("string_view"); +// ASSERT_EQ(view->get_view_template(), "string_view"); +//} +// +//TEST_F(TestViews, test_to_string) +//{ +// view->set_view_template("

*name=*

"); +// view->set_name("string_view"); +// ASSERT_EQ(view->to_string(*string_property), +// "

name=sting_view

"); +//} +// +//TEST_F(TestViews, test_add_subview) +//{ +// view->set_view_template("

*name=*

"); +// view->set_name("string_view"); +// View *subview = new View(); +// subview->set_view_template("

*name=*

"); +// subview->set_name("substring_view"); +// view->append_in_subview(*subview,view->get_path()); +// +// ASSERT_EQ(view->to_string(*string_property), +// "

name=sting_view

name=substring_view

"); +//} +//TEST_F(TestViews, test_remove_subview) +//{ +// view->set_view_template("

*name=*

"); +// view->set_name("string_view"); +// View *subview = new View(); +// subview->set_view_template("

*name=*

"); +// subview->set_name("substring_view"); +// view->append_in_subview(*subview,view->get_path()); +// view->remove_subview(*view,subview->get_path()); +// ASSERT_EQ(view->to_string(*string_property), +// "

name=sting_view

"); +//} +//TEST_F(TestViews, test_remove_subview_by_name) +//{ +// view->set_view_template("

*name=*

"); +// view->set_name("string_view"); +// View *subview = new View(); +// subview->set_view_template("

*name=*

"); +// subview->set_name("substring_view"); +// view->append_in_subview(*subview,view->get_path()); +// view->remove_subview(*view, +// view->get_subview_by_name(*view,"subsring_view").get_path()); +// ASSERT_EQ(view->to_string(*string_property), +// "

name=sting_view

"); +//} +// +// +//class TestTextViews : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// string_property = new StringProperty(); +// tv = new TextView(); +// +// } +// void TearDown() override +// { +// delete string_property; +// delete tv; +// } +// TextView *tv; +// StringProperty *string_property; +//}; +//TEST_F(TestTextViews, test_to_string) +//{ +// tv->set_view_template("

*name=**text*

"); +// tv->set_name("text_view"); +// tv->set_text("sample_text"); +// ASSERT_EQ(tv->to_string(*string_property), "

name=sting_view sample_text

"); +//} +// +//class TestImageViews : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// string_property = new StringProperty(); +// iv = new ImageView(); +// +// } +// void TearDown() override +// { +// delete string_property; +// delete iv; +// } +// ImageView *iv; +// StringProperty *string_property; +//}; +//TEST_F(TestImageViews, test_to_string) +//{ +// iv->set_view_template("

*name=**img=*

"); +// iv->set_name("text_view"); +// iv->set_image_path("image_path"); +// ASSERT_EQ(iv->to_string(*string_property), "

name=sting_view sample_text

"); +//} +// +//class TestButtons : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// string_property = new StringProperty(); +// button = new Button(); +// +// } +// void TearDown() override +// { +// delete string_property; +// delete button; +// } +// Button* button; +// StringProperty *string_property; +//}; +// +// +//class TestTableViews : public ::testing::Test +//{ +//protected: +// void SetUp() override +// { +// string_property = new StringProperty(); +// tableView = new TableView(2,2); +// columnView = new ColumnView(tableView->get_row_count()); +// rowView = new RowView(); +// } +// void TearDown() override +// { +// delete string_property; +// delete rowView; +// delete columnView; +// delete tableView; +// } +// RowView *rowView; +// ColumnView *columnView; +// TableView *tableView; +// StringProperty *string_property; +//}; +// +//TEST_F(TestTableViews, test_append) +//{ +// tableView->set_view_template("table_view_template"); +// tableView->set_name("table_view_name"); +// tableView->append_in_row(View(),"container/table/row"); +// ASSERT_EQ( tableView->to_string(*string_property), +// "template_for_tableview_with_params_and_new_row"); +//} +//TEST_F(TestTableViews, test_delete) +//{ +// tableView->set_view_template("table_view_template"); +// tableView->set_name("table_view_name"); +// tableView->remove_row(View(),"container/table/row"); +// tableView->remove_column(View(),"container/table/row"); +// ASSERT_EQ( tableView->to_string(*string_property), +// "template_for_tableview_with_deleted_rows_and_columns"); +//} +// +//TEST_F(TestTableViews, test_index_for_columns) +//{ +// tableView->set_view_template("table_view_template"); +// tableView->set_name("table_view_name"); +// tableView->remove_row(View(),"container/table/row"); +// tableView->remove_column(View(),"container/table/column"); +// ASSERT_THROW(tableView->remove_row(View(),"container/table/row"), std::out_of_range); +//} diff --git a/Page.cpp b/Page.cpp deleted file mode 100644 index 3fe3bff..0000000 --- a/Page.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-07. -// - -#include "Page.h" - -PageGenerator::PageGenerator() { - -} - -Page PageGenerator::generate_start_page() { - return Page(); -} - -Page PageGenerator::generate_result_page(PageData m_data) { - return Page(); -} - -PageData PageGenerator::get_page_data() { - return PageData(); -} - -void PageManager::get_from_server() { - -} - -void PageManager::push_to_server() { - -} - -PageManager::PageManager() { - -} - -PageManager::PageManager(PageData m_data) { - -} - -PageGenerator PageManager::get_page_generator() { - return PageGenerator(); -} - -Page::Page() { - -} - -void Page::append_to_head(PageData page_data, string sv_path) { - -} - -void Page::append_in_view(PageData page_data, string sv_path) { - -} - -void Page::delete_view(string m_name) { - -} - -string Page::to_string() { - return std::string(); -} - -Page::Page(PageData page_data) { - -} - - -void PageData::get_static() { -} - -PageData::PageData(string response_from_server) { - -} - -PageData::PageData() { - -} diff --git a/Page.h b/Page.h deleted file mode 100644 index 5d6e78a..0000000 --- a/Page.h +++ /dev/null @@ -1,65 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-07. -// - -#ifndef CPPROJECT_PAGE_H -#define CPPROJECT_PAGE_H - - -#include "View.h" -#include - -using std::string; -using std::vector; -class PageData{ -public: - PageData(); - PageData(string response_from_server); - vector image_urls; - vector user_urls; - map static_files; - void get_static(); -}; - - -class Page { -protected: - View view; -public: - Page(); - Page(PageData page_data); - void append_to_head(PageData page_data, string sv_path); - void append_in_view(PageData page_data, string sv_path); - void delete_view(string m_name); - string to_string(); -}; - -class PageGenerator{ -private: - string url; - PageData data; -protected: - Page page; -public: - PageGenerator(); - Page generate_start_page(); - Page generate_result_page(PageData m_data); - PageData get_page_data(); - -}; - -class PageManager{ -private: - PageData data; - PageGenerator pageGenerator; -public: - PageManager(); - PageManager(PageData m_data); - void get_from_server(); - void push_to_server(); - PageGenerator get_page_generator(); - -}; - - -#endif //CPPROJECT_PAGE_H diff --git a/Sources/.DS_Store b/Sources/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1b2e3757b20483c52c9c3e96f3c926f1e2a19f1b GIT binary patch literal 6148 zcmeHK-D=c86h5=v+Sx6|y%5^V+z4JQvg=BVh!EC_^g<{^>V-<1bVD0RGfR>+=(>^{ zA41>2NAU@K5FbFlGc#TG$KHy_960&TocYd#`6gs$h)4`4qdrlGh$Nh`(Zb^o#{KMT z*07l^pwMI7r*j(9_$XE9YiyVJ7Zu>OlXOKPC6v*^`bDXV(8nLfWB9#a+7J;n=@|SA zig}$Ec;9Z~MO87jyzkLCO^UMD`ym<|&COd|QnqD#r~Nj#R8>%h<)j#f`D<<+hvj8t zBrfpFM6sZ@L_AaZSfkuBA5&DF37V~ zWf#aXf9F~tdQLH9jVXsU%x7iT$k&)4}=v%A} zq6a2SDbSP(d&Ll@9C^?3e2cX~Q%=HOK7@UaYD*M_{u X0noQt8$<@?4gy*R_izgQRRw+nJCcxt literal 0 HcmV?d00001 diff --git a/Sources/Page/Page.cpp b/Sources/Page/Page.cpp new file mode 100644 index 0000000..2924959 --- /dev/null +++ b/Sources/Page/Page.cpp @@ -0,0 +1,43 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#include "Page.h" + +//Page::Page(){ +// view = new View("main", Type::DIV); +// makeTemplate(); +//} +// +//void Page::makeTemplate(){ +// +// view->append(*new View("html",Type::HTML)); +// view->appendInSubview("html", +// *new SecondaryView("meta", +// Type::META, +// std::vector{ +// Attribute("charset","UTF-8") +// })); +// view->appendInSubview("html",(*new TextView("title",Type::TITLE,"FINDFACE"))); +// view->appendInSubview("html", +// *new SecondaryView("attributes", +// Type::LINK, std::vector{ +// Attribute("rel","stylesheet"), +// Attribute("href","https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"), +// Attribute("integrity","sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"), +// Attribute("crossorigin","anonymous") +// })); +// +// view->appendInSubview("html",* new View("body",Type::BODY)); +//} +// +//void Page::appendInBody(ContainerView& containerView){ +// view->appendInSubview("body", containerView); +//} +// +//std::string Page::toString(){ +// std::string res; +// res += "\n"; +// res+=view->toString(0); +// return res; +//} \ No newline at end of file diff --git a/Sources/Page/Page.h b/Sources/Page/Page.h new file mode 100644 index 0000000..580bc81 --- /dev/null +++ b/Sources/Page/Page.h @@ -0,0 +1,60 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#ifndef CPPROJECT_PAGE_H +#define CPPROJECT_PAGE_H + +#include "Views/View/View.h" +#include "Views/SecondaryView/SecondaryView.h" +#include "Views/TextView/TextView.h" +#include + +class Page { +public: + View* view; + Page(){ + view = new View("main", Type::DIV); + makeTemplate(); + } + + void makeTemplate(){ + + view->append(*new View("html",Type::HTML)); + view->appendInSubview("html", + *new SecondaryView("meta", + Type::META, + std::vector{ + Attribute("charset","UTF-8") + })); + view->appendInSubview("html",(*new TextView("title",Type::TITLE,"FINDFACE"))); + view->appendInSubview("html", + *new SecondaryView("attributes", + Type::LINK, std::vector{ + Attribute("rel","stylesheet"), + Attribute("href","https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"), + Attribute("integrity","sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"), + Attribute("crossorigin","anonymous") + })); + + view->appendInSubview("html",* new View("body",Type::BODY)); + } + + void appendInBody(ContainerView& containerView){ + view->appendInSubview("body", containerView); + } + + std::string toString(){ + std::string res; + res += "\n"; + res+=view->toString(0); + return res; + } +}; + + + + + + +#endif //CPPROJECT_PAGE_H diff --git a/Sources/PageData/PageData.cpp b/Sources/PageData/PageData.cpp new file mode 100644 index 0000000..b21ffcc --- /dev/null +++ b/Sources/PageData/PageData.cpp @@ -0,0 +1,16 @@ +// +// Created by Сергей Петренко on 2019-12-05. +// + +#include "PageData.h" +PageData::PageData(std::vector u, PageType t, Organize o){ + type = t; + userData = u; + organize = o; +} +void PageData::setOrganizeType(Organize o){ + organize = o; +} +void PageData::setPageType(PageType t) { + type = t; +} \ No newline at end of file diff --git a/Sources/PageData/PageData.h b/Sources/PageData/PageData.h new file mode 100644 index 0000000..7418294 --- /dev/null +++ b/Sources/PageData/PageData.h @@ -0,0 +1,43 @@ +// +// Created by Сергей Петренко on 2019-12-05. +// + +#ifndef CPPROJECT_PAGEDATA_H +#define CPPROJECT_PAGEDATA_H + +#include +#include "../Views/UserData/UserData.h" +enum class PageType: uint8_t +{ + ONE_USER_PAGE, + TABLE_OF_USERS, + START_PAGE, + +}; +enum class Organize: uint8_t +{ + ONE_LINE_VERTICAL, + ONE_LINE_HORIZONTAL, + SQUARE, + RECT_HORIZONTAL, + RECT_VERTICAL + +}; + +class PageData { +public: + + std::vector userData; + + PageData(std::vector u, PageType t, Organize o); + void setOrganizeType(Organize o); + void setPageType(PageType o); + PageType getpageType(){ return type;} + Organize getpageOrganizeType(){ return organize;} +private: + Organize organize; + PageType type; +}; + + +#endif //CPPROJECT_PAGEDATA_H diff --git a/Sources/PageGenerator/PageGenerator.cpp b/Sources/PageGenerator/PageGenerator.cpp new file mode 100644 index 0000000..3737f90 --- /dev/null +++ b/Sources/PageGenerator/PageGenerator.cpp @@ -0,0 +1,72 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "PageGenerator.h" +void PageGenerator::organizeCells(Organize o, int& rows, int& cells, int count){ + switch(o){ + case Organize::ONE_LINE_VERTICAL: + rows = 1; + cells = count; + break; + case Organize::ONE_LINE_HORIZONTAL: + cells = 2; + rows = count; + break; + + case Organize::RECT_HORIZONTAL: + break; + case Organize::RECT_VERTICAL: + break; + } +} +Page* PageGenerator::generateTablePage(std::vector userData, Organize o){ + page = new Page(); + std::vector persons; + for(auto &u : userData){ + persons.push_back(new PersonView(*u)); + } + + int rowsCount = 0; + int cellsCount = 0; + organizeCells(o,rowsCount,cellsCount,userData.size()); + + View* view = new View("Main",Type::DIV,BClass::CARD_DECK); + + TableView* tableView = new TableView("Table",rowsCount,cellsCount); + int r = 0; + int c = 0; + tableView->appendCell(*new CellView(c,rowsCount)); + for(auto &p: persons){ + tableView->appendRowInCell(c,*new RowView(r, *p)); + r++; + if(r >= rowsCount){ + r = 0; + tableView->appendCell(*new CellView(++c,rowsCount)); + } + } + page->appendInBody(*tableView); + return page; +} +Page* PageGenerator::generateStartPage(){ + +} + +Page* PageGenerator::generateUserPage(std::vector userData){ + +} + +Page* PageGenerator::generatePage(PageData &pageData){ + switch(pageData.getpageType()){ + case PageType::TABLE_OF_USERS : + page = generateTablePage(pageData.userData, pageData.getpageOrganizeType()); + break; + case PageType::ONE_USER_PAGE : + page = generateUserPage(pageData.userData); + break; + case PageType::START_PAGE : + page = generateStartPage(); + break; + } + return page; +} \ No newline at end of file diff --git a/Sources/PageGenerator/PageGenerator.h b/Sources/PageGenerator/PageGenerator.h new file mode 100644 index 0000000..adfb89d --- /dev/null +++ b/Sources/PageGenerator/PageGenerator.h @@ -0,0 +1,32 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_PAGEGENERATOR_H +#define CPPROJECT_PAGEGENERATOR_H + +#include +#include "Page/Page.h" +#include "Views/PersonView/PersonView.h" +#include "PageData/PageData.h" + + +class PageGenerator{ + +public: + + Page* page; + PageGenerator() = default; + void organizeCells(Organize o, int& rows, int& cells, int count); + Page* generateTablePage(std::vector userData, Organize o); + + Page* generateStartPage(); + + Page* generateUserPage(std::vector userData); + + Page* generatePage(PageData &pageData); + +}; + + +#endif //CPPROJECT_PAGEGENERATOR_H diff --git a/Sources/PageManager/PageManager.cpp b/Sources/PageManager/PageManager.cpp new file mode 100644 index 0000000..f6b2703 --- /dev/null +++ b/Sources/PageManager/PageManager.cpp @@ -0,0 +1,8 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "PageManager.h" + + + diff --git a/Sources/PageManager/PageManager.h b/Sources/PageManager/PageManager.h new file mode 100644 index 0000000..0fe9adf --- /dev/null +++ b/Sources/PageManager/PageManager.h @@ -0,0 +1,21 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_PAGEMANAGER_H +#define CPPROJECT_PAGEMANAGER_H + +#include "PageGenerator/PageGenerator.h" + + +class PageManager{ +private: + PageData data; + PageGenerator pageGenerator; +public: + PageManager(); + PageManager(PageData m_data); + +}; + +#endif //CPPROJECT_PAGEMANAGER_H diff --git a/Sources/Views/Button/Button.cpp b/Sources/Views/Button/Button.cpp new file mode 100644 index 0000000..631860b --- /dev/null +++ b/Sources/Views/Button/Button.cpp @@ -0,0 +1,6 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "Button.h" + diff --git a/Sources/Views/Button/Button.h b/Sources/Views/Button/Button.h new file mode 100644 index 0000000..85fcef4 --- /dev/null +++ b/Sources/Views/Button/Button.h @@ -0,0 +1,12 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_BUTTON_H +#define CPPROJECT_BUTTON_H + + + + + +#endif //CPPROJECT_BUTTON_H diff --git a/Sources/Views/Cell/CellView.cpp b/Sources/Views/Cell/CellView.cpp new file mode 100644 index 0000000..3233dc8 --- /dev/null +++ b/Sources/Views/Cell/CellView.cpp @@ -0,0 +1,94 @@ +// +// Created by Сергей Петренко on 2019-12-02. +// + +#include "CellView.h" + +CellView::CellView(int mRows){ + type = enumToString(Type::CELL); + rowsCount = mRows; +} +CellView::CellView(int indx,int mRows){ + type = enumToString(Type::CELL); + rowsCount = mRows; + index = indx; + +} + +CellView::CellView(int indx, std::vector rows){ + type = enumToString(Type::CELL); + rowsCount = rows.size(); + index = indx; + appendRows(rows); +} + +void CellView::setIndex(int indx){ + index = indx; +} + +std::string CellView::toString(int depth){ + std::string res; + if(depth == 0){ + res += "<"+type +">\n\n"; + depth++; + } + if(!rows.empty()) { + for (RowView &v: rows) { + res += v.toStringOpen(depth); + depth++; + if (!v.subviews.empty()) { + res += v.toString(depth); + } + res+=v.toStringClose(--depth); + } + } + if(--depth == 0){ + res += " \n\n"; + } + return res; + +} + +std::string CellView::toStringOpen(int depth){ + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "<"+type +"> \n\n"; + return res; +} +std::string CellView::toStringClose(int depth){ + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "\n\n"; + return res; +} + + +void CellView::append(ContainerView &mView){ + subviews.push_back(mView); +} +void CellView::appendRow(RowView &mView){ + rows.push_back(mView); +} + +void CellView::appendRows(std::vector mRows){ + if(rows.size() + mRows.size() <= rowsCount) { + for(RowView& rowView : mRows){ + rows.push_back(rowView); + rowView.setIndex(rows.size()); + } + } +} + +bool CellView::appendInSubview(std::string subviewName, ContainerView& mView){ + +} +void CellView::removeSubview(std::string subviewName){ + +} +void CellView::destroy(){ + +} \ No newline at end of file diff --git a/Sources/Views/Cell/CellView.h b/Sources/Views/Cell/CellView.h new file mode 100644 index 0000000..63af1ab --- /dev/null +++ b/Sources/Views/Cell/CellView.h @@ -0,0 +1,37 @@ +// +// Created by Сергей Петренко on 2019-12-02. +// + +#ifndef CPPROJECT_CELLVIEW_H +#define CPPROJECT_CELLVIEW_H + +#include "Container/ContainerView.h" +#include "Row/RowView.h" + +class CellView: public ContainerView { +public: + int rowsCount;; + int index; + std::vector rows; + + CellView(int mRows); + CellView(int indx,int mRows); + CellView(int indx, std::vector rows); + void setIndex(int indx); + void append(ContainerView &mView); + void appendRow(RowView &mView); + void appendRows(std::vector mRows); + void removeSubview(std::string subviewName); + bool appendInSubview(std::string subviewName, ContainerView& mView); + void destroy(); + + std::string toString(int depth); + std::string toStringOpen(int depth); + std::string toStringClose(int depth); + + + +}; + + +#endif //CPPROJECT_CELLVIEW_H diff --git a/Sources/Views/Container/ContainerView.cpp b/Sources/Views/Container/ContainerView.cpp new file mode 100644 index 0000000..a171c3b --- /dev/null +++ b/Sources/Views/Container/ContainerView.cpp @@ -0,0 +1,24 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#include "ContainerView.h" +// +//ContainerView::ContainerView(string n, string t, string c){ +// name = n; +// type = t; +// _class =c; +//} +// +//std::string ContainerView::getType(){ +// return type; +//} +//std::string ContainerView::getClass(){ +// return _class; +//} +// +// +//std::string ContainerView::getName() { +// return this.name; +//} + diff --git a/Sources/Views/Container/ContainerView.h b/Sources/Views/Container/ContainerView.h new file mode 100644 index 0000000..f0044a0 --- /dev/null +++ b/Sources/Views/Container/ContainerView.h @@ -0,0 +1,177 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#ifndef CPPROJECT_CONTAINERVIEW_H +#define CPPROJECT_CONTAINERVIEW_H +#include +#include +#include +#include +#include "UserData/UserData.h" + + +enum class BClass: uint8_t +{ + CARD_DECK, + CARD_MB4_SHADOW, + CARD_BODY, + CARD_HEADER, + TEXT_NORMAL, + MB4, + LIST_ITEM, + TABLE, + +}; +enum class Type: uint8_t +{ + HTML, + BODY, + IMG, + DIV, + H4, + UL, + LI, + TABLE, + ROW, + CELL, + TITLE, + META, + LINK, + HREF, + INTEGRITY, + CROSSORIGIN, + + + + + + + +}; +inline const char* enumToString(Type t) +{ + switch (t) + { + case Type::HTML : + return "html"; + + case Type::BODY : + return "body"; + case Type::IMG : + return "img"; + + case Type::DIV : + return "div"; + + case Type::H4 : + return "h4"; + + case Type::UL : + return "ul"; + + case Type::LI : + return "li"; + + case Type::TABLE : + return "table"; + + case Type::ROW : + return "th"; + + case Type::CELL : + return "tr"; + + case Type::TITLE : + return "title"; + + case Type::LINK : + return "link"; + + case Type::META : + return "meta"; + + default: + return "[Unknown type]"; + } +} +inline const char* enumToString(BClass b) + +{ + switch (b) + { + case BClass::CARD_DECK : + return "card-deck mb-3 text-center"; + + case BClass::CARD_BODY : + return "card-body"; + + case BClass::CARD_HEADER : + return "card-header"; + + case BClass::CARD_MB4_SHADOW : + return "card mb-4 shadow-sm"; + + case BClass::TEXT_NORMAL : + return "my-0 font-weight-normal"; + + case BClass::MB4 : + return "mb-4"; + + case BClass::LIST_ITEM: + return "list-group-item"; + + case BClass::TABLE : + return "table"; + + default: + return "[Unknown class]"; + } +} + +class ContainerView { +protected: + std::string name; + std::string type; + std::string _class; + +public: + std::vector> subviews; + + + + virtual std::string toString(int depth) = 0; + virtual std::string toStringOpen(int depth) = 0; + virtual std::string toStringClose(int depth) = 0; + + + + virtual void append(ContainerView &mView) = 0; + virtual bool appendInSubview(std::string subviewName, ContainerView& mView) = 0; + virtual void removeSubview(std::string subviewName) = 0; + virtual void destroy() = 0; + + std::string getName(){ + return name; + } + + std::string getType(){ + return type; + } + std::string getClass(){ + return _class; + } + + ContainerView() = default; + + ContainerView(std::string n, Type t, std::string c){ + name = n; + type = enumToString(t); + _class = c; + } + + +}; + + +#endif //CPPROJECT_CONTAINERVIEW_H diff --git a/Sources/Views/ImageView/ImageView.cpp b/Sources/Views/ImageView/ImageView.cpp new file mode 100644 index 0000000..4db7013 --- /dev/null +++ b/Sources/Views/ImageView/ImageView.cpp @@ -0,0 +1,43 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "ImageView.h" + +void ImageView::append(ContainerView &mView){} +bool ImageView::appendInSubview(std::string subviewName, ContainerView& mView){return false;} +void ImageView::removeSubview(std::string subviewName){} +void ImageView::destroy(){} + + +ImageView::ImageView(std::string n, Type t, BClass c, std::string s, int h, int w){ + name = n; + type = enumToString(t); + _class = enumToString(c); + src = s; + height = h; + width = w; +} +std::string ImageView::toStringOpen(int depth) { + std::string res = ""; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "<"+type + + " class=\"" + + _class + + "\" src=\"" + + src +"\"" + + R"( alt="" width=")" + + std::to_string(width) + +"\" height=\"" + + std::to_string(height) + + "\">\n\n"; + return res; +} +std::string ImageView::toStringClose(int depth ) { +return ""; +} +std::string ImageView::toString(int depth) { +return toStringOpen(depth)+toStringClose(depth); +} \ No newline at end of file diff --git a/Sources/Views/ImageView/ImageView.h b/Sources/Views/ImageView/ImageView.h new file mode 100644 index 0000000..00c8722 --- /dev/null +++ b/Sources/Views/ImageView/ImageView.h @@ -0,0 +1,32 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_IMAGEVIEW_H +#define CPPROJECT_IMAGEVIEW_H + + +#include "Container/ContainerView.h" + +class ImageView: public ContainerView{ + + +private: + std::string src; + int height; + int width; + +public: + void append(ContainerView &mView); + bool appendInSubview(std::string subviewName, ContainerView& mView); + void removeSubview(std::string subviewName); + void destroy(); + ImageView() = default; + ImageView(std::string n, Type t, BClass c, std::string s, int h, int w); + std::string toStringOpen(int depth = 0) override; + std::string toStringClose(int depth = 0) override; + std::string toString(int depth = 0) override; +}; + + +#endif //CPPROJECT_IMAGEVIEW_H diff --git a/Sources/Views/PersonView/PersonView.cpp b/Sources/Views/PersonView/PersonView.cpp new file mode 100644 index 0000000..4667aaf --- /dev/null +++ b/Sources/Views/PersonView/PersonView.cpp @@ -0,0 +1,85 @@ +// +// Created by Сергей Петренко on 2019-12-02. +// + +#include "PersonView.h" + +PersonView::PersonView(UserData userData){ +type = enumToString(Type::DIV); +_class = enumToString(BClass::CARD_DECK); +name = "PersonView"; +userImage = new ImageView("userImage", + Type::IMG, + BClass::MB4, + userData.imageUrl, + imageHeight, + imageWidth); +username = new TextView("slug", + Type::H4, + BClass::TEXT_NORMAL, + userData.slug); + +infoTable = new TableView("table", + rowsCount, + cellCount); + + +infoTable->appendCells(std::vector { + + *new CellView(0,std::vector{ + *new RowView(0, + *new TextView( + "fNameView", + Type::H4, + BClass::TEXT_NORMAL, + userData.firstName)) + }), + + *new CellView(1,std::vector{ + *new RowView(0, + *new TextView( + "snameView", + Type::H4, + BClass::TEXT_NORMAL, + userData.secondName)) + }), + + *new CellView(2,std::vector{ + *new RowView(0, + *new TextView( + "ageView", + Type::H4, + BClass::TEXT_NORMAL, + std::to_string(userData.age))) + }) +}); + +makeTemplate(); +} + + +void PersonView::makeTemplate(){ + + append(*new View("Frame", + Type::DIV, BClass::CARD_DECK)); + appendInSubview("Frame", + *new View("Shadow", + Type::DIV, + BClass::CARD_MB4_SHADOW)); + + appendInSubview("Shadow", + *new View("CardHeader", + Type::DIV, + BClass::CARD_HEADER)); + + appendInSubview("CardHeader",*username); + + appendInSubview("Shadow", + *new View("CardBody", + Type::DIV, + BClass::CARD_BODY)); + + appendInSubview("CardBody", *userImage); + appendInSubview("CardBody", *infoTable); + +} \ No newline at end of file diff --git a/Sources/Views/PersonView/PersonView.h b/Sources/Views/PersonView/PersonView.h new file mode 100644 index 0000000..77b578d --- /dev/null +++ b/Sources/Views/PersonView/PersonView.h @@ -0,0 +1,31 @@ +// +// Created by Сергей Петренко on 2019-12-02. +// + +#ifndef CPPROJECT_PERSONVIEW_H +#define CPPROJECT_PERSONVIEW_H + +#include "View/View.h" +#include "ImageView/ImageView.h" +#include "TextView/TextView.h" +#include "TableView/TableView.h" + + +class PersonView: public View { +public: + const int cellCount = 3; + const int rowsCount = 1; + const int imageHeight = 256; + const int imageWidth = 256; + ImageView* userImage; + TextView* username; + TableView* infoTable; + + PersonView(UserData userData); + +private: + void makeTemplate(); +}; + + +#endif //CPPROJECT_PERSONVIEW_H diff --git a/Sources/Views/Row/RowView.cpp b/Sources/Views/Row/RowView.cpp new file mode 100644 index 0000000..b705040 --- /dev/null +++ b/Sources/Views/Row/RowView.cpp @@ -0,0 +1,79 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "RowView.h" + + +RowView::RowView(int indx){ + type = enumToString(Type::ROW); + scope = "scope"; + index = indx; +} +RowView::RowView(int indx, ContainerView& containerView){ + type = enumToString(Type::ROW); + scope = "scope"; + index = indx; + append(containerView); +} +RowView::RowView( ContainerView& containerView){ +type = enumToString(Type::ROW); +scope = "scope"; +append(containerView); +} + +void RowView::setIndex(int indx){ + index = indx; +} + +std::string RowView::toString(int depth) { +std::string res; +if(depth == 0){ +res += "<"+getType() + " scope=\""+ scope+"\">\n\n"; +depth++; +} +if(!subviews.empty()) { +for (ContainerView &v: subviews) { +res += v.toStringOpen(depth); +depth++; +if (!v.subviews.empty()) { +res += v.toString(depth); +} +res+=v.toStringClose(--depth); +} +} +if(--depth == 0){ +res+="\n\n"; +} +return res; +} + +std::string RowView::toStringOpen(int depth){ + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "<"+type + " scope=\""+ scope+"\">\n\n"; + return res; +} +std::string RowView::toStringClose(int depth){ + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "\n\n"; + return res; +} + +void RowView::append(ContainerView &mView){ + subviews.push_back(mView); +} +bool RowView::appendInSubview(std::string subviewName, ContainerView& mView){ + +} +void RowView::removeSubview(std::string subviewName){ + +} +void RowView::destroy(){ + +} \ No newline at end of file diff --git a/Sources/Views/Row/RowView.h b/Sources/Views/Row/RowView.h new file mode 100644 index 0000000..91feeb3 --- /dev/null +++ b/Sources/Views/Row/RowView.h @@ -0,0 +1,30 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_ROWVIEW_H +#define CPPROJECT_ROWVIEW_H + + +#include "Container/ContainerView.h" + +class RowView: public ContainerView{ +public: + int index; + std::string scope; + RowView(int indx); + RowView(int indx, ContainerView& containerView); + RowView( ContainerView& containerView); + void setIndex(int indx); + std::string toString(int depth = 0) override; + std::string toStringOpen(int depth); + std::string toStringClose(int depth); + void append(ContainerView &mView); + bool appendInSubview(std::string subviewName, ContainerView& mView); + void removeSubview(std::string subviewName); + void destroy(); +}; + + + +#endif //CPPROJECT_ROWVIEW_H diff --git a/Sources/Views/SecondaryView/SecondaryView.cpp b/Sources/Views/SecondaryView/SecondaryView.cpp new file mode 100644 index 0000000..b3b1889 --- /dev/null +++ b/Sources/Views/SecondaryView/SecondaryView.cpp @@ -0,0 +1,44 @@ +// +// Created by Сергей Петренко on 2019-12-04. +// + +#include "SecondaryView.h" + +SecondaryView::SecondaryView(std::string name, Type t, std::vector attr){ + attributes = attr; + type = enumToString(t); +} + +std::string SecondaryView::toStringOpen(int depth){ + std::string res; + res+="<"+type+" "; + for(int i = 0; i < attributes.size();i++){ + res+=attributes[i].key + "=\"" + attributes[i].value+"\" "; + } + return res; +} + +std::string SecondaryView::toStringClose(int depth) { + return ">\n"; +} + +std::string SecondaryView::toString(int depth) { + return toStringOpen(depth)+toStringClose(depth); +} + + +bool SecondaryView::appendInSubview(std::string subviewName, ContainerView& mView) { + return false; +} + +void SecondaryView::append(ContainerView &mView){ + +} + +void SecondaryView::destroy() { + +} + +void SecondaryView::removeSubview(std::string subviewName) { + +} \ No newline at end of file diff --git a/Sources/Views/SecondaryView/SecondaryView.h b/Sources/Views/SecondaryView/SecondaryView.h new file mode 100644 index 0000000..e350e51 --- /dev/null +++ b/Sources/Views/SecondaryView/SecondaryView.h @@ -0,0 +1,41 @@ +// +// Created by Сергей Петренко on 2019-12-04. +// + +#ifndef CPPROJECT_SECONDARYVIEW_H +#define CPPROJECT_SECONDARYVIEW_H +#include "View/View.h" +#include "Container/ContainerView.h" +class Attribute{ +public: + std::string key; + std::string value; + Attribute(std::string k, std::string v){ + key = k; + value = v; + } +}; +class SecondaryView: public ContainerView { +public: + std::vector attributes; + SecondaryView(std::string name, Type t, std::vector attr); + + std::string toStringOpen(int depth = 0) override; + + std::string toStringClose(int depth = 0) override; + + std::string toString(int depth = 0) override; + + + bool appendInSubview(std::string subviewName, ContainerView& mView) override; + + void append(ContainerView &mView) override; + + void destroy() override; + + void removeSubview(std::string subviewName) override; + +}; + + +#endif //CPPROJECT_SECONDARYVIEW_H diff --git a/Sources/Views/TableView/TableView.cpp b/Sources/Views/TableView/TableView.cpp new file mode 100644 index 0000000..4bbf23d --- /dev/null +++ b/Sources/Views/TableView/TableView.cpp @@ -0,0 +1,111 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "TableView.h" + +TableView::TableView(std::string mName,int mRows, int mCells){ + type = enumToString(Type::TABLE); + _class = enumToString(BClass::TABLE); + name = mName; + rowsCount = mRows; + cellsCount = mCells; + append(*new View("tablediv",Type::DIV, BClass::CARD_DECK)); +} + + +std::string TableView::toString(int depth){ + std::string res; + if(depth == 0){ + res += "<"+type + " class=\""+ _class+"\"> \n\n"; + depth++; + } + if(!cells.empty()) { + for (CellView &v: cells) { + res += v.toStringOpen(depth); + depth++; + if (!v.rows.empty()) { + res += v.toString(depth); + } + res+=v.toStringClose(--depth); + } + } + if(--depth == 0){ + res += " \n\n"; + } + return res; + +} + +std::string TableView::toStringOpen(int depth){ + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "<"+type + " class=\""+ _class+"\"> \n\n"; + return res; +} +std::string TableView::toStringClose(int depth){ + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += " \n\n"; + return res; +} + + + +void TableView::append(ContainerView &mView){ + subviews.push_back(mView); +} +void TableView::appendCell(CellView &mView){ + + if(cells.size() < cellsCount) { + + cells.push_back(mView); + mView.setIndex(cells.size()); + } +} +void TableView::appendCells(std::vector mViews){ + + if(cells.size() + mViews.size() <= cellsCount) { + for(CellView& cellView : mViews){ + cells.push_back(cellView); + cellView.setIndex(cells.size()); + } + } +} +bool TableView::appendInSubview(std::string subviewName, ContainerView& mView){ + +} + +bool TableView::appendRowInCell(int cellIndex, RowView& mView){ + if(cellIndex <= cellsCount && cells.size() + 1 <= cellsCount){ + if(cells[cellIndex].rows.size() + 1 <= rowsCount){ + cells[cellIndex].rows.emplace_back(mView); + return true; + } + + } + return false; +} + +bool TableView::appendRowsInCell(int cellIndex, std::vector mViews){ + if(cellIndex <= cellsCount && cells.size() < cellsCount){ + if(cells[cellIndex].rows.size() + mViews.size() < cellsCount){ + for(RowView &rowView: mViews){ + cells[cellIndex].appendRow(rowView); + rowView.setIndex(cells[cellIndex].rows.size()); + } + } + } + return false; +} + +void TableView::removeSubview(std::string subviewName) { + +} +void TableView::destroy(){ + +} diff --git a/Sources/Views/TableView/TableView.h b/Sources/Views/TableView/TableView.h new file mode 100644 index 0000000..e27070b --- /dev/null +++ b/Sources/Views/TableView/TableView.h @@ -0,0 +1,37 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_TABLEVIEW_H +#define CPPROJECT_TABLEVIEW_H + +#include +#include "Container/ContainerView.h" +#include "Row/RowView.h" +#include "Cell/CellView.h" +#include "View/View.h" + +class TableView: public ContainerView{ +public: + int rowsCount; + int cellsCount; + std::string name; + std::vector cells; + + TableView(std::string mName,int mRows, int mCells); + std::string toString(int depth); + std::string toStringOpen(int depth); + std::string toStringClose(int depth); + void append(ContainerView &mView); + void appendCell(CellView &mView); + void appendCells(std::vector mViews); + bool appendInSubview(std::string subviewName, ContainerView& mView) override ; + bool appendRowInCell(int cellIndex, RowView& mView); + bool appendRowsInCell(int cellIndex, std::vector mViews); + void removeSubview(std::string subviewName) override; + void destroy() override; + +}; + + +#endif //CPPROJECT_TABLEVIEW_H diff --git a/Sources/Views/TextView/TextView.cpp b/Sources/Views/TextView/TextView.cpp new file mode 100644 index 0000000..2cb6b0b --- /dev/null +++ b/Sources/Views/TextView/TextView.cpp @@ -0,0 +1,58 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#include "TextView.h" + +void TextView::append(ContainerView &mView){ + +} +bool TextView::appendInSubview(std::string subviewName, ContainerView& mView){ + +} +void TextView::removeSubview(std::string subviewName){ + +} +void TextView::destroy(){ + +} + + +TextView::TextView(std::string n, Type t, BClass c, std::string txt){ +name = n; +type = enumToString(t); +_class = enumToString(c); +text = txt; +}; +TextView::TextView(std::string n, Type t, std::string txt){ +name = n; +type = enumToString(t); +_class = ""; +text = txt; +}; + +void TextView::setText(std::string mText){ + text = mText; +} + +std::string TextView::getText(){ + return text; +} + +std::string TextView::toStringOpen(int depth) { +std::string res; +for(int i=0;i<3*depth;i++){ +res+=" "; +} +res += "<"+type + " class=\""+ _class+"\">"+text; +return res; +} +std::string TextView::toStringClose(int depth) { +std::string res; +res += "\n\n"; +return res; +} +std::string TextView::toString(int depth) { + +return toStringOpen(depth)+toStringClose(depth); +} \ No newline at end of file diff --git a/Sources/Views/TextView/TextView.h b/Sources/Views/TextView/TextView.h new file mode 100644 index 0000000..629b457 --- /dev/null +++ b/Sources/Views/TextView/TextView.h @@ -0,0 +1,30 @@ +// +// Created by Сергей Петренко on 2019-11-16. +// + +#ifndef CPPROJECT_TEXTVIEW_H +#define CPPROJECT_TEXTVIEW_H + +#include "Container/ContainerView.h" + +class TextView: public ContainerView{ +private: + std::string text; + +public: + void append(ContainerView &mView); + bool appendInSubview(std::string subviewName, ContainerView& mView); + void removeSubview(std::string subviewName); + void destroy(); + TextView(std::string n, Type t, BClass c, std::string txt); + TextView(std::string n, Type t, std::string txt); + void setText(std::string mText); + std::string getText(); + std::string toStringOpen(int depth = 0) override; + std::string toStringClose(int depth = 0) override; + std::string toString(int depth = 0) override; + +}; + + +#endif //CPPROJECT_TEXTVIEW_H diff --git a/Sources/Views/UserData/UserData.cpp b/Sources/Views/UserData/UserData.cpp new file mode 100644 index 0000000..8f8f4c1 --- /dev/null +++ b/Sources/Views/UserData/UserData.cpp @@ -0,0 +1,12 @@ +// +// Created by Сергей Петренко on 2019-12-05. +// + +#include "UserData.h" +UserData::UserData(std::string slg, std::string fn, std::string sn, std::string img, int a){ +slug = slg; +firstName = fn; +secondName = sn; +age = a; +imageUrl = img; +} \ No newline at end of file diff --git a/Sources/Views/UserData/UserData.h b/Sources/Views/UserData/UserData.h new file mode 100644 index 0000000..9effc6f --- /dev/null +++ b/Sources/Views/UserData/UserData.h @@ -0,0 +1,21 @@ +// +// Created by Сергей Петренко on 2019-12-05. +// + +#ifndef CPPROJECT_USERDATA_H +#define CPPROJECT_USERDATA_H + +#include + +class UserData{ +public: + std::string slug; + std::string firstName; + std::string secondName; + std::string imageUrl; + int age; + UserData(std::string slg, std::string fn, std::string sn, std::string img, int a); +}; + + +#endif //CPPROJECT_USERDATA_H diff --git a/Sources/Views/View/View.cpp b/Sources/Views/View/View.cpp new file mode 100644 index 0000000..1e9f903 --- /dev/null +++ b/Sources/Views/View/View.cpp @@ -0,0 +1,116 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#include "View.h" + + + +View::View(std::string n, Type t, BClass c){ +name = n; +type = enumToString(t); +_class = enumToString(c); +} +View::View(std::string n, Type t){ +name = n; +type = enumToString(t); +_class = ""; +} + + + +std::string View::toStringOpen(int depth ) { +std::string res; +for(int i=0;i<3*depth;i++){ +res+=" "; +} +res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; +return res; +} + +std::string View::toStringClose(int depth ) { +std::string res; +for(int i=0;i<3*depth;i++){ +res+=" "; +} +res+="\n\n"; +return res; +} + +std::string View::toString(int depth ) { +std::string res; +if(depth == 0){ +res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; +depth++; +} +if(!subviews.empty()) { +for (ContainerView &v: subviews) { +res += v.toStringOpen(depth); +depth++; +if (!v.subviews.empty()) { +res += v.toString(depth); +} +res+=v.toStringClose(--depth); + +} + +} +if(--depth == 0){ +res+="\n\n"; +} +return res; +} + + +bool View::appendInSubview(std::string subviewName, ContainerView& mView) { + for(ContainerView& v : subviews){ + if(std::strcmp(subviewName.data(), v.getName().data()) == 0){ + v.append(mView); + return true; + } + if(!v.subviews.empty()){ + v.appendInSubview(subviewName, mView); + } + } + return false; +} + +void View::append(ContainerView &mView){ + subviews.emplace_back(mView); +} + +void View::destroy() { + int i = 0; + for(ContainerView &v: subviews){ + if(!v.subviews.empty()){ + v.destroy(); + } + subviews.clear(); + i++; + } +} + +void View::removeSubview(std::string subviewName){ + int i = 0; + for(ContainerView &v : subviews){ + auto it = std::find_if(v.subviews.begin(), v.subviews.end(), + [&](ContainerView &v) { + return std::strcmp(v.getName().data(),subviewName.data()); + }); + if(it == v.subviews.end()){ + v.subviews[i].get().destroy(); + v.subviews.erase( v.subviews.begin() + i); + } + + if(std::strcmp(subviewName.data(), v.getName().data()) == 0){ + v.destroy(); + } + if(!v.subviews.empty()){ + v.removeSubview(subviewName); + } + i++; + } +} + + + diff --git a/Sources/Views/View/View.h b/Sources/Views/View/View.h new file mode 100644 index 0000000..fab9592 --- /dev/null +++ b/Sources/Views/View/View.h @@ -0,0 +1,33 @@ +// +// Created by Сергей Петренко on 2019-11-07. +// + +#ifndef CPPROJECT_VIEW_H +#define CPPROJECT_VIEW_H +#include "Container/ContainerView.h" + + + +class View: public ContainerView{ +public: + View()= default; + View(std::string n, Type t, BClass c); + View(std::string n, Type t); + + std::string toStringOpen(int depth = 0) override; + + std::string toStringClose(int depth = 0) override; + + std::string toString(int depth = 0) override; + + + bool appendInSubview(std::string subviewName, ContainerView& mView) override; + + void append(ContainerView &mView) override; + + void removeSubview(std::string subviewName) override; + void destroy () override; + +}; + +#endif //CPPROJECT_VIEW_H diff --git a/Sources/main.cpp b/Sources/main.cpp new file mode 100644 index 0000000..d5c8153 --- /dev/null +++ b/Sources/main.cpp @@ -0,0 +1,40 @@ +#include +#include +#include "Views/PersonView/PersonView.h" +#include "Views/Cell/CellView.h" +#include "Views/TableView/TableView.h" +#include "PageGenerator/PageGenerator.h" + + + +using namespace std; + + +int main(){ + + + + std::vector userDataVec { + new UserData("1Stalin.su","Дмитрий", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), + new UserData("2Kek","Дмитрий", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), + new UserData("3Averkiller","Александр", "Аверкиев","https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Anonymous.svg/866px-Anonymous.svg.png",69 ), + + new UserData("4Stalin.su","Дмитрий2", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), + new UserData("5Kek","Дмитрий2", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), + new UserData("6Averkiller","Александр2", "Аверкиев","https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Anonymous.svg/866px-Anonymous.svg.png",69 ), + + new UserData("7Stalin.su","Дмитрий3", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), + new UserData("8Kek","Дмитрий3", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), + + + + }; + + PageGenerator* pageGenerator = new PageGenerator(); + pageGenerator->generatePage( *new PageData(userDataVec, PageType::TABLE_OF_USERS, Organize::ONE_LINE_VERTICAL)); + std::cout<page->toString(); + + + + return 0; +} \ No newline at end of file diff --git a/View.cpp b/View.cpp deleted file mode 100644 index 86eece1..0000000 --- a/View.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-07. -// - -#include "View.h" - -void View::append_in_subview(View m_view, string sv_path) { - -} - - - -View::View() { - -} - -View::View(string m_view_template) { - -} - -View View::get_subview_by_name(View m_view, string name) { - return View(); -} - -string View::to_string(StringProperty property) { - return std::string(); -} - -void View::set_name(string m_name) { - -} - -void View::set_view_template(string m_view_template) { - -} - -string View::get_view_template() { - return std::string(); -} - -string View::get_name() { - return std::string(); -} - -void View::remove_subview(View m_view, string sv_path) { - -} - -ImageView::ImageView() { - -} - -ImageView::ImageView(string m_image_path) : View(m_image_path) { - -} - -void ImageView::set_image_path(string m_image_path) { - -} - -string ImageView::get_image_path() { - return std::string(); -} - -StringProperty::StringProperty() { - -} - -TextView::TextView() { - -} - -TextView::TextView(string m_text) : View(m_text) { - -} - -void TextView::set_text(string m_text) { - -} - -string TextView::get_text() { - return std::string(); -} - -Button::Button() { - -} - -Button::Button(string path, string text) { - -} - -RowView::RowView() { - -} - -ColumnView::ColumnView() { - -} - -ColumnView::ColumnView(int rows_count) { - -} - -TableView::TableView() { - -} - -TableView::TableView(int rows, int columns) { - -} - -void TableView::append_in_row(View m_view, string path) { - -} - -int TableView::get_row_count() { - return 0; -} - -int TableView::get_colums_count() { - return 0; -} - -void TableView::remove_column(View m_view, string path) { - -} -void TableView::remove_row(View m_view, string path) { - -} \ No newline at end of file diff --git a/View.h b/View.h deleted file mode 100644 index 49a5269..0000000 --- a/View.h +++ /dev/null @@ -1,105 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-07. -// - -#ifndef CPPROJECT_VIEW_H -#define CPPROJECT_VIEW_H - - -#include "ContainerView.h" -#include -#include -#include -#include -using std::vector; -using std::string; -using std::map; - -class StringProperty{ -public: - bool is_new_line; - bool is_tag_close; - int indent; - StringProperty(); -}; - -class View: public ContainerView{ -protected: - string name; - string type; - string view_template; - vector subviews; - -public: - View(); - View(string m_view_template); - View get_subview_by_name(View m_view, string name); - - string to_string(StringProperty property); - void set_name(string m_name); - void set_view_template(string m_view_template); - void append_in_subview(View m_view,string sv_path); - void remove_subview(View m_view,string sv_path); - string get_view_template(); - string get_name(); -}; - -class ImageView: public View{ -private: - string image_path; -public: - ImageView(); - ImageView(string m_image_path); - void set_image_path(string m_image_path); - string get_image_path(); - -}; - -class TextView: public View{ -private: - string text; -public: - TextView(); - TextView(string m_text); - void set_text(string m_text); - string get_text(); - -}; - -class Button: public TextView, public ImageView{ -public: - Button(); - Button(string path,string text); -}; - -class RowView: protected View{ -public: - RowView(); -}; - -class ColumnView: public View{ -protected: - vector rows; -public: - ColumnView(); - ColumnView(int rows_count); -}; - -class TableView: public View{ -private: - int rows_count; - int columns_count; -protected: - vector rows; -public: - TableView(); - TableView(int rows, int columns); - void append_in_row(View m_row, string path); - void remove_column(View m_column, string path); - void remove_row(View m_row, string path); - int get_row_count(); - int get_colums_count(); - -}; - -#endif //CPPROJECT_VIEW_H diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 1cb17f6..0000000 --- a/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - - return 0; -} \ No newline at end of file From 1c3ae2bc18f8df109409eaf7dda04e2e14c71b8d Mon Sep 17 00:00:00 2001 From: SPetrenko17 Date: Sat, 7 Dec 2019 15:36:29 +0300 Subject: [PATCH 4/5] RK3 Commit --- .DS_Store | Bin 6148 -> 6148 bytes CMakeLists.txt | 2 - Google_tests/page_tests.cpp | 91 ------ Google_tests/view_tests.cpp | 258 +++++------------- README.md | 2 - Sources/PageData/PageData.h | 8 +- Sources/PageGenerator/PageGenerator.cpp | 28 +- Sources/PageGenerator/PageGenerator.h | 6 +- Sources/PageManager/PageManager.h | 58 +++- Sources/Views/Button/Button.cpp | 6 - Sources/Views/Button/Button.h | 12 - Sources/Views/Cell/CellView.cpp | 33 ++- Sources/Views/Cell/CellView.h | 27 +- Sources/Views/Container/ContainerView.cpp | 35 ++- Sources/Views/Container/ContainerView.h | 26 +- Sources/Views/ImageView/ImageView.cpp | 40 +-- Sources/Views/ImageView/ImageView.h | 17 +- Sources/Views/PersonView/PersonView.cpp | 49 ++-- Sources/Views/PersonView/PersonView.h | 3 +- Sources/Views/Row/RowView.cpp | 57 +--- Sources/Views/Row/RowView.h | 20 +- Sources/Views/SecondaryView/SecondaryView.cpp | 10 +- Sources/Views/SecondaryView/SecondaryView.h | 17 +- Sources/Views/TableView/TableView.cpp | 47 ++-- Sources/Views/TableView/TableView.h | 26 +- Sources/Views/TextView/TextView.cpp | 51 ++-- Sources/Views/TextView/TextView.h | 15 +- Sources/Views/UserData/UserData.cpp | 10 +- Sources/Views/View/View.cpp | 87 +++--- Sources/Views/View/View.h | 9 +- Sources/main.cpp | 13 +- 31 files changed, 410 insertions(+), 653 deletions(-) delete mode 100644 Google_tests/page_tests.cpp delete mode 100644 README.md delete mode 100644 Sources/Views/Button/Button.cpp delete mode 100644 Sources/Views/Button/Button.h diff --git a/.DS_Store b/.DS_Store index 8d58a1a26baff785a7b5e921fe1755bff6673161..39385de241e11bb93352bf26b5fabeb8b29ffc1c 100644 GIT binary patch delta 70 zcmV-M0J;B!FoZCWPXPz9P`d*G2a^m0FO$6m5R*#;CzCn^DwCW9|C7xH9sw7Vz6BnW c3I>k|F*i3XAT2X6v!MoN0g-?*vj+(M59>!28UO$Q delta 91 zcmZoMXfc@J&&aVcU^g=($7CKB{mI2Fnv++t%1`!Yk(@k-<-af|LlA>2gCm0rgD;TQ uW5{JlnXJPiKlvmpKTsV%W9#HytZO;UOiXnYbWJTc=d-0TZf58B%MSo)ml%iu diff --git a/CMakeLists.txt b/CMakeLists.txt index 38ad8e6..2413a06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,6 @@ set(ALL_SOURCES ${CMAKE_MODULE_PATH}/Views/SecondaryView/SecondaryView.cpp ${CMAKE_MODULE_PATH}/Views/UserData/UserData.cpp ${CMAKE_MODULE_PATH}/Views/Container/ContainerView.cpp - ${CMAKE_MODULE_PATH}/Views/Button/Button.cpp ${CMAKE_MODULE_PATH}/Views/Cell/CellView.cpp ${CMAKE_MODULE_PATH}/Views/Row/RowView.cpp ${CMAKE_MODULE_PATH}/Views/ImageView/ImageView.cpp @@ -37,7 +36,6 @@ set(ALL_SOURCES set(ALL_VIEWS_HEADERS ${CMAKE_MODULE_PATH}/Views/UserData/ ${CMAKE_MODULE_PATH}/Views/Container/ - ${CMAKE_MODULE_PATH}/Views/Button/ ${CMAKE_MODULE_PATH}/Views/Cell/ ${CMAKE_MODULE_PATH}/Views/Row/ ${CMAKE_MODULE_PATH}/Views/ImageView/ diff --git a/Google_tests/page_tests.cpp b/Google_tests/page_tests.cpp deleted file mode 100644 index 8ef1b73..0000000 --- a/Google_tests/page_tests.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-08. -// -#include -#include "gtest/gtest.h" -#include "UserData/UserData.h" -#include -#include -#include "View/View.h" -#include "Page.h" - -class TestPage : public ::testing::Test -{ -public: - PageGenerator* pageGenerator; - //UserData* userData1 = new UserData("SLUG1","fname", "sname","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ); - //UserData* userData2 = new UserData("SLUG2","fname", "sname","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ); - //std::vector userData { - //PageData* pageData = new PageData(userData,PageType::TABLE_OF_USERS, Organize::ONE_LINE_VERTICAL); - std::string res; -protected: - void SetUp() override - { - pageGenerator = new PageGenerator(); - - //res = pageGenerator->generatePage()->toString(); - - } - void TearDown() override - { - delete pageGenerator; - } - -}; -TEST_F(TestPage, testTableCorrectOneLineVertical){ - - ASSERT_STREQ("hi","hi"); -} - -// -//class TestPageViews : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// stringProperty = new StringProperty(); -// view = new View(); -// -// } -// View *view; -// StringProperty *stringProperty; -//}; -// -// -// -//class TestPageGenerator : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// page_generator = new PageGenerator(); -// page_data = new PageData(); -// } -// PageGenerator *page_generator; -// PageData *page_data; -// -//}; -// -//TEST_F(TestPageGenerator, test_generate_result_page) -//{ -// auto generated_page = page_generator->generate_result_page(*page_data); -// ASSERT_EQ(generated_page.to_string(), "my_generated_page"); -//} -// -// -//class TestPageManager : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// page_manager = new PageManager(); -// } -// void TearDown() override -// { -// delete page_manager; -// -// } -// PageManager *page_manager; -//}; - - diff --git a/Google_tests/view_tests.cpp b/Google_tests/view_tests.cpp index a77ff1c..3c83787 100644 --- a/Google_tests/view_tests.cpp +++ b/Google_tests/view_tests.cpp @@ -1,205 +1,73 @@ // // Created by Сергей Петренко on 2019-11-08. // +#include +#include +#include #include "gtest/gtest.h" #include "Container/ContainerView.h" #include "View/View.h" -//class TestViews : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// string_property = new StringProperty(); -// view = new View(); -// -// } -// void TearDown() override -// { -// delete string_property; -// delete view; -// } -// View *view; -// StringProperty *string_property; -//}; -// -//TEST_F(TestViews, test_set_get_template) -//{ -// view->set_view_template("p"); -// ASSERT_EQ(view->get_view_template(), "p"); -//} -// -//TEST_F(TestViews, test_set_get_name) -//{ -// view->set_name("string_view"); -// ASSERT_EQ(view->get_view_template(), "string_view"); -//} -// -//TEST_F(TestViews, test_to_string) -//{ -// view->set_view_template("

*name=*

"); -// view->set_name("string_view"); -// ASSERT_EQ(view->to_string(*string_property), -// "

name=sting_view

"); -//} -// -//TEST_F(TestViews, test_add_subview) -//{ -// view->set_view_template("

*name=*

"); -// view->set_name("string_view"); -// View *subview = new View(); -// subview->set_view_template("

*name=*

"); -// subview->set_name("substring_view"); -// view->append_in_subview(*subview,view->get_path()); -// -// ASSERT_EQ(view->to_string(*string_property), -// "

name=sting_view

name=substring_view

"); -//} -//TEST_F(TestViews, test_remove_subview) -//{ -// view->set_view_template("

*name=*

"); -// view->set_name("string_view"); -// View *subview = new View(); -// subview->set_view_template("

*name=*

"); -// subview->set_name("substring_view"); -// view->append_in_subview(*subview,view->get_path()); -// view->remove_subview(*view,subview->get_path()); -// ASSERT_EQ(view->to_string(*string_property), -// "

name=sting_view

"); -//} -//TEST_F(TestViews, test_remove_subview_by_name) -//{ -// view->set_view_template("

*name=*

"); -// view->set_name("string_view"); -// View *subview = new View(); -// subview->set_view_template("

*name=*

"); -// subview->set_name("substring_view"); -// view->append_in_subview(*subview,view->get_path()); -// view->remove_subview(*view, -// view->get_subview_by_name(*view,"subsring_view").get_path()); -// ASSERT_EQ(view->to_string(*string_property), -// "

name=sting_view

"); -//} -// -// -//class TestTextViews : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// string_property = new StringProperty(); -// tv = new TextView(); -// -// } -// void TearDown() override -// { -// delete string_property; -// delete tv; -// } -// TextView *tv; -// StringProperty *string_property; -//}; -//TEST_F(TestTextViews, test_to_string) -//{ -// tv->set_view_template("

*name=**text*

"); -// tv->set_name("text_view"); -// tv->set_text("sample_text"); -// ASSERT_EQ(tv->to_string(*string_property), "

name=sting_view sample_text

"); -//} -// -//class TestImageViews : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// string_property = new StringProperty(); -// iv = new ImageView(); -// -// } -// void TearDown() override -// { -// delete string_property; -// delete iv; -// } -// ImageView *iv; -// StringProperty *string_property; -//}; -//TEST_F(TestImageViews, test_to_string) -//{ -// iv->set_view_template("

*name=**img=*

"); -// iv->set_name("text_view"); -// iv->set_image_path("image_path"); -// ASSERT_EQ(iv->to_string(*string_property), "

name=sting_view sample_text

"); -//} -// -//class TestButtons : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// string_property = new StringProperty(); -// button = new Button(); -// -// } -// void TearDown() override -// { -// delete string_property; -// delete button; -// } -// Button* button; -// StringProperty *string_property; -//}; -// -// -//class TestTableViews : public ::testing::Test -//{ -//protected: -// void SetUp() override -// { -// string_property = new StringProperty(); -// tableView = new TableView(2,2); -// columnView = new ColumnView(tableView->get_row_count()); -// rowView = new RowView(); -// } -// void TearDown() override -// { -// delete string_property; -// delete rowView; -// delete columnView; -// delete tableView; -// } -// RowView *rowView; -// ColumnView *columnView; -// TableView *tableView; -// StringProperty *string_property; -//}; -// -//TEST_F(TestTableViews, test_append) -//{ -// tableView->set_view_template("table_view_template"); -// tableView->set_name("table_view_name"); -// tableView->append_in_row(View(),"container/table/row"); -// ASSERT_EQ( tableView->to_string(*string_property), -// "template_for_tableview_with_params_and_new_row"); -//} -//TEST_F(TestTableViews, test_delete) -//{ -// tableView->set_view_template("table_view_template"); -// tableView->set_name("table_view_name"); -// tableView->remove_row(View(),"container/table/row"); -// tableView->remove_column(View(),"container/table/row"); -// ASSERT_EQ( tableView->to_string(*string_property), -// "template_for_tableview_with_deleted_rows_and_columns"); -//} -// -//TEST_F(TestTableViews, test_index_for_columns) -//{ -// tableView->set_view_template("table_view_template"); -// tableView->set_name("table_view_name"); -// tableView->remove_row(View(),"container/table/row"); -// tableView->remove_column(View(),"container/table/column"); -// ASSERT_THROW(tableView->remove_row(View(),"container/table/row"), std::out_of_range); -//} +class TestViews : public ::testing::Test +{ +protected: + void SetUp() override + { + + view = new View("view", Type::DIV, BClass::CARD_DECK); + + } + void TearDown() override + { + delete view; + } + View *view; +}; + +TEST_F(TestViews, test_view_vonstructor) +{ + EXPECT_EQ(view->toString(),"
\n\n
\n\n"); +} + +TEST_F(TestViews, test_append_in_view) +{ + view->append(*new View("test",Type::DIV,BClass::CARD_MB4_SHADOW)); + + EXPECT_EQ(view->toString(),"
\n\n
\n\n
\n\n
\n\n"); +} + +TEST_F(TestViews, test_append_and_delete) +{ + view->append(*new View("test",Type::DIV,BClass::CARD_MB4_SHADOW)); + view->removeSubview("test"); + EXPECT_EQ(view->toString(),"
\n\n
\n\n"); +} + +TEST_F(TestViews, test_append_in_subview) +{ + view->append(*new View("test",Type::DIV,BClass::CARD_MB4_SHADOW)); + view->appendInSubview("test",*new View("testInSubview",Type::DIV,BClass::CARD_MB4_SHADOW)); + + EXPECT_EQ(view->toString(),"
\n\n" + "
\n\n" + "
\n\n " + "
\n\n
\n\n
\n\n"); +} + +TEST_F(TestViews, test_append_in_subview_and_delete) +{ + view->append(*new View("test",Type::DIV,BClass::CARD_MB4_SHADOW)); + view->removeSubview("testInSubview"); + EXPECT_EQ(view->toString(),"
\n\n
\n\n"); +} + + +TEST_F(TestViews, test_add_subview) +{ + view->append(*new View("test",Type::DIV,BClass::CARD_MB4_SHADOW)); + view->removeSubview("test"); + EXPECT_EQ(view->toString(),"
\n\n
\n\n"); +} diff --git a/README.md b/README.md deleted file mode 100644 index 7306ffd..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# FindFace -findface diff --git a/Sources/PageData/PageData.h b/Sources/PageData/PageData.h index 7418294..9bc3e94 100644 --- a/Sources/PageData/PageData.h +++ b/Sources/PageData/PageData.h @@ -32,8 +32,12 @@ class PageData { PageData(std::vector u, PageType t, Organize o); void setOrganizeType(Organize o); void setPageType(PageType o); - PageType getpageType(){ return type;} - Organize getpageOrganizeType(){ return organize;} + PageType getpageType(){ + return type; + } + Organize getPageOrganizeType(){ + return organize; + } private: Organize organize; PageType type; diff --git a/Sources/PageGenerator/PageGenerator.cpp b/Sources/PageGenerator/PageGenerator.cpp index 3737f90..50ab170 100644 --- a/Sources/PageGenerator/PageGenerator.cpp +++ b/Sources/PageGenerator/PageGenerator.cpp @@ -3,6 +3,7 @@ // #include "PageGenerator.h" + void PageGenerator::organizeCells(Organize o, int& rows, int& cells, int count){ switch(o){ case Organize::ONE_LINE_VERTICAL: @@ -20,6 +21,7 @@ void PageGenerator::organizeCells(Organize o, int& rows, int& cells, int count){ break; } } + Page* PageGenerator::generateTablePage(std::vector userData, Organize o){ page = new Page(); std::vector persons; @@ -36,13 +38,13 @@ Page* PageGenerator::generateTablePage(std::vector userData, Organize TableView* tableView = new TableView("Table",rowsCount,cellsCount); int r = 0; int c = 0; - tableView->appendCell(*new CellView(c,rowsCount)); + tableView->appendCell(std::make_shared(*new CellView(c,rowsCount))); for(auto &p: persons){ - tableView->appendRowInCell(c,*new RowView(r, *p)); + tableView->appendRowInCell(c,std::make_shared(*new RowView(r, *p))); r++; if(r >= rowsCount){ r = 0; - tableView->appendCell(*new CellView(++c,rowsCount)); + tableView->appendCell(std::make_shared(*new CellView(++c,rowsCount))); } } page->appendInBody(*tableView); @@ -52,21 +54,9 @@ Page* PageGenerator::generateStartPage(){ } -Page* PageGenerator::generateUserPage(std::vector userData){ - +Page* PageGenerator::generateUserPage(UserData userData){ + Page *page = new Page(); + page->appendInBody(*new TextView("test", Type::H4, BClass::TEXT_NORMAL, "hello world")); + return page; } -Page* PageGenerator::generatePage(PageData &pageData){ - switch(pageData.getpageType()){ - case PageType::TABLE_OF_USERS : - page = generateTablePage(pageData.userData, pageData.getpageOrganizeType()); - break; - case PageType::ONE_USER_PAGE : - page = generateUserPage(pageData.userData); - break; - case PageType::START_PAGE : - page = generateStartPage(); - break; - } - return page; -} \ No newline at end of file diff --git a/Sources/PageGenerator/PageGenerator.h b/Sources/PageGenerator/PageGenerator.h index adfb89d..88df016 100644 --- a/Sources/PageGenerator/PageGenerator.h +++ b/Sources/PageGenerator/PageGenerator.h @@ -17,14 +17,16 @@ class PageGenerator{ Page* page; PageGenerator() = default; + void organizeCells(Organize o, int& rows, int& cells, int count); + Page* generateTablePage(std::vector userData, Organize o); Page* generateStartPage(); - Page* generateUserPage(std::vector userData); + Page* generateUserPage(UserData userData); + - Page* generatePage(PageData &pageData); }; diff --git a/Sources/PageManager/PageManager.h b/Sources/PageManager/PageManager.h index 0fe9adf..43a5b2f 100644 --- a/Sources/PageManager/PageManager.h +++ b/Sources/PageManager/PageManager.h @@ -5,16 +5,62 @@ #ifndef CPPROJECT_PAGEMANAGER_H #define CPPROJECT_PAGEMANAGER_H -#include "PageGenerator/PageGenerator.h" - +#include +#include +#include +#include class PageManager{ private: - PageData data; - PageGenerator pageGenerator; + PageData* data; + PageGenerator* pageGenerator; public: - PageManager(); - PageManager(PageData m_data); + PageManager(PageData* mData){ + data = mData; + pageGenerator = new PageGenerator(); + } + ~PageManager(){ + } + + Page* generatePage(PageData &pageData){ + switch(pageData.getpageType()){ + case PageType::TABLE_OF_USERS : + return pageGenerator->generateTablePage(pageData.userData, pageData.getPageOrganizeType()); + + case PageType::ONE_USER_PAGE : + return pageGenerator->generateUserPage(reinterpret_cast(data->userData[0])); + + case PageType::START_PAGE : + return pageGenerator->generateStartPage(); + } + } + + + + void generatePages(){ + std::ofstream out("tablepage.html"); + out <generateTablePage(data->userData, data->getPageOrganizeType())->toString(); + out.close(); + std::vector vecOfThreads; + int i = 0; + for(auto& userData: data->userData) { + std::string name = "userpage" + std::to_string(i++); + vecOfThreads.push_back(std::thread(std::bind(&PageManager::threadGeneratePage, *this))); + } + for (std::thread & th : vecOfThreads) + { + if (th.joinable()){ + th.join(); + } + } + } + + void threadGeneratePage(){ + UserData* testData = new UserData("slug","fname", "sname", "imgsrc",19); + std::ofstream out("file.txt"); + out << pageGenerator->generateUserPage(*testData); + out.close(); + } }; diff --git a/Sources/Views/Button/Button.cpp b/Sources/Views/Button/Button.cpp deleted file mode 100644 index 631860b..0000000 --- a/Sources/Views/Button/Button.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-16. -// - -#include "Button.h" - diff --git a/Sources/Views/Button/Button.h b/Sources/Views/Button/Button.h deleted file mode 100644 index 85fcef4..0000000 --- a/Sources/Views/Button/Button.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// Created by Сергей Петренко on 2019-11-16. -// - -#ifndef CPPROJECT_BUTTON_H -#define CPPROJECT_BUTTON_H - - - - - -#endif //CPPROJECT_BUTTON_H diff --git a/Sources/Views/Cell/CellView.cpp b/Sources/Views/Cell/CellView.cpp index 3233dc8..12edf04 100644 --- a/Sources/Views/Cell/CellView.cpp +++ b/Sources/Views/Cell/CellView.cpp @@ -15,7 +15,7 @@ CellView::CellView(int indx,int mRows){ } -CellView::CellView(int indx, std::vector rows){ +CellView::CellView(int indx, std::vector> rows){ type = enumToString(Type::CELL); rowsCount = rows.size(); index = indx; @@ -33,13 +33,13 @@ std::string CellView::toString(int depth){ depth++; } if(!rows.empty()) { - for (RowView &v: rows) { - res += v.toStringOpen(depth); + for (std::shared_ptr &v: rows) { + res += v->toStringOpen(depth); depth++; - if (!v.subviews.empty()) { - res += v.toString(depth); + if (!v->subviews.empty()) { + res += v->toString(depth); } - res+=v.toStringClose(--depth); + res+=v->toStringClose(--depth); } } if(--depth == 0){ @@ -67,28 +67,31 @@ std::string CellView::toStringClose(int depth){ } -void CellView::append(ContainerView &mView){ - subviews.push_back(mView); +bool CellView::append(ContainerView &mView){ + return false; } -void CellView::appendRow(RowView &mView){ +void CellView::appendRow(std::shared_ptr &mView){ rows.push_back(mView); } -void CellView::appendRows(std::vector mRows){ +void CellView::appendRows(std::vector> mRows){ if(rows.size() + mRows.size() <= rowsCount) { - for(RowView& rowView : mRows){ + for(std::shared_ptr& rowView : mRows){ rows.push_back(rowView); - rowView.setIndex(rows.size()); + rowView->setIndex(rows.size()); } } } bool CellView::appendInSubview(std::string subviewName, ContainerView& mView){ - + return false; } -void CellView::removeSubview(std::string subviewName){ - +bool CellView::removeSubview(std::string subviewName){ + return false; } void CellView::destroy(){ +} +CellView::~CellView(){ + } \ No newline at end of file diff --git a/Sources/Views/Cell/CellView.h b/Sources/Views/Cell/CellView.h index 63af1ab..910fb71 100644 --- a/Sources/Views/Cell/CellView.h +++ b/Sources/Views/Cell/CellView.h @@ -12,22 +12,23 @@ class CellView: public ContainerView { public: int rowsCount;; int index; - std::vector rows; + std::vector> rows; - CellView(int mRows); + explicit CellView(int mRows); CellView(int indx,int mRows); - CellView(int indx, std::vector rows); + CellView(int indx, std::vector> rows); + ~CellView(); void setIndex(int indx); - void append(ContainerView &mView); - void appendRow(RowView &mView); - void appendRows(std::vector mRows); - void removeSubview(std::string subviewName); - bool appendInSubview(std::string subviewName, ContainerView& mView); - void destroy(); - - std::string toString(int depth); - std::string toStringOpen(int depth); - std::string toStringClose(int depth); + bool append(ContainerView &mView)override; + void appendRow(std::shared_ptr &mView); + void appendRows(std::vector> mRows); + bool removeSubview(std::string subviewName) override ; + bool appendInSubview(std::string subviewName, ContainerView& mView) override; + void destroy()override; + + std::string toString(int depth) override; + std::string toStringOpen(int depth) override; + std::string toStringClose(int depth) override; diff --git a/Sources/Views/Container/ContainerView.cpp b/Sources/Views/Container/ContainerView.cpp index a171c3b..6c967ef 100644 --- a/Sources/Views/Container/ContainerView.cpp +++ b/Sources/Views/Container/ContainerView.cpp @@ -3,22 +3,21 @@ // #include "ContainerView.h" -// -//ContainerView::ContainerView(string n, string t, string c){ -// name = n; -// type = t; -// _class =c; -//} -// -//std::string ContainerView::getType(){ -// return type; -//} -//std::string ContainerView::getClass(){ -// return _class; -//} -// -// -//std::string ContainerView::getName() { -// return this.name; -//} + +std::string ContainerView::getName(){ + return name; +} + +std::string ContainerView::getType(){ + return type; +} +std::string ContainerView::getClass(){ + return _class; +} + +ContainerView::ContainerView(std::string n, Type t, std::string c){ + name = n; + type = enumToString(t); + _class = c; +} diff --git a/Sources/Views/Container/ContainerView.h b/Sources/Views/Container/ContainerView.h index f0044a0..e8c269c 100644 --- a/Sources/Views/Container/ContainerView.h +++ b/Sources/Views/Container/ContainerView.h @@ -144,31 +144,17 @@ class ContainerView { virtual std::string toStringOpen(int depth) = 0; virtual std::string toStringClose(int depth) = 0; - - - virtual void append(ContainerView &mView) = 0; + virtual bool append(ContainerView &mView) = 0; virtual bool appendInSubview(std::string subviewName, ContainerView& mView) = 0; - virtual void removeSubview(std::string subviewName) = 0; + virtual bool removeSubview(std::string subviewName) = 0; virtual void destroy() = 0; - std::string getName(){ - return name; - } - - std::string getType(){ - return type; - } - std::string getClass(){ - return _class; - } - + std::string getName(); + std::string getType(); + std::string getClass(); ContainerView() = default; - ContainerView(std::string n, Type t, std::string c){ - name = n; - type = enumToString(t); - _class = c; - } + ContainerView(std::string n, Type t, std::string c); }; diff --git a/Sources/Views/ImageView/ImageView.cpp b/Sources/Views/ImageView/ImageView.cpp index 4db7013..ac2dc8e 100644 --- a/Sources/Views/ImageView/ImageView.cpp +++ b/Sources/Views/ImageView/ImageView.cpp @@ -4,11 +4,18 @@ #include "ImageView.h" -void ImageView::append(ContainerView &mView){} -bool ImageView::appendInSubview(std::string subviewName, ContainerView& mView){return false;} -void ImageView::removeSubview(std::string subviewName){} -void ImageView::destroy(){} +bool ImageView::append(ContainerView &mView){ + return false; +} +bool ImageView::appendInSubview(std::string subviewName, ContainerView& mView){ + return false; +} +bool ImageView::removeSubview(std::string subviewName){ + return false; +} +void ImageView::destroy(){ +} ImageView::ImageView(std::string n, Type t, BClass c, std::string s, int h, int w){ name = n; @@ -21,23 +28,20 @@ ImageView::ImageView(std::string n, Type t, BClass c, std::string s, int h, int std::string ImageView::toStringOpen(int depth) { std::string res = ""; for(int i=0;i<3*depth;i++){ - res+=" "; + res+=" "; } - res += "<"+type - + " class=\"" - + _class + - "\" src=\"" - + src +"\"" - + R"( alt="" width=")" - + std::to_string(width) - +"\" height=\"" - + std::to_string(height) - + "\">\n\n"; + res += "<"+type + " class=\""+ _class +"\" src=\"" + src + "\"" + + R"( alt="" width=")" + std::to_string(width) + + "\" height=\"" + std::to_string(height) + "\">\n\n"; return res; } std::string ImageView::toStringClose(int depth ) { -return ""; + return ""; } std::string ImageView::toString(int depth) { -return toStringOpen(depth)+toStringClose(depth); -} \ No newline at end of file + return toStringOpen(depth)+toStringClose(depth); +} + +ImageView::~ImageView() { + +} diff --git a/Sources/Views/ImageView/ImageView.h b/Sources/Views/ImageView/ImageView.h index 00c8722..969ee59 100644 --- a/Sources/Views/ImageView/ImageView.h +++ b/Sources/Views/ImageView/ImageView.h @@ -9,23 +9,22 @@ #include "Container/ContainerView.h" class ImageView: public ContainerView{ - - private: std::string src; int height; int width; + void destroy() override; public: - void append(ContainerView &mView); - bool appendInSubview(std::string subviewName, ContainerView& mView); - void removeSubview(std::string subviewName); - void destroy(); + bool append(ContainerView &mView) override; + bool appendInSubview(std::string subviewName, ContainerView& mView) override; + bool removeSubview(std::string subviewName) override; ImageView() = default; + ~ImageView(); ImageView(std::string n, Type t, BClass c, std::string s, int h, int w); - std::string toStringOpen(int depth = 0) override; - std::string toStringClose(int depth = 0) override; - std::string toString(int depth = 0) override; + std::string toStringOpen(int depth) override; + std::string toStringClose(int depth) override; + std::string toString(int depth) override; }; diff --git a/Sources/Views/PersonView/PersonView.cpp b/Sources/Views/PersonView/PersonView.cpp index 4667aaf..58e58ef 100644 --- a/Sources/Views/PersonView/PersonView.cpp +++ b/Sources/Views/PersonView/PersonView.cpp @@ -24,34 +24,33 @@ infoTable = new TableView("table", cellCount); -infoTable->appendCells(std::vector { +infoTable->appendCells(std::vector> { - *new CellView(0,std::vector{ - *new RowView(0, + std::make_shared(*new CellView(0,std::vector>{ + std::make_shared(*new RowView(0, *new TextView( "fNameView", Type::H4, BClass::TEXT_NORMAL, userData.firstName)) - }), - - *new CellView(1,std::vector{ - *new RowView(0, - *new TextView( - "snameView", - Type::H4, - BClass::TEXT_NORMAL, - userData.secondName)) - }), - - *new CellView(2,std::vector{ - *new RowView(0, - *new TextView( - "ageView", - Type::H4, - BClass::TEXT_NORMAL, - std::to_string(userData.age))) - }) + )})), + + std::make_shared(*new CellView(1,std::vector>{ + std::make_shared(*new RowView(0, + *new TextView( + "sNameView", + Type::H4, + BClass::TEXT_NORMAL, + userData.secondName)) + )})), + + std::make_shared(*new CellView(2,std::vector>{ + std::make_shared(*new RowView(0, + *new TextView( + "ageView", + Type::H4, + BClass::TEXT_NORMAL, + std::to_string(userData.age))))})), }); makeTemplate(); @@ -82,4 +81,8 @@ void PersonView::makeTemplate(){ appendInSubview("CardBody", *userImage); appendInSubview("CardBody", *infoTable); -} \ No newline at end of file +} + +PersonView::~PersonView() { + +} diff --git a/Sources/Views/PersonView/PersonView.h b/Sources/Views/PersonView/PersonView.h index 77b578d..96f7c4c 100644 --- a/Sources/Views/PersonView/PersonView.h +++ b/Sources/Views/PersonView/PersonView.h @@ -21,7 +21,8 @@ class PersonView: public View { TextView* username; TableView* infoTable; - PersonView(UserData userData); + explicit PersonView(UserData userData); + ~PersonView(); private: void makeTemplate(); diff --git a/Sources/Views/Row/RowView.cpp b/Sources/Views/Row/RowView.cpp index b705040..8457952 100644 --- a/Sources/Views/Row/RowView.cpp +++ b/Sources/Views/Row/RowView.cpp @@ -16,64 +16,17 @@ RowView::RowView(int indx, ContainerView& containerView){ index = indx; append(containerView); } -RowView::RowView( ContainerView& containerView){ -type = enumToString(Type::ROW); -scope = "scope"; -append(containerView); +RowView::RowView(ContainerView& containerView){ + type = enumToString(Type::ROW); + scope = "scope"; + append(containerView); } void RowView::setIndex(int indx){ index = indx; } -std::string RowView::toString(int depth) { -std::string res; -if(depth == 0){ -res += "<"+getType() + " scope=\""+ scope+"\">\n\n"; -depth++; -} -if(!subviews.empty()) { -for (ContainerView &v: subviews) { -res += v.toStringOpen(depth); -depth++; -if (!v.subviews.empty()) { -res += v.toString(depth); -} -res+=v.toStringClose(--depth); -} -} -if(--depth == 0){ -res+="\n\n"; -} -return res; -} - -std::string RowView::toStringOpen(int depth){ - std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; - } - res += "<"+type + " scope=\""+ scope+"\">\n\n"; - return res; -} -std::string RowView::toStringClose(int depth){ - std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; - } - res += "\n\n"; - return res; -} - -void RowView::append(ContainerView &mView){ - subviews.push_back(mView); -} -bool RowView::appendInSubview(std::string subviewName, ContainerView& mView){ - -} -void RowView::removeSubview(std::string subviewName){ +RowView::~RowView() { } -void RowView::destroy(){ -} \ No newline at end of file diff --git a/Sources/Views/Row/RowView.h b/Sources/Views/Row/RowView.h index 91feeb3..bdea099 100644 --- a/Sources/Views/Row/RowView.h +++ b/Sources/Views/Row/RowView.h @@ -5,24 +5,16 @@ #ifndef CPPROJECT_ROWVIEW_H #define CPPROJECT_ROWVIEW_H - -#include "Container/ContainerView.h" - -class RowView: public ContainerView{ +#include +class RowView: public View{ public: - int index; + int index{}; std::string scope; - RowView(int indx); + explicit RowView(int indx); RowView(int indx, ContainerView& containerView); - RowView( ContainerView& containerView); + ~RowView(); + explicit RowView( ContainerView& containerView); void setIndex(int indx); - std::string toString(int depth = 0) override; - std::string toStringOpen(int depth); - std::string toStringClose(int depth); - void append(ContainerView &mView); - bool appendInSubview(std::string subviewName, ContainerView& mView); - void removeSubview(std::string subviewName); - void destroy(); }; diff --git a/Sources/Views/SecondaryView/SecondaryView.cpp b/Sources/Views/SecondaryView/SecondaryView.cpp index b3b1889..00aa752 100644 --- a/Sources/Views/SecondaryView/SecondaryView.cpp +++ b/Sources/Views/SecondaryView/SecondaryView.cpp @@ -31,7 +31,7 @@ bool SecondaryView::appendInSubview(std::string subviewName, ContainerView& mVie return false; } -void SecondaryView::append(ContainerView &mView){ +bool SecondaryView::append(ContainerView &mView){ } @@ -39,6 +39,10 @@ void SecondaryView::destroy() { } -void SecondaryView::removeSubview(std::string subviewName) { +bool SecondaryView::removeSubview(std::string subviewName) { -} \ No newline at end of file +} + +SecondaryView::~SecondaryView() { + +} diff --git a/Sources/Views/SecondaryView/SecondaryView.h b/Sources/Views/SecondaryView/SecondaryView.h index e350e51..5ead64c 100644 --- a/Sources/Views/SecondaryView/SecondaryView.h +++ b/Sources/Views/SecondaryView/SecondaryView.h @@ -5,35 +5,38 @@ #ifndef CPPROJECT_SECONDARYVIEW_H #define CPPROJECT_SECONDARYVIEW_H #include "View/View.h" + +#include #include "Container/ContainerView.h" class Attribute{ public: std::string key; std::string value; Attribute(std::string k, std::string v){ - key = k; - value = v; + key = std::move(k); + value = std::move(v); } }; class SecondaryView: public ContainerView { public: std::vector attributes; SecondaryView(std::string name, Type t, std::vector attr); + ~SecondaryView(); - std::string toStringOpen(int depth = 0) override; + std::string toStringOpen(int depth) override; - std::string toStringClose(int depth = 0) override; + std::string toStringClose(int depth) override; - std::string toString(int depth = 0) override; + std::string toString(int depth) override; bool appendInSubview(std::string subviewName, ContainerView& mView) override; - void append(ContainerView &mView) override; + bool append(ContainerView &mView) override; void destroy() override; - void removeSubview(std::string subviewName) override; + bool removeSubview(std::string subviewName) override; }; diff --git a/Sources/Views/TableView/TableView.cpp b/Sources/Views/TableView/TableView.cpp index 4bbf23d..6c3ad7d 100644 --- a/Sources/Views/TableView/TableView.cpp +++ b/Sources/Views/TableView/TableView.cpp @@ -21,13 +21,13 @@ std::string TableView::toString(int depth){ depth++; } if(!cells.empty()) { - for (CellView &v: cells) { - res += v.toStringOpen(depth); + for (std::shared_ptr v: cells) { + res += v->toStringOpen(depth); depth++; - if (!v.rows.empty()) { - res += v.toString(depth); + if (!v->rows.empty()) { + res += v->toString(depth); } - res+=v.toStringClose(--depth); + res+=v->toStringClose(--depth); } } if(--depth == 0){ @@ -56,23 +56,23 @@ std::string TableView::toStringClose(int depth){ -void TableView::append(ContainerView &mView){ - subviews.push_back(mView); +bool TableView::append(ContainerView &mView){ + subviews.emplace_back(mView); } -void TableView::appendCell(CellView &mView){ +void TableView::appendCell(std::shared_ptr mView){ if(cells.size() < cellsCount) { cells.push_back(mView); - mView.setIndex(cells.size()); + mView->setIndex(cells.size()); } } -void TableView::appendCells(std::vector mViews){ +void TableView::appendCells(std::vector> mViews){ if(cells.size() + mViews.size() <= cellsCount) { - for(CellView& cellView : mViews){ + for(std::shared_ptr cellView : mViews){ cells.push_back(cellView); - cellView.setIndex(cells.size()); + cellView->setIndex(cells.size()); } } } @@ -80,32 +80,35 @@ bool TableView::appendInSubview(std::string subviewName, ContainerView& mView){ } -bool TableView::appendRowInCell(int cellIndex, RowView& mView){ +bool TableView::appendRowInCell(int cellIndex, std::shared_ptr mView){ if(cellIndex <= cellsCount && cells.size() + 1 <= cellsCount){ - if(cells[cellIndex].rows.size() + 1 <= rowsCount){ - cells[cellIndex].rows.emplace_back(mView); + if(cells[cellIndex]->rows.size() + 1 <= rowsCount){ + cells[cellIndex]->rows.emplace_back(mView); return true; } - } return false; } -bool TableView::appendRowsInCell(int cellIndex, std::vector mViews){ +bool TableView::appendRowsInCell(int cellIndex, std::vector> mViews){ if(cellIndex <= cellsCount && cells.size() < cellsCount){ - if(cells[cellIndex].rows.size() + mViews.size() < cellsCount){ - for(RowView &rowView: mViews){ - cells[cellIndex].appendRow(rowView); - rowView.setIndex(cells[cellIndex].rows.size()); + if(cells[cellIndex]->rows.size() + mViews.size() < cellsCount){ + for(std::shared_ptr &rowView: mViews){ + cells[cellIndex]->appendRow(rowView); + rowView->setIndex(cells[cellIndex]->rows.size()); } } } return false; } -void TableView::removeSubview(std::string subviewName) { +bool TableView::removeSubview(std::string subviewName) { } void TableView::destroy(){ } + +TableView::~TableView() { + +} diff --git a/Sources/Views/TableView/TableView.h b/Sources/Views/TableView/TableView.h index e27070b..a78017f 100644 --- a/Sources/Views/TableView/TableView.h +++ b/Sources/Views/TableView/TableView.h @@ -12,23 +12,27 @@ #include "View/View.h" class TableView: public ContainerView{ -public: +private: int rowsCount; int cellsCount; std::string name; - std::vector cells; + std::vector> cells; +public: + + TableView(std::string mName,int mRows, int mCells); - std::string toString(int depth); - std::string toStringOpen(int depth); - std::string toStringClose(int depth); - void append(ContainerView &mView); - void appendCell(CellView &mView); - void appendCells(std::vector mViews); + ~TableView(); + std::string toString(int depth) override; + std::string toStringOpen(int depth) override; + std::string toStringClose(int depth) override; + bool append(ContainerView &mView) override; + void appendCell(std::shared_ptr mView); + void appendCells(std::vector> mViews); bool appendInSubview(std::string subviewName, ContainerView& mView) override ; - bool appendRowInCell(int cellIndex, RowView& mView); - bool appendRowsInCell(int cellIndex, std::vector mViews); - void removeSubview(std::string subviewName) override; + bool appendRowInCell(int cellIndex, std::shared_ptr mView); + bool appendRowsInCell(int cellIndex, std::vector> mViews); + bool removeSubview(std::string subviewName) override; void destroy() override; }; diff --git a/Sources/Views/TextView/TextView.cpp b/Sources/Views/TextView/TextView.cpp index 2cb6b0b..32f0cca 100644 --- a/Sources/Views/TextView/TextView.cpp +++ b/Sources/Views/TextView/TextView.cpp @@ -4,14 +4,14 @@ #include "TextView.h" -void TextView::append(ContainerView &mView){ - +bool TextView::append(ContainerView &mView){ + return false; } bool TextView::appendInSubview(std::string subviewName, ContainerView& mView){ - + return false; } -void TextView::removeSubview(std::string subviewName){ - +bool TextView::removeSubview(std::string subviewName){ + return false; } void TextView::destroy(){ @@ -19,16 +19,16 @@ void TextView::destroy(){ TextView::TextView(std::string n, Type t, BClass c, std::string txt){ -name = n; -type = enumToString(t); -_class = enumToString(c); -text = txt; + name = std::move(n); + type = enumToString(t); + _class = enumToString(c); + text = std::move(txt); }; TextView::TextView(std::string n, Type t, std::string txt){ -name = n; -type = enumToString(t); -_class = ""; -text = txt; + name = std::move(n); + type = enumToString(t); + _class = ""; + text = std::move(txt); }; void TextView::setText(std::string mText){ @@ -40,19 +40,22 @@ std::string TextView::getText(){ } std::string TextView::toStringOpen(int depth) { -std::string res; -for(int i=0;i<3*depth;i++){ -res+=" "; -} -res += "<"+type + " class=\""+ _class+"\">"+text; -return res; + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "<"+type + " class=\""+ _class+"\">"+text; + return res; } std::string TextView::toStringClose(int depth) { -std::string res; -res += "\n\n"; -return res; + std::string res; + res += "\n\n"; + return res; } std::string TextView::toString(int depth) { + return toStringOpen(depth)+toStringClose(depth); +} + +TextView::~TextView() { -return toStringOpen(depth)+toStringClose(depth); -} \ No newline at end of file +} diff --git a/Sources/Views/TextView/TextView.h b/Sources/Views/TextView/TextView.h index 629b457..18117fe 100644 --- a/Sources/Views/TextView/TextView.h +++ b/Sources/Views/TextView/TextView.h @@ -12,17 +12,18 @@ class TextView: public ContainerView{ std::string text; public: - void append(ContainerView &mView); - bool appendInSubview(std::string subviewName, ContainerView& mView); - void removeSubview(std::string subviewName); - void destroy(); + bool append(ContainerView &mView) override; + bool appendInSubview(std::string subviewName, ContainerView& mView) override; + bool removeSubview(std::string subviewName) override; + void destroy() override; TextView(std::string n, Type t, BClass c, std::string txt); TextView(std::string n, Type t, std::string txt); + ~TextView(); void setText(std::string mText); std::string getText(); - std::string toStringOpen(int depth = 0) override; - std::string toStringClose(int depth = 0) override; - std::string toString(int depth = 0) override; + std::string toStringOpen(int depth) override; + std::string toStringClose(int depth) override; + std::string toString(int depth) override; }; diff --git a/Sources/Views/UserData/UserData.cpp b/Sources/Views/UserData/UserData.cpp index 8f8f4c1..d01d433 100644 --- a/Sources/Views/UserData/UserData.cpp +++ b/Sources/Views/UserData/UserData.cpp @@ -4,9 +4,9 @@ #include "UserData.h" UserData::UserData(std::string slg, std::string fn, std::string sn, std::string img, int a){ -slug = slg; -firstName = fn; -secondName = sn; -age = a; -imageUrl = img; + slug = slg; + firstName = fn; + secondName = sn; + age = a; + imageUrl = img; } \ No newline at end of file diff --git a/Sources/Views/View/View.cpp b/Sources/Views/View/View.cpp index 1e9f903..c350574 100644 --- a/Sources/Views/View/View.cpp +++ b/Sources/Views/View/View.cpp @@ -4,63 +4,58 @@ #include "View.h" - - View::View(std::string n, Type t, BClass c){ -name = n; -type = enumToString(t); -_class = enumToString(c); + name = n; + type = enumToString(t); + _class = enumToString(c); } View::View(std::string n, Type t){ -name = n; -type = enumToString(t); -_class = ""; + name = n; + type = enumToString(t); + _class = ""; } - - std::string View::toStringOpen(int depth ) { -std::string res; -for(int i=0;i<3*depth;i++){ -res+=" "; -} -res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; -return res; + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; + return res; } std::string View::toStringClose(int depth ) { -std::string res; -for(int i=0;i<3*depth;i++){ -res+=" "; -} -res+="\n\n"; -return res; + std::string res; + for(int i=0;i<3*depth;i++){ + res+=" "; + } + res+="\n\n"; + return res; } std::string View::toString(int depth ) { -std::string res; -if(depth == 0){ -res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; -depth++; -} -if(!subviews.empty()) { -for (ContainerView &v: subviews) { -res += v.toStringOpen(depth); -depth++; -if (!v.subviews.empty()) { -res += v.toString(depth); -} -res+=v.toStringClose(--depth); + std::string res; + if(depth == 0){ + res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; + depth++; + } + if(!subviews.empty()) { + for (ContainerView &v: subviews) { + res += v.toStringOpen(depth); + depth++; + if (!v.subviews.empty()) { + res += v.toString(depth); + } + res+=v.toStringClose(--depth); -} + } + } + if(--depth == 0){ + res+="\n\n"; + } + return res; } -if(--depth == 0){ -res+="\n\n"; -} -return res; -} - bool View::appendInSubview(std::string subviewName, ContainerView& mView) { for(ContainerView& v : subviews){ @@ -75,7 +70,7 @@ bool View::appendInSubview(std::string subviewName, ContainerView& mView) { return false; } -void View::append(ContainerView &mView){ +bool View::append(ContainerView &mView){ subviews.emplace_back(mView); } @@ -90,7 +85,7 @@ void View::destroy() { } } -void View::removeSubview(std::string subviewName){ +bool View::removeSubview(std::string subviewName){ int i = 0; for(ContainerView &v : subviews){ auto it = std::find_if(v.subviews.begin(), v.subviews.end(), @@ -112,5 +107,9 @@ void View::removeSubview(std::string subviewName){ } } +View::~View() { + +} + diff --git a/Sources/Views/View/View.h b/Sources/Views/View/View.h index fab9592..101fc86 100644 --- a/Sources/Views/View/View.h +++ b/Sources/Views/View/View.h @@ -10,7 +10,8 @@ class View: public ContainerView{ public: - View()= default; + View() = default; + ~View(); View(std::string n, Type t, BClass c); View(std::string n, Type t); @@ -20,12 +21,12 @@ class View: public ContainerView{ std::string toString(int depth = 0) override; - bool appendInSubview(std::string subviewName, ContainerView& mView) override; - void append(ContainerView &mView) override; + bool append(ContainerView &mView) override; + + bool removeSubview(std::string subviewName) override; - void removeSubview(std::string subviewName) override; void destroy () override; }; diff --git a/Sources/main.cpp b/Sources/main.cpp index d5c8153..63f48ef 100644 --- a/Sources/main.cpp +++ b/Sources/main.cpp @@ -4,6 +4,7 @@ #include "Views/Cell/CellView.h" #include "Views/TableView/TableView.h" #include "PageGenerator/PageGenerator.h" +#include "PageManager.h" @@ -25,16 +26,16 @@ int main(){ new UserData("7Stalin.su","Дмитрий3", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), new UserData("8Kek","Дмитрий3", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), - - - }; PageGenerator* pageGenerator = new PageGenerator(); - pageGenerator->generatePage( *new PageData(userDataVec, PageType::TABLE_OF_USERS, Organize::ONE_LINE_VERTICAL)); - std::cout<page->toString(); - + pageGenerator->generateTablePage( userDataVec,Organize::ONE_LINE_VERTICAL); + std::cout<page->toString(); + PageData *pageData = new PageData(userDataVec,PageType::TABLE_OF_USERS,Organize::ONE_LINE_VERTICAL); + PageManager* pageManager = new PageManager(pageData); + pageManager->generatePages(); + return 0; } \ No newline at end of file From 90e78677aecc6d9ab0f4add998ea22af29642d81 Mon Sep 17 00:00:00 2001 From: SPetrenko17 Date: Sat, 7 Dec 2019 17:09:45 +0300 Subject: [PATCH 5/5] RK3 Commit without comments in code --- .DS_Store | Bin 6148 -> 6148 bytes Sources/Page/Page.cpp | 38 -------- Sources/Page/Page.h | 65 +++++++------- Sources/PageData/PageData.cpp | 7 +- Sources/PageData/PageData.h | 22 +++-- Sources/PageGenerator/PageGenerator.cpp | 43 +++++---- Sources/PageGenerator/PageGenerator.h | 20 ++--- Sources/PageManager/PageManager.h | 42 +++++---- Sources/Views/Cell/CellView.cpp | 62 +++++++------ Sources/Views/Cell/CellView.h | 26 ++++-- Sources/Views/Container/ContainerView.h | 45 +++++----- Sources/Views/ImageView/ImageView.cpp | 31 ++++--- Sources/Views/ImageView/ImageView.h | 16 +++- Sources/Views/PersonView/PersonView.cpp | 12 +-- Sources/Views/PersonView/PersonView.h | 17 ++-- Sources/Views/Row/RowView.cpp | 10 ++- Sources/Views/Row/RowView.h | 13 ++- Sources/Views/SecondaryView/SecondaryView.cpp | 18 ++-- Sources/Views/SecondaryView/SecondaryView.h | 18 ++-- Sources/Views/TableView/TableView.cpp | 71 ++++++++------- Sources/Views/TableView/TableView.h | 21 ++++- Sources/Views/TextView/TextView.h | 18 +++- Sources/Views/UserData/UserData.h | 1 + Sources/Views/View/View.cpp | 84 +++++++++--------- Sources/Views/View/View.h | 12 ++- Sources/main.cpp | 25 +++--- 26 files changed, 403 insertions(+), 334 deletions(-) diff --git a/.DS_Store b/.DS_Store index 39385de241e11bb93352bf26b5fabeb8b29ffc1c..4faad6b3ad4163afb85aa183af691cb1c6a8df40 100644 GIT binary patch delta 78 zcmZoMXffDe&BFVNfq^0CKNL)EV3CpW%*jtq%E?axN(eA8Fh(FN*xbNk$;f*QMd%o- Goe%(K1tn_$ delta 78 zcmZoMXffDe&BANVz`&sK9}E~6CO5Fi$av=DCnx3PCjlh{fOsXcg3S#qmW;gOC_=|r G?Sueh4jq>O diff --git a/Sources/Page/Page.cpp b/Sources/Page/Page.cpp index 2924959..ee41a21 100644 --- a/Sources/Page/Page.cpp +++ b/Sources/Page/Page.cpp @@ -3,41 +3,3 @@ // #include "Page.h" - -//Page::Page(){ -// view = new View("main", Type::DIV); -// makeTemplate(); -//} -// -//void Page::makeTemplate(){ -// -// view->append(*new View("html",Type::HTML)); -// view->appendInSubview("html", -// *new SecondaryView("meta", -// Type::META, -// std::vector{ -// Attribute("charset","UTF-8") -// })); -// view->appendInSubview("html",(*new TextView("title",Type::TITLE,"FINDFACE"))); -// view->appendInSubview("html", -// *new SecondaryView("attributes", -// Type::LINK, std::vector{ -// Attribute("rel","stylesheet"), -// Attribute("href","https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"), -// Attribute("integrity","sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"), -// Attribute("crossorigin","anonymous") -// })); -// -// view->appendInSubview("html",* new View("body",Type::BODY)); -//} -// -//void Page::appendInBody(ContainerView& containerView){ -// view->appendInSubview("body", containerView); -//} -// -//std::string Page::toString(){ -// std::string res; -// res += "\n"; -// res+=view->toString(0); -// return res; -//} \ No newline at end of file diff --git a/Sources/Page/Page.h b/Sources/Page/Page.h index 580bc81..d2250ef 100644 --- a/Sources/Page/Page.h +++ b/Sources/Page/Page.h @@ -5,56 +5,61 @@ #ifndef CPPROJECT_PAGE_H #define CPPROJECT_PAGE_H -#include "Views/View/View.h" -#include "Views/SecondaryView/SecondaryView.h" -#include "Views/TextView/TextView.h" +#include +#include +#include #include class Page { public: - View* view; - Page(){ - view = new View("main", Type::DIV); + View *view; + + Page() { + view = new View("main", Type::DIV); makeTemplate(); } - void makeTemplate(){ + void makeTemplate() { - view->append(*new View("html",Type::HTML)); + view->append(*new View("html", Type::HTML)); view->appendInSubview("html", - *new SecondaryView("meta", - Type::META, - std::vector{ - Attribute("charset","UTF-8") - })); - view->appendInSubview("html",(*new TextView("title",Type::TITLE,"FINDFACE"))); + *new SecondaryView("meta", + Type::META, + std::vector{ + Attribute("charset", + "UTF-8") + })); + view->appendInSubview("html", (*new TextView("title", Type::TITLE, + "FINDFACE"))); view->appendInSubview("html", - *new SecondaryView("attributes", - Type::LINK, std::vector{ - Attribute("rel","stylesheet"), - Attribute("href","https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"), - Attribute("integrity","sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"), - Attribute("crossorigin","anonymous") - })); - - view->appendInSubview("html",* new View("body",Type::BODY)); + *new SecondaryView("attributes", + Type::LINK, + std::vector{ + Attribute("rel", + "stylesheet"), + Attribute("href", + "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"), + Attribute("integrity", + "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"), + Attribute( + "crossorigin", + "anonymous") + })); + + view->appendInSubview("html", *new View("body", Type::BODY)); } - void appendInBody(ContainerView& containerView){ + void appendInBody(ContainerView &containerView) { view->appendInSubview("body", containerView); } - std::string toString(){ + std::string toString() { std::string res; res += "\n"; - res+=view->toString(0); + res += view->toString(0); return res; } }; - - - - #endif //CPPROJECT_PAGE_H diff --git a/Sources/PageData/PageData.cpp b/Sources/PageData/PageData.cpp index b21ffcc..1585e56 100644 --- a/Sources/PageData/PageData.cpp +++ b/Sources/PageData/PageData.cpp @@ -3,14 +3,17 @@ // #include "PageData.h" -PageData::PageData(std::vector u, PageType t, Organize o){ + +PageData::PageData(std::vector u, PageType t, Organize o) { type = t; userData = u; organize = o; } -void PageData::setOrganizeType(Organize o){ + +void PageData::setOrganizeType(Organize o) { organize = o; } + void PageData::setPageType(PageType t) { type = t; } \ No newline at end of file diff --git a/Sources/PageData/PageData.h b/Sources/PageData/PageData.h index 9bc3e94..cc2e790 100644 --- a/Sources/PageData/PageData.h +++ b/Sources/PageData/PageData.h @@ -6,16 +6,15 @@ #define CPPROJECT_PAGEDATA_H #include -#include "../Views/UserData/UserData.h" -enum class PageType: uint8_t -{ +#include + +enum class PageType : uint8_t { ONE_USER_PAGE, TABLE_OF_USERS, START_PAGE, }; -enum class Organize: uint8_t -{ +enum class Organize : uint8_t { ONE_LINE_VERTICAL, ONE_LINE_HORIZONTAL, SQUARE, @@ -27,17 +26,22 @@ enum class Organize: uint8_t class PageData { public: - std::vector userData; + std::vector userData; + + PageData(std::vector u, PageType t, Organize o); - PageData(std::vector u, PageType t, Organize o); void setOrganizeType(Organize o); + void setPageType(PageType o); - PageType getpageType(){ + + PageType getpageType() { return type; } - Organize getPageOrganizeType(){ + + Organize getPageOrganizeType() { return organize; } + private: Organize organize; PageType type; diff --git a/Sources/PageGenerator/PageGenerator.cpp b/Sources/PageGenerator/PageGenerator.cpp index 50ab170..5b4abf9 100644 --- a/Sources/PageGenerator/PageGenerator.cpp +++ b/Sources/PageGenerator/PageGenerator.cpp @@ -4,8 +4,9 @@ #include "PageGenerator.h" -void PageGenerator::organizeCells(Organize o, int& rows, int& cells, int count){ - switch(o){ +void +PageGenerator::organizeCells(Organize o, int &rows, int &cells, int count) { + switch (o) { case Organize::ONE_LINE_VERTICAL: rows = 1; cells = count; @@ -22,41 +23,47 @@ void PageGenerator::organizeCells(Organize o, int& rows, int& cells, int count){ } } -Page* PageGenerator::generateTablePage(std::vector userData, Organize o){ - page = new Page(); - std::vector persons; - for(auto &u : userData){ +Page * +PageGenerator::generateTablePage(std::vector userData, Organize o) { + page = new Page(); + std::vector persons; + for (auto &u : userData) { persons.push_back(new PersonView(*u)); } int rowsCount = 0; int cellsCount = 0; - organizeCells(o,rowsCount,cellsCount,userData.size()); + organizeCells(o, rowsCount, cellsCount, userData.size()); - View* view = new View("Main",Type::DIV,BClass::CARD_DECK); + View *view = new View("Main", Type::DIV, BClass::CARD_DECK); - TableView* tableView = new TableView("Table",rowsCount,cellsCount); + TableView *tableView = new TableView("Table", rowsCount, cellsCount); int r = 0; int c = 0; - tableView->appendCell(std::make_shared(*new CellView(c,rowsCount))); - for(auto &p: persons){ - tableView->appendRowInCell(c,std::make_shared(*new RowView(r, *p))); + tableView->appendCell( + std::make_shared(*new CellView(c, rowsCount))); + for (auto &p: persons) { + tableView->appendRowInCell(c, std::make_shared( + *new RowView(r, *p))); r++; - if(r >= rowsCount){ + if (r >= rowsCount) { r = 0; - tableView->appendCell(std::make_shared(*new CellView(++c,rowsCount))); + tableView->appendCell( + std::make_shared(*new CellView(++c, rowsCount))); } } page->appendInBody(*tableView); return page; } -Page* PageGenerator::generateStartPage(){ + +Page *PageGenerator::generateStartPage() { } -Page* PageGenerator::generateUserPage(UserData userData){ - Page *page = new Page(); - page->appendInBody(*new TextView("test", Type::H4, BClass::TEXT_NORMAL, "hello world")); +Page *PageGenerator::generateUserPage(UserData userData) { + Page *page = new Page(); + page->appendInBody(*new TextView("test", Type::H4, BClass::TEXT_NORMAL, + "hello world")); return page; } diff --git a/Sources/PageGenerator/PageGenerator.h b/Sources/PageGenerator/PageGenerator.h index 88df016..54ea827 100644 --- a/Sources/PageGenerator/PageGenerator.h +++ b/Sources/PageGenerator/PageGenerator.h @@ -6,26 +6,26 @@ #define CPPROJECT_PAGEGENERATOR_H #include -#include "Page/Page.h" -#include "Views/PersonView/PersonView.h" -#include "PageData/PageData.h" +#include +#include +#include -class PageGenerator{ +class PageGenerator { public: - Page* page; - PageGenerator() = default; + Page *page; - void organizeCells(Organize o, int& rows, int& cells, int count); + PageGenerator() = default; - Page* generateTablePage(std::vector userData, Organize o); + void organizeCells(Organize o, int &rows, int &cells, int count); - Page* generateStartPage(); + Page *generateTablePage(std::vector userData, Organize o); - Page* generateUserPage(UserData userData); + Page *generateStartPage(); + Page *generateUserPage(UserData userData); }; diff --git a/Sources/PageManager/PageManager.h b/Sources/PageManager/PageManager.h index 43a5b2f..9d311c4 100644 --- a/Sources/PageManager/PageManager.h +++ b/Sources/PageManager/PageManager.h @@ -10,25 +10,28 @@ #include #include -class PageManager{ +class PageManager { private: - PageData* data; - PageGenerator* pageGenerator; + PageData *data; + PageGenerator *pageGenerator; public: - PageManager(PageData* mData){ + PageManager(PageData *mData) { data = mData; pageGenerator = new PageGenerator(); } - ~PageManager(){ + + ~PageManager() { } - Page* generatePage(PageData &pageData){ - switch(pageData.getpageType()){ + Page *generatePage(PageData &pageData) { + switch (pageData.getpageType()) { case PageType::TABLE_OF_USERS : - return pageGenerator->generateTablePage(pageData.userData, pageData.getPageOrganizeType()); + return pageGenerator->generateTablePage(pageData.userData, + pageData.getPageOrganizeType()); case PageType::ONE_USER_PAGE : - return pageGenerator->generateUserPage(reinterpret_cast(data->userData[0])); + return pageGenerator->generateUserPage( + reinterpret_cast(data->userData[0])); case PageType::START_PAGE : return pageGenerator->generateStartPage(); @@ -36,27 +39,28 @@ class PageManager{ } - - void generatePages(){ + void generatePages() { std::ofstream out("tablepage.html"); - out <generateTablePage(data->userData, data->getPageOrganizeType())->toString(); + out << pageGenerator->generateTablePage(data->userData, + data->getPageOrganizeType())->toString(); out.close(); std::vector vecOfThreads; int i = 0; - for(auto& userData: data->userData) { + for (auto &userData: data->userData) { std::string name = "userpage" + std::to_string(i++); - vecOfThreads.push_back(std::thread(std::bind(&PageManager::threadGeneratePage, *this))); + vecOfThreads.push_back(std::thread( + std::bind(&PageManager::threadGeneratePage, *this))); } - for (std::thread & th : vecOfThreads) - { - if (th.joinable()){ + for (std::thread &th : vecOfThreads) { + if (th.joinable()) { th.join(); } } } - void threadGeneratePage(){ - UserData* testData = new UserData("slug","fname", "sname", "imgsrc",19); + void threadGeneratePage() { + UserData *testData = new UserData("slug", "fname", "sname", "imgsrc", + 19); std::ofstream out("file.txt"); out << pageGenerator->generateUserPage(*testData); out.close(); diff --git a/Sources/Views/Cell/CellView.cpp b/Sources/Views/Cell/CellView.cpp index 12edf04..850e53d 100644 --- a/Sources/Views/Cell/CellView.cpp +++ b/Sources/Views/Cell/CellView.cpp @@ -4,94 +4,100 @@ #include "CellView.h" -CellView::CellView(int mRows){ +CellView::CellView(int mRows) { type = enumToString(Type::CELL); rowsCount = mRows; } -CellView::CellView(int indx,int mRows){ + +CellView::CellView(int indx, int mRows) { type = enumToString(Type::CELL); rowsCount = mRows; index = indx; } -CellView::CellView(int indx, std::vector> rows){ +CellView::CellView(int indx, std::vector> rows) { type = enumToString(Type::CELL); rowsCount = rows.size(); index = indx; appendRows(rows); } -void CellView::setIndex(int indx){ +void CellView::setIndex(int indx) { index = indx; } -std::string CellView::toString(int depth){ +std::string CellView::toString(int depth) { std::string res; - if(depth == 0){ - res += "<"+type +">\n\n"; + if (depth == 0) { + res += "<" + type + ">\n\n"; depth++; } - if(!rows.empty()) { + if (!rows.empty()) { for (std::shared_ptr &v: rows) { res += v->toStringOpen(depth); depth++; if (!v->subviews.empty()) { res += v->toString(depth); } - res+=v->toStringClose(--depth); + res += v->toStringClose(--depth); } } - if(--depth == 0){ - res += " \n\n"; + if (--depth == 0) { + res += " \n\n"; } return res; } -std::string CellView::toStringOpen(int depth){ +std::string CellView::toStringOpen(int depth) { std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res += "<"+type +"> \n\n"; + res += "<" + type + "> \n\n"; return res; } -std::string CellView::toStringClose(int depth){ + +std::string CellView::toStringClose(int depth) { std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res += "\n\n"; + res += "\n\n"; return res; } -bool CellView::append(ContainerView &mView){ +bool CellView::append(ContainerView &mView) { return false; } -void CellView::appendRow(std::shared_ptr &mView){ + +void CellView::appendRow(std::shared_ptr &mView) { rows.push_back(mView); } -void CellView::appendRows(std::vector> mRows){ - if(rows.size() + mRows.size() <= rowsCount) { - for(std::shared_ptr& rowView : mRows){ +void CellView::appendRows(std::vector> mRows) { + if (rows.size() + mRows.size() <= rowsCount) { + for (std::shared_ptr &rowView : mRows) { rows.push_back(rowView); rowView->setIndex(rows.size()); } } } -bool CellView::appendInSubview(std::string subviewName, ContainerView& mView){ +bool CellView::appendInSubview(std::string subviewName, ContainerView &mView) { return false; } -bool CellView::removeSubview(std::string subviewName){ + +bool CellView::removeSubview(std::string subviewName) { return false; } -void CellView::destroy(){ + +void CellView::destroy() { } -CellView::~CellView(){ + +CellView::~CellView() { } \ No newline at end of file diff --git a/Sources/Views/Cell/CellView.h b/Sources/Views/Cell/CellView.h index 910fb71..25f17f4 100644 --- a/Sources/Views/Cell/CellView.h +++ b/Sources/Views/Cell/CellView.h @@ -8,28 +8,40 @@ #include "Container/ContainerView.h" #include "Row/RowView.h" -class CellView: public ContainerView { +class CellView : public ContainerView { public: int rowsCount;; int index; std::vector> rows; explicit CellView(int mRows); - CellView(int indx,int mRows); + + CellView(int indx, int mRows); + CellView(int indx, std::vector> rows); + ~CellView(); + void setIndex(int indx); - bool append(ContainerView &mView)override; + + bool append(ContainerView &mView) override; + void appendRow(std::shared_ptr &mView); + void appendRows(std::vector> mRows); - bool removeSubview(std::string subviewName) override ; - bool appendInSubview(std::string subviewName, ContainerView& mView) override; - void destroy()override; + + bool removeSubview(std::string subviewName) override; + + bool + appendInSubview(std::string subviewName, ContainerView &mView) override; + + void destroy() override; std::string toString(int depth) override; + std::string toStringOpen(int depth) override; - std::string toStringClose(int depth) override; + std::string toStringClose(int depth) override; }; diff --git a/Sources/Views/Container/ContainerView.h b/Sources/Views/Container/ContainerView.h index e8c269c..d9353cc 100644 --- a/Sources/Views/Container/ContainerView.h +++ b/Sources/Views/Container/ContainerView.h @@ -4,15 +4,15 @@ #ifndef CPPROJECT_CONTAINERVIEW_H #define CPPROJECT_CONTAINERVIEW_H + #include #include #include #include -#include "UserData/UserData.h" +#include -enum class BClass: uint8_t -{ +enum class BClass : uint8_t { CARD_DECK, CARD_MB4_SHADOW, CARD_BODY, @@ -23,8 +23,7 @@ enum class BClass: uint8_t TABLE, }; -enum class Type: uint8_t -{ +enum class Type : uint8_t { HTML, BODY, IMG, @@ -43,16 +42,10 @@ enum class Type: uint8_t CROSSORIGIN, - - - - - }; -inline const char* enumToString(Type t) -{ - switch (t) - { + +inline const char *enumToString(Type t) { + switch (t) { case Type::HTML : return "html"; @@ -95,11 +88,9 @@ inline const char* enumToString(Type t) return "[Unknown type]"; } } -inline const char* enumToString(BClass b) -{ - switch (b) - { +inline const char *enumToString(BClass b) { + switch (b) { case BClass::CARD_DECK : return "card-deck mb-3 text-center"; @@ -113,10 +104,10 @@ inline const char* enumToString(BClass b) return "card mb-4 shadow-sm"; case BClass::TEXT_NORMAL : - return "my-0 font-weight-normal"; + return "my-0 font-weight-normal"; case BClass::MB4 : - return "mb-4"; + return "mb-4"; case BClass::LIST_ITEM: return "list-group-item"; @@ -139,19 +130,27 @@ class ContainerView { std::vector> subviews; - virtual std::string toString(int depth) = 0; + virtual std::string toStringOpen(int depth) = 0; - virtual std::string toStringClose(int depth) = 0; + + virtual std::string toStringClose(int depth) = 0; virtual bool append(ContainerView &mView) = 0; - virtual bool appendInSubview(std::string subviewName, ContainerView& mView) = 0; + + virtual bool + appendInSubview(std::string subviewName, ContainerView &mView) = 0; + virtual bool removeSubview(std::string subviewName) = 0; + virtual void destroy() = 0; std::string getName(); + std::string getType(); + std::string getClass(); + ContainerView() = default; ContainerView(std::string n, Type t, std::string c); diff --git a/Sources/Views/ImageView/ImageView.cpp b/Sources/Views/ImageView/ImageView.cpp index ac2dc8e..87263fb 100644 --- a/Sources/Views/ImageView/ImageView.cpp +++ b/Sources/Views/ImageView/ImageView.cpp @@ -4,20 +4,24 @@ #include "ImageView.h" -bool ImageView::append(ContainerView &mView){ +bool ImageView::append(ContainerView &mView) { return false; } -bool ImageView::appendInSubview(std::string subviewName, ContainerView& mView){ + +bool ImageView::appendInSubview(std::string subviewName, ContainerView &mView) { return false; } -bool ImageView::removeSubview(std::string subviewName){ + +bool ImageView::removeSubview(std::string subviewName) { return false; } -void ImageView::destroy(){ + +void ImageView::destroy() { } -ImageView::ImageView(std::string n, Type t, BClass c, std::string s, int h, int w){ +ImageView::ImageView(std::string n, Type t, BClass c, std::string s, int h, + int w) { name = n; type = enumToString(t); _class = enumToString(c); @@ -25,21 +29,24 @@ ImageView::ImageView(std::string n, Type t, BClass c, std::string s, int h, int height = h; width = w; } + std::string ImageView::toStringOpen(int depth) { std::string res = ""; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res += "<"+type + " class=\""+ _class +"\" src=\"" + src + "\"" - + R"( alt="" width=")" + std::to_string(width) - + "\" height=\"" + std::to_string(height) + "\">\n\n"; + res += "<" + type + " class=\"" + _class + "\" src=\"" + src + "\"" + + R"( alt="" width=")" + std::to_string(width) + + "\" height=\"" + std::to_string(height) + "\">\n\n"; return res; } -std::string ImageView::toStringClose(int depth ) { + +std::string ImageView::toStringClose(int depth) { return ""; } + std::string ImageView::toString(int depth) { - return toStringOpen(depth)+toStringClose(depth); + return toStringOpen(depth) + toStringClose(depth); } ImageView::~ImageView() { diff --git a/Sources/Views/ImageView/ImageView.h b/Sources/Views/ImageView/ImageView.h index 969ee59..3624a38 100644 --- a/Sources/Views/ImageView/ImageView.h +++ b/Sources/Views/ImageView/ImageView.h @@ -6,24 +6,34 @@ #define CPPROJECT_IMAGEVIEW_H -#include "Container/ContainerView.h" +#include -class ImageView: public ContainerView{ +class ImageView : public ContainerView { private: std::string src; int height; int width; + void destroy() override; public: bool append(ContainerView &mView) override; - bool appendInSubview(std::string subviewName, ContainerView& mView) override; + + bool + appendInSubview(std::string subviewName, ContainerView &mView) override; + bool removeSubview(std::string subviewName) override; + ImageView() = default; + ~ImageView(); + ImageView(std::string n, Type t, BClass c, std::string s, int h, int w); + std::string toStringOpen(int depth) override; + std::string toStringClose(int depth) override; + std::string toString(int depth) override; }; diff --git a/Sources/Views/PersonView/PersonView.cpp b/Sources/Views/PersonView/PersonView.cpp index 58e58ef..a1dbc0b 100644 --- a/Sources/Views/PersonView/PersonView.cpp +++ b/Sources/Views/PersonView/PersonView.cpp @@ -8,12 +8,12 @@ PersonView::PersonView(UserData userData){ type = enumToString(Type::DIV); _class = enumToString(BClass::CARD_DECK); name = "PersonView"; -userImage = new ImageView("userImage", - Type::IMG, - BClass::MB4, - userData.imageUrl, - imageHeight, - imageWidth); + userImage = new ImageView("userImage", + Type::IMG, + BClass::MB4, + userData.imageUrl, + imageHeight, + imageWidth); username = new TextView("slug", Type::H4, BClass::TEXT_NORMAL, diff --git a/Sources/Views/PersonView/PersonView.h b/Sources/Views/PersonView/PersonView.h index 96f7c4c..08a3cdc 100644 --- a/Sources/Views/PersonView/PersonView.h +++ b/Sources/Views/PersonView/PersonView.h @@ -5,23 +5,24 @@ #ifndef CPPROJECT_PERSONVIEW_H #define CPPROJECT_PERSONVIEW_H -#include "View/View.h" -#include "ImageView/ImageView.h" -#include "TextView/TextView.h" -#include "TableView/TableView.h" +#include +#include +#include +#include -class PersonView: public View { +class PersonView : public View { public: const int cellCount = 3; const int rowsCount = 1; const int imageHeight = 256; const int imageWidth = 256; - ImageView* userImage; - TextView* username; - TableView* infoTable; + ImageView *userImage; + TextView *username; + TableView *infoTable; explicit PersonView(UserData userData); + ~PersonView(); private: diff --git a/Sources/Views/Row/RowView.cpp b/Sources/Views/Row/RowView.cpp index 8457952..9439372 100644 --- a/Sources/Views/Row/RowView.cpp +++ b/Sources/Views/Row/RowView.cpp @@ -5,24 +5,26 @@ #include "RowView.h" -RowView::RowView(int indx){ +RowView::RowView(int indx) { type = enumToString(Type::ROW); scope = "scope"; index = indx; } -RowView::RowView(int indx, ContainerView& containerView){ + +RowView::RowView(int indx, ContainerView &containerView) { type = enumToString(Type::ROW); scope = "scope"; index = indx; append(containerView); } -RowView::RowView(ContainerView& containerView){ + +RowView::RowView(ContainerView &containerView) { type = enumToString(Type::ROW); scope = "scope"; append(containerView); } -void RowView::setIndex(int indx){ +void RowView::setIndex(int indx) { index = indx; } diff --git a/Sources/Views/Row/RowView.h b/Sources/Views/Row/RowView.h index bdea099..59c00f2 100644 --- a/Sources/Views/Row/RowView.h +++ b/Sources/Views/Row/RowView.h @@ -6,17 +6,22 @@ #define CPPROJECT_ROWVIEW_H #include -class RowView: public View{ + +class RowView : public View { public: int index{}; std::string scope; + explicit RowView(int indx); - RowView(int indx, ContainerView& containerView); + + RowView(int indx, ContainerView &containerView); + ~RowView(); - explicit RowView( ContainerView& containerView); + + explicit RowView(ContainerView &containerView); + void setIndex(int indx); }; - #endif //CPPROJECT_ROWVIEW_H diff --git a/Sources/Views/SecondaryView/SecondaryView.cpp b/Sources/Views/SecondaryView/SecondaryView.cpp index 00aa752..90b5520 100644 --- a/Sources/Views/SecondaryView/SecondaryView.cpp +++ b/Sources/Views/SecondaryView/SecondaryView.cpp @@ -4,16 +4,17 @@ #include "SecondaryView.h" -SecondaryView::SecondaryView(std::string name, Type t, std::vector attr){ +SecondaryView::SecondaryView(std::string name, Type t, + std::vector attr) { attributes = attr; type = enumToString(t); } -std::string SecondaryView::toStringOpen(int depth){ +std::string SecondaryView::toStringOpen(int depth) { std::string res; - res+="<"+type+" "; - for(int i = 0; i < attributes.size();i++){ - res+=attributes[i].key + "=\"" + attributes[i].value+"\" "; + res += "<" + type + " "; + for (int i = 0; i < attributes.size(); i++) { + res += attributes[i].key + "=\"" + attributes[i].value + "\" "; } return res; } @@ -23,15 +24,16 @@ std::string SecondaryView::toStringClose(int depth) { } std::string SecondaryView::toString(int depth) { - return toStringOpen(depth)+toStringClose(depth); + return toStringOpen(depth) + toStringClose(depth); } -bool SecondaryView::appendInSubview(std::string subviewName, ContainerView& mView) { +bool +SecondaryView::appendInSubview(std::string subviewName, ContainerView &mView) { return false; } -bool SecondaryView::append(ContainerView &mView){ +bool SecondaryView::append(ContainerView &mView) { } diff --git a/Sources/Views/SecondaryView/SecondaryView.h b/Sources/Views/SecondaryView/SecondaryView.h index 5ead64c..e8bbf69 100644 --- a/Sources/Views/SecondaryView/SecondaryView.h +++ b/Sources/Views/SecondaryView/SecondaryView.h @@ -4,23 +4,28 @@ #ifndef CPPROJECT_SECONDARYVIEW_H #define CPPROJECT_SECONDARYVIEW_H -#include "View/View.h" +#include "View/View.h" #include -#include "Container/ContainerView.h" -class Attribute{ +#include + +class Attribute { public: std::string key; std::string value; - Attribute(std::string k, std::string v){ + + Attribute(std::string k, std::string v) { key = std::move(k); value = std::move(v); } }; -class SecondaryView: public ContainerView { + +class SecondaryView : public ContainerView { public: std::vector attributes; + SecondaryView(std::string name, Type t, std::vector attr); + ~SecondaryView(); std::string toStringOpen(int depth) override; @@ -30,7 +35,8 @@ class SecondaryView: public ContainerView { std::string toString(int depth) override; - bool appendInSubview(std::string subviewName, ContainerView& mView) override; + bool + appendInSubview(std::string subviewName, ContainerView &mView) override; bool append(ContainerView &mView) override; diff --git a/Sources/Views/TableView/TableView.cpp b/Sources/Views/TableView/TableView.cpp index 6c3ad7d..a171045 100644 --- a/Sources/Views/TableView/TableView.cpp +++ b/Sources/Views/TableView/TableView.cpp @@ -4,85 +4,88 @@ #include "TableView.h" -TableView::TableView(std::string mName,int mRows, int mCells){ +TableView::TableView(std::string mName, int mRows, int mCells) { type = enumToString(Type::TABLE); _class = enumToString(BClass::TABLE); name = mName; rowsCount = mRows; cellsCount = mCells; - append(*new View("tablediv",Type::DIV, BClass::CARD_DECK)); + append(*new View("tablediv", Type::DIV, BClass::CARD_DECK)); } -std::string TableView::toString(int depth){ +std::string TableView::toString(int depth) { std::string res; - if(depth == 0){ - res += "<"+type + " class=\""+ _class+"\"> \n\n"; + if (depth == 0) { + res += "<" + type + " class=\"" + _class + "\"> \n\n"; depth++; } - if(!cells.empty()) { + if (!cells.empty()) { for (std::shared_ptr v: cells) { res += v->toStringOpen(depth); depth++; if (!v->rows.empty()) { res += v->toString(depth); } - res+=v->toStringClose(--depth); + res += v->toStringClose(--depth); } } - if(--depth == 0){ - res += " \n\n"; + if (--depth == 0) { + res += " \n\n"; } return res; } -std::string TableView::toStringOpen(int depth){ +std::string TableView::toStringOpen(int depth) { std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res += "<"+type + " class=\""+ _class+"\"> \n\n"; + res += "<" + type + " class=\"" + _class + "\"> \n\n"; return res; } -std::string TableView::toStringClose(int depth){ + +std::string TableView::toStringClose(int depth) { std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res += " \n\n"; + res += " \n\n"; return res; } - -bool TableView::append(ContainerView &mView){ +bool TableView::append(ContainerView &mView) { subviews.emplace_back(mView); } -void TableView::appendCell(std::shared_ptr mView){ - if(cells.size() < cellsCount) { +void TableView::appendCell(std::shared_ptr mView) { + + if (cells.size() < cellsCount) { cells.push_back(mView); mView->setIndex(cells.size()); } } -void TableView::appendCells(std::vector> mViews){ - if(cells.size() + mViews.size() <= cellsCount) { - for(std::shared_ptr cellView : mViews){ +void TableView::appendCells(std::vector> mViews) { + + if (cells.size() + mViews.size() <= cellsCount) { + for (std::shared_ptr cellView : mViews) { cells.push_back(cellView); cellView->setIndex(cells.size()); } } } -bool TableView::appendInSubview(std::string subviewName, ContainerView& mView){ + +bool TableView::appendInSubview(std::string subviewName, ContainerView &mView) { } -bool TableView::appendRowInCell(int cellIndex, std::shared_ptr mView){ - if(cellIndex <= cellsCount && cells.size() + 1 <= cellsCount){ - if(cells[cellIndex]->rows.size() + 1 <= rowsCount){ +bool TableView::appendRowInCell(int cellIndex, std::shared_ptr mView) { + if (cellIndex <= cellsCount && cells.size() + 1 <= cellsCount) { + if (cells[cellIndex]->rows.size() + 1 <= rowsCount) { cells[cellIndex]->rows.emplace_back(mView); return true; } @@ -90,10 +93,11 @@ bool TableView::appendRowInCell(int cellIndex, std::shared_ptr mView){ return false; } -bool TableView::appendRowsInCell(int cellIndex, std::vector> mViews){ - if(cellIndex <= cellsCount && cells.size() < cellsCount){ - if(cells[cellIndex]->rows.size() + mViews.size() < cellsCount){ - for(std::shared_ptr &rowView: mViews){ +bool TableView::appendRowsInCell(int cellIndex, + std::vector> mViews) { + if (cellIndex <= cellsCount && cells.size() < cellsCount) { + if (cells[cellIndex]->rows.size() + mViews.size() < cellsCount) { + for (std::shared_ptr &rowView: mViews) { cells[cellIndex]->appendRow(rowView); rowView->setIndex(cells[cellIndex]->rows.size()); } @@ -105,7 +109,8 @@ bool TableView::appendRowsInCell(int cellIndex, std::vector mView); + void appendCells(std::vector> mViews); - bool appendInSubview(std::string subviewName, ContainerView& mView) override ; + + bool + appendInSubview(std::string subviewName, ContainerView &mView) override; + bool appendRowInCell(int cellIndex, std::shared_ptr mView); - bool appendRowsInCell(int cellIndex, std::vector> mViews); + + bool appendRowsInCell(int cellIndex, + std::vector> mViews); + bool removeSubview(std::string subviewName) override; + void destroy() override; }; diff --git a/Sources/Views/TextView/TextView.h b/Sources/Views/TextView/TextView.h index 18117fe..9f76e34 100644 --- a/Sources/Views/TextView/TextView.h +++ b/Sources/Views/TextView/TextView.h @@ -5,24 +5,36 @@ #ifndef CPPROJECT_TEXTVIEW_H #define CPPROJECT_TEXTVIEW_H -#include "Container/ContainerView.h" +#include -class TextView: public ContainerView{ +class TextView : public ContainerView { private: std::string text; public: bool append(ContainerView &mView) override; - bool appendInSubview(std::string subviewName, ContainerView& mView) override; + + bool + appendInSubview(std::string subviewName, ContainerView &mView) override; + bool removeSubview(std::string subviewName) override; + void destroy() override; + TextView(std::string n, Type t, BClass c, std::string txt); + TextView(std::string n, Type t, std::string txt); + ~TextView(); + void setText(std::string mText); + std::string getText(); + std::string toStringOpen(int depth) override; + std::string toStringClose(int depth) override; + std::string toString(int depth) override; }; diff --git a/Sources/Views/UserData/UserData.h b/Sources/Views/UserData/UserData.h index 9effc6f..f9549e8 100644 --- a/Sources/Views/UserData/UserData.h +++ b/Sources/Views/UserData/UserData.h @@ -14,6 +14,7 @@ class UserData{ std::string secondName; std::string imageUrl; int age; + UserData(std::string slg, std::string fn, std::string sn, std::string img, int a); }; diff --git a/Sources/Views/View/View.cpp b/Sources/Views/View/View.cpp index c350574..1195c8a 100644 --- a/Sources/Views/View/View.cpp +++ b/Sources/Views/View/View.cpp @@ -4,80 +4,81 @@ #include "View.h" -View::View(std::string n, Type t, BClass c){ +View::View(std::string n, Type t, BClass c) { name = n; type = enumToString(t); _class = enumToString(c); } -View::View(std::string n, Type t){ + +View::View(std::string n, Type t) { name = n; type = enumToString(t); _class = ""; } -std::string View::toStringOpen(int depth ) { +std::string View::toStringOpen(int depth) { std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; + res += "<" + getType() + " class=\"" + getClass() + "\">\n\n"; return res; } -std::string View::toStringClose(int depth ) { +std::string View::toStringClose(int depth) { std::string res; - for(int i=0;i<3*depth;i++){ - res+=" "; + for (int i = 0; i < 3 * depth; i++) { + res += " "; } - res+="\n\n"; + res += "\n\n"; return res; } -std::string View::toString(int depth ) { +std::string View::toString(int depth) { std::string res; - if(depth == 0){ - res += "<"+getType() + " class=\""+ getClass()+"\">\n\n"; + if (depth == 0) { + res += "<" + getType() + " class=\"" + getClass() + "\">\n\n"; depth++; } - if(!subviews.empty()) { + if (!subviews.empty()) { for (ContainerView &v: subviews) { res += v.toStringOpen(depth); depth++; if (!v.subviews.empty()) { res += v.toString(depth); } - res+=v.toStringClose(--depth); + res += v.toStringClose(--depth); } } - if(--depth == 0){ - res+="\n\n"; + if (--depth == 0) { + res += "\n\n"; } return res; } -bool View::appendInSubview(std::string subviewName, ContainerView& mView) { - for(ContainerView& v : subviews){ - if(std::strcmp(subviewName.data(), v.getName().data()) == 0){ +bool View::appendInSubview(std::string subviewName, ContainerView &mView) { + for (ContainerView &v : subviews) { + if (std::strcmp(subviewName.data(), v.getName().data()) == 0) { v.append(mView); return true; } - if(!v.subviews.empty()){ + if (!v.subviews.empty()) { v.appendInSubview(subviewName, mView); } } return false; } -bool View::append(ContainerView &mView){ +bool View::append(ContainerView &mView) { subviews.emplace_back(mView); } void View::destroy() { int i = 0; - for(ContainerView &v: subviews){ - if(!v.subviews.empty()){ + for (ContainerView &v: subviews) { + if (!v.subviews.empty()) { v.destroy(); } subviews.clear(); @@ -85,26 +86,27 @@ void View::destroy() { } } -bool View::removeSubview(std::string subviewName){ +bool View::removeSubview(std::string subviewName) { int i = 0; - for(ContainerView &v : subviews){ - auto it = std::find_if(v.subviews.begin(), v.subviews.end(), - [&](ContainerView &v) { - return std::strcmp(v.getName().data(),subviewName.data()); - }); - if(it == v.subviews.end()){ - v.subviews[i].get().destroy(); - v.subviews.erase( v.subviews.begin() + i); - } + for (ContainerView &v : subviews) { + auto it = std::find_if(v.subviews.begin(), v.subviews.end(), + [&](ContainerView &v) { + return std::strcmp(v.getName().data(), + subviewName.data()); + }); + if (it == v.subviews.end()) { + v.subviews[i].get().destroy(); + v.subviews.erase(v.subviews.begin() + i); + } - if(std::strcmp(subviewName.data(), v.getName().data()) == 0){ - v.destroy(); - } - if(!v.subviews.empty()){ - v.removeSubview(subviewName); - } - i++; + if (std::strcmp(subviewName.data(), v.getName().data()) == 0) { + v.destroy(); + } + if (!v.subviews.empty()) { + v.removeSubview(subviewName); } + i++; + } } View::~View() { diff --git a/Sources/Views/View/View.h b/Sources/Views/View/View.h index 101fc86..2b0079c 100644 --- a/Sources/Views/View/View.h +++ b/Sources/Views/View/View.h @@ -4,15 +4,18 @@ #ifndef CPPROJECT_VIEW_H #define CPPROJECT_VIEW_H -#include "Container/ContainerView.h" +#include -class View: public ContainerView{ +class View : public ContainerView { public: View() = default; + ~View(); + View(std::string n, Type t, BClass c); + View(std::string n, Type t); std::string toStringOpen(int depth = 0) override; @@ -21,13 +24,14 @@ class View: public ContainerView{ std::string toString(int depth = 0) override; - bool appendInSubview(std::string subviewName, ContainerView& mView) override; + bool + appendInSubview(std::string subviewName, ContainerView &mView) override; bool append(ContainerView &mView) override; bool removeSubview(std::string subviewName) override; - void destroy () override; + void destroy() override; }; diff --git a/Sources/main.cpp b/Sources/main.cpp index 63f48ef..de1d3fc 100644 --- a/Sources/main.cpp +++ b/Sources/main.cpp @@ -1,10 +1,7 @@ #include -#include -#include "Views/PersonView/PersonView.h" -#include "Views/Cell/CellView.h" -#include "Views/TableView/TableView.h" -#include "PageGenerator/PageGenerator.h" -#include "PageManager.h" +#include +#include +#include @@ -16,26 +13,26 @@ int main(){ std::vector userDataVec { - new UserData("1Stalin.su","Дмитрий", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), + new UserData("1Stalin.su","Дмитрий", "Болдин","https://sun9-70.userapi.com/c205424/v205424565/2840/Q9ExfkJtduQ.jpg",19 ), new UserData("2Kek","Дмитрий", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), - new UserData("3Averkiller","Александр", "Аверкиев","https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Anonymous.svg/866px-Anonymous.svg.png",69 ), + new UserData("3Averkiller","Александр", "Аверкиев","https://sun9-6.userapi.com/c857536/v857536032/10e4a0/yPxRO3gAIb0.jpg",69 ), - new UserData("4Stalin.su","Дмитрий2", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), + new UserData("4Stalin.su","Дмитрий2", "Болдин","https://sun9-70.userapi.com/c205424/v205424565/2840/Q9ExfkJtduQ.jpg",19 ), new UserData("5Kek","Дмитрий2", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), - new UserData("6Averkiller","Александр2", "Аверкиев","https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Anonymous.svg/866px-Anonymous.svg.png",69 ), + new UserData("6Averkiller","Александр2", "Аверкиев","https://sun9-6.userapi.com/c857536/v857536032/10e4a0/yPxRO3gAIb0.jpg",69 ), - new UserData("7Stalin.su","Дмитрий3", "Болдин","https://sun9-60.userapi.com/c855624/v855624982/135c19/xi-ReZmdN70.jpg",19 ), + new UserData("7Stalin.su","Дмитрий3", "Болдин","https://sun9-70.userapi.com/c205424/v205424565/2840/Q9ExfkJtduQ.jpg",19 ), new UserData("8Kek","Дмитрий3", "Гуляченков","https://sun9-14.userapi.com/c844321/v844321164/1e3f38/sjVui97PcoU.jpg",9 ), }; PageGenerator* pageGenerator = new PageGenerator(); - pageGenerator->generateTablePage( userDataVec,Organize::ONE_LINE_VERTICAL); + pageGenerator->generateTablePage( userDataVec,Organize::ONE_LINE_HORIZONTAL); std::cout<page->toString(); - PageData *pageData = new PageData(userDataVec,PageType::TABLE_OF_USERS,Organize::ONE_LINE_VERTICAL); + PageData *pageData = new PageData(userDataVec,PageType::TABLE_OF_USERS,Organize::ONE_LINE_HORIZONTAL); PageManager* pageManager = new PageManager(pageData); pageManager->generatePages(); - + return 0; } \ No newline at end of file