Created a memory stream
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
This commit is contained in:
parent
f3404e7b11
commit
3ed9bc885a
@ -1,13 +1,69 @@
|
||||
// Assignment 1 (C++).cpp : This file contains the 'main' function. Program execution begins and ends there.
|
||||
// Assignment 1 (C++).cpp : This file contains the 'main' function. Program execution begins and ends there.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello World!\n";
|
||||
std::cout << "┌────────────────────────────────────────────────┐\n";
|
||||
std::cout << "│ 159.341 2021 Semester 1, Assignment 1 (C++) │\n";
|
||||
std::cout << "│ Submitted by Brychan Dempsey, 14299890 │\n";
|
||||
std::cout << "└────────────────────────────────────────────────┘\n";
|
||||
|
||||
bool exit = false;
|
||||
while (!exit) {
|
||||
std::vector<char> MemoryChars(1024); // Pre-reserve
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct MemoryStream {
|
||||
private:
|
||||
long position = 0;
|
||||
long length = 0;
|
||||
std::vector<char> chars;
|
||||
|
||||
bool ensureCapacity(long step) {
|
||||
// Size exceeds the bounds of the vector, resize
|
||||
if (position + step >= chars.size()) {
|
||||
chars.resize(position + step);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
MemoryStream(long Reserved) {
|
||||
chars.assign(Reserved, 0);
|
||||
}
|
||||
|
||||
char ReadChar() {
|
||||
if (++position >= length) return -1;
|
||||
return chars[position];
|
||||
}
|
||||
|
||||
char PeekChar() {
|
||||
char result = ReadChar();
|
||||
position--;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool writeChar(char c) {
|
||||
ensureCapacity(1);
|
||||
if (position == length) length++;
|
||||
chars[++position] = c;
|
||||
}
|
||||
|
||||
bool writeChars(char* c, int count) {
|
||||
ensureCapacity(count);
|
||||
if (position >= length - count) length = position + count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
chars[i + position] = *(c + i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
|
||||
// Debug program: F5 or Debug > Start Debugging menu
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user