Navigation Menu

Skip to content

Commit

Permalink
libcore: constexpr constructor for Vector; other minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 6f5a2a2 commit fa89e98
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 10 deletions.
5 changes: 5 additions & 0 deletions doomsday/libs/core/include/de/core/app.h
Expand Up @@ -283,6 +283,11 @@ class DE_PUBLIC App : DE_OBSERVES(Clock, TimeChange)
*/
static NativePath tempPath();

/**
* Returns a native directory for caching non-user-specific (native) files.
*/
static NativePath cachePath();

/**
* Changes the application's current native working directory.
*
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libs/core/include/de/core/vector.h
Expand Up @@ -107,7 +107,7 @@ class Vector2
typedef Type value_type;

public:
Vector2(Type a = Type(0), Type b = Type(0)) : x(a), y(b) {}
constexpr Vector2(Type a = Type(0), Type b = Type(0)) : x(a), y(b) {}
Vector2(Type const *ab) : x(ab[0]), y(ab[1]) {}
Vector2(Value const &value) { *this = vectorFromValue<Vector2<Type>>(value); }
Vector2(Vector2 const &other) = default;
Expand Down Expand Up @@ -323,7 +323,7 @@ template <typename Type>
class Vector3 : public Vector2<Type>
{
public:
Vector3(Type a = 0, Type b = 0, Type c = 0) : Vector2<Type>(a, b), z(c) {}
constexpr Vector3(Type a = 0, Type b = 0, Type c = 0) : Vector2<Type>(a, b), z(c) {}
Vector3(Vector2<Type> const &v2, Type c = 0) : Vector2<Type>(v2), z(c) {}
Vector3(Type const *abc) : Vector2<Type>(abc), z(abc[2]) {}
Vector3(Value const &value) { *this = vectorFromValue< Vector3<Type> >(value); }
Expand Down Expand Up @@ -552,7 +552,7 @@ template <typename Type>
class Vector4 : public Vector3<Type>
{
public:
Vector4(Type a = 0, Type b = 0, Type c = 0, Type d = 0) : Vector3<Type>(a, b, c), w(d) {}
constexpr Vector4(Type a = 0, Type b = 0, Type c = 0, Type d = 0) : Vector3<Type>(a, b, c), w(d) {}
Vector4(Vector3<Type> const &v3, Type d = 0) : Vector3<Type>(v3), w(d) {}
Vector4(Vector2<Type> const &a, Vector2<Type> const &b) : Vector3<Type>(a, b.x), w(b.y) {}
Vector4(Type const *abcd) : Vector3<Type>(abcd), w(abcd[3]) {}
Expand Down
6 changes: 5 additions & 1 deletion doomsday/libs/core/include/de/data/bitarray.h
Expand Up @@ -39,12 +39,16 @@ class DE_PUBLIC BitArray
dsize size() const;
dsize count(bool bit) const;

inline int sizei() const { return int(_bits.size()); }
void clear();
void resize(dsize count);
void fill(bool bit);
void setBit(dsize pos, bool bit);
void setBit(dsize pos, bool bit = true);

BitArray &operator=(const BitArray &);

BitArray &operator<<(bool bit);

private:
std::vector<char> _bits;
};
Expand Down
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/data/hash.h
Expand Up @@ -54,6 +54,7 @@ class Hash : public std::unordered_map<Key, Value, HashFn, KeyEqual>
using Base::find;

bool isEmpty() const { return empty(); }
inline int sizei() const { return int(Base::size()); }

iterator insert(const Key &key, const Value &value) { return Base::insert(std::make_pair(key, value)).first; }
void remove(const Key &key) { Base::erase(key); }
Expand Down
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/data/map.h
Expand Up @@ -44,6 +44,7 @@ class Map : public std::map<Key, Value, Compare>
using const_reverse_iterator = typename Base::const_reverse_iterator;

inline bool isEmpty() const { return Base::empty(); }
inline int sizei() const { return int(Base::size()); }

iterator insert(const Key &key, const Value &value)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/string.h
Expand Up @@ -318,7 +318,7 @@ class DE_PUBLIC String : public IByteArray

bool contains(char c) const;
bool contains(Char c) const;
bool contains(const char *cStr) const;
bool contains(const char *cStr, Sensitivity cs = CaseSensitive) const;
int count(char ch) const;

bool beginsWith(const String &s, Sensitivity cs = CaseSensitive) const
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/time.h
Expand Up @@ -62,7 +62,7 @@ class DE_PUBLIC Time : public ISerializable
*
* @param seconds Length of the time span.
*/
Span(ddouble seconds = 0.0)
constexpr Span(ddouble seconds = 0.0)
: _seconds(seconds)
{}

Expand Down
6 changes: 4 additions & 2 deletions doomsday/libs/core/include/de/data/variable.h
Expand Up @@ -143,14 +143,14 @@ class DE_PUBLIC Variable : public Deletable, public ISerializable
*
* @param v New value. Variable gets ownership. Cannot be NULL.
*/
Variable &operator = (Value *v);
Variable &operator=(Value *v);

/**
* Sets the value of the variable.
*
* @param textValue Text string. A new TextValue is created.
*/
Variable &operator = (String const &textValue);
Variable &operator=(String const &textValue);

/**
* Sets the value of the variable.
Expand All @@ -172,6 +172,8 @@ class DE_PUBLIC Variable : public Deletable, public ISerializable
Value *valuePtr();
Value const *valuePtr() const;

bool operator==(const String &text) const;

/**
* Returns the value of the variable.
*/
Expand Down
6 changes: 6 additions & 0 deletions doomsday/libs/core/include/de/libcore.h
Expand Up @@ -143,6 +143,12 @@
# undef DE_UNUSED
#endif

#if defined (__clang__)
# define DE_FALLTHROUGH [[clang::fallthrough]]
#else
# define DE_FALLTHROUGH
#endif

#ifndef NDEBUG
# define DE_DEBUG
DE_EXTERN_C DE_PUBLIC void LogBuffer_Flush(void);
Expand Down
6 changes: 6 additions & 0 deletions doomsday/libs/core/src/core/app.cpp
Expand Up @@ -682,6 +682,12 @@ NativePath App::tempPath()
#endif
}

NativePath App::cachePath()
{
DE_ASSERT_FAIL("App::cachePath() not implemented");
return NativePath();
}

bool App::setCurrentWorkPath(NativePath const &cwd)
{
return NativePath::setWorkPath(cwd);
Expand Down
11 changes: 11 additions & 0 deletions doomsday/libs/core/src/data/bitarray.cpp
Expand Up @@ -51,6 +51,11 @@ dsize BitArray::count(bool bit) const
return num;
}

void BitArray::clear()
{
_bits.clear();
}

void BitArray::resize(dsize count)
{
return _bits.resize(count);
Expand All @@ -76,4 +81,10 @@ BitArray &BitArray::operator=(const BitArray &other)
return *this;
}

BitArray &BitArray::operator<<(bool bit)
{
_bits.push_back(bit ? 1 : 0);
return *this;
}

} // namespace de
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/data/string.cpp
Expand Up @@ -192,9 +192,9 @@ bool String::contains(Char c) const
return contains(mb.bytes);
}

bool String::contains(const char *cStr) const
bool String::contains(const char *cStr, Sensitivity cs) const
{
return indexOfCStr_String(&_str, cStr) != iInvalidPos;
return indexOfCStrSc_String(&_str, cStr, cs) != iInvalidPos;
}

int String::count(char ch) const
Expand Down
5 changes: 5 additions & 0 deletions doomsday/libs/core/src/data/variable.cpp
Expand Up @@ -178,6 +178,11 @@ Value const *Variable::valuePtr() const
return d->value;
}

bool Variable::operator==(const String &text) const
{
return d->value && d->value->compare(TextValue(text)) == 0;
}

Record &Variable::valueAsRecord()
{
return value<RecordValue>().dereference();
Expand Down

0 comments on commit fa89e98

Please sign in to comment.