Skip to content

Commit

Permalink
libcore: Conveniently checking if String and Block are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 14, 2017
1 parent 0b59393 commit 64b10f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
52 changes: 27 additions & 25 deletions doomsday/sdk/libcore/include/de/data/block.h
Expand Up @@ -81,37 +81,14 @@ class DENG2_PUBLIC Block : public QByteArray, public IByteArray, public IBlock,
*/
Block(IByteArray const &array, Offset at, Size count);

// Implements IByteArray.
Size size() const;
void get(Offset at, Byte *values, Size count) const;
void set(Offset at, Byte const *values, Size count);

// Implements IBlock.
void clear();
void copyFrom(IByteArray const &array, Offset at, Size count);
void resize(Size size);
Byte const *data() const;

// Implements ISerializable.
/**
* Writes @a block into the destination buffer. Writes the size of the
* block in addition to its contents, so a Reader will not need to know
* beforehand how large the block is.
*
* @param block Block to write.
*
* @return Reference to the Writer.
*/
void operator >> (Writer &to) const;

void operator << (Reader &from);

Byte *data();
Byte const *dataConst() const;

Block &append(Byte b);
Block &append(char const *str, int len);

inline explicit operator bool() const { return !isEmpty(); }

Block &operator += (char const *nullTerminatedCStr);
Block &operator += (QByteArray const &bytes);

Expand All @@ -131,6 +108,31 @@ class DENG2_PUBLIC Block : public QByteArray, public IByteArray, public IBlock,
Block md5Hash() const;
String asHexadecimalText() const;

// Implements IByteArray.
Size size() const;
void get(Offset at, Byte *values, Size count) const;
void set(Offset at, Byte const *values, Size count);

// Implements IBlock.
void clear();
void copyFrom(IByteArray const &array, Offset at, Size count);
void resize(Size size);
Byte const *data() const;

// Implements ISerializable.
/**
* Writes @a block into the destination buffer. Writes the size of the
* block in addition to its contents, so a Reader will not need to know
* beforehand how large the block is.
*
* @param block Block to write.
*
* @return Reference to the Writer.
*/
void operator >> (Writer &to) const;

void operator << (Reader &from);

public:
static Block join(QList<Block> const &blocks, Block const &sep = Block());
};
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/data/string.h
Expand Up @@ -106,6 +106,8 @@ class DENG2_PUBLIC String : public QString
return *this;
}

inline explicit operator bool() const { return size() > 0; }

/// Conversion to a character pointer.
operator QChar const *() const {
return data();
Expand Down

0 comments on commit 64b10f0

Please sign in to comment.