Skip to content

Commit 3d2060b

Browse files
committed
Replace shared_str with xr_string for log and fs.
1 parent 80433fa commit 3d2060b

File tree

10 files changed

+28
-37
lines changed

10 files changed

+28
-37
lines changed

src/utils/xrLCUtil/LevelCompilerLoggerWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ void LevelCompilerLoggerWindow::LogThreadProc()
101101
BOOL bWasChanges = FALSE;
102102
char tbuf[256];
103103
csLog.Enter();
104-
if (LogSize != LogFile->size())
104+
if (LogSize != LogFile.size())
105105
{
106106
bWasChanges = TRUE;
107-
for (; LogSize < LogFile->size(); LogSize++)
107+
for (; LogSize < LogFile.size(); LogSize++)
108108
{
109-
const char* S = *(*LogFile)[LogSize];
109+
const char* S = LogFile[LogSize].c_str();
110110
if (!S)
111111
S = "";
112112
SendMessage(hwLog, LB_ADDSTRING, 0, (LPARAM)S);

src/xrCore/FS.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class XRCORE_API IWriter
4141
xr_stack<u32> chunk_pos;
4242

4343
public:
44-
shared_str fName;
44+
xr_string fName;
4545

4646
public:
4747
IWriter() {}
48-
virtual ~IWriter() { R_ASSERT3(chunk_pos.empty(), "Opened chunk not closed.", *fName); }
48+
virtual ~IWriter() { R_ASSERT3(chunk_pos.empty(), "Opened chunk not closed.", fName.c_str()); }
4949
// kernel
5050
virtual void seek(u32 pos) = 0;
5151
virtual u32 tell() = 0;

src/xrCore/FS_internal.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class CFileWriter : public IWriter
2222
{
2323
R_ASSERT(name && name[0]);
2424
fName = name;
25-
VerifyPath(*fName);
25+
VerifyPath(fName.c_str());
2626
if (exclusive)
2727
{
28-
int handle = _sopen(*fName, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, SH_DENYWR);
28+
int handle = _sopen(fName.c_str(), _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, SH_DENYWR);
2929
#ifdef _EDITOR
3030
if (handle == -1)
3131
Msg("!Can't create file: '%s'. Error: '%s'.", *fName, _sys_errlist[errno]);
@@ -34,9 +34,9 @@ class CFileWriter : public IWriter
3434
}
3535
else
3636
{
37-
hf = fopen(*fName, "wb");
37+
hf = fopen(fName.c_str(), "wb");
3838
if (hf == 0)
39-
Msg("!Can't write file: '%s'. Error: '%s'.", *fName, _sys_errlist[errno]);
39+
Msg("!Can't write file: '%s'. Error: '%s'.", fName.c_str(), _sys_errlist[errno]);
4040
}
4141
}
4242

@@ -46,11 +46,11 @@ class CFileWriter : public IWriter
4646
{
4747
fclose(hf);
4848
// release RO attrib
49-
DWORD dwAttr = GetFileAttributes(*fName);
49+
DWORD dwAttr = GetFileAttributes(fName.c_str());
5050
if ((dwAttr != u32(-1)) && (dwAttr & FILE_ATTRIBUTE_READONLY))
5151
{
5252
dwAttr &= ~FILE_ATTRIBUTE_READONLY;
53-
SetFileAttributes(*fName, dwAttr);
53+
SetFileAttributes(fName.c_str(), dwAttr);
5454
}
5555
}
5656
}

src/xrCore/LocatorAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ void CLocatorAPI::w_close(IWriter*& S)
13711371
{
13721372
R_ASSERT(S->fName.size());
13731373
string_path fname;
1374-
xr_strcpy(fname, sizeof fname, *S->fName);
1374+
xr_strcpy(fname, sizeof fname, S->fName.c_str());
13751375
bool bReg = S->valid();
13761376
xr_delete(S);
13771377

src/xrCore/log.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static Lock logCS(MUTEX_PROFILE_ID(log));
1818
#else // CONFIG_PROFILE_LOCKS
1919
static Lock logCS;
2020
#endif // CONFIG_PROFILE_LOCKS
21-
xr_vector<shared_str>* LogFile = NULL;
21+
xr_vector<xr_string> LogFile;
2222
static LogCallback LogCB = 0;
2323

2424
void FlushLog()
@@ -29,9 +29,9 @@ void FlushLog()
2929
IWriter* f = FS.w_open(logFName);
3030
if (f)
3131
{
32-
for (u32 it = 0; it < LogFile->size(); it++)
32+
for (const auto &i : LogFile)
3333
{
34-
LPCSTR s = *((*LogFile)[it]);
34+
LPCSTR s = i.c_str();
3535
f->w_string(s ? s : "");
3636
}
3737
FS.w_close(f);
@@ -42,20 +42,14 @@ void FlushLog()
4242

4343
void AddOne(const char* split)
4444
{
45-
if (!LogFile)
46-
return;
47-
4845
logCS.Enter();
4946

5047
#ifdef DEBUG
5148
OutputDebugString(split);
5249
OutputDebugString("\n");
5350
#endif
5451

55-
{
56-
shared_str temp = shared_str(split);
57-
LogFile->push_back(temp);
58-
}
52+
LogFile.push_back(split);
5953

6054
// exec CallBack
6155
if (LogExecCB && LogCB)
@@ -191,9 +185,7 @@ LogCallback SetLogCB(const LogCallback& cb)
191185
LPCSTR log_name() { return (log_file_name); }
192186
void InitLog()
193187
{
194-
R_ASSERT(LogFile == NULL);
195-
LogFile = new xr_vector<shared_str>();
196-
LogFile->reserve(1000);
188+
LogFile.reserve(1000);
197189
}
198190

199191
void CreateLog(BOOL nl)
@@ -217,6 +209,5 @@ void CreateLog(BOOL nl)
217209
void CloseLog(void)
218210
{
219211
FlushLog();
220-
LogFile->clear();
221-
xr_delete(LogFile);
212+
LogFile.clear();
222213
}

src/xrCore/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void InitLog();
4242
void CloseLog();
4343
void XRCORE_API FlushLog();
4444

45-
extern XRCORE_API xr_vector<shared_str>* LogFile;
45+
extern XRCORE_API xr_vector<xr_string> LogFile;
4646
extern XRCORE_API BOOL LogExecCB;
4747

4848
#endif

src/xrEngine/Text_Console.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void CTextConsole::DrawLog(HDC hDC, RECT* pRect)
249249
TextOut(hDC, xb, Height - tm.tmHeight - 3, s_edt, xr_strlen(s_edt));
250250

251251
SetTextColor(hDC, RGB(205, 205, 225));
252-
u32 log_line = LogFile->size() - 1;
252+
u32 log_line = LogFile.size() - 1;
253253
string16 q, q2;
254254
xr_itoa(log_line, q, 10);
255255
xr_strcpy(q2, sizeof(q2), "[");
@@ -260,14 +260,14 @@ void CTextConsole::DrawLog(HDC hDC, RECT* pRect)
260260
TextOut(hDC, Width - 8 * qn, Height - tm.tmHeight - tm.tmHeight, q2, qn);
261261

262262
int ypos = Height - tm.tmHeight - tm.tmHeight;
263-
for (int i = LogFile->size() - 1 - scroll_delta; i >= 0; --i)
263+
for (int i = LogFile.size() - 1 - scroll_delta; i >= 0; --i)
264264
{
265265
ypos -= tm.tmHeight;
266266
if (ypos < y_top_max)
267267
{
268268
break;
269269
}
270-
LPCSTR ls = ((*LogFile)[i]).c_str();
270+
LPCSTR ls = LogFile[i].c_str();
271271

272272
if (!ls)
273273
{

src/xrEngine/XR_IOConsole.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void CConsole::OnRender()
329329
}
330330

331331
// ---------------------
332-
u32 log_line = LogFile->size() - 1;
332+
u32 log_line = LogFile.size() - 1;
333333
ypos -= LDIST;
334334
for (int i = log_line - scroll_delta; i >= 0; --i)
335335
{
@@ -338,7 +338,7 @@ void CConsole::OnRender()
338338
{
339339
break;
340340
}
341-
LPCSTR ls = ((*LogFile)[i]).c_str();
341+
LPCSTR ls = LogFile[i].c_str();
342342

343343
if (!ls)
344344
{

src/xrEngine/XR_IOConsole_callback.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void CConsole::Register_callbacks()
4343
void CConsole::Prev_log() // DIK_PRIOR=PAGE_UP
4444
{
4545
scroll_delta++;
46-
if (scroll_delta > int(LogFile->size()) - 1)
46+
if (scroll_delta > int(LogFile.size()) - 1)
4747
{
48-
scroll_delta = LogFile->size() - 1;
48+
scroll_delta = LogFile.size() - 1;
4949
}
5050
}
5151

@@ -60,7 +60,7 @@ void CConsole::Next_log() // DIK_NEXT=PAGE_DOWN
6060

6161
void CConsole::Begin_log() // PAGE_UP+Ctrl
6262
{
63-
scroll_delta = LogFile->size() - 1;
63+
scroll_delta = LogFile.size() - 1;
6464
}
6565

6666
void CConsole::End_log() // PAGE_DOWN+Ctrl

src/xrGame/console_commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ class CCC_ClearLog : public IConsole_Command
736736
CCC_ClearLog(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = true; };
737737
virtual void Execute(LPCSTR)
738738
{
739-
LogFile->clear();
739+
LogFile.clear();
740740
FlushLog();
741741
Msg("* Log file has been cleaned successfully!");
742742
}

0 commit comments

Comments
 (0)