Skip to content

Commit

Permalink
libcore: Continuing removal of Qt dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 1d3cf55 commit 9a73627
Show file tree
Hide file tree
Showing 54 changed files with 669 additions and 492 deletions.
6 changes: 4 additions & 2 deletions doomsday/libs/core/include/de/concurrency/async.h
Expand Up @@ -23,6 +23,7 @@
#include "../Loop"
#include "../String"
#include "../Thread"
#include "../Garbage"

#include <atomic>
#include <utility>
Expand Down Expand Up @@ -62,7 +63,7 @@ class AsyncTaskThread : public AsyncTask
Loop::mainCall([this] ()
{
if (valid) completion(result);
deleteLater();
de::trash(this);
});
}

Expand Down Expand Up @@ -141,7 +142,7 @@ AsyncTask *async(Task const &task)
* Utility for invalidating the completion callbacks of async tasks whose initiator
* has gone out of scope.
*/
class DE_PUBLIC AsyncScope
class DE_PUBLIC AsyncScope : DE_OBSERVES(Thread, Finished)
{
public:
AsyncScope() = default;
Expand All @@ -150,6 +151,7 @@ class DE_PUBLIC AsyncScope
AsyncScope &operator += (AsyncTask *task);
bool isAsyncFinished() const;
void waitForFinished(TimeSpan timeout = 0.0);
void threadFinished(Thread &) override;

private:
LockableT<Set<AsyncTask *>> _tasks;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libs/core/include/de/concurrency/task.h
Expand Up @@ -21,6 +21,7 @@

#include "../libcore.h"
#include "../TaskPool"
#include "../Deletable"

namespace de {

Expand All @@ -37,7 +38,7 @@ class DE_PUBLIC IRunnable
*
* @ingroup concurrency
*/
class DE_PUBLIC Task : public IRunnable
class DE_PUBLIC Task : public IRunnable, public Deletable
{
public:
Task();
Expand Down
7 changes: 4 additions & 3 deletions doomsday/libs/core/include/de/concurrency/thread.h
Expand Up @@ -22,6 +22,7 @@
#include "../libcore.h"
#include "../Time"
#include "../Observers"
#include "../Waitable"

struct Impl_Thread;

Expand All @@ -30,20 +31,20 @@ namespace de {
/**
* Base class for running a thread.
*/
class DE_PUBLIC Thread
class DE_PUBLIC Thread : public Waitable
{
public:
Thread();

virtual ~Thread();

virtual void run() = 0;

void start();
void join();
bool isRunning() const;
bool isFinished() const;

virtual void run() = 0;

static void sleep(const TimeSpan &span);

public:
Expand Down
11 changes: 6 additions & 5 deletions doomsday/libs/core/include/de/core/app.h
Expand Up @@ -75,6 +75,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
DisablePlugins = 0x1,
DisablePersistentData = 0x2
};
using SubsystemInitFlags = Flags;

/// Attempting to access persistent data when it has been disabled at init.
/// @ingroup errors
Expand Down Expand Up @@ -168,7 +169,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*
* @param flags How to/which subsystems to initialize.
*/
virtual void initSubsystems(Flags subsystemInitflags = DefaultSubsystems);
virtual void initSubsystems(SubsystemInitFlags subsystemInitflags = DefaultSubsystems);

/**
* Adds a system to the application. The order of systems is preserved; the
Expand Down Expand Up @@ -315,7 +316,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*
* @return Number of files found.
*/
static int findInPackages(String const &partialPath, FileIndex::FoundFiles &files);
static int findInPackages(const CString &partialPath, FileIndex::FoundFiles &files);

/**
* Checks if an asset exists.
Expand All @@ -324,7 +325,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*
* @return @c true, if assetInfo() can be called.
*/
static bool assetExists(String const &identifier);
static bool assetExists(const CString &identifier);

/**
* Retrieves the namespace of an asset.
Expand All @@ -333,7 +334,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*
* @return Asset namespace accessor.
*/
static Package::Asset asset(String const &identifier);
static Package::Asset asset(const CString &identifier);

/**
* Returns the application's script system.
Expand All @@ -354,7 +355,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*
* @return Variable.
*/
static Variable &config(String const &name);
static Variable &config(const CString &name);

/**
* Returns the web API URL. Always includes the protocol and ends with a slash.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/core/log.h
Expand Up @@ -342,7 +342,7 @@ class DE_PUBLIC LogEntry : public Lockable, public ISerializable
if (text.endsWith("Dev"))
{
val |= Dev;
text = text.remove(text.size() - 3);
text = text.remove(text.sizeb() - 3);
}
for (int i = FirstDomainBit; i <= LastDomainBit; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/core/range.h
Expand Up @@ -38,7 +38,7 @@ struct Range
Type start;
Type end;

Range(Type const &a = 0, Type const &b = 0) : start(a), end(b) {}
Range(Type const &a = Type(0), Type const &b = Type(0)) : start(a), end(b) {}
static Range fromSize(Type const &a, Type const &size) { return Range(a, a + size); }
inline bool isEmpty() const { return end == start; }
explicit inline operator bool() const { return !isEmpty(); }
Expand Down
7 changes: 3 additions & 4 deletions doomsday/libs/core/include/de/data/bitfield.h
Expand Up @@ -21,10 +21,9 @@

#include <de/Block>
#include <de/Error>
#include <de/Set>
#include <de/String>

#include <QSet>

namespace de {

/**
Expand Down Expand Up @@ -52,7 +51,7 @@ class DE_PUBLIC BitField
Id id; ///< User-provided identifier for the element.
int numBits; ///< 32 bits at most.
};
typedef QSet<Id> Ids;
typedef Set<Id> Ids;

/**
* Metadata about the elements of a bit field.
Expand All @@ -76,7 +75,7 @@ class DE_PUBLIC BitField

void add(Spec const *elements, dsize count);

void add(QList<Spec> const &elements);
void add(const List<Spec> &elements);

void clear();

Expand Down
10 changes: 5 additions & 5 deletions doomsday/libs/core/include/de/data/conditionaltrigger.h
Expand Up @@ -24,7 +24,7 @@
namespace de {

/**
* Conditional trigger that calls a method
* Conditional trigger that calls a method.
*/
class DE_PUBLIC ConditionalTrigger
{
Expand All @@ -42,9 +42,9 @@ class DE_PUBLIC ConditionalTrigger
*
* @param variable Variable for configuring the conditional trigger.
*/
void setCondition(Variable const &variable);
void setCondition(const Variable &variable);

Variable const &condition() const;
const Variable &condition() const;

/**
* Checks if a trigger will cause activation, and if so, call the appropriate
Expand All @@ -53,13 +53,13 @@ class DE_PUBLIC ConditionalTrigger
* @param trigger Trigger to check.
* @return @c true if the trigger was activated, otherwise @c false.
*/
bool tryTrigger(String const &trigger);
bool tryTrigger(const String &trigger);

/**
* Called when the trigger is activated.
* @param trigger Trigger that caused activation.
*/
virtual void handleTriggered(String const &trigger) = 0;
virtual void handleTriggered(const String &trigger) = 0;

private:
DE_PRIVATE(d)
Expand Down
3 changes: 3 additions & 0 deletions doomsday/libs/core/include/de/data/cstring.h
Expand Up @@ -36,6 +36,7 @@ class DE_PUBLIC CString
CString(const char *cStr) : _range{cStr, nullptr} {} // lazy init
CString(const char *start, const char *end) : _range{start, end} {}
CString(const std::string &str) : _range{str.data(), str.data() + str.size()} {}
CString(const String &str) : _range{str.data(), str.data() + str.size()} {}
CString(const iRangecc &cc) : _range{cc.start, cc.end} {}

inline void updateEnd() const
Expand All @@ -56,6 +57,8 @@ class DE_PUBLIC CString
dsize indexOf(char ch, size_t from = 0) const;
dsize indexOf(const char *cStr, size_t from = 0) const;
CString substr(size_t start, size_t count = npos) const;
const char *begin() const { return _range.start; }
const char *end() const { updateEnd(); return _range.end; }

static size_t npos;

Expand Down
15 changes: 9 additions & 6 deletions doomsday/libs/core/include/de/data/date.h
Expand Up @@ -32,28 +32,28 @@ namespace de {
*
* @ingroup types
*/
class DE_PUBLIC Date : public Time, public LogEntry::Arg::Base
class DE_PUBLIC Date : public LogEntry::Arg::Base
{
public:
/**
* Constructs a new Date out of the current time.
*/
Date();

Date(Time const &time);
Date(const Time &time);

int year() const;
int month() const;
int dayOfMonth() const;
int hours() const;
int minutes() const;
int seconds() const;
int daysTo(Date const &other) const;
int daysTo(const Date &other) const;

/**
* Forms a textual representation of the date.
*/
String asText() const;
String format(const char *format = "%F") const;

/**
* Converts the date back to a Time.
Expand All @@ -67,11 +67,14 @@ class DE_PUBLIC Date : public Time, public LogEntry::Arg::Base
return LogEntry::Arg::StringArgument;
}

static Date fromText(String const &text);
static Date fromText(const String &text);

private:
DE_PRIVATE(d)
};

DE_PUBLIC std::ostream &operator << (std::ostream &os, Date const &date);

}
} // namespace de

#endif /* LIBCORE_DATE_H */
3 changes: 3 additions & 0 deletions doomsday/libs/core/include/de/data/dictionaryvalue.h
Expand Up @@ -27,6 +27,7 @@
namespace de {

class ArrayValue;
class Record;

/**
* Subclass of Value that contains an array of values, indexed by any value.
Expand Down Expand Up @@ -100,6 +101,8 @@ class DE_PUBLIC DictionaryValue : public Value
*/
ArrayValue *contentsAsArray(ContentSelection selection) const;

Record toRecord() const;

inline const Value &operator[](const Value &index) const { return element(index); }
inline Value & operator[](const Value &index) { return element(index); }

Expand Down
3 changes: 1 addition & 2 deletions doomsday/libs/core/include/de/data/infobank.h
Expand Up @@ -45,8 +45,7 @@ class File;
class DE_PUBLIC InfoBank : public Bank, public IObject
{
public:
InfoBank(char const *nameForLog = "InfoBank",
Bank::Flags const &flags = Bank::DefaultFlags,
InfoBank(char const *nameForLog = "InfoBank", Flags const &flags = Bank::DefaultFlags,
String const &hotStorageLocation = "/home/cache");

/**
Expand Down
7 changes: 3 additions & 4 deletions doomsday/libs/core/include/de/data/json.h
Expand Up @@ -22,7 +22,6 @@
#ifndef LIBCORE_JSON_H
#define LIBCORE_JSON_H

#include <QVariant>
#include <de/String>

namespace de {
Expand All @@ -31,13 +30,13 @@ class Block;
class Record;

/**
* Parses text as JSON and returns the data structured in a QVariant.
* Parses text as JSON and returns the data structured in a Block.
*
* @param jsonText Text to parse.
*
* @return Parsed data, or an invalid variant if an error occurred.
*/
DE_PUBLIC QVariant parseJSON(String const &jsonText);
DE_PUBLIC Record parseJSON(String const &jsonText);

/**
* Composes a JSON representation of a Record.
Expand All @@ -46,7 +45,7 @@ DE_PUBLIC QVariant parseJSON(String const &jsonText);
*
* @return JSON in UTF-8 encoding.
*/
DE_PUBLIC Block composeJSON(Record const &rec);
DE_PUBLIC String composeJSON(Record const &rec);

} // namespace de

Expand Down
8 changes: 6 additions & 2 deletions doomsday/libs/core/include/de/data/list.h
Expand Up @@ -38,7 +38,7 @@ class List : public std::vector<T>
List(List &&moved) : Base(moved) {}
List(const std::initializer_list<T> &init) {
for (const auto &i : init) {
push_back(i);
Base::push_back(i);
}
}

Expand All @@ -47,6 +47,8 @@ class List : public std::vector<T>
using reverse_iterator = typename Base::reverse_iterator;
using const_reverse_iterator = typename Base::const_reverse_iterator;

using Base::begin;
using Base::end;
void pop_front() { removeFirst(); } // slow...

// Qt style methods:
Expand All @@ -57,17 +59,19 @@ class List : public std::vector<T>
void append(const T &s) { Base::push_back(s); }
void prepend(const T &s) { Base::push_front(s); }
void insert(int pos, const T &value) { Base::insert(Base::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 &first() const { return Base::front(); }
const T &last() const { return Base::back(); }
T takeFirst() { T v = first(); Base::pop_front(); return std::move(v); }
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); }
void removeFirst() { Base::erase(Base::begin()); }
void removeLast() { Base::erase(Base::begin() + size() - 1); }
void removeAt(int pos) { Base::erase(Base::begin() + pos); }
void removeAll(const T &v) { Base::erase(std::remove(begin(), end(), v), end()); }
List & operator=(const List &other) { Base::operator=(other); return *this; }
List & operator=(List &&other) { Base::operator=(other); return *this; }

Expand Down
4 changes: 4 additions & 0 deletions doomsday/libs/core/include/de/data/map.h
Expand Up @@ -38,6 +38,10 @@ class Map : public std::map<Key, Value>
using const_iterator = typename Base::const_iterator;
using reverse_iterator = typename Base::reverse_iterator;
using const_reverse_iterator = typename Base::const_reverse_iterator;

void insert(const Key &key, const Value &value) { Base::operator[](key) = value; }
bool contains(const Key &key) const { return Base::find(key) != Base::end(); }
const_iterator constFind(const Key &key) const { return Base::find(key); }
};

} // namespace de
Expand Down

0 comments on commit 9a73627

Please sign in to comment.