Skip to content

Commit

Permalink
Get rid of global namespace polluting silly typedef.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Nov 12, 2017
1 parent 2a44a75 commit e311ece
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/xrCore/xrstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ str_container::str_container() :
#endif
{}

str_value* str_container::dock(str_c value)
str_value* str_container::dock(pcstr value)
{
if (0 == value)
return 0;
Expand Down
22 changes: 6 additions & 16 deletions src/xrCore/xrstring.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#ifndef xrstringH
#define xrstringH
#pragma once

// TODO: tamlin: Get rid of _std_extensions.h as compile-time dependency, if possible.
#include "_types.h"
#include "_std_extensions.h"

#pragma pack(push, 4)
//////////////////////////////////////////////////////////////////////////
// TODO: tamlin: Get rid of this blobal namespace polluting silly typedef.
typedef const char* str_c;

//////////////////////////////////////////////////////////////////////////
#pragma warning(push)
#pragma warning(disable : 4200)
struct XRCORE_API str_value
Expand Down Expand Up @@ -45,7 +38,7 @@ class XRCORE_API str_container
str_container();
~str_container();

str_value* dock(str_c value);
str_value* dock(pcstr value);
void clean();
void dump();
void dump(IWriter* W);
Expand All @@ -60,7 +53,6 @@ XRCORE_API extern str_container* g_pStringContainer;
//////////////////////////////////////////////////////////////////////////
class shared_str
{
private:
str_value* p_;

protected:
Expand All @@ -75,7 +67,7 @@ class shared_str
}

public:
void _set(str_c rhs)
void _set(pcstr rhs)
{
str_value* v = g_pStringContainer->dock(rhs);
if (0 != v)
Expand All @@ -98,7 +90,7 @@ class shared_str
public:
// construction
shared_str() { p_ = 0; }
shared_str(str_c rhs)
shared_str(pcstr rhs)
{
p_ = 0;
_set(rhs);
Expand All @@ -110,7 +102,7 @@ class shared_str
}
~shared_str() { _dec(); }
// assignment & accessors
shared_str& operator=(str_c rhs)
shared_str& operator=(pcstr rhs)
{
_set(rhs);
return (shared_str&)*this;
Expand All @@ -121,10 +113,10 @@ class shared_str
return (shared_str&)*this;
}
// XXX tamlin: Remove operator*(). It may be convenient, but it's dangerous. Use
str_c operator*() const { return p_ ? p_->value : 0; }
pcstr operator*() const { return p_ ? p_->value : 0; }
bool operator!() const { return p_ == 0; }
char operator[](size_t id) { return p_->value[id]; }
str_c c_str() const { return p_ ? p_->value : 0; }
pcstr c_str() const { return p_ ? p_->value : 0; }
// misc func
u32 size() const
{
Expand Down Expand Up @@ -172,5 +164,3 @@ IC int xr_strcmp(const shared_str& a, const shared_str& b) throw()
void xr_strlwr(shared_str& src);

#pragma pack(pop)

#endif
4 changes: 2 additions & 2 deletions src/xrGame/game_cl_capture_the_artefact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ void game_cl_CaptureTheArtefact::OnVoteStart(NET_Packet& P)
{
if (!xr_strcmp(cmd_name, ttable[i][0]))
{
str_c ted_str = st.translate(ttable[i][1]).c_str();
pcstr ted_str = st.translate(ttable[i][1]).c_str();
VERIFY(ted_str);
tcmd_len = xr_strlen(ted_str) + 1;
tcmd_name = static_cast<char*>(_alloca(tcmd_len));
Expand All @@ -1312,7 +1312,7 @@ void game_cl_CaptureTheArtefact::OnVoteStart(NET_Packet& P)
xr_strcat(vstr, vstr_size, " ");
xr_strcat(vstr, vstr_size, st.translate(args[i]).c_str());
}
str_c t_vote_str = st.translate("mp_voting_started").c_str();
pcstr t_vote_str = st.translate("mp_voting_started").c_str();
VERIFY(t_vote_str);
u32 fin_str_size = xr_strlen(t_vote_str) + vstr_size + xr_strlen(player) + 1;
char* fin_str = static_cast<char*>(_alloca(fin_str_size));
Expand Down

0 comments on commit e311ece

Please sign in to comment.