Skip to content

Commit

Permalink
libcore: Continuing removal of Qt dependencies
Browse files Browse the repository at this point in the history
Added a static string literal macro in the likeness of QStringLiteral.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 807b989 commit 7b1e43d
Show file tree
Hide file tree
Showing 33 changed files with 540 additions and 377 deletions.
8 changes: 4 additions & 4 deletions doomsday/libs/core/include/de/core/app.h
Expand Up @@ -322,7 +322,7 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*
* @return Number of files found.
*/
static int findInPackages(const CString &partialPath, FileIndex::FoundFiles &files);
static int findInPackages(const String &partialPath, FileIndex::FoundFiles &files);

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

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

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

/**
* Returns the web API URL. Always includes the protocol and ends with a slash.
Expand Down
14 changes: 7 additions & 7 deletions doomsday/libs/core/include/de/core/config.h
Expand Up @@ -78,27 +78,27 @@ class DE_PUBLIC Config : public RecordAccessor, public IObject
*
* @return Variable whose value was set.
*/
Variable &set(const CString &name, bool value);
Variable &set(const String &name, bool value);

/// @copydoc set()
Variable &set(const CString &name, Value::Text const &value);
Variable &set(const String &name, Value::Text const &value);

/// @copydoc set()
Variable &set(const CString &name, Value::Number const &value);
Variable &set(const String &name, Value::Number const &value);

/// @copydoc set()
Variable &set(const CString &name, dint value);
Variable &set(const String &name, dint value);

/// @copydoc set()
Variable &set(const CString &name, duint value);
Variable &set(const String &name, duint value);

/**
* Sets the value of a variable, creating the variable if it doesn't exist.
*
* @param name Name of the variable. May contain subrecords using the dot notation.
* @param value Array to use as the value of the variable. Ownership taken.
*/
Variable &set(const CString &name, ArrayValue *value);
Variable &set(const String &name, ArrayValue *value);

/**
* Returns the old version, when a new installed version has been detected.
Expand All @@ -111,7 +111,7 @@ class DE_PUBLIC Config : public RecordAccessor, public IObject
Record const &objectNamespace() const;

static Config &get();
static Variable &get(const CString &name);
static Variable &get(const String &name);
static bool exists();

private:
Expand Down
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/data/block.h
Expand Up @@ -57,6 +57,7 @@ class DE_PUBLIC Block
Block(const Block &other);
Block(Block &&moved);
Block(const char *nullTerminatedCStr);
Block(const std::string &str);
Block(const void *data, Size length);

/**
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libs/core/include/de/data/cstring.h
Expand Up @@ -56,6 +56,8 @@ class DE_PUBLIC CString
updateEnd();
return _range.size();
}
bool isEmpty() const { return size() == 0; }
bool empty() const { return size() == 0; }
bool contains(char ch) const;
dsize indexOf(char ch, size_t from = 0) const;
dsize indexOf(const char *cStr, size_t from = 0) const;
Expand Down
49 changes: 47 additions & 2 deletions doomsday/libs/core/include/de/data/hash.h
Expand Up @@ -35,10 +35,55 @@ class Hash : public std::unordered_map<Key, Value>
public:
Hash();

void insert(const Key &key, const Value &value) { Base::operator[](key) = value; }
bool contains(const Key &key) const { return Base::find(key) != Base::end(); }
void insert(const Key &key, const Value &value) { Base::operator[](key) = value; }
void remove(const Key &key) { Base::erase(key); }
bool contains(const Key &key) const { return Base::find(key) != Base::end(); }
Value & operator[](const Key &key) { return Base::operator[](key); }
const Value &operator[](const Key &key) const { return Base::find(key)->second; }
};

template <typename Key, typename Value>
class MutableHashIterator
{
using Container = Hash<Key, Value>;
using Iterator = typename Container::iterator;

Container _hash;
Iterator _cur;
Iterator _next;

public:
MutableHashIterator(Container &c) : _hash(c)
{
_next = c.begin();
}

bool hasNext() const
{
return _next != _hash.end();
}

Iterator &next()
{
_cur = _next++;
return _cur;
}

const typename Container::key_type &key() const
{
return _cur->first;
}

const typename Container::value_type::second_type &value() const
{
return _cur->second;
}

void remove()
{
_hash.erase(_cur);
}
};
} // namespace de

#endif // LIBCORE_HASH_H
49 changes: 49 additions & 0 deletions doomsday/libs/core/include/de/data/map.h
Expand Up @@ -40,8 +40,57 @@ class Map : public std::map<Key, Value>
using const_reverse_iterator = typename Base::const_reverse_iterator;

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

void deleteAll()
{
for (auto i : *this) { delete i->second; }
}
};

template <typename Key, typename Value>
class MutableMapIterator
{
using Container = Map<Key, Value>;
using Iterator = typename Container::iterator;

Container _map;
Iterator _cur;
Iterator _next;

public:
MutableMapIterator(Container &c) : _map(c)
{
_next = c.begin();
}

bool hasNext() const
{
return _next != _map.end();
}

Iterator &next()
{
_cur = _next++;
return _cur;
}

const typename Container::key_type &key() const
{
return _cur->first;
}

const typename Container::value_type::second_type &value() const
{
return _cur->second;
}

void remove()
{
_map.erase(_cur);
}
};

} // namespace de
Expand Down

0 comments on commit 7b1e43d

Please sign in to comment.