From 6645dca35f70bbe295ab3e6bebf0bc3b5b8e68e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Skaaden?= Date: Wed, 15 Jan 2020 13:13:42 +0100 Subject: [PATCH] =?UTF-8?q?Added=20=C3=98ving=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Oving 1/.dep.inc | 5 + Oving 1/Makefile | 128 ++++ Oving 1/include/Graph_lib/GUI.cpp | 77 +++ Oving 1/include/Graph_lib/GUI.h | 167 +++++ Oving 1/include/Graph_lib/Graph.cpp | 358 ++++++++++ Oving 1/include/Graph_lib/Graph.h | 623 ++++++++++++++++++ Oving 1/include/Graph_lib/Makefile | 27 + Oving 1/include/Graph_lib/Point.h | 23 + Oving 1/include/Graph_lib/Simple_window.h | 48 ++ Oving 1/include/Graph_lib/Window.cpp | 76 +++ Oving 1/include/Graph_lib/Window.h | 56 ++ Oving 1/include/Graph_lib/fltk.h | 20 + Oving 1/include/std_lib_facilities.h | 261 ++++++++ Oving 1/main.cpp | 108 +++ Oving 1/nbproject/Makefile-Debug.mk | 83 +++ Oving 1/nbproject/Makefile-Release.mk | 83 +++ Oving 1/nbproject/Makefile-impl.mk | 133 ++++ Oving 1/nbproject/Makefile-variables.mk | 35 + Oving 1/nbproject/Package-Debug.bash | 76 +++ Oving 1/nbproject/Package-Release.bash | 76 +++ Oving 1/nbproject/configurations.xml | 69 ++ .../nbproject/private/Makefile-variables.mk | 7 + .../private/c_standard_headers_indexer.c | 75 +++ Oving 1/nbproject/private/configurations.xml | 72 ++ .../private/cpp_standard_headers_indexer.cpp | 135 ++++ Oving 1/nbproject/private/launcher.properties | 42 ++ Oving 1/nbproject/private/private.xml | 13 + Oving 1/nbproject/project.xml | 30 + 28 files changed, 2906 insertions(+) create mode 100644 Oving 1/.dep.inc create mode 100644 Oving 1/Makefile create mode 100644 Oving 1/include/Graph_lib/GUI.cpp create mode 100644 Oving 1/include/Graph_lib/GUI.h create mode 100644 Oving 1/include/Graph_lib/Graph.cpp create mode 100644 Oving 1/include/Graph_lib/Graph.h create mode 100644 Oving 1/include/Graph_lib/Makefile create mode 100644 Oving 1/include/Graph_lib/Point.h create mode 100644 Oving 1/include/Graph_lib/Simple_window.h create mode 100644 Oving 1/include/Graph_lib/Window.cpp create mode 100644 Oving 1/include/Graph_lib/Window.h create mode 100644 Oving 1/include/Graph_lib/fltk.h create mode 100644 Oving 1/include/std_lib_facilities.h create mode 100644 Oving 1/main.cpp create mode 100644 Oving 1/nbproject/Makefile-Debug.mk create mode 100644 Oving 1/nbproject/Makefile-Release.mk create mode 100644 Oving 1/nbproject/Makefile-impl.mk create mode 100644 Oving 1/nbproject/Makefile-variables.mk create mode 100644 Oving 1/nbproject/Package-Debug.bash create mode 100644 Oving 1/nbproject/Package-Release.bash create mode 100644 Oving 1/nbproject/configurations.xml create mode 100644 Oving 1/nbproject/private/Makefile-variables.mk create mode 100644 Oving 1/nbproject/private/c_standard_headers_indexer.c create mode 100644 Oving 1/nbproject/private/configurations.xml create mode 100644 Oving 1/nbproject/private/cpp_standard_headers_indexer.cpp create mode 100644 Oving 1/nbproject/private/launcher.properties create mode 100644 Oving 1/nbproject/private/private.xml create mode 100644 Oving 1/nbproject/project.xml diff --git a/Oving 1/.dep.inc b/Oving 1/.dep.inc new file mode 100644 index 0000000..38ba445 --- /dev/null +++ b/Oving 1/.dep.inc @@ -0,0 +1,5 @@ +# This code depends on make tool being used +DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES})) +ifneq (${DEPFILES},) +include ${DEPFILES} +endif diff --git a/Oving 1/Makefile b/Oving 1/Makefile new file mode 100644 index 0000000..05de621 --- /dev/null +++ b/Oving 1/Makefile @@ -0,0 +1,128 @@ +# +# There exist several targets which are by default empty and which can be +# used for execution of your targets. These targets are usually executed +# before and after some main targets. They are: +# +# .build-pre: called before 'build' target +# .build-post: called after 'build' target +# .clean-pre: called before 'clean' target +# .clean-post: called after 'clean' target +# .clobber-pre: called before 'clobber' target +# .clobber-post: called after 'clobber' target +# .all-pre: called before 'all' target +# .all-post: called after 'all' target +# .help-pre: called before 'help' target +# .help-post: called after 'help' target +# +# Targets beginning with '.' are not intended to be called on their own. +# +# Main targets can be executed directly, and they are: +# +# build build a specific configuration +# clean remove built files from a configuration +# clobber remove all built files +# all build all configurations +# help print help mesage +# +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and +# .help-impl are implemented in nbproject/makefile-impl.mk. +# +# Available make variables: +# +# CND_BASEDIR base directory for relative paths +# CND_DISTDIR default top distribution directory (build artifacts) +# CND_BUILDDIR default top build directory (object files, ...) +# CONF name of current configuration +# CND_PLATFORM_${CONF} platform name (current configuration) +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) +# CND_PACKAGE_NAME_${CONF} name of package (current configuration) +# CND_PACKAGE_PATH_${CONF} path to package (current configuration) +# +# NOCDDL + + +# Environment +MKDIR=mkdir +CP=cp +CCADMIN=CCadmin + + +# build +build: .build-post + +.build-pre: +# Add your pre 'build' code here... + +.build-post: .build-impl +# Add your post 'build' code here... + + +# clean +clean: .clean-post + +.clean-pre: +# Add your pre 'clean' code here... + +.clean-post: .clean-impl +# Add your post 'clean' code here... + + +# clobber +clobber: .clobber-post + +.clobber-pre: +# Add your pre 'clobber' code here... + +.clobber-post: .clobber-impl +# Add your post 'clobber' code here... + + +# all +all: .all-post + +.all-pre: +# Add your pre 'all' code here... + +.all-post: .all-impl +# Add your post 'all' code here... + + +# build tests +build-tests: .build-tests-post + +.build-tests-pre: +# Add your pre 'build-tests' code here... + +.build-tests-post: .build-tests-impl +# Add your post 'build-tests' code here... + + +# run tests +test: .test-post + +.test-pre: build-tests +# Add your pre 'test' code here... + +.test-post: .test-impl +# Add your post 'test' code here... + + +# help +help: .help-post + +.help-pre: +# Add your pre 'help' code here... + +.help-post: .help-impl +# Add your post 'help' code here... + + + +# include project implementation makefile +include nbproject/Makefile-impl.mk + +# include project make variables +include nbproject/Makefile-variables.mk diff --git a/Oving 1/include/Graph_lib/GUI.cpp b/Oving 1/include/Graph_lib/GUI.cpp new file mode 100644 index 0000000..f7b053d --- /dev/null +++ b/Oving 1/include/Graph_lib/GUI.cpp @@ -0,0 +1,77 @@ +#include "GUI.h" +#include "std_lib_facilities.h" +#include + +using namespace Graph_lib; + + +void Button::attach(Graph_lib::Window& win) +{ + pw = new Fl_Button(loc.x, loc.y, width, height, label.c_str()); + pw->callback(reinterpret_cast(do_it), &win); // pass the window + own = &win; +} + +int In_box::get_int() +{ + Fl_Input& pi = reference_to(pw); + const char* p = pi.value(); + if (!isdigit(p[0])) + return -999999; + return atoi(p); +} + +string In_box::get_string() +{ + Fl_Input& pi = reference_to(pw); + return string(pi.value()); +} + +void In_box::attach(Graph_lib::Window& win) +{ + pw = new Fl_Input(loc.x, loc.y, width, height, label.c_str()); + own = &win; +} + +void Out_box::put(int i) +{ + Fl_Output& po = reference_to(pw); + std::stringstream ss; + ss << i; + po.value(ss.str().c_str()); +} + +void Out_box::put(const string& s) +{ + reference_to(pw).value(s.c_str()); +} + +void Out_box::attach(Graph_lib::Window& win) +{ + pw = new Fl_Output(loc.x, loc.y, width, height, label.c_str()); + own = &win; +} + +int Menu::attach(Button& b) +{ + b.width = width; + b.height = height; + + switch (k) { + case horizontal: + b.loc = Point{loc.x + offset, loc.y}; + offset += b.width; + break; + case vertical: + b.loc = Point{loc.x, loc.y + offset}; + offset += b.height; + break; + } + selection.push_back(&b); + return int(selection.size() - 1); +} + +int Menu::attach(Button* p) +{ + return attach(*p); +} diff --git a/Oving 1/include/Graph_lib/GUI.h b/Oving 1/include/Graph_lib/GUI.h new file mode 100644 index 0000000..e8c831d --- /dev/null +++ b/Oving 1/include/Graph_lib/GUI.h @@ -0,0 +1,167 @@ + +// +// This is a GUI support code to the chapters 12-16 of the book +// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup +// + +#ifndef GUI_GUARD +#define GUI_GUARD + +#include "Window.h" +#include "Graph.h" + +namespace Graph_lib { + +//------------------------------------------------------------------------------ + +typedef void* Address; // Address is a synonym for void* +typedef void (*Callback)(Address, Address); // FLTK's required function type for all callbacks + +//------------------------------------------------------------------------------ + +template W& reference_to(Address pw) +// treat an address as a reference to a W +{ + return *static_cast(pw); +} + +//------------------------------------------------------------------------------ + +class Widget +{ + // Widget is a handle to an Fl_widget - it is *not* an Fl_widget + // We try to keep our interface classes at arm's length from FLTK +public: + Widget(Point xy, int w, int h, const string& s, Callback cb) + : loc(xy), width(w), height(h), label(s), do_it(cb) + {} + + void redraw() + { + pw->redraw(); // Schedules redrawing of widget, as per FLTK docs + } + + virtual void move(int dx, int dy) + { + hide(); + pw->position(loc.x += dx, loc.y += dy); + show(); + } + virtual void hide() + { + pw->hide(); + } + virtual void show() + { + pw->show(); + } + virtual void attach(Window&) = 0; + + virtual void clear_value() + {} + + virtual void set_label(string l) + { + label = l; + pw->label(label.c_str()); + } + + Point loc; + int width; + int height; + string label; + Callback do_it; + + virtual ~Widget() + {} + +protected: + Window* own; // every Widget belongs to a Window + Fl_Widget* pw; // connection to the FLTK Widget +private: + Widget& operator=(const Widget&); // don't copy Widgets + Widget(const Widget&); +}; + +//------------------------------------------------------------------------------ + +struct Button : Widget +{ + Button(Point xy, int w, int h, const string& label, Callback cb) : Widget(xy, w, h, label, cb) + {} + + void attach(Window&); +}; + +//------------------------------------------------------------------------------ + +struct In_box : Widget +{ + In_box(Point xy, int w, int h, const string& s) : Widget(xy, w, h, s, nullptr) + {} + int get_int(); + string get_string(); + void clear_value() override + { + static_cast(pw)->value(""); + } + + void attach(Window& win) override; +}; + +//------------------------------------------------------------------------------ + +struct Out_box : Widget +{ + Out_box(Point xy, int w, int h, const string& s) : Widget(xy, w, h, s, nullptr) + {} + void put(int); + void put(const string&); + + void attach(Graph_lib::Window& win) override; +}; + +//------------------------------------------------------------------------------ + +struct Menu : Widget +{ + enum Kind { horizontal, vertical }; + Menu(Point xy, int w, int h, Kind kk, const string& label) + : Widget(xy, w, h, label, nullptr), k(kk), offset(0) + {} + + Vector_ref