Skip to content

Commit

Permalink
Replace shared_str operator* by c_str() for xrCore
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Nov 13, 2017
1 parent 2039fc6 commit 7b342ee
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 76 deletions.
6 changes: 3 additions & 3 deletions src/xrCore/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class XRCORE_API IWriter

public:
IWriter() {}
virtual ~IWriter() { R_ASSERT3(chunk_pos.empty(), "Opened chunk not closed.", *fName); }
virtual ~IWriter() { R_ASSERT3(chunk_pos.empty(), "Opened chunk not closed.", fName.c_str()); }
// kernel
virtual void seek(u32 pos) = 0;
virtual u32 tell() = 0;
Expand All @@ -71,12 +71,12 @@ class XRCORE_API IWriter
IC void w_stringZ(const char* p) { w(p, (u32)xr_strlen(p) + 1); }
IC void w_stringZ(const shared_str& p)
{
w(*p ? *p : "", p.size());
w(p.c_str() ? p.c_str() : "", p.size());
w_u8(0);
}
IC void w_stringZ(shared_str& p)
{
w(*p ? *p : "", p.size());
w(p.c_str() ? p.c_str() : "", p.size());
w_u8(0);
}
IC void w_stringZ(const xr_string& p)
Expand Down
14 changes: 7 additions & 7 deletions src/xrCore/FS_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ class CFileWriter : public IWriter
{
R_ASSERT(name && name[0]);
fName = name;
VerifyPath(*fName);
VerifyPath(fName.c_str());
if (exclusive)
{
int handle = _sopen(*fName, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, SH_DENYWR);
int handle = _sopen(fName.c_str(), _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, SH_DENYWR);
#ifdef _EDITOR
if (handle == -1)
Msg("!Can't create file: '%s'. Error: '%s'.", *fName, _sys_errlist[errno]);
Msg("!Can't create file: '%s'. Error: '%s'.", fName.c_str(), _sys_errlist[errno]);
#endif
hf = _fdopen(handle, "wb");
}
else
{
hf = fopen(*fName, "wb");
hf = fopen(fName.c_str(), "wb");
if (hf == 0)
Msg("!Can't write file: '%s'. Error: '%s'.", *fName, _sys_errlist[errno]);
Msg("!Can't write file: '%s'. Error: '%s'.", fName.c_str(), _sys_errlist[errno]);
}
}

Expand All @@ -46,11 +46,11 @@ class CFileWriter : public IWriter
{
fclose(hf);
// release RO attrib
DWORD dwAttr = GetFileAttributes(*fName);
DWORD dwAttr = GetFileAttributes(fName.c_str());
if ((dwAttr != u32(-1)) && (dwAttr & FILE_ATTRIBUTE_READONLY))
{
dwAttr &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(*fName, dwAttr);
SetFileAttributes(fName.c_str(), dwAttr);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ LPCSTR EFS_Utils::AppendFolderToName(
{
*d = 0;
if (depth < sv_depth)
xr_strcat(dest_name, dest_name_size, *tmp);
xr_strcat(dest_name, dest_name_size, tmp.c_str());
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void CLocatorAPI::archive::open()
if (hSrcFile && hSrcMap)
return;

hSrcFile = CreateFile(*path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
hSrcFile = CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
R_ASSERT(hSrcFile != INVALID_HANDLE_VALUE);
hSrcMap = CreateFileMapping(hSrcFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
R_ASSERT(hSrcMap != INVALID_HANDLE_VALUE);
Expand Down Expand Up @@ -1137,7 +1137,7 @@ void CLocatorAPI::file_from_archive(IReader*& R, pcstr fname, const file& desc)
VERIFY3(ptr, "cannot create file mapping on file", fname);

string512 temp;
xr_sprintf(temp, sizeof temp, "%s:%s", *A.path, fname);
xr_sprintf(temp, sizeof temp, "%s:%s", A.path.c_str(), fname);

#ifdef FS_DEBUG
register_file_mapping(ptr, sz, temp);
Expand Down Expand Up @@ -1371,7 +1371,7 @@ void CLocatorAPI::w_close(IWriter*& S)
{
R_ASSERT(S->fName.size());
string_path fname;
xr_strcpy(fname, sizeof fname, *S->fName);
xr_strcpy(fname, sizeof fname, S->fName.c_str());
bool bReg = S->valid();
xr_delete(S);

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/PostProcess/PostProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class XRCORE_API BasicPostProcessAnimator
virtual ~BasicPostProcessAnimator();
void Clear();
virtual void Load(LPCSTR name, bool internalFs = true);
IC LPCSTR Name() { return *m_Name; }
IC LPCSTR Name() { return m_Name.c_str(); }
virtual void Stop(float speed);
void SetDesiredFactor(float f, float sp);
void SetCurrentFactor(float f);
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/XML/XMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void XMLDocument::Load(pcstr path_alias, pcstr path, pcstr _xml_filename)
shared_str fn = correct_file_name(path, _xml_filename);

string_path str;
xr_sprintf(str, "%s\\%s", path, *fn);
xr_sprintf(str, "%s\\%s", path, fn.c_str());
return Load(path_alias, str);
}

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void FlushLog()
{
for (u32 it = 0; it < LogFile->size(); it++)
{
LPCSTR s = *((*LogFile)[it]);
pcstr s = (*LogFile)[it].c_str();
f->w_string(s ? s : "");
}
FS.w_close(f);
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/net_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ class XRCORE_API NET_Packet
IC void w_stringZ(const shared_str& p)
{
W_guard g(&w_allow);
if (*p)
w(*p, p.size() + 1);
if (p.c_str())
w(p.c_str(), p.size() + 1);
else
{
IIniFileStream* tmp = inistream;
Expand Down
60 changes: 30 additions & 30 deletions src/xrCore/xr_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ void CInifile::Destroy(CInifile* ini) { xr_delete(ini); }

bool sect_pred(const CInifile::Sect* x, pcstr val)
{
return xr_strcmp(*x->Name, val) < 0;
return xr_strcmp(x->Name.c_str(), val) < 0;
}

bool item_pred(const CInifile::Item& x, pcstr val)
{
if (!x.first || !val)
return x.first < val;
return xr_strcmp(*x.first, val) < 0;
return xr_strcmp(x.first.c_str(), val) < 0;
}

XRCORE_API bool _parse(pstr dest, pcstr src)
Expand Down Expand Up @@ -87,10 +87,10 @@ XRCORE_API void _decorate(pstr dest, pcstr src)
bool CInifile::Sect::line_exist(pcstr line, pcstr* value)
{
auto A = std::lower_bound(Data.begin(), Data.end(), line, item_pred);
if (A != Data.end() && xr_strcmp(*A->first, line) == 0)
if (A != Data.end() && xr_strcmp(A->first.c_str(), line) == 0)
{
if (value)
*value = *A->second;
*value = A->second.c_str();
return true;
}
return false;
Expand Down Expand Up @@ -147,7 +147,7 @@ CInifile::~CInifile()

static void insert_item(CInifile::Sect* tgt, const CInifile::Item& I)
{
auto sect_it = std::lower_bound(tgt->Data.begin(), tgt->Data.end(), *I.first, item_pred);
auto sect_it = std::lower_bound(tgt->Data.begin(), tgt->Data.end(), I.first.c_str(), item_pred);
if (sect_it != tgt->Data.end() && sect_it->first.equal(I.first))
{
sect_it->second = I.second;
Expand Down Expand Up @@ -240,9 +240,9 @@ void CInifile::Load(IReader* F, pcstr path, allow_include_func_t allow_include_f
if (Current)
{
// store previous section
auto I = std::lower_bound(DATA.begin(), DATA.end(), *Current->Name, sect_pred);
auto I = std::lower_bound(DATA.begin(), DATA.end(), Current->Name.c_str(), sect_pred);
if (I != DATA.end() && (*I)->Name == Current->Name)
xrDebug::Fatal(DEBUG_INFO, "Duplicate section '%s' found.", *Current->Name);
xrDebug::Fatal(DEBUG_INFO, "Duplicate section '%s' found.", Current->Name.c_str());
DATA.insert(I, Current);
}
Current = new Sect();
Expand Down Expand Up @@ -329,11 +329,11 @@ void CInifile::Load(IReader* F, pcstr path, allow_include_func_t allow_include_f
//#endif

if (m_flags.test(eReadOnly))
if (*I.first)
if (I.first.c_str())
insert_item(Current, I);
else
{
if (*I.first || *I.second
if (I.first.c_str() || I.second.c_str()
//#ifdef DEBUG
// || *I.comment
//#endif
Expand All @@ -345,9 +345,9 @@ void CInifile::Load(IReader* F, pcstr path, allow_include_func_t allow_include_f
}
if (Current)
{
auto I = std::lower_bound(DATA.begin(), DATA.end(), *Current->Name, sect_pred);
auto I = std::lower_bound(DATA.begin(), DATA.end(), Current->Name.c_str(), sect_pred);
if (I != DATA.end() && (*I)->Name == Current->Name)
xrDebug::Fatal(DEBUG_INFO, "Duplicate section '%s' found.", *Current->Name);
xrDebug::Fatal(DEBUG_INFO, "Duplicate section '%s' found.", Current->Name.c_str());
DATA.insert(I, Current);
}
}
Expand All @@ -369,11 +369,11 @@ void CInifile::save_as(IWriter& writer, bool bcheck) const
for (auto s_it = (*r_it)->Data.begin(); s_it != (*r_it)->Data.end(); ++s_it)
{
const Item& I = *s_it;
if (*I.first)
if (I.first.c_str())
{
if (*I.second)
if (I.second.c_str())
{
_decorate(val, *I.second);
_decorate(val, I.second.c_str());
// only name and value
xr_sprintf(temp, sizeof temp, "%8s%-32s = %-32s", " ", I.first.c_str(), val);
}
Expand Down Expand Up @@ -415,7 +415,7 @@ bool CInifile::save_as(pcstr new_fname)
bool CInifile::section_exist(pcstr S) const
{
auto I = std::lower_bound(DATA.begin(), DATA.end(), S, sect_pred);
return I != DATA.end() && xr_strcmp(*(*I)->Name, S) == 0;
return I != DATA.end() && xr_strcmp((*I)->Name.c_str(), S) == 0;
}

bool CInifile::line_exist(pcstr S, pcstr L) const
Expand All @@ -424,7 +424,7 @@ bool CInifile::line_exist(pcstr S, pcstr L) const
return false;
Sect& I = r_section(S);
auto A = std::lower_bound(I.Data.begin(), I.Data.end(), L, item_pred);
return A != I.Data.end() && xr_strcmp(*A->first, L) == 0;
return A != I.Data.end() && xr_strcmp(A->first.c_str(), L) == 0;
}

u32 CInifile::line_count(pcstr Sname) const
Expand All @@ -433,17 +433,17 @@ u32 CInifile::line_count(pcstr Sname) const
auto I = S.Data.cbegin();
u32 C = 0;
for (; I != S.Data.cend(); I++)
if (*I->first)
if (I->first.c_str())
C++;
return C;
}

u32 CInifile::section_count() const { return DATA.size(); }
//--------------------------------------------------------------------------------------
CInifile::Sect& CInifile::r_section(const shared_str& S) const { return r_section(*S); }
bool CInifile::line_exist(const shared_str& S, const shared_str& L)const { return line_exist(*S, *L); }
u32 CInifile::line_count(const shared_str& S) const { return line_count(*S); }
bool CInifile::section_exist(const shared_str& S) const { return section_exist(*S); }
CInifile::Sect& CInifile::r_section(const shared_str& S) const { return r_section(S.c_str()); }
bool CInifile::line_exist(const shared_str& S, const shared_str& L)const { return line_exist(S.c_str(), L.c_str()); }
u32 CInifile::line_count(const shared_str& S) const { return line_count(S.c_str()); }
bool CInifile::section_exist(const shared_str& S) const { return section_exist(S.c_str()); }
//--------------------------------------------------------------------------------------
// Read functions
//--------------------------------------------------------------------------------------
Expand All @@ -453,7 +453,7 @@ CInifile::Sect& CInifile::r_section(pcstr S) const
xr_strcpy(section, sizeof section, S);
xr_strlwr(section);
auto I = std::lower_bound(DATA.cbegin(), DATA.cend(), section, sect_pred);
if (!(I != DATA.cend() && xr_strcmp(*(*I)->Name, section) == 0))
if (!(I != DATA.cend() && xr_strcmp((*I)->Name.c_str(), section) == 0))
{
// g_pStringContainer->verify();

Expand All @@ -477,8 +477,8 @@ pcstr CInifile::r_string(pcstr S, pcstr L) const
Sect const& I = r_section(S);
auto A = std::lower_bound(I.Data.cbegin(), I.Data.cend(), L, item_pred);

if (A != I.Data.cend() && xr_strcmp(*A->first, L) == 0)
return *A->second;
if (A != I.Data.cend() && xr_strcmp(A->first.c_str(), L) == 0)
return A->second.c_str();

xrDebug::Fatal(DEBUG_INFO, "Can't find variable %s in [%s]", L, S);
return nullptr;
Expand Down Expand Up @@ -659,14 +659,14 @@ bool CInifile::r_line(pcstr S, int L, pcstr* N, pcstr* V) const
for (auto I = SS.Data.cbegin(); I != SS.Data.cend(); I++)
if (!L--)
{
*N = *I->first;
*V = *I->second;
*N = I->first.c_str();
*V = I->second.c_str();
return true;
}
return false;
}

bool CInifile::r_line(const shared_str& S, int L, pcstr* N, pcstr* V) const { return r_line(*S, L, N, V); }
bool CInifile::r_line(const shared_str& S, int L, pcstr* N, pcstr* V) const { return r_line(S.c_str(), L, N, V); }
//--------------------------------------------------------------------------------------------------------
// Write functions
//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -703,12 +703,12 @@ void CInifile::w_string(pcstr S, pcstr L, pcstr V, pcstr comment)
//#ifdef DEBUG
// I.comment = (comment?comment:0);
//#endif
auto it = std::lower_bound(data.Data.begin(), data.Data.end(), *I.first, item_pred);
auto it = std::lower_bound(data.Data.begin(), data.Data.end(), I.first.c_str(), item_pred);

if (it != data.Data.end())
{
// Check for "first" matching
if (0 == xr_strcmp(*it->first, *I.first))
if (0 == xr_strcmp(it->first.c_str(), I.first.c_str()))
{
bool b = m_flags.test(eOverrideNames);
R_ASSERT2(b, make_string("name[%s] already exist in section[%s]", line, sect).c_str());
Expand Down Expand Up @@ -849,7 +849,7 @@ void CInifile::remove_line(pcstr S, pcstr L)
{
Sect& data = r_section(S);
auto A = std::lower_bound(data.Data.begin(), data.Data.end(), L, item_pred);
R_ASSERT(A != data.Data.end() && xr_strcmp(*A->first, L) == 0);
R_ASSERT(A != data.Data.end() && xr_strcmp(A->first.c_str(), L) == 0);
data.Data.erase(A);
}
}
38 changes: 19 additions & 19 deletions src/xrCore/xr_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,45 @@ class XRCORE_API CInifile
Root& sections() { return DATA; }
Root const& sections() const { return DATA; }
CLASS_ID r_clsid(pcstr S, pcstr L) const;
CLASS_ID r_clsid(const shared_str& S, pcstr L) const { return r_clsid(*S, L); }
CLASS_ID r_clsid(const shared_str& S, pcstr L) const { return r_clsid(S.c_str(), L); }
pcstr r_string(pcstr S, pcstr L) const; // Left quotes in place
pcstr r_string(const shared_str& S, pcstr L) const { return r_string(*S, L); } // Left quotes in place
pcstr r_string(const shared_str& S, pcstr L) const { return r_string(S.c_str(), L); } // Left quotes in place
shared_str r_string_wb(pcstr S, pcstr L) const; // Remove quotes
shared_str r_string_wb(const shared_str& S, pcstr L) const { return r_string_wb(*S, L); } // Remove quotes
shared_str r_string_wb(const shared_str& S, pcstr L) const { return r_string_wb(S.c_str(), L); } // Remove quotes
u8 r_u8(pcstr S, pcstr L) const;
u8 r_u8(const shared_str& S, pcstr L) const { return r_u8(*S, L); }
u8 r_u8(const shared_str& S, pcstr L) const { return r_u8(S.c_str(), L); }
u16 r_u16(pcstr S, pcstr L) const;
u16 r_u16(const shared_str& S, pcstr L) const { return r_u16(*S, L); }
u16 r_u16(const shared_str& S, pcstr L) const { return r_u16(S.c_str(), L); }
u32 r_u32(pcstr S, pcstr L) const;
u32 r_u32(const shared_str& S, pcstr L) const { return r_u32(*S, L); }
u32 r_u32(const shared_str& S, pcstr L) const { return r_u32(S.c_str(), L); }
u64 r_u64(pcstr S, pcstr L) const;
s8 r_s8(pcstr S, pcstr L) const;
s8 r_s8(const shared_str& S, pcstr L) const { return r_s8(*S, L); }
s8 r_s8(const shared_str& S, pcstr L) const { return r_s8(S.c_str(), L); }
s16 r_s16(pcstr S, pcstr L) const;
s16 r_s16(const shared_str& S, pcstr L) const { return r_s16(*S, L); }
s16 r_s16(const shared_str& S, pcstr L) const { return r_s16(S.c_str(), L); }
s32 r_s32(pcstr S, pcstr L) const;
s32 r_s32(const shared_str& S, pcstr L) const { return r_s32(*S, L); }
s32 r_s32(const shared_str& S, pcstr L) const { return r_s32(S.c_str(), L); }
s64 r_s64(pcstr S, pcstr L) const;
float r_float(pcstr S, pcstr L) const;
float r_float(const shared_str& S, pcstr L) const { return r_float(*S, L); }
float r_float(const shared_str& S, pcstr L) const { return r_float(S.c_str(), L); }
Fcolor r_fcolor(pcstr S, pcstr L) const;
Fcolor r_fcolor(const shared_str& S, pcstr L) const { return r_fcolor(*S, L); }
Fcolor r_fcolor(const shared_str& S, pcstr L) const { return r_fcolor(S.c_str(), L); }
u32 r_color(pcstr S, pcstr L) const;
u32 r_color(const shared_str& S, pcstr L) const { return r_color(*S, L); }
u32 r_color(const shared_str& S, pcstr L) const { return r_color(S.c_str(), L); }
Ivector2 r_ivector2(pcstr S, pcstr L) const;
Ivector2 r_ivector2(const shared_str& S, pcstr L) const { return r_ivector2(*S, L); }
Ivector2 r_ivector2(const shared_str& S, pcstr L) const { return r_ivector2(S.c_str(), L); }
Ivector3 r_ivector3(pcstr S, pcstr L) const;
Ivector3 r_ivector3(const shared_str& S, pcstr L) const { return r_ivector3(*S, L); }
Ivector3 r_ivector3(const shared_str& S, pcstr L) const { return r_ivector3(S.c_str(), L); }
Ivector4 r_ivector4(pcstr S, pcstr L) const;
Ivector4 r_ivector4(const shared_str& S, pcstr L) const { return r_ivector4(*S, L); }
Ivector4 r_ivector4(const shared_str& S, pcstr L) const { return r_ivector4(S.c_str(), L); }
Fvector2 r_fvector2(pcstr S, pcstr L) const;
Fvector2 r_fvector2(const shared_str& S, pcstr L) const { return r_fvector2(*S, L); }
Fvector2 r_fvector2(const shared_str& S, pcstr L) const { return r_fvector2(S.c_str(), L); }
Fvector3 r_fvector3(pcstr S, pcstr L) const;
Fvector3 r_fvector3(const shared_str& S, pcstr L) const { return r_fvector3(*S, L); }
Fvector3 r_fvector3(const shared_str& S, pcstr L) const { return r_fvector3(S.c_str(), L); }
Fvector4 r_fvector4(pcstr S, pcstr L) const;
Fvector4 r_fvector4(const shared_str& S, pcstr L) const { return r_fvector4(*S, L); }
Fvector4 r_fvector4(const shared_str& S, pcstr L) const { return r_fvector4(S.c_str(), L); }
bool r_bool(pcstr S, pcstr L) const;
bool r_bool(const shared_str& S, pcstr L) const { return r_bool(*S, L); }
bool r_bool(const shared_str& S, pcstr L) const { return r_bool(S.c_str(), L); }
int r_token(pcstr S, pcstr L, const xr_token* token_list) const;
bool r_line(pcstr S, int L, pcstr* N, pcstr* V) const;
bool r_line(const shared_str& S, int L, pcstr* N, pcstr* V) const;
Expand Down
Loading

0 comments on commit 7b342ee

Please sign in to comment.