array demo
This commit is contained in:
@ -86,10 +86,11 @@ int main() {
|
||||
// TODO: Implement RBT tree interface implementation
|
||||
// TODO: Switch treealloc so the underlying tree can be swapped easily
|
||||
// TODO: Implement realloc so ArrayList can realloc instead of newly allocate bigger block
|
||||
// TODO: Array wrapper
|
||||
// DONE: Array wrapper
|
||||
// DONE: Rewrite Logging with a basic logger
|
||||
// TODO: String wrapper
|
||||
// DONE: Linked List
|
||||
// DONE: Iterator support for structures
|
||||
//
|
||||
// NOTE: Cleanup + Refactor
|
||||
// DONE: Use templates for queue so threads don't have to be casted down from chain
|
||||
@ -113,6 +114,7 @@ int main() {
|
||||
// DONE: Synchronize the outstream
|
||||
// TODO: Use singleton pattern for some device classes/classes used only in globals
|
||||
// TODO: Introduce name to threads?
|
||||
// DONE: Remove Iterator from List.h
|
||||
|
||||
// Scheduler doesn't return
|
||||
return 0;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "user/MainMenu.h"
|
||||
#include "user/demo/ArrayDemo.h"
|
||||
#include "user/demo/ArrayListDemo.h"
|
||||
#include "user/demo/BlueScreenDemo.h"
|
||||
#include "user/demo/HeapDemo.h"
|
||||
@ -55,11 +56,17 @@ void MainMenu::run() {
|
||||
case '7':
|
||||
choosen_demo = new PreemptiveThreadDemo(3);
|
||||
break;
|
||||
case '8':
|
||||
choosen_demo = new ArrayListDemo();
|
||||
break;
|
||||
case '9':
|
||||
choosen_demo = new LinkedListDemo();
|
||||
|
||||
// Temporary extra demos for testing
|
||||
|
||||
// case '0':
|
||||
// choosen_demo = new ArrayListDemo();
|
||||
// break;
|
||||
// case '0':
|
||||
// choosen_demo = new LinkedListDemo();
|
||||
// break;
|
||||
case '0':
|
||||
choosen_demo = new ArrayDemo();
|
||||
break;
|
||||
}
|
||||
|
||||
|
41
c_os/user/demo/ArrayDemo.cc
Normal file
41
c_os/user/demo/ArrayDemo.cc
Normal file
@ -0,0 +1,41 @@
|
||||
#include "user/demo/ArrayDemo.h"
|
||||
|
||||
void ArrayDemo::run() {
|
||||
Array<int, 10> arr1 {};
|
||||
Array<int, 10> arr2 {};
|
||||
Array<Thread*, 10> arr3 {};
|
||||
|
||||
kout.lock();
|
||||
kout.clear();
|
||||
|
||||
kout << "Adding..." << endl;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
arr1[i] = i;
|
||||
}
|
||||
|
||||
kout << "Iterator printing arr1:" << endl;
|
||||
for (int i : arr1) {
|
||||
kout << i << " ";
|
||||
}
|
||||
kout << endl;
|
||||
|
||||
kout << "Swapping arr1 and arr2..." << endl;
|
||||
arr1.swap(arr2);
|
||||
|
||||
kout << "Iterator printing arr1:" << endl;
|
||||
for (int i : arr1) {
|
||||
kout << i << " ";
|
||||
}
|
||||
kout << endl;
|
||||
|
||||
kout << "Iterator printing arr2:" << endl;
|
||||
for (int i : arr2) {
|
||||
kout << i << " ";
|
||||
}
|
||||
kout << endl;
|
||||
|
||||
// arr1.swap(arr3); // Not possible as type/size has to match
|
||||
|
||||
kout.unlock();
|
||||
scheduler.exit();
|
||||
}
|
19
c_os/user/demo/ArrayDemo.h
Normal file
19
c_os/user/demo/ArrayDemo.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __ArrayDemo_include__
|
||||
#define __ArrayDemo_include__
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
#include "user/lib/Array.h"
|
||||
|
||||
class ArrayDemo : public Thread {
|
||||
private:
|
||||
ArrayDemo(const ArrayDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
ArrayDemo() {
|
||||
kout << "Initialized ArrayDemo" << endl;
|
||||
}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user