VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
TextStorage.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "Macros.h"
16#include <sstream>
17#include <fstream>
18#include <vector>
19
20namespace vc64 {
21
22class TextStorage {
23
24 // Maximum number of stored lines
25 static constexpr usize capacity = 512;
26
27 // The stored lines
28 std::vector<string> storage;
29
30public:
31
32 // Optional output stream for debugging
33 std::ostream *ostream = nullptr;
34
35
36 //
37 // Reading
38 //
39
40public:
41
42 // Returns the number of stored lines
43 isize size() const { return (isize)storage.size(); }
44
45 // Returns a single line
46 string operator [] (isize i) const;
47 string& operator [] (isize i);
48
49 // Returns the whole storage contents
50 void text(string &all);
51
52
53 //
54 // Writing
55 //
56
57public:
58
59 // Initializes the storage with a single empty line
60 void clear();
61
62private:
63
64 // Appends a new line
65 void append(const string &line);
66
67public:
68
69 // Appends a single character or a string
70 TextStorage &operator<<(char c);
71 TextStorage &operator<<(const string &s);
72 TextStorage &operator<<(std::stringstream &ss);
73};
74
75}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16