#ifndef NBTMODIFIER_ABSTRACTTAG_H #define NBTMODIFIER_ABSTRACTTAG_H #include class QDataStream; /** * Interface for all NBT tags */ class AbstractTag { public: /** * When tag is destruct */ virtual inline ~AbstractTag () {}; /** * The tag's id * * @return The tag's id */ const quint8 id () const; /** * Extract next tag's id from data (not consuming) * * @param data The data to read * * @return The next tag's id */ static const quint8 extractId (const QByteArray &data); /** * Create an empty tag of a giving id * * @param id The new tag's id * * @return The new tag, or nullptr if no valid id provided */ static AbstractTag *createEmptyFromId (const quint8 id); /** * Create an empty tag of the next tag's id from data (not consuming) * * @param data The data to read * * @return The new tag, or nullptr if invalid data provided */ static AbstractTag *createEmptyFromData (const QByteArray &data); /** * Read a tag from a data stream * * @param data The data stream * * @return True if read is success, otherwise false */ virtual void readFromData (QDataStream &data) = 0; /** * Write a tag to a data stream * * @param data The data stream * * @return True if write is success, otherwise false */ virtual void writeToData (QDataStream &data) const = 0; /** * Convenient operator to read a tag from a data stream * * @param tag The tag read * @param data The data stream * * @return The data stream (allow call chaining) * * @see readFromData */ friend QDataStream &operator >> (QDataStream &data, AbstractTag &tag); /** * Convenient operator to write a tag to a data stream * * @param data The data stream * @param tag The tag to write * * @return The data stream (allow call chaining) * * @see writeToData */ friend QDataStream &operator << (QDataStream &data, const AbstractTag &tag); protected: /** * Create a new tag * * @param id */ explicit AbstractTag (const quint8 id); private: /** * The tag's ID */ const quint8 m_id; }; #endif //NBTMODIFIER_ABSTRACTTAG_H