Skip to content

Commit 5e4c068

Browse files
committed
Codechange: Use std::string directly instead of via a typdef.
Additionally use const std::string & when possible.
1 parent b417099 commit 5e4c068

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

src/catcodec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
202202
strncpy(sfo_file, argv[2], sizeof(sfo_file));
203203
char *ext = strrchr(sfo_file, '.');
204204
if (ext == NULL || strlen(ext) != 4 || strcmp(ext, ".cat") != 0) {
205-
throw string("Unexpected extension; expected \".cat\"");
205+
throw std::string("Unexpected extension; expected \".cat\"");
206206
}
207207
strcpy(ext, ".sfo");
208208

@@ -235,7 +235,7 @@ int main(int argc, char *argv[])
235235
}
236236
if (_interactive) printf("\nDone\n");
237237

238-
} catch (const string &s) {
238+
} catch (const std::string &s) {
239239
fprintf(stderr, "An error occured: %s\n", s.c_str());
240240
ret = -1;
241241
}

src/io.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "stdafx.h"
2424
#include "io.hpp"
2525

26-
FileReader::FileReader(string filename, bool binary)
26+
FileReader::FileReader(const std::string &filename, bool binary)
2727
{
2828
this->file = fopen(filename.c_str(), binary ? "rb" : "r");
2929
this->filename = filename;
@@ -84,13 +84,13 @@ uint32_t FileReader::GetPos()
8484
return ftell(this->file);
8585
}
8686

87-
string FileReader::GetFilename() const
87+
const std::string &FileReader::GetFilename() const
8888
{
8989
return this->filename;
9090
}
9191

9292

93-
FileWriter::FileWriter(string filename, bool binary)
93+
FileWriter::FileWriter(const std::string &filename, bool binary)
9494
{
9595
this->filename_new = filename + ".new";
9696
this->filename = filename;
@@ -156,7 +156,7 @@ uint32_t FileWriter::GetPos()
156156
return ftell(this->file);
157157
}
158158

159-
string FileWriter::GetFilename() const
159+
const std::string &FileWriter::GetFilename() const
160160
{
161161
return this->filename;
162162
}
@@ -168,7 +168,7 @@ void FileWriter::Close()
168168
this->file = NULL;
169169

170170
/* Then remove the existing .bak file */
171-
string filename_bak = this->filename + ".bak";
171+
std::string filename_bak = this->filename + ".bak";
172172
if (unlink(filename_bak.c_str()) != 0 && errno != ENOENT) {
173173
fprintf(stderr, "Warning: could not remove %s (%s)\n", filename_bak.c_str(), strerror(errno));
174174
}

src/io.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,20 @@
2323
#ifndef IO_H
2424
#define IO_H
2525

26-
/** A string is a string; simple as that */
27-
typedef std::string string;
28-
2926
/**
3027
* Simple class to perform binary and string reading from a file.
3128
*/
3229
class FileReader {
3330
FILE *file; ///< The file to be read by this instance
34-
string filename; ///< The filename of the file
31+
std::string filename; ///< The filename of the file
3532

3633
public:
3734
/**
3835
* Create a new reader for the given file.
3936
* @param filename the file to read from
4037
* @param binary read the file as binary or text?
4138
*/
42-
FileReader(string filename, bool binary = true);
39+
FileReader(const std::string &filename, bool binary = true);
4340

4441
/**
4542
* Cleans up our mess
@@ -96,24 +93,24 @@ class FileReader {
9693
* Get the filename of this file.
9794
* @return the filename
9895
*/
99-
string GetFilename() const;
96+
const std::string &GetFilename() const;
10097
};
10198

10299
/**
103100
* Simple class to perform binary and string writing to a file.
104101
*/
105102
class FileWriter {
106103
FILE *file; ///< The file to be read by this instance
107-
string filename; ///< The filename of the file
108-
string filename_new; ///< The filename for the temporary file
104+
std::string filename; ///< The filename of the file
105+
std::string filename_new; ///< The filename for the temporary file
109106

110107
public:
111108
/**
112109
* Create a new writer for the given file.
113110
* @param filename the file to write to
114111
* @param binary write the file as binary or text?
115112
*/
116-
FileWriter(string filename, bool binary = true);
113+
FileWriter(const std::string &filename, bool binary = true);
117114

118115
/**
119116
* Cleans up our mess
@@ -162,7 +159,7 @@ class FileWriter {
162159
* Get the filename of this file.
163160
* @return the filename
164161
*/
165-
string GetFilename() const;
162+
const std::string &GetFilename() const;
166163

167164
/**
168165
* Close the output, i.e. commit the file to disk.

src/sample.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static const uint32_t RIFF_HEADER_SIZE = 44;
5555
* @param reader the reader to read from
5656
* @return the read string
5757
*/
58-
static string ReadString(FileReader &reader)
58+
static std::string ReadString(FileReader &reader)
5959
{
6060
uint8_t name_len = reader.ReadByte();
6161
char buffer[256];
@@ -71,7 +71,7 @@ static string ReadString(FileReader &reader)
7171
* @param str the string to write
7272
* @param writer the writer to write to
7373
*/
74-
static void WriteString(const string str, FileWriter &writer)
74+
static void WriteString(const std::string &str, FileWriter &writer)
7575
{
7676
uint8_t str_len = (uint8_t)(str.length() + 1);
7777
writer.WriteByte(str_len);
@@ -85,7 +85,7 @@ Sample::Sample(FileReader &reader)
8585
this->size = reader.ReadDword();
8686
}
8787

88-
Sample::Sample(string filename, string name) :
88+
Sample::Sample(const std::string &filename, const std::string &name) :
8989
offset(0),
9090
name(name),
9191
filename(filename)
@@ -210,12 +210,12 @@ void Sample::WriteCatEntry(FileWriter &writer) const
210210
WriteString(this->GetFilename(), writer);
211211
}
212212

213-
string Sample::GetName() const
213+
const std::string &Sample::GetName() const
214214
{
215215
return this->name;
216216
}
217217

218-
string Sample::GetFilename() const
218+
const std::string &Sample::GetFilename() const
219219
{
220220
return this->filename;
221221
}

src/sample.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Sample {
3434
uint32_t offset; ///< Offset from the begin of the cat
3535
uint32_t size; ///< The size of the WAV RIFF, i.e. excluding name and filename
3636

37-
string name; ///< The name of the sample
38-
string filename; ///< The filename of the sample
37+
std::string name; ///< The name of the sample
38+
std::string filename; ///< The filename of the sample
3939

4040
uint16_t num_channels; ///< Number of channels; either 1 or 2
4141
uint32_t sample_rate; ///< Sample rate; either 11025, 22050 or 44100
@@ -58,7 +58,7 @@ class Sample {
5858
* @param filename the file to read the sample from
5959
* @param name the name of the sample
6060
*/
61-
Sample(string filename, string name);
61+
Sample(const std::string &filename, const std::string &name);
6262

6363
/**
6464
* Reads a sample from a reader.
@@ -95,13 +95,13 @@ class Sample {
9595
* Get the name of the sample.
9696
* @return the name of the sample
9797
*/
98-
string GetName() const;
98+
const std::string &GetName() const;
9999

100100
/**
101101
* Get the filename of the sample
102102
* @return the filename of the sample
103103
*/
104-
string GetFilename() const;
104+
const std::string &GetFilename() const;
105105

106106

107107
/**

0 commit comments

Comments
 (0)