[ox] Make String::String(String const&) explicit

This commit is contained in:
Gary Talent 2023-12-01 23:39:40 -06:00
parent 742427584a
commit 3de03bf1fd
9 changed files with 12 additions and 12 deletions

View File

@ -44,7 +44,7 @@ bool ClArgs::getBool(ox::CRStringView arg, bool defaultValue) const noexcept {
String ClArgs::getString(ox::CRStringView arg, const char *defaultValue) const noexcept { String ClArgs::getString(ox::CRStringView arg, const char *defaultValue) const noexcept {
auto [value, err] = m_strings.at(arg); auto [value, err] = m_strings.at(arg);
return !err ? *value : ox::String(defaultValue); return !err ? ox::String(std::move(*value)) : ox::String(defaultValue);
} }
int ClArgs::getInt(ox::CRStringView arg, int defaultValue) const noexcept { int ClArgs::getInt(ox::CRStringView arg, int defaultValue) const noexcept {

View File

@ -361,7 +361,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
oxReturnError(handler.setTypeInfo("Map", 0, {}, len * 2)); oxReturnError(handler.setTypeInfo("Map", 0, {}, len * 2));
// this loop body needs to be in a lambda because of the potential alloca call // this loop body needs to be in a lambda because of the potential alloca call
constexpr auto loopBody = [](auto &handler, auto const&key, auto const&val) -> ox::Error { constexpr auto loopBody = [](auto &handler, auto const&key, auto const&val) -> ox::Error {
const auto keyLen = ox_strlen(key); const auto keyLen = key.len();
auto wkey = ox_malloca(keyLen + 1, char, 0); auto wkey = ox_malloca(keyLen + 1, char, 0);
memcpy(wkey.get(), key.c_str(), keyLen + 1); memcpy(wkey.get(), key.c_str(), keyLen + 1);
oxReturnError(handler.fieldCString("", wkey.get(), keyLen)); oxReturnError(handler.fieldCString("", wkey.get(), keyLen));

View File

@ -209,7 +209,7 @@ constexpr Error TypeDescWriter::field(CRStringView name, UnionView<T, force> val
if (m_type) { if (m_type) {
const auto t = type(val); const auto t = type(val);
oxAssert(t != nullptr, "field(const char *name, T val): Type not found or generated"); oxAssert(t != nullptr, "field(const char *name, T val): Type not found or generated");
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, t->typeName); m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, ox::String(t->typeName));
return OxError(0); return OxError(0);
} }
return OxError(1); return OxError(1);
@ -238,7 +238,7 @@ template<typename ...Args>
constexpr Error TypeDescWriter::fieldCString(CRStringView name, Args&&...) noexcept { constexpr Error TypeDescWriter::fieldCString(CRStringView name, Args&&...) noexcept {
constexpr auto s = ""; constexpr auto s = "";
const auto t = type(s); const auto t = type(s);
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, t->typeName); m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, ox::String(t->typeName));
return {}; return {};
} }

View File

@ -350,7 +350,7 @@ class ModelObject {
constexpr ModelObject(const ModelObject &other) noexcept { constexpr ModelObject(const ModelObject &other) noexcept {
for (const auto &f : other.m_fieldsOrder) { for (const auto &f : other.m_fieldsOrder) {
auto &field = m_fieldsOrder.emplace_back(new Field{f->name, f->value}); auto &field = m_fieldsOrder.emplace_back(new Field{ox::String(f->name), f->value});
m_fields[field->name] = &field->value; m_fields[field->name] = &field->value;
} }
m_type = other.m_type; m_type = other.m_type;
@ -427,7 +427,7 @@ class ModelObject {
return *this; return *this;
} }
for (const auto &f : other.m_fieldsOrder) { for (const auto &f : other.m_fieldsOrder) {
auto &field = m_fieldsOrder.emplace_back(new Field{f->name, f->value}); auto &field = m_fieldsOrder.emplace_back(new Field{ox::String(f->name), f->value});
m_fields[field->name] = &field->value; m_fields[field->name] = &field->value;
} }
m_type = other.m_type; m_type = other.m_type;
@ -528,7 +528,7 @@ class ModelUnion {
public: public:
constexpr ModelUnion(const ModelUnion &other) noexcept { constexpr ModelUnion(const ModelUnion &other) noexcept {
for (auto i = 0; const auto &f : other.m_fieldsOrder) { for (auto i = 0; const auto &f : other.m_fieldsOrder) {
auto &field = m_fieldsOrder.emplace_back(new Field{i, f->name, f->value}); auto &field = m_fieldsOrder.emplace_back(new Field{i, ox::String(f->name), f->value});
m_fields[field->name] = field.get(); m_fields[field->name] = field.get();
++i; ++i;
} }

View File

@ -46,7 +46,7 @@ constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept {
template<typename T> template<typename T>
[[nodiscard]] [[nodiscard]]
constexpr auto ox_strlen(T str1) noexcept { constexpr auto ox_strlen(T const&str1) noexcept {
std::size_t len = 0; std::size_t len = 0;
for (; str1[len]; len++); for (; str1[len]; len++);
return len; return len;

View File

@ -186,7 +186,7 @@ constexpr Fmt<segementCnt> fmtSegments(StringView fmt) noexcept {
template<typename StringType = String, typename ...Args> template<typename StringType = String, typename ...Args>
[[nodiscard]] [[nodiscard]]
constexpr StringType sfmt(StringView fmt, Args... args) noexcept { constexpr StringType sfmt(StringView fmt, Args&&... args) noexcept {
assert(ox::detail::argCount(fmt) == sizeof...(args)); assert(ox::detail::argCount(fmt) == sizeof...(args));
StringType out; StringType out;
const auto fmtSegments = ox::detail::fmtSegments<sizeof...(args)+1>(fmt); const auto fmtSegments = ox::detail::fmtSegments<sizeof...(args)+1>(fmt);

View File

@ -212,7 +212,7 @@ template<typename K, typename T>
constexpr void HashMap<K, T>::expand() { constexpr void HashMap<K, T>::expand() {
Vector<Pair*> r; Vector<Pair*> r;
for (std::size_t i = 0; i < m_keys.size(); ++i) { for (std::size_t i = 0; i < m_keys.size(); ++i) {
auto k = m_keys[i]; K k{m_keys[i]};
access(r, k) = std::move(access(m_pairs, k)); access(r, k) = std::move(access(m_pairs, k));
} }
m_pairs = std::move(r); m_pairs = std::move(r);

View File

@ -40,7 +40,7 @@ class BasicString {
constexpr explicit BasicString(CRStringView str) noexcept; constexpr explicit BasicString(CRStringView str) noexcept;
constexpr BasicString(BasicString const&) noexcept; constexpr explicit BasicString(BasicString const&) noexcept;
constexpr BasicString(BasicString&&) noexcept; constexpr BasicString(BasicString&&) noexcept;

View File

@ -159,7 +159,7 @@ class OutStream {
} }
#else #else
template<std::size_t fmtSegmentCnt, typename ...Args> template<std::size_t fmtSegmentCnt, typename ...Args>
constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, Args... args) noexcept { constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, Args const&...args) noexcept {
//static_assert(sizeof...(args) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format."); //static_assert(sizeof...(args) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
m_msg.file = file; m_msg.file = file;
m_msg.line = line; m_msg.line = line;