Add some API type functions into headers

This commit is contained in:
baldurk
2016-11-25 14:15:33 +01:00
parent 90a1b03a0f
commit ddd6eac703
2 changed files with 36 additions and 40 deletions
+36
View File
@@ -184,4 +184,40 @@ struct str : public rdctype::array<char>
const char *c_str() const { return elems ? elems : ""; }
};
inline str &str::operator=(const std::string &in)
{
Delete();
count = (int32_t)in.size();
if(count == 0)
{
elems = (char *)allocate(sizeof(char));
elems[0] = 0;
}
else
{
elems = (char *)allocate(sizeof(char) * (count + 1));
memcpy(elems, &in[0], sizeof(char) * in.size());
elems[count] = 0;
}
return *this;
}
inline str &str::operator=(const char *const in)
{
Delete();
count = (int32_t)strlen(in);
if(count == 0)
{
elems = (char *)allocate(sizeof(char));
elems[0] = 0;
}
else
{
elems = (char *)allocate(sizeof(char) * (count + 1));
memcpy(elems, &in[0], sizeof(char) * count);
elems[count] = 0;
}
return *this;
}
}; // namespace rdctype
-40
View File
@@ -45,43 +45,3 @@ string ToStrHelper<false, ResourceId>::Get(const ResourceId &el)
return tostrBuf;
}
namespace rdctype
{
str &str::operator=(const std::string &in)
{
Delete();
count = (int32_t)in.size();
if(count == 0)
{
elems = (char *)allocate(sizeof(char));
elems[0] = 0;
}
else
{
elems = (char *)allocate(sizeof(char) * (count + 1));
memcpy(elems, &in[0], sizeof(char) * in.size());
elems[count] = 0;
}
return *this;
}
str &str::operator=(const char *const in)
{
Delete();
count = (int32_t)strlen(in);
if(count == 0)
{
elems = (char *)allocate(sizeof(char));
elems[0] = 0;
}
else
{
elems = (char *)allocate(sizeof(char) * (count + 1));
memcpy(elems, &in[0], sizeof(char) * count);
elems[count] = 0;
}
return *this;
}
}; // namespace rdctype