xTachyon

Untitled

Oct 24th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #ifndef REDI_NBT_BASE
  2. # define REDI_NBT_BASE
  3.  
  4. # include <iostream>
  5. # include <memory>
  6.  
  7. namespace redi
  8. {
  9. namespace nbt
  10. {
  11.  
  12. enum class NBTType : std::uint8_t
  13. {
  14.   End,
  15.   Byte,
  16.   Short,
  17.   Int,
  18.   Long,
  19.   Float,
  20.   Double,
  21.   ByteArray,
  22.   String,
  23.   List,
  24.   Compound,
  25.   IntArray
  26. };
  27.  
  28. inline std::ostream& operator<<(std::ostream& os, NBTType type)
  29. {
  30.   os << static_cast<int>(type);
  31.   return os;
  32. }
  33.  
  34. template <typename T, NBTType tagType>
  35. class ScalarTag;
  36.  
  37. using TagByte = ScalarTag<std::int8_t, NBTType::Byte>;
  38. using TagShort = ScalarTag<std::int16_t, NBTType::Short>;
  39. using TagInt = ScalarTag<std::int32_t, NBTType::Int>;
  40. using TagLong = ScalarTag<std::int64_t, NBTType::Long>;
  41. using TagFloat = ScalarTag<float, NBTType::Float>;
  42. using TagDouble = ScalarTag<double, NBTType::Double>;
  43.  
  44. class Tag
  45. {
  46. public:
  47.  
  48.   Tag(NBTType type);
  49.  
  50.   virtual ~Tag() = 0;
  51.  
  52.   NBTType getType() const { return mType; }
  53.  
  54.   //template <typename T>
  55.   //T& get()
  56.   //{
  57.   //  T* ptr = dynamic_cast<T*>(this);
  58.   //  if (ptr) return *ptr;
  59.   //  throw std::invalid_argument("");
  60.   //}
  61.  
  62.   //template <typename T>
  63.   //const T& get() const
  64.   //{
  65.   // const T* ptr = dynamic_cast<const T*>(this);
  66.   // if (ptr) return *ptr;
  67.   // throw std::invalid_argument("");
  68.   //}
  69.  
  70.   template <NBTType type>
  71.   void get()
  72.   {
  73.  
  74.   }
  75.  
  76.  
  77.  
  78.   /*
  79.   {
  80.   blah<E::b>();
  81.   blah<E::a>();
  82.   }
  83.   enum class E { a, b };
  84.  
  85.   template <E e>
  86.   void blah() { cout << "0"; }
  87.  
  88.   template <>
  89.   void blah<E::a>() { cout << "1"; }  //
  90.   */
  91.  
  92. protected:
  93.  
  94.   NBTType mType;
  95. };
  96.  
  97. template <>
  98. inline TagByte Tag::get<NBTType::Byte>()
  99. {
  100.   //return get<TagByte>();
  101.   return TagByte();
  102. }
  103.  
  104. using TagPtr = std::shared_ptr<Tag>;
  105.  
  106. } // namespace nbt
  107. } // namespace redi
  108.  
  109. #endif
  110.  
  111.  
  112. Severity    Code    Description Project File    Line    Suppression State
  113. Error   C2910   'redi::nbt::Tag::get': cannot be explicitly specialized redi    e:\info\repos\redstoneinside\src\nbt\tag.hpp    102
  114. x 3
Advertisement
Add Comment
Please, Sign In to add comment