ソースを参照

移除无用的部分

akemimadoka 7 年 前
コミット
913812643a
5 ファイル変更47 行追加40 行削除
  1. 3 8
      YumeBot/Jce.cpp
  2. 32 26
      YumeBot/Jce.h
  3. 2 2
      YumeBot/JceStructDef.h
  4. 2 4
      YumeBot/YumeBot.h
  5. 8 0
      YumeBot/YumeBot.vcxproj

+ 3 - 8
YumeBot/Jce.cpp

@@ -34,19 +34,14 @@ JceOutputStream::~JceOutputStream()
 {
 }
 
-#define JCE_STRUCT(name, code) \
+#define JCE_STRUCT(name) \
 	name::~name()\
 	{\
 	}\
 	\
-	std::string_view name::GetJceStructName() const noexcept\
+	nStrView name::GetJceStructName() const noexcept\
 	{\
-		return #name;\
-	}\
-	\
-	JceCode name::GetJceStructType() const noexcept\
-	{\
-		return JceCode::name;\
+		return u8 ## #name ## _nv;\
 	}
 
 #include "JceStructDef.h"

+ 32 - 26
YumeBot/Jce.h

@@ -1,6 +1,7 @@
 #pragma once
 #include <natBinary.h>
 #include <optional>
+#include <string_view>
 #include "Utility.h"
 
 namespace YumeBot::Jce
@@ -9,14 +10,12 @@ namespace YumeBot::Jce
 	DeclareException(JceDecodeException, JceException, u8"YumeBot::Jce::JceDecodeException");
 	DeclareException(JceEncodeException, JceException, u8"YumeBot::Jce::JceEncodeException");
 
-	enum class JceCode;
-
 	// Jce 中 Byte 是有符号的,此处表示为无符号,使用时需注意
 	class JceStruct
 		: public NatsuLib::natRefObj
 	{
 	public:
-#define JCE_FIELD_TYPE(OP)\
+#define JCE_FIELD_TYPE(OP) \
 	OP(Byte, 0x00, std::uint8_t)\
 	OP(Short, 0x01, std::int16_t)\
 	OP(Int, 0x02, std::int32_t)\
@@ -39,12 +38,26 @@ namespace YumeBot::Jce
 #undef ENUM_OP
 		};
 
+		static constexpr nStrView GetTypeString(TypeEnum type) noexcept
+		{
+			using namespace NatsuLib::StringLiterals;
+			switch (type)
+			{
+#define STRINGIFY_OP(name, code, type) \
+			case TypeEnum::name:\
+				return u8 ## #name ## _nv;
+			JCE_FIELD_TYPE(STRINGIFY_OP)
+#undef STRINGIFY_OP
+			default:
+				return u8"UnknownType"_nv;
+			}
+		}
+
 		static constexpr std::size_t MaxStringLength = 0x06400000;
 
 		~JceStruct();
 
-		virtual std::string_view GetJceStructName() const noexcept = 0;
-		virtual JceCode GetJceStructType() const noexcept = 0;
+		virtual nStrView GetJceStructName() const noexcept = 0;
 	};
 
 	template <typename T>
@@ -769,13 +782,6 @@ namespace YumeBot::Jce
 		}
 	};
 
-	enum class JceCode
-	{
-#define JCE_STRUCT(name, code) name = code,
-#include "JceStructDef.h"
-
-	};
-
 	struct NoOp
 	{
 		template <typename T>
@@ -814,7 +820,7 @@ namespace YumeBot::Jce
 	{\
 	};
 
-JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
+	JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 
 #undef FIELD_TYPE_BUILDER_OP
 
@@ -850,15 +856,14 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 			return tag;\
 		}
 
-#define JCE_STRUCT(name, code) \
+#define JCE_STRUCT(name) \
 	class name\
 		: public NatsuLib::natRefObjImpl<name, JceStruct>\
 	{\
 	public:\
 		~name();\
 		\
-		std::string_view GetJceStructName() const noexcept override;\
-		JceCode GetJceStructType() const noexcept override;
+		nStrView GetJceStructName() const noexcept override;
 
 #define END_JCE_STRUCT(name) \
 	};
@@ -872,16 +877,17 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 
 // 读取 optional 的时候不会返回 false
 #define FIELD(name, tag, type, ...) \
-	{\
-		using FieldType = typename Utility::MayRemoveTemplate<Utility::RemoveCvRef<decltype(ret->Get##name())>, std::optional>::Type;\
-		if (!stream.Read(tag, ret->Get##name(),\
-			Utility::ReturnFirst<Utility::ConcatTrait<Utility::ConcatTrait<Utility::RemoveCvRef, Utility::BindTrait<std::is_same, Detail::NoneType>::Result>::Result, std::negation>::Result, Detail::NoneType>(__VA_ARGS__)))\
-		{\
-			nat_Throw(JceDecodeException, u8"Deserializing failed : Failed to read field \"" #name "\" which is not optional.");\
-		}\
-	}
+			{\
+				using FieldType = typename Utility::MayRemoveTemplate<Utility::RemoveCvRef<decltype(ret->Get##name())>, std::optional>::Type;\
+				if (!stream.Read(tag, ret->Get##name(),\
+					Utility::ReturnFirst<Utility::ConcatTrait<Utility::ConcatTrait<Utility::RemoveCvRef, Utility::BindTrait<std::is_same,\
+						Detail::NoneType>::Result>::Result, std::negation>::Result, Detail::NoneType>(__VA_ARGS__)))\
+				{\
+					nat_Throw(JceDecodeException, u8"Deserializing failed : Failed to read field \"" #name "\" which is not optional.");\
+				}\
+			}
 
-#define JCE_STRUCT(name, code) \
+#define JCE_STRUCT(name) \
 	template <>\
 	struct JceDeserializer<name>\
 	{\
@@ -899,7 +905,7 @@ JCE_FIELD_TYPE(FIELD_TYPE_BUILDER_OP)
 
 #define FIELD(name, tag, type, ...) stream.Write(tag, value->Get##name());
 
-#define JCE_STRUCT(name, code) \
+#define JCE_STRUCT(name) \
 	template <>\
 	struct JceSerializer<name>\
 	{\

+ 2 - 2
YumeBot/JceStructDef.h

@@ -1,5 +1,5 @@
 #ifndef JCE_STRUCT
-#define JCE_STRUCT(name, code)
+#define JCE_STRUCT(name)
 #endif
 
 #ifndef END_JCE_STRUCT
@@ -74,7 +74,7 @@
 #define SIMPLE_LIST(name, tag, ...) FIELD(name, tag, SimpleList, __VA_ARGS__)
 #endif
 
-JCE_STRUCT(JceTest, 0)
+JCE_STRUCT(JceTest)
 	INT(TestInt, 0)
 	FLOAT(TestFloat, 1, IS_OPTIONAL(1.0f))
 	MAP(TestMap, 2, TEMPLATE_ARGUMENT(std::int32_t, float))

+ 2 - 4
YumeBot/YumeBot.h

@@ -1,9 +1,5 @@
 #pragma once
 
-#pragma warning (disable : 4996)
-
-#include <natRefObj.h>
-
 #ifdef _WIN32
 #include <SDKDDKVer.h>
 #endif // _WIN32
@@ -12,6 +8,8 @@
 #define _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING 1
 #include <asio.hpp>
 
+#include <natRefObj.h>
+
 namespace YumeBot
 {
 	class Bot

+ 8 - 0
YumeBot/YumeBot.vcxproj

@@ -119,6 +119,8 @@
       <ConformanceMode>true</ConformanceMode>
       <AdditionalIncludeDirectories>$(SolutionDir)Extern\NatsuLib\NatsuLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <LanguageStandard>stdcpplatest</LanguageStandard>
+      <DisableSpecificWarnings>
+      </DisableSpecificWarnings>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -142,6 +144,8 @@
       <ConformanceMode>true</ConformanceMode>
       <AdditionalIncludeDirectories>$(SolutionDir)Extern\NatsuLib\NatsuLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <LanguageStandard>stdcpplatest</LanguageStandard>
+      <DisableSpecificWarnings>
+      </DisableSpecificWarnings>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -167,6 +171,8 @@
       <ConformanceMode>true</ConformanceMode>
       <AdditionalIncludeDirectories>$(SolutionDir)Extern\NatsuLib\NatsuLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <LanguageStandard>stdcpplatest</LanguageStandard>
+      <DisableSpecificWarnings>
+      </DisableSpecificWarnings>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -194,6 +200,8 @@
       <ConformanceMode>true</ConformanceMode>
       <AdditionalIncludeDirectories>$(SolutionDir)Extern\NatsuLib\NatsuLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <LanguageStandard>stdcpplatest</LanguageStandard>
+      <DisableSpecificWarnings>
+      </DisableSpecificWarnings>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>