summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-26 14:11:00 +0200
committerOskar <[email protected]>2024-09-26 14:11:00 +0200
commit88f7c0cfde5bb7d5cb310dad788dce23382a249f (patch)
tree755a0d1bf636a929a294864bce6e967f7a9a9cfe
parent33182dd9dd7ceafce41ed7a7f57a21d159b1b4d5 (diff)
more
-rw-r--r--7p31.cpp25
-rw-r--r--7p32.cpp11
-rw-r--r--7p33.cpp20
-rw-r--r--screen.hpp108
4 files changed, 127 insertions, 37 deletions
diff --git a/7p31.cpp b/7p31.cpp
new file mode 100644
index 0000000..0be5a2f
--- /dev/null
+++ b/7p31.cpp
@@ -0,0 +1,25 @@
+
+/*
+ *
+ * 7.31
+ *
+ *
+ */
+
+class myY;
+
+class myX {
+public:
+ myY *Yptr;
+};
+
+class myY {
+public:
+ myX Xob;
+};
+
+int main () {
+
+
+ return 0;
+}
diff --git a/7p32.cpp b/7p32.cpp
new file mode 100644
index 0000000..2737423
--- /dev/null
+++ b/7p32.cpp
@@ -0,0 +1,11 @@
+
+/*
+ *
+ * 7.32
+ *
+ * Done in screen.hpp
+ */
+
+int main () {
+ return 0;
+}
diff --git a/7p33.cpp b/7p33.cpp
new file mode 100644
index 0000000..d771764
--- /dev/null
+++ b/7p33.cpp
@@ -0,0 +1,20 @@
+
+/*
+ *
+ * 7.33
+ *
+ *
+ */
+
+int main () {
+
+ /* Fixed version
+
+ Screen::pos Screen::size() const
+ {
+ return height * width;
+ }
+
+ */
+ return 0;
+}
diff --git a/screen.hpp b/screen.hpp
index 3afa53a..3912147 100644
--- a/screen.hpp
+++ b/screen.hpp
@@ -1,62 +1,96 @@
#ifndef SCREEN_H
#define SCREEN_H
+
#include <string>
+#include <vector>
#include <iostream>
+class Screen;
+
+class Window_mgr {
+public:
+ using screen_index = std::vector<Screen>::size_type; // size type
+ void clear(screen_index); // clear screen
+ Window_mgr(); //
+
+private:
+ std::vector<Screen> screens; // private data member
+};
+
class Screen {
+ friend void Window_mgr::clear(screen_index); // Tell screen class we have a friend function from Window_mgr
+
public:
- typedef std::string::size_type Pos;
+ using pos = std::string::size_type; // pos type
+ using content_type = char; // content type
Screen() = default;
- Screen(Pos ht, Pos wd): Height(ht), Width(wd), Contents(ht * wd, ' ') { }
- Screen(Pos ht, Pos wd, char c): Height(ht), Width(wd), Contents(ht * wd, c) { }
- char get() const { return Contents[Cursor]; }
- inline char get(Pos ht, Pos wd) const;
- Screen &move(Pos r, Pos c);
- inline Screen &set(char c);
- inline Screen &set(Pos r, Pos col, char ch);
- Screen &display(std::ostream &os) { do_display(os); return *this; }
- const Screen &display(std::ostream &os) const { do_display(os); return *this; }
- void printheight(Pos Height);
+ Screen(pos ht, pos wd): height(ht), width(wd), contents(ht * wd, ' ') {}
+ Screen(pos ht, pos wd, content_type c): height(ht), width(wd), contents(ht * wd, c) {}
+ const content_type &get() const { return contents[cursor]; }
+ const content_type &get(pos row, pos col) const;
+ Screen &set(content_type c);
+ Screen &set(pos row, pos col, content_type c);
+ Screen &move(pos row, pos col);
+ const Screen &display(std::ostream &os) const;
+ Screen &display(std::ostream &os);
+
private:
- void do_display(std::ostream &os) const {os << Contents;}
- Pos Cursor = 0;
- Pos Height = 0;
- Pos Width = 0;
- std::string Contents;
+ void do_display(std::ostream &os) const;
+ pos cursor = 0;
+ pos height = 0;
+ pos width = 0;
+ std::string contents;
};
-inline Screen &Screen::set(char c)
-{
- Contents[Cursor] = c; // set the new value at the current cursor location
+inline
+const Screen::content_type &Screen::get(pos row, pos col) const {
+ return contents[row * width + col];
+}
+
+inline
+Screen &Screen::set(content_type c) {
+ contents[cursor] = c;
return *this;
- // return this object as an lvalue
}
-inline Screen &Screen::set(Pos r, Pos col, char ch)
-{
- Contents[r*Width + col] = ch; // set specified location to given value
+inline
+Screen &Screen::set(pos row, pos col, content_type c) {
+ contents[row * width + col] = c;
return *this;
- // return this object as an lvalue
}
-inline Screen &Screen::move(Pos r, Pos c)
-{
- Pos row = r * Width; // compute the row location
- Cursor = row + c;
- // move cursor to the column within that row
+inline
+Screen &Screen::move(pos row, pos col) {
+ cursor = row * width + col;
return *this;
- // return this object as an lvalue
}
-char Screen::get(Pos r, Pos c) const // declared as inline in the class
-{
- Pos row = r * Width;
- // compute row location
- return Contents[row + c]; // return character at the given column
+inline
+const Screen &Screen::display(std::ostream &os) const {
+ do_display(os);
+ return *this;
+}
+
+inline
+Screen &Screen::display(std::ostream &os) {
+ do_display(os);
+ return *this;
}
-void printheight(Screen::Pos Height) {
- std::cout << Height;
+inline
+void Screen::do_display(std::ostream &os) const {
+ for (pos i = 0; i != contents.size(); ++i) {
+ os << contents[i];
+ if ((i + 1) % width == 0 && i + 1 != contents.size())
+ os << "\n";
+ }
+}
+
+Window_mgr::Window_mgr() : screens{Screen(24, 80)} {}
+
+void Window_mgr::clear(screen_index i) {
+ Screen &s = screens[i];
+ s.contents = std::string(s.height * s.width, ' ');
}
#endif