Skip to content

Commit 0cbf95e

Browse files
committed
Move Load-Api to StringView
1 parent c6b2e20 commit 0cbf95e

12 files changed

Lines changed: 98 additions & 114 deletions

File tree

src/lcf/ldb/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ namespace LDB_Reader {
3030
/**
3131
* Loads Database.
3232
*/
33-
std::unique_ptr<lcf::rpg::Database> Load(const std::string& filename, const std::string& encoding);
33+
std::unique_ptr<lcf::rpg::Database> Load(StringView filename, StringView encoding = "");
3434

3535
/**
3636
* Saves Database.
3737
*/
38-
bool Save(const std::string& filename, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
38+
bool Save(StringView filename, const lcf::rpg::Database& db, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
3939

4040
/**
4141
* Saves Database as XML.
4242
*/
43-
bool SaveXml(const std::string& filename, const lcf::rpg::Database& db);
43+
bool SaveXml(StringView filename, const lcf::rpg::Database& db);
4444

4545
/**
4646
* Load Database as XML.
4747
*/
48-
std::unique_ptr<lcf::rpg::Database> LoadXml(const std::string& filename);
48+
std::unique_ptr<lcf::rpg::Database> LoadXml(StringView filename);
4949

5050
/**
5151
* Loads Database.
5252
*/
53-
std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, const std::string& encoding);
53+
std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, StringView encoding = "");
5454

5555
/**
5656
* Saves Database.
5757
*/
58-
bool Save(std::ostream& filestream, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
58+
bool Save(std::ostream& filestream, const lcf::rpg::Database& db, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
5959

6060
/**
6161
* Saves Database as XML.

src/lcf/lmt/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ namespace LMT_Reader {
2525
/**
2626
* Loads Map Tree.
2727
*/
28-
std::unique_ptr<lcf::rpg::TreeMap> Load(const std::string& filename, const std::string &encoding);
28+
std::unique_ptr<lcf::rpg::TreeMap> Load(StringView filename, StringView encoding = "");
2929

3030
/**
3131
* Saves Map Tree.
3232
*/
33-
bool Save(const std::string& filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
33+
bool Save(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
3434

3535
/**
3636
* Saves Map Tree as XML.
3737
*/
38-
bool SaveXml(const std::string& filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine);
38+
bool SaveXml(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine);
3939

4040
/**
4141
* Loads Map Tree as XML.
4242
*/
43-
std::unique_ptr<lcf::rpg::TreeMap> LoadXml(const std::string& filename);
43+
std::unique_ptr<lcf::rpg::TreeMap> LoadXml(StringView filename);
4444

4545
/**
4646
* Loads Map Tree.
4747
*/
48-
std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, const std::string &encoding);
48+
std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, StringView encoding = "");
4949

5050
/**
5151
* Saves Map Tree.
5252
*/
53-
bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
53+
bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
5454

5555
/**
5656
* Saves Map Tree as XML.

src/lcf/lmu/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ namespace LMU_Reader {
3030
/**
3131
* Loads map.
3232
*/
33-
std::unique_ptr<rpg::Map> Load(const std::string& filename, const std::string& encoding);
33+
std::unique_ptr<rpg::Map> Load(StringView filename, StringView encoding = "");
3434

3535
/**
3636
* Saves map.
3737
*/
38-
bool Save(const std::string& filename, const rpg::Map& map, EngineVersion engine, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
38+
bool Save(StringView filename, const rpg::Map& map, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
3939

4040
/**
4141
* Saves map as XML.
4242
*/
43-
bool SaveXml(const std::string& filename, const rpg::Map& map, EngineVersion engine);
43+
bool SaveXml(StringView filename, const rpg::Map& map, EngineVersion engine);
4444

4545
/**
4646
* Loads map as XML.
4747
*/
48-
std::unique_ptr<rpg::Map> LoadXml(const std::string& filename);
48+
std::unique_ptr<rpg::Map> LoadXml(StringView filename);
4949

5050
/**
5151
* Loads map.
5252
*/
53-
std::unique_ptr<rpg::Map> Load(std::istream& filestream, const std::string& encoding);
53+
std::unique_ptr<rpg::Map> Load(std::istream& filestream, StringView encoding = "");
5454

5555
/**
5656
* Saves map.
5757
*/
58-
bool Save(std::ostream& filestream, const rpg::Map& map, EngineVersion engine, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
58+
bool Save(std::ostream& filestream, const rpg::Map& map, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
5959

6060
/**
6161
* Saves map as XML.

src/lcf/lsd/reader.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ namespace LSD_Reader {
2727
/**
2828
* Converts from UNIX timestamp to Delphi's TDateTime format.
2929
*/
30-
double ToTDateTime(std::time_t const t);
30+
double ToTDateTime(std::time_t t);
3131

3232
/**
3333
* Converts from Delphi's TDateTime format to UNIX timestamp.
3434
*/
35-
std::time_t ToUnixTimestamp(double const ms);
35+
std::time_t ToUnixTimestamp(double ms);
3636

3737
/**
3838
* Returns current system time encoded in Delphi's TDateTime format.
3939
*/
40-
double GenerateTimestamp(std::time_t const t = std::time(NULL));
40+
double GenerateTimestamp(std::time_t t = std::time(nullptr));
4141

4242
/**
4343
* Increment the save save_count and update the timestamp.
@@ -47,32 +47,32 @@ namespace LSD_Reader {
4747
/**
4848
* Loads Savegame.
4949
*/
50-
std::unique_ptr<rpg::Save> Load(const std::string& filename, const std::string &encoding);
50+
std::unique_ptr<rpg::Save> Load(StringView filename, StringView encoding = "");
5151

5252
/**
5353
* Saves Savegame.
5454
*/
55-
bool Save(const std::string& filename, const rpg::Save& save, EngineVersion engine, const std::string &encoding);
55+
bool Save(StringView filename, const rpg::Save& save, EngineVersion engine, StringView encoding = "");
5656

5757
/*
5858
* Saves Savegame as XML.
5959
*/
60-
bool SaveXml(const std::string& filename, const rpg::Save& save, EngineVersion engine);
60+
bool SaveXml(StringView filename, const rpg::Save& save, EngineVersion engine);
6161

6262
/**
6363
* Loads Savegame as XML.
6464
*/
65-
std::unique_ptr<rpg::Save> LoadXml(const std::string& filename);
65+
std::unique_ptr<rpg::Save> LoadXml(StringView filename);
6666

6767
/**
6868
* Loads Savegame.
6969
*/
70-
std::unique_ptr<rpg::Save> Load(std::istream& filestream, const std::string &encoding);
70+
std::unique_ptr<rpg::Save> Load(std::istream& filestream, StringView encoding = "");
7171

7272
/**
7373
* Saves Savegame.
7474
*/
75-
bool Save(std::ostream& filestream, const rpg::Save& save, EngineVersion engine, const std::string &encoding);
75+
bool Save(std::ostream& filestream, const rpg::Save& save, EngineVersion engine, StringView encoding = "");
7676

7777
/*
7878
* Saves Savegame as XML.

src/lcf/reader_lcf.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ class LcfReader {
3838
* @param filestream already opened filestream.
3939
* @param encoding name of the encoding.
4040
*/
41-
LcfReader(std::istream& filestream, std::string encoding = "");
42-
43-
/**
44-
* Destructor. Closes the opened file.
45-
*/
46-
~LcfReader();
41+
explicit LcfReader(std::istream& filestream, std::string encoding = "");
4742

4843
/**
4944
* Returns the last set error.

src/lcf/writer_lcf.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ class LcfWriter {
4242
*/
4343
LcfWriter(std::ostream& filestream, EngineVersion engine, std::string encoding = "");
4444

45-
/**
46-
* Destructor. Closes the opened file.
47-
*/
48-
~LcfWriter();
49-
5045
/**
5146
* Writes raw data to the stream (fwrite() wrapper).
5247
*

src/ldb_reader.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,44 @@ void LDB_Reader::PrepareSave(rpg::Database& db) {
2222
++db.system.save_count;
2323
}
2424

25-
std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(const std::string& filename, const std::string& encoding) {
26-
std::ifstream stream(filename.c_str(), std::ios::binary);
25+
std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(StringView filename, StringView encoding) {
26+
std::ifstream stream(ToString(filename), std::ios::binary);
2727
if (!stream.is_open()) {
28-
fprintf(stderr, "Failed to open LDB file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
28+
fprintf(stderr, "Failed to open LDB file `%s' for reading : %s\n", ToString(filename).c_str(), strerror(errno));
2929
return nullptr;
3030
}
3131
return LDB_Reader::Load(stream, encoding);
3232
}
3333

34-
bool LDB_Reader::Save(const std::string& filename, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt) {
35-
std::ofstream stream(filename.c_str(), std::ios::binary);
34+
bool LDB_Reader::Save(StringView filename, const lcf::rpg::Database& db, StringView encoding, SaveOpt opt) {
35+
std::ofstream stream(ToString(filename), std::ios::binary);
3636
if (!stream.is_open()) {
37-
fprintf(stderr, "Failed to open LDB file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
37+
fprintf(stderr, "Failed to open LDB file `%s' for writing : %s\n", ToString(filename).c_str(), strerror(errno));
3838
return false;
3939
}
4040
return LDB_Reader::Save(stream, db, encoding, opt);
4141
}
4242

43-
bool LDB_Reader::SaveXml(const std::string& filename, const lcf::rpg::Database& db) {
44-
std::ofstream stream(filename.c_str(), std::ios::binary);
43+
bool LDB_Reader::SaveXml(StringView filename, const lcf::rpg::Database& db) {
44+
std::ofstream stream(ToString(filename), std::ios::binary);
4545
if (!stream.is_open()) {
46-
fprintf(stderr, "Failed to open LDB XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
46+
fprintf(stderr, "Failed to open LDB XML file `%s' for writing : %s\n", ToString(filename).c_str(), strerror(errno));
4747
return false;
4848
}
4949
return LDB_Reader::SaveXml(stream, db);
5050
}
5151

52-
std::unique_ptr<lcf::rpg::Database> LDB_Reader::LoadXml(const std::string& filename) {
53-
std::ifstream stream(filename.c_str(), std::ios::binary);
52+
std::unique_ptr<lcf::rpg::Database> LDB_Reader::LoadXml(StringView filename) {
53+
std::ifstream stream(ToString(filename), std::ios::binary);
5454
if (!stream.is_open()) {
55-
fprintf(stderr, "Failed to open LDB XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
55+
fprintf(stderr, "Failed to open LDB XML file `%s' for reading : %s\n", ToString(filename).c_str(), strerror(errno));
5656
return nullptr;
5757
}
5858
return LDB_Reader::LoadXml(stream);
5959
}
6060

61-
std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, const std::string& encoding) {
62-
LcfReader reader(filestream, encoding);
61+
std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, StringView encoding) {
62+
LcfReader reader(filestream, ToString(encoding));
6363
if (!reader.IsOk()) {
6464
LcfReader::SetError("Couldn't parse database file.\n");
6565
return nullptr;
@@ -87,9 +87,9 @@ std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, c
8787
return db;
8888
}
8989

90-
bool LDB_Reader::Save(std::ostream& filestream, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt) {
90+
bool LDB_Reader::Save(std::ostream& filestream, const lcf::rpg::Database& db, StringView encoding, SaveOpt opt) {
9191
const auto engine = GetEngineVersion(db);
92-
LcfWriter writer(filestream, engine, encoding);
92+
LcfWriter writer(filestream, engine, ToString(encoding));
9393
if (!writer.IsOk()) {
9494
LcfReader::SetError("Couldn't parse database file.\n");
9595
return false;

src/lmt_reader.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,44 @@
1818

1919
namespace lcf {
2020

21-
std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(const std::string& filename, const std::string& encoding) {
22-
std::ifstream stream(filename.c_str(), std::ios::binary);
21+
std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(StringView filename, StringView encoding) {
22+
std::ifstream stream(ToString(filename), std::ios::binary);
2323
if (!stream.is_open()) {
24-
fprintf(stderr, "Failed to open LMT file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
24+
fprintf(stderr, "Failed to open LMT file `%s' for reading : %s\n", ToString(filename).c_str(), strerror(errno));
2525
return nullptr;
2626
}
2727
return LMT_Reader::Load(stream, encoding);
2828
}
2929

30-
bool LMT_Reader::Save(const std::string& filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, const std::string& encoding, SaveOpt opt) {
31-
std::ofstream stream(filename.c_str(), std::ios::binary);
30+
bool LMT_Reader::Save(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding, SaveOpt opt) {
31+
std::ofstream stream(ToString(filename), std::ios::binary);
3232
if (!stream.is_open()) {
33-
fprintf(stderr, "Failed to open LMT file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
33+
fprintf(stderr, "Failed to open LMT file `%s' for writing : %s\n", ToString(filename).c_str(), strerror(errno));
3434
return false;
3535
}
3636
return LMT_Reader::Save(stream, tmap, engine, encoding, opt);
3737
}
3838

39-
bool LMT_Reader::SaveXml(const std::string& filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine) {
40-
std::ofstream stream(filename.c_str(), std::ios::binary);
39+
bool LMT_Reader::SaveXml(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine) {
40+
std::ofstream stream(ToString(filename), std::ios::binary);
4141
if (!stream.is_open()) {
42-
fprintf(stderr, "Failed to open LMT XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
42+
fprintf(stderr, "Failed to open LMT XML file `%s' for writing : %s\n", ToString(filename).c_str(), strerror(errno));
4343
return false;
4444
}
4545
return LMT_Reader::SaveXml(stream, tmap, engine);
4646
}
4747

48-
std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::LoadXml(const std::string& filename) {
49-
std::ifstream stream(filename.c_str(), std::ios::binary);
48+
std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::LoadXml(StringView filename) {
49+
std::ifstream stream(ToString(filename), std::ios::binary);
5050
if (!stream.is_open()) {
51-
fprintf(stderr, "Failed to open LMT XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
51+
fprintf(stderr, "Failed to open LMT XML file `%s' for reading : %s\n", ToString(filename).c_str(), strerror(errno));
5252
return nullptr;
5353
}
5454
return LMT_Reader::LoadXml(stream);
5555
}
5656

57-
std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(std::istream& filestream, const std::string &encoding) {
58-
LcfReader reader(filestream, encoding);
57+
std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(std::istream& filestream, StringView encoding) {
58+
LcfReader reader(filestream, ToString(encoding));
5959
if (!reader.IsOk()) {
6060
LcfReader::SetError("Couldn't parse map tree file.\n");
6161
return nullptr;
@@ -75,8 +75,8 @@ std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(std::istream& filestream, co
7575
return tmap;
7676
}
7777

78-
bool LMT_Reader::Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, const std::string &encoding, SaveOpt opt) {
79-
LcfWriter writer(filestream, engine, encoding);
78+
bool LMT_Reader::Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding, SaveOpt opt) {
79+
LcfWriter writer(filestream, engine, ToString(encoding));
8080
if (!writer.IsOk()) {
8181
LcfReader::SetError("Couldn't parse map tree file.\n");
8282
return false;

0 commit comments

Comments
 (0)