You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
#ifndef NBTMODIFIER_NBT_PAYLOAD_ABSTRACTNUMERIC_H
|
|
#define NBTMODIFIER_NBT_PAYLOAD_ABSTRACTNUMERIC_H
|
|
|
|
#include <QtCore/qpoint.h>
|
|
#include "IPayload.h"
|
|
|
|
namespace NBT {
|
|
namespace Payload {
|
|
/**
|
|
* NBT "numeric" payload (Byte, Short, Int, Long, Float, Double)
|
|
*/
|
|
template<typename T>
|
|
class AbstractNumeric : public IPayload {
|
|
static_assert(
|
|
std::is_same<T, qint8>::value
|
|
|| std::is_same<T, qint16>::value
|
|
|| std::is_same<T, qint32>::value
|
|
|| std::is_same<T, qint64>::value
|
|
|| std::is_same<T, float>::value
|
|
|| std::is_same<T, double>::value,
|
|
"The \"AbstractNumeric\" payload must be type of qint8 (Byte), qint16 (Short), qint32 (Int), qint64 (Long), float or double"
|
|
);
|
|
|
|
public:
|
|
/**
|
|
* New payload
|
|
*
|
|
* @param value The payload value
|
|
*/
|
|
AbstractNumeric (T const value = 0);
|
|
|
|
/**
|
|
* The payload value
|
|
*
|
|
* @return The payload value
|
|
*/
|
|
const T value () const;
|
|
/**
|
|
* Change the payload value
|
|
*
|
|
* @param value The new value
|
|
*/
|
|
void setValue (T const value);
|
|
|
|
virtual void readFromData (QDataStream &stream) override;
|
|
virtual void writeToData (QDataStream &stream) const override;
|
|
|
|
private:
|
|
T m_value;
|
|
};
|
|
|
|
#define IMPLEMENTS_ABSTRACTNUMERIC(className, templateType, id) class className : public AbstractNumeric<templateType> { virtual inline quint8 const ID () const override { return id; } };
|
|
|
|
IMPLEMENTS_ABSTRACTNUMERIC(Byte, qint8, 1)
|
|
|
|
IMPLEMENTS_ABSTRACTNUMERIC(Short, qint16, 2)
|
|
|
|
IMPLEMENTS_ABSTRACTNUMERIC(Int, qint32, 3)
|
|
|
|
IMPLEMENTS_ABSTRACTNUMERIC(Long, qint64, 4)
|
|
|
|
IMPLEMENTS_ABSTRACTNUMERIC(Float, float, 5)
|
|
|
|
IMPLEMENTS_ABSTRACTNUMERIC(Double, double, 6)
|
|
}
|
|
}
|
|
|
|
#include "AbstractNumeric.tpp"
|
|
|
|
#endif //NBTMODIFIER_NBT_PAYLOAD_ABSTRACTNUMERIC_H
|