diff --git a/doomsday/libs/core/include/de/core/commandline.h b/doomsday/libs/core/include/de/core/commandline.h index 4694170b0d..506d7508a4 100644 --- a/doomsday/libs/core/include/de/core/commandline.h +++ b/doomsday/libs/core/include/de/core/commandline.h @@ -84,7 +84,11 @@ class DE_PUBLIC CommandLine * Returns the number of arguments. This includes the program name, which * is the first argument in the list. */ - dint count() const; + dsize count() const; + + inline dsize size() const { return count(); } + + dint sizei() const; void clear(); @@ -106,14 +110,14 @@ class DE_PUBLIC CommandLine * @param pos Index at which the new argument will be at. * @param arg Argument to insert. */ - void insert(duint pos, String const &arg); + void insert(dsize pos, String const &arg); /** * Removes an argument by index. * * @param pos Index of argument to remove. */ - void remove(duint pos); + void remove(dsize pos); /** * Checks whether @a arg is in the arguments. Since the first argument is @@ -140,7 +144,7 @@ class DE_PUBLIC CommandLine * @return Number of parameters handled. */ int forAllParameters(String const &arg, - std::function paramHandler) const; + std::function paramHandler) const; /** * Gets the parameter for an argument. @@ -166,14 +170,14 @@ class DE_PUBLIC CommandLine /** * Determines whether an argument is an option, i.e., it begins with a hyphen. */ - bool isOption(duint pos) const; + bool isOption(dsize pos) const; /** * Determines whether an argument is an option, i.e., it begins with a hyphen. */ static bool isOption(String const &arg); - String at(duint pos) const; + String at(dsize pos) const; /** * Returns a list of pointers to the arguments. The list contains @@ -188,7 +192,7 @@ class DE_PUBLIC CommandLine * * @param pos Argument index. */ - void makeAbsolutePath(duint pos); + void makeAbsolutePath(dsize pos); /** * Reads a native file and parses its contents using parse(). diff --git a/doomsday/libs/core/include/de/data/list.h b/doomsday/libs/core/include/de/data/list.h index 92f129d75a..bab268e305 100644 --- a/doomsday/libs/core/include/de/data/list.h +++ b/doomsday/libs/core/include/de/data/list.h @@ -50,12 +50,13 @@ class List : public std::vector using Base::begin; using Base::end; using Base::push_back; + using Base::size; void pop_front() { removeFirst(); } // slow... void push_front(const T &v) { prepend(v); } // slow... // Qt style methods: - int size() const { return int(Base::size()); } + int sizei() const { return int(Base::size()); } void clear() { Base::clear(); } bool isEmpty() const { return Base::size() == 0; } inline explicit operator bool() const { return !isEmpty(); } @@ -69,21 +70,25 @@ class List : public std::vector void append(const T &v) { push_back(v); } void append(const List &list) { for (const T &v : list) push_back(v); } void prepend(const T &v) { Base::insert(begin(), v); } - void insert(int pos, const T &value) { Base::insert(begin() + pos, value); } +// void insert(int pos, const T &value) { Base::insert(begin() + pos, value); } + void insert(size_t pos, const T &value) { Base::insert(begin() + pos, value); } void insert(const const_iterator &i, const T &value) { Base::insert(i, value); } - const T &operator[](int pos) const { return Base::at(pos); } - T & operator[](int pos) { return Base::operator[](pos); } - const T &at(int pos) const { return Base::at(pos); } +// const T &operator[](int pos) const { return Base::at(pos); } + const T &operator[](size_t pos) const { return Base::at(pos); } +// T & operator[](int pos) { return Base::operator[](pos); } + T & operator[](size_t pos) { return Base::operator[](pos); } +// const T &at(int pos) const { return Base::at(pos); } + const T &at(size_t pos) const { return Base::at(pos); } const T &first() const { return Base::front(); } const T &last() const { return Base::back(); } T & first() { return Base::front(); } T & last() { return Base::back(); } T takeFirst() { T v = first(); pop_front(); return std::move(v); } T takeLast() { T v = last(); Base::pop_back(); return std::move(v); } - T takeAt(int pos) { T v = std::move(at(pos)); Base::erase(Base::begin() + pos); return std::move(v); } + T takeAt(size_t pos) { T v = std::move(at(pos)); Base::erase(Base::begin() + pos); return std::move(v); } void removeFirst() { Base::erase(Base::begin()); } void removeLast() { Base::erase(Base::begin() + size() - 1); } - void removeAt(int pos) { Base::erase(Base::begin() + pos); } + void removeAt(size_t pos) { Base::erase(Base::begin() + pos); } void removeAll(const T &v) { Base::erase(std::remove(begin(), end(), v), end()); } void removeOne(const T &v) { diff --git a/doomsday/libs/core/include/de/libcore.h b/doomsday/libs/core/include/de/libcore.h index abb422694e..ea1886580f 100644 --- a/doomsday/libs/core/include/de/libcore.h +++ b/doomsday/libs/core/include/de/libcore.h @@ -229,7 +229,7 @@ * Asserts that the object really exists (not null). */ #define DE_SELF(Type, Var) \ - DE_ASSERT(Var != 0); \ + DE_ASSERT(Var != nullptr); \ de::Type *self = reinterpret_cast(Var); /** diff --git a/doomsday/libs/core/src/c_wrapper.cpp b/doomsday/libs/core/src/c_wrapper.cpp index e164947f5a..67e6e15aac 100644 --- a/doomsday/libs/core/src/c_wrapper.cpp +++ b/doomsday/libs/core/src/c_wrapper.cpp @@ -122,13 +122,13 @@ void CommandLine_Alias(char const *longname, char const *shortname) int CommandLine_Count(void) { - return DE_COMMANDLINE().count(); + return DE_COMMANDLINE().sizei(); } char const *CommandLine_At(int i) { DE_ASSERT(i >= 0); - DE_ASSERT(i < DE_COMMANDLINE().count()); + DE_ASSERT(i < DE_COMMANDLINE().sizei()); return *(DE_COMMANDLINE().argv() + i); } @@ -145,7 +145,7 @@ char const *CommandLine_Next(void) if (!argLastMatch || argLastMatch >= CommandLine_Count() - 1) { // No more arguments following the last match. - return 0; + return nullptr; } return CommandLine_At(++argLastMatch); } @@ -155,7 +155,7 @@ char const *CommandLine_NextAsPath(void) if (!argLastMatch || argLastMatch >= CommandLine_Count() - 1) { // No more arguments following the last match. - return 0; + return nullptr; } DE_COMMANDLINE().makeAbsolutePath(argLastMatch + 1); return CommandLine_Next(); @@ -228,7 +228,7 @@ de_Info *Info_NewFromString(char const *utf8text) catch (de::Error const &er) { LOG_WARNING(er.asText()); - return 0; + return nullptr; } } @@ -243,7 +243,7 @@ de_Info *Info_NewFromFile(char const *nativePath) catch (de::Error const &er) { LOG_WARNING(er.asText()); - return 0; + return nullptr; } } diff --git a/doomsday/libs/core/src/core/commandline.cpp b/doomsday/libs/core/src/core/commandline.cpp index d32ddb8160..24870ce35e 100644 --- a/doomsday/libs/core/src/core/commandline.cpp +++ b/doomsday/libs/core/src/core/commandline.cpp @@ -95,7 +95,7 @@ DE_PIMPL(CommandLine) DE_ASSERT(pointers.back() == nullptr); } - void insert(int pos, String const &arg) + void insert(dsize pos, String const &arg) { if (pos > arguments.size()) { @@ -106,12 +106,12 @@ DE_PIMPL(CommandLine) arguments.insert(pos, arg); pointers.insert(pointers.begin() + pos, duplicateStringAsUtf8(arg)); - DE_ASSERT(pointers.back() == 0); + DE_ASSERT(pointers.back() == nullptr); } - void remove(duint pos) + void remove(dsize pos) { - if (pos >= (duint) arguments.size()) + if (pos >= arguments.size()) { /// @throw OutOfRangeError @a pos is out of range. throw OutOfRangeError("CommandLine::remove", "Index out of range"); @@ -130,7 +130,7 @@ CommandLine::CommandLine() : d(new Impl(*this)) CommandLine::CommandLine(const StringList &args) : d(new Impl(*this)) { - for (int i = 0; i < args.size(); ++i) + for (dsize i = 0; i < args.size(); ++i) { mb_iterator arg = args.at(i); if (*arg == '@') @@ -147,9 +147,9 @@ CommandLine::CommandLine(const StringList &args) : d(new Impl(*this)) CommandLine::CommandLine(const CommandLine &other) : d(new Impl(*this)) { - DE_FOR_EACH_CONST(Impl::Arguments, i, other.d->arguments) + for (const auto &i : other.d->arguments) { - d->appendArg(*i); + d->appendArg(i); } } @@ -158,11 +158,16 @@ NativePath CommandLine::startupPath() return d->initialDir; } -dint CommandLine::count() const +dsize CommandLine::count() const { return d->arguments.size(); } +dint CommandLine::sizei() const +{ + return dint(count()); +} + void CommandLine::clear() { d->clear(); @@ -173,12 +178,12 @@ void CommandLine::append(String const &arg) d->appendArg(arg); } -void CommandLine::insert(duint pos, String const &arg) +void CommandLine::insert(dsize pos, String const &arg) { d->insert(pos, arg); } -void CommandLine::remove(duint pos) +void CommandLine::remove(dsize pos) { d->remove(pos); } @@ -214,7 +219,7 @@ CommandLine::ArgWithParams CommandLine::check(String const &arg, dint numParams) } int CommandLine::forAllParameters(String const &arg, - std::function paramHandler) const + std::function paramHandler) const { int total = 0; bool inside = false; @@ -267,9 +272,9 @@ dint CommandLine::has(String const &arg) const return howMany; } -bool CommandLine::isOption(duint pos) const +bool CommandLine::isOption(dsize pos) const { - if (pos >= (duint) d->arguments.size()) + if (pos >= d->arguments.size()) { /// @throw OutOfRangeError @a pos is out of range. throw OutOfRangeError("CommandLine::isOption", "Index out of range"); @@ -283,20 +288,20 @@ bool CommandLine::isOption(String const &arg) return !(arg.empty() || arg.first() != '-'); } -String CommandLine::at(duint pos) const +String CommandLine::at(dsize pos) const { return d->arguments.at(pos); } char const *const *CommandLine::argv() const { - DE_ASSERT(*d->pointers.rbegin() == 0); // the list itself must be null-terminated + DE_ASSERT(*d->pointers.rbegin() == nullptr); // the list itself must be null-terminated return &d->pointers[0]; } -void CommandLine::makeAbsolutePath(duint pos) +void CommandLine::makeAbsolutePath(dsize pos) { - if (pos >= (duint) d->arguments.size()) + if (pos >= d->arguments.size()) { /// @throw OutOfRangeError @a pos is out of range. throw OutOfRangeError("CommandLine::makeAbsolutePath", "Index out of range"); diff --git a/doomsday/libs/core/src/core/logbuffer.cpp b/doomsday/libs/core/src/core/logbuffer.cpp index 95e4193c8c..0b19a9985f 100644 --- a/doomsday/libs/core/src/core/logbuffer.cpp +++ b/doomsday/libs/core/src/core/logbuffer.cpp @@ -66,7 +66,7 @@ DE_PIMPL(LogBuffer) , maxEntryCount(maxEntryCount) , useStandardOutput(true) , flushingEnabled(true) - , fileLogSink(0) + , fileLogSink(nullptr) //#ifndef WIN32 , outSink(std::cout) , errSink(std::cerr) @@ -162,7 +162,7 @@ LogBuffer::~LogBuffer() setOutputFile(""); clear(); - if (_appBuffer == this) _appBuffer = 0; + if (_appBuffer == this) _appBuffer = nullptr; } void LogBuffer::clear() @@ -189,10 +189,10 @@ void LogBuffer::latestEntries(Entries &entries, int count) const { DE_GUARD(this); entries.clear(); - for (int i = d->entries.size() - 1; i >= 0; --i) + for (int i = d->entries.sizei() - 1; i >= 0; --i) { entries.append(d->entries[i]); - if (count && entries.size() >= count) + if (count && entries.sizei() >= count) { return; } @@ -213,7 +213,7 @@ void LogBuffer::setEntryFilter(IFilter const *entryFilter) bool LogBuffer::isEnabled(duint32 entryMetadata) const { - DE_ASSERT(d->entryFilter != 0); + DE_ASSERT(d->entryFilter != nullptr); DE_ASSERT(entryMetadata & LogEntry::DomainMask); // must have a domain if (entryMetadata & LogEntry::Privileged) { @@ -338,7 +338,7 @@ void LogBuffer::flush() // d->lastFlushedAt = Time(); // Too many entries? Now they can be destroyed since we have flushed everything. - while (d->entries.size() > d->maxEntryCount) + while (d->entries.sizei() > d->maxEntryCount) { LogEntry *old = d->entries.front(); d->entries.pop_front(); @@ -353,13 +353,13 @@ void LogBuffer::setAppBuffer(LogBuffer &appBuffer) LogBuffer &LogBuffer::get() { - DE_ASSERT(_appBuffer != 0); + DE_ASSERT(_appBuffer != nullptr); return *_appBuffer; } bool LogBuffer::appBufferExists() { - return _appBuffer != 0; + return _appBuffer != nullptr; } } // namespace de diff --git a/doomsday/libs/core/src/core/memorylogsink.cpp b/doomsday/libs/core/src/core/memorylogsink.cpp index 33a7ad7ddd..93eceec124 100644 --- a/doomsday/libs/core/src/core/memorylogsink.cpp +++ b/doomsday/libs/core/src/core/memorylogsink.cpp @@ -73,14 +73,14 @@ int MemoryLogSink::entryCount() const { DE_GUARD(this); - return _entries.size(); + return _entries.sizei(); } LogEntry const &MemoryLogSink::entry(int index) const { DE_GUARD(this); DE_ASSERT(index >= 0); - DE_ASSERT(index < _entries.size()); + DE_ASSERT(index < _entries.sizei()); return *_entries.at(index); } diff --git a/doomsday/libs/core/src/core/monospacelogsinkformatter.cpp b/doomsday/libs/core/src/core/monospacelogsinkformatter.cpp index a776600513..1928a2454e 100644 --- a/doomsday/libs/core/src/core/monospacelogsinkformatter.cpp +++ b/doomsday/libs/core/src/core/monospacelogsinkformatter.cpp @@ -129,7 +129,7 @@ struct TabFiller int tabWidth = 0; // Find the widest position for this tab stop by checking all lines. - for (int idx = 0; idx < fills.size(); ++idx) + for (int idx = 0; idx < fills.sizei(); ++idx) { String const &ln = fills.at(idx); int w = (idx > 0? minIndent : 0); @@ -162,7 +162,7 @@ struct TabFiller replaceTabs: // Fill up (replace) the tabs with spaces according to the widest found // position. - for (int idx = 0; idx < fills.size(); ++idx) + for (int idx = 0; idx < fills.sizei(); ++idx) { String &ln = fills[idx]; int w = (idx > 0? minIndent : 0); @@ -339,7 +339,9 @@ StringList MonospaceLogSinkFormatter::logEntryToTextLines(LogEntry const &entry) // For lines other than the first one, print an indentation. if (pos > 0) { - lineText = wstring(wrapIndent, L' ') + lineText; + wstring indented(wrapIndent, L' '); + indented += lineText; + lineText = indented; } // The wrap indent for this paragraph depends on the first line's content. diff --git a/doomsday/libs/core/src/data/bitfield_elements.cpp b/doomsday/libs/core/src/data/bitfield_elements.cpp index 3202b5c9e9..252dad8886 100644 --- a/doomsday/libs/core/src/data/bitfield_elements.cpp +++ b/doomsday/libs/core/src/data/bitfield_elements.cpp @@ -89,7 +89,7 @@ BitField::Elements &BitField::Elements::add(Id id, dsize numBits) // Update the lookup table. int pos = elem.firstBit / 8; int endPos = (elem.firstBit + (numBits - 1)) / 8; - while (d->lookup.size() <= endPos) + while (d->lookup.sizei() <= endPos) { d->lookup.append(Ids()); } diff --git a/doomsday/libs/core/src/data/block.cpp b/doomsday/libs/core/src/data/block.cpp index 3676936885..bf5b097ab8 100644 --- a/doomsday/libs/core/src/data/block.cpp +++ b/doomsday/libs/core/src/data/block.cpp @@ -348,7 +348,7 @@ Block Block::join(const List &blocks, const Block &sep) // static if (blocks.isEmpty()) return Block(); Block joined = blocks.at(0); - for (int i = 1; i < blocks.size(); ++i) + for (int i = 1; i < blocks.sizei(); ++i) { joined += sep; joined += blocks.at(i); diff --git a/doomsday/libs/core/src/data/profiles.cpp b/doomsday/libs/core/src/data/profiles.cpp index c0874fbfd6..1e32b321ba 100644 --- a/doomsday/libs/core/src/data/profiles.cpp +++ b/doomsday/libs/core/src/data/profiles.cpp @@ -264,7 +264,7 @@ void Profiles::serialize() const os << "\nprofile {\n" " name: " << prof->name().c_str() << "\n"; - for (const auto &line : prof->toInfoSource().splitRef('\n')) + for (const auto &line : prof->toInfoSource().split('\n')) { os << " " << line.toStdString() << "\n"; } diff --git a/doomsday/libs/core/src/data/string.cpp b/doomsday/libs/core/src/data/string.cpp index 9edc142c8f..1b6f21521e 100644 --- a/doomsday/libs/core/src/data/string.cpp +++ b/doomsday/libs/core/src/data/string.cpp @@ -872,7 +872,7 @@ String String::join(const StringList &stringList, const char *sep) if (stringList.isEmpty()) return {}; String joined = stringList.at(0); - for (int i = 1; i < stringList.size(); ++i) + for (dsize i = 1; i < stringList.size(); ++i) { joined += sep; joined += stringList.at(i); diff --git a/doomsday/libs/core/src/widgets/widget.cpp b/doomsday/libs/core/src/widgets/widget.cpp index d126d7ca69..c09204db37 100644 --- a/doomsday/libs/core/src/widgets/widget.cpp +++ b/doomsday/libs/core/src/widgets/widget.cpp @@ -172,7 +172,7 @@ DE_PIMPL(Widget) // When we run out of siblings, try to ascend to parent and continue from // there without handling the parent again. - if (pos < 0 || pos >= children.size()) + if (pos < 0 || pos >= children.sizei()) { if (verticalDir > 0) { @@ -531,7 +531,7 @@ void Widget::moveChildBefore(Widget *child, Widget const &otherChild) int to = -1; // Note: O(n) - for (int i = 0; i < d->children.size() && (from < 0 || to < 0); ++i) + for (int i = 0; i < d->children.sizei() && (from < 0 || to < 0); ++i) { if (d->children.at(i) == child) { @@ -624,7 +624,7 @@ Widget::NotifyArgs::Result Widget::notifyTree(NotifyArgs const &args) NotifyArgs::Result result = NotifyArgs::Continue; bool preNotified = false; - for (int idx = 0; idx < d->children.size(); ++idx) + for (int idx = 0; idx < d->children.sizei(); ++idx) { Widget *i = d->children.at(idx); @@ -855,7 +855,7 @@ const Record &Widget::objectNamespace() const void Widget::setFocusCycle(WidgetList const &order) { - for (int i = 0; i < order.size(); ++i) + for (dsize i = 0; i < order.size(); ++i) { Widget *a = order[i]; Widget *b = order[(i + 1) % order.size()];