-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileAccess.cpp
More file actions
150 lines (97 loc) · 2.68 KB
/
Copy pathFileAccess.cpp
File metadata and controls
150 lines (97 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// Implementation of file access class.
//
#include "stdafx.h"
#include "FileAccess.h"
/**/
/*
FileAccess()
NAME
FileAccess() - Constructor that also opens file
SYNOPSIS
FileAccess::FileAccess( int argc, char *argv[] )
argc --> input from command line. holds number of inputs read
argv[] --> input from command line. holds what was read in an array
DESCRIPTION
This Constructor begins the process of reading the file by opening it
RETURNS
Does not Return anything.
AUTHOR
Victor Miller
DATE
7:26pm 12/19/2021
*/
/**/
FileAccess::FileAccess( int argc, char *argv[] )
{
// Check that there is exactly one run time parameter.
if( argc != 2 ) {
cerr << "Usage: Assem <FileName>" << endl;
exit( 1 );
}
// Open the file. One might question if this is the best place to open the file.
// One might also question whether we need a file access class.
m_sfile.open( argv[1], ios::in );
// If the open failed, report the error and terminate.
if( ! m_sfile ) {
cerr << "Source file could not be opened, assembler terminated." << endl;
exit( 1 );
}
}
FileAccess::~FileAccess( )
{
// Not that necessary in that the file will be closed when the program terminates, but good form.
m_sfile.close( );
}
/**/
/*
GetNextLine()
NAME
GetNextLine() - Gets the next line from file
SYNOPSIS
bool FileAccess::GetNextLine( string &a_line );
a_line --> a string holding the line, will input current line and set it to next line
DESCRIPTION
This function will set a_line to the next line in the file
RETURNS
Returns false if it cannot get the next line
Returns true if successfully gets next line
AUTHOR
Victor Miller
DATE
7:26pm 12/19/2021
*/
/**/
bool FileAccess::GetNextLine( string &a_line )
{
// If there is no more data, return false.
if( m_sfile.eof() ) {
return false;
}
getline( m_sfile, a_line );
// Return indicating success.
return true;
}
/**/
/*
rewind( )
NAME
rewind( ) - rewinds to top of file
SYNOPSIS
void FileAccess::rewind( );
DESCRIPTION
This function will bring allow us to read from the top of a file again
RETURNS
Returns void
AUTHOR
Victor Miller
DATE
7:26pm 12/19/2021
*/
/**/
// Clean all file flags and go back to the beginning of the file.
void FileAccess::rewind( )
{
m_sfile.clear();
m_sfile.seekg( 0, ios::beg );
}