Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __NBTHPP__
- #define __NBTHPP__
- #include <string>
- #include <vector>
- #include <cstdint>
- enum NBT_Types {
- TAG_End_id,
- TAG_Byte_id,
- TAG_Short_id,
- TAG_Int_id,
- TAG_Long_id,
- TAG_Float_id,
- TAG_Double_id,
- TAG_Byte_Array_id,
- TAG_String_id,
- TAG_List_id,
- TAG_Compound_id,
- TAG_Int_Array_id
- };
- class TAG {
- public:
- virtual ~TAG(){};
- virtual unsigned char* encode(unsigned char*) =0;
- virtual unsigned char* decode(unsigned char*) =0;
- virtual unsigned int tag_size() =0;
- virtual std::string pretty_print(int) =0;
- virtual int get_id() =0;
- std::string get_name();
- void set_name(std::string);
- protected:
- std::string name;
- };
- template<typename T, int id>
- class _TAG_Numeric: public TAG {
- public:
- _TAG_Numeric(){};
- _TAG_Numeric(T);
- virtual ~_TAG_Numeric(){};
- unsigned int tag_size();
- std::string pretty_print(int);
- int get_id();
- T get_val();
- void set_val(T);
- protected:
- T val;
- };
- template<typename T, typename Shift_T, int id>
- class _TAG_Integral: public _TAG_Numeric<T, id> {
- public:
- _TAG_Integral(): _TAG_Numeric<T, id>(){};
- _TAG_Integral(T new_val): _TAG_Numeric<T, id>(new_val){};
- virtual ~_TAG_Integral(){};
- unsigned char* encode(unsigned char*);
- unsigned char* decode(unsigned char*);
- protected:
- using _TAG_Numeric<T, id>::val;
- };
- typedef _TAG_Integral<int8_t, uint8_t, TAG_Byte_id> TAG_Byte;
- typedef _TAG_Integral<int16_t, uint16_t, TAG_Short_id> TAG_Short;
- typedef _TAG_Integral<int32_t, uint32_t, TAG_Int_id> TAG_Int;
- typedef _TAG_Integral<int64_t, uint64_t, TAG_Long_id> TAG_Long;
- template<typename T, typename Shift_T, int id>
- class _TAG_Precision: public _TAG_Numeric<T, id> {
- public:
- _TAG_Precision(): _TAG_Numeric<T, id>(){};
- _TAG_Precision(T new_val): _TAG_Numeric<T, id>(new_val){};
- virtual ~_TAG_Precision(){};
- unsigned char* encode(unsigned char*);
- unsigned char* decode(unsigned char*);
- protected:
- using _TAG_Numeric<T, id>::val;
- };
- typedef _TAG_Precision<float, uint32_t, TAG_Float_id> TAG_Float;
- typedef _TAG_Precision<double, uint64_t, TAG_Double_id> TAG_Double;
- template<typename T, class TAG_T, int id>
- class _TAG_Array: public TAG {
- public:
- virtual ~_TAG_Array(){};
- unsigned char* encode(unsigned char*);
- unsigned char* decode(unsigned char*);
- unsigned int tag_size();
- std::string pretty_print(int);
- int get_id();
- T& operator[](unsigned int);
- unsigned int array_size();
- void resize(unsigned int);
- protected:
- std::vector<T> vtr;
- };
- typedef _TAG_Array<int8_t, TAG_Byte, TAG_Byte_Array_id> TAG_Byte_Array;
- typedef _TAG_Array<int32_t, TAG_Int, TAG_Int_Array_id> TAG_Int_Array;
- class TAG_String: public TAG {
- public:
- TAG_String(){};
- TAG_String(std::string);
- unsigned char* encode(unsigned char*);
- unsigned char* decode(unsigned char*);
- unsigned int tag_size();
- std::string pretty_print(int);
- int get_id();
- std::string get_val();
- void set_val(std::string);
- protected:
- std::string str;
- };
- class TAG_List: public TAG {
- public:
- TAG_List(){};
- TAG_List(int, int);
- ~TAG_List();
- unsigned char* encode(unsigned char*);
- unsigned char* decode(unsigned char*);
- unsigned int tag_size();
- std::string pretty_print(int);
- int get_id();
- TAG* operator[](unsigned int);
- unsigned int array_size();
- void resize(unsigned int);
- int get_type();
- void set_type(int);
- protected:
- std::vector<TAG*> vtr;
- int tag_type;
- };
- class TAG_Compound: public TAG {
- public:
- unsigned char* encode(unsigned char*);
- unsigned char* decode(unsigned char*);
- unsigned int tag_size();
- std::string pretty_print(int);
- int get_id();
- TAG* operator[](unsigned int);
- TAG* operator[](std::string);
- unsigned int array_size();
- void resize(unsigned int);
- protected:
- std::vector<TAG*> vtr;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement