浏览代码

Refactoring

Panagiotis Christopoulos Charitos 14 年之前
父节点
当前提交
e0f221fb9a

文件差异内容过多而无法显示
+ 0 - 1
build/debug/Makefile


+ 1 - 1
shaders/PpsSsao.glsl

@@ -66,7 +66,7 @@ vec3 getPosition(in vec2 uv)
 	fragPosVspace.xy = (((uv) * 2.0) - 1.0) * limitsOfNearPlane;
 	
 	float sc = -fragPosVspace.z / zNear;
-    fragPosVspace.xy *= sc;
+	fragPosVspace.xy *= sc;
 
 	return fragPosVspace;
 }

+ 6 - 6
src/Misc/Parser.h

@@ -33,30 +33,30 @@ namespace Parser {
 /// @param arr The array that the func returns the numbers
 /// @exception Exception
 template <typename Type>
-void parseArrOfNumbers(Scanner& scanner, bool bracket, bool signs, uint size, Type* arr);
+void parseArrOfNumbers(Scanner::Scanner& scanner, bool bracket, bool signs, uint size, Type* arr);
 
 /// Parse a single number
 /// @param scanner The scanner that we will use
 /// @param sign If true expect sign or not
 /// @param out The output number
 template <typename Type>
-void parseNumber(Scanner& scanner, bool sign, Type& out);
+void parseNumber(Scanner::Scanner& scanner, bool sign, Type& out);
 
 /// Parses a math structure (Vec3, Vec4, Mat3 etc) with leading and following brackets. Eg {0.1 0.2 0.3}
 template <typename Type>
-void parseMathVector(Scanner& scanner, Type& out);
+void parseMathVector(Scanner::Scanner& scanner, Type& out);
 
 /// Parse true or false identifiers
-extern bool parseBool(Scanner& scanner);
+extern bool parseBool(Scanner::Scanner& scanner);
 
 /// Parse identifier
-extern std::string parseIdentifier(Scanner& scanner, const char* expectedIdentifier = NULL);
+extern std::string parseIdentifier(Scanner::Scanner& scanner, const char* expectedIdentifier = NULL);
 
 /// Is identifier
 extern bool isIdentifier(const Scanner::Token* token, const char* str);
 
 /// Parse string
-extern std::string parseString(Scanner& scanner);
+extern std::string parseString(Scanner::Scanner& scanner);
 
 } // end namespace Parser
 

+ 6 - 6
src/Misc/Parser.inl.h

@@ -10,7 +10,7 @@ namespace Parser {
 // parseArrOfNumbers                                                                                                   =
 //======================================================================================================================
 template <typename Type>
-void parseArrOfNumbers(Scanner& scanner, bool bracket, bool signs, uint size, Type* arr)
+void parseArrOfNumbers(Scanner::Scanner& scanner, bool bracket, bool signs, uint size, Type* arr)
 {
 	const Scanner::Token* token;
 
@@ -83,7 +83,7 @@ void parseArrOfNumbers(Scanner& scanner, bool bracket, bool signs, uint size, Ty
 // parseNumber                                                                                                         =
 //======================================================================================================================
 template <typename Type>
-void parseNumber(Scanner& scanner, bool sign, Type& out)
+void parseNumber(Scanner::Scanner& scanner, bool sign, Type& out)
 {
 	try
 	{
@@ -137,7 +137,7 @@ void parseNumber(Scanner& scanner, bool sign, Type& out)
 // parseMathVector                                                                                                     =
 //======================================================================================================================
 template <typename Type>
-void parseMathVector(Scanner& scanner, Type& out)
+void parseMathVector(Scanner::Scanner& scanner, Type& out)
 {
 	try
 	{
@@ -175,7 +175,7 @@ void parseMathVector(Scanner& scanner, Type& out)
 //======================================================================================================================
 // parseBool                                                                                                           =
 //======================================================================================================================
-inline bool parseBool(Scanner& scanner)
+inline bool parseBool(Scanner::Scanner& scanner)
 {
 	const char* errMsg = "identifier true or false";
 
@@ -203,7 +203,7 @@ inline bool parseBool(Scanner& scanner)
 //======================================================================================================================
 // parseIdentifier                                                                                                     =
 //======================================================================================================================
-inline std::string parseIdentifier(Scanner& scanner, const char* expectedIdentifier)
+inline std::string parseIdentifier(Scanner::Scanner& scanner, const char* expectedIdentifier)
 {
 	const Scanner::Token* token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_IDENTIFIER)
@@ -239,7 +239,7 @@ inline bool isIdentifier(const Scanner::Token* token, const char* str)
 //======================================================================================================================
 // parseString                                                                                                         =
 //======================================================================================================================
-inline std::string parseString(Scanner& scanner)
+inline std::string parseString(Scanner::Scanner& scanner)
 {
 	const Scanner::Token* token = &scanner.getNextToken();
 	if(token->getCode() != Scanner::TC_STRING)

+ 1 - 1
src/Resources/ShaderProg/ShaderPrePreprocessor.cpp

@@ -71,7 +71,7 @@ void ShaderPrePreprocessor::parseFileForPragmas(const std::string& filename, int
 		throw EXCEPTION("File \"" + filename + "\": Cannot open or empty");
 	}
 
-	Scanner scanner(filename.c_str(), false);
+	Scanner::Scanner scanner(filename.c_str(), false);
 	const Scanner::Token* token;
 
 	while(true)

+ 8 - 8
src/Resources/SkelAnim.cpp

@@ -7,7 +7,7 @@
 //======================================================================================================================
 void SkelAnim::load(const char* filename)
 {
-	Scanner scanner(filename);
+	Scanner::Scanner scanner(filename);
 	const Scanner::Token* token;
 
 	// keyframes
@@ -26,10 +26,10 @@ void SkelAnim::load(const char* filename)
 	{
 		throw PARSER_EXCEPTION_EXPECTED("integer");
 	}
-	bones.resize(token->getValue().getInt());
+	boneAnims.resize(token->getValue().getInt());
 
 	// poses
-	for(uint i=0; i<bones.size(); i++)
+	for(uint i = 0; i < boneAnims.size(); i++)
 	{
 		// has anim?
 		token = &scanner.getNextToken();
@@ -41,17 +41,17 @@ void SkelAnim::load(const char* filename)
 		// it has
 		if(token->getValue().getInt() == 1)
 		{
-			bones[i].keyframes.resize(keyframes.size());
-
-			for(uint j=0; j<keyframes.size(); ++j)
+			for(uint j = 0; j < keyframes.size(); ++j)
 			{
 				// parse the quat
 				float tmp[4];
 				Parser::parseArrOfNumbers(scanner, false, true, 4, &tmp[0]);
-				bones[i].keyframes[j].rotation = Quat(tmp[1], tmp[2], tmp[3], tmp[0]);
 
 				// parse the vec3
-				Parser::parseArrOfNumbers(scanner, false, true, 3, &bones[i].keyframes[j].translation[0]);
+				Vec3 trs;
+				Parser::parseArrOfNumbers(scanner, false, true, 3, &trs[0]);
+
+				boneAnims[i].bonePoses.push_back(BonePose(Quat(tmp[1], tmp[2], tmp[3], tmp[0]), trs));
 			}
 		}
 	} // end for all bones

+ 64 - 54
src/Resources/SkelAnim.h

@@ -3,71 +3,81 @@
 
 #include "Math.h"
 #include "Vec.h"
+#include "Accessors.h"
+
+
+/// Bone pose
+struct BonePose
+{
+	public:
+		BonePose(const Quat& r, const Vec3& trs): rotation(r), translation(trs) {}
+
+		/// Copy contructor
+		BonePose(const BonePose& b): rotation(b.rotation), translation(b.translation) {}
+
+		/// @name Accessors
+		/// @{
+		GETTER_R(Quat, rotation, getRotation)
+		GETTER_R(Vec3, translation, getTranslation)
+		/// @}
+
+	private:
+		Quat rotation;
+		Vec3 translation;
+};
+
+
+/// Bone animation
+class BoneAnim
+{
+	friend class SkelAnim;
+
+	public:
+		/// @name Accessors
+		/// @{
+		GETTER_R(Vec<BonePose>, bonePoses, getBonePoses)
+		/// @}
+
+	private:
+		Vec<BonePose> bonePoses; ///< The poses for every keyframe. Its empty if the bone doesnt have any animation
+};
 
 
 /// Skeleton animation resource
 ///
-/// The format will be changed to:
-///
+/// The binary file format:
 /// @code
-/// keyframes {<integer> <integer> ... <integer>}
-/// bones
-/// {
-/// 	num <integer>
-/// 	boneAnims
-/// 	{
-/// 		boneAnim
-/// 		{
-/// 			hasAnim <true | false>
-/// 			[bonePoses
-/// 			{
-/// 				bonePose
-/// 				{
-/// 					quat {<float> <float> <float> <float>}
-/// 					trf {<float> <float> <float>}
-/// 				}
-/// 				...
-/// 				bonePose
-/// 				{
-/// 					...
-/// 				}
-/// 			}]
-/// 		}
-/// 		...
-/// 		boneAnim
-/// 		{
-/// 			...
-/// 		}
-/// 	}
-/// }
+/// magic: ANKIANIM
+/// uint: Keyframes number m
+/// m * uint: The keyframe numbers
+/// uint: Bone animations num, n, The n is equal to skeleton's bone number
+/// n * BoneAnim: Bone animations
+///
+/// BoneAnim:
+/// uint: Bone poses number. Its zero or m
+/// m * BonePose: Bone poses
+///
+/// BonePose:
+/// 4 * float: Quaternion for rotation
+/// 3 * float: Traslation
 /// @endcode
 class SkelAnim
 {
 	public:
-		/// Bone pose
-		class BonePose
-		{
-			public:
-				Quat rotation;
-				Vec3 translation;
-		};
-
-		/// Bone animation
-		class BoneAnim
-		{
-			public:
-				Vec<BonePose> keyframes; ///< The poses for every keyframe. Its empty if the bone doesnt have any animation
-
-				BoneAnim() {}
-				~BoneAnim() {}
-		};
-		
-		Vec<uint> keyframes;
-		uint framesNum;
-		Vec<BoneAnim> bones;
+		/// @name Accessors
+		/// @{
+		GETTER_R(Vec<uint>, keyframes, getKeyframes)
+		GETTER_R_BY_VAL(uint, framesNum, getFramesNum)
+		GETTER_R(Vec<BoneAnim>, boneAnims, getBoneAnims)
+		/// @}
 
-		/// Implements Resource::loat
+		/// Load
 		void load(const char* filename);
+
+	private:
+		Vec<uint> keyframes;
+		uint framesNum;
+		Vec<BoneAnim> boneAnims;
 };
 
 

+ 1 - 1
src/Resources/Skin.cpp

@@ -56,7 +56,7 @@ void Skin::load(const char* filename)
 		BOOST_FOREACH(const RsrcPtr<SkelAnim>& skelAnim, skelAnims)
 		{
 			// Bone number problem
-			if(skelAnim->bones.size() != skeleton->getBones().size())
+			if(skelAnim->getBoneAnims().size() != skeleton->getBones().size())
 			{
 				throw EXCEPTION("Skeleton animation \"" + skelAnim.getRsrcName() + "\" and skeleton \"" +
 								skeleton.getRsrcName() + "\" dont have equal bone count");

+ 12 - 12
src/Scene/Controllers/SkelAnimModelNodeCtrl.cpp

@@ -24,11 +24,11 @@ SkelAnimModelNodeCtrl::SkelAnimModelNodeCtrl(SkinNode& skinNode_):
 void SkelAnimModelNodeCtrl::interpolate(const SkelAnim& animation, float frame,
                                         Vec<Vec3>& boneTranslations, Vec<Mat3>& boneRotations)
 {
-	ASSERT(frame < animation.framesNum);
+	ASSERT(frame < animation.getFramesNum());
 
 	// calculate the t (used in slerp and lerp) using the keyframs and the frame and
 	// calc the lPose and rPose witch indicate the pose IDs in witch the frame lies between
-	const Vec<uint>& keyframes = animation.keyframes;
+	const Vec<uint>& keyframes = animation.getKeyframes();
 	float t = 0.0;
 	uint lPose = 0, rPose = 0;
 	for(uint j=0; j<keyframes.size(); j++)
@@ -50,27 +50,27 @@ void SkelAnimModelNodeCtrl::interpolate(const SkelAnim& animation, float frame,
 
 	// now for all bones update bone's poses
 	ASSERT(boneRotations.size() >= 1);
-	for(uint i=0; i<boneRotations.size(); i++)
+	for(uint i=0; i < boneRotations.size(); i++)
 	{
-		const SkelAnim::BoneAnim& banim = animation.bones[i];
+		const BoneAnim& banim = animation.getBoneAnims()[i];
 
 		Mat3& localRot = boneRotations[i];
 		Vec3& localTransl = boneTranslations[i];
 
 		// if the bone has animations then slerp and lerp to find the rotation and translation
-		if(banim.keyframes.size() != 0)
+		if(banim.getBonePoses().size() != 0)
 		{
-			const SkelAnim::BonePose& lBpose = banim.keyframes[lPose];
-			const SkelAnim::BonePose& rBpose = banim.keyframes[rPose];
+			const BonePose& lBpose = banim.getBonePoses()[lPose];
+			const BonePose& rBpose = banim.getBonePoses()[rPose];
 
 			// rotation
-			const Quat& q0 = lBpose.rotation;
-			const Quat& q1 = rBpose.rotation;
+			const Quat& q0 = lBpose.getRotation();
+			const Quat& q1 = rBpose.getRotation();
 			localRot = Mat3(q0.slerp(q1, t));
 
 			// translation
-			const Vec3& v0 = lBpose.translation;
-			const Vec3& v1 = rBpose.translation;
+			const Vec3& v0 = lBpose.getTranslation();
+			const Vec3& v1 = rBpose.getTranslation();
 			localTransl = v0.lerp(v1, t);
 		}
 		// else put the idents
@@ -159,7 +159,7 @@ void SkelAnimModelNodeCtrl::deform(const Skeleton& skeleton, const Vec<Vec3>& bo
 void SkelAnimModelNodeCtrl::update(float)
 {
 	frame += step;
-	if(frame > skelAnim->framesNum) // if the crnt is finished then play the next or loop the crnt
+	if(frame > skelAnim->getFramesNum()) // if the crnt is finished then play the next or loop the crnt
 	{
 		frame = 0.0;
 	}

+ 2 - 2
src/Util/Accessors.h

@@ -1,5 +1,5 @@
-#ifndef PROPERTIES_H
-#define PROPERTIES_H
+#ifndef ACCESSORS_H
+#define ACCESSORS_H
 
 
 /// Read only getter, cause we are to bored to write

+ 1 - 1
src/Util/CharPtrHashMap.h

@@ -8,7 +8,7 @@
 /// The hash function
 struct CreateCharPtrHashMapKey
 {
-  size_t operator()(const char* str) const
+	size_t operator()(const char* str) const
 	{
 		size_t h = 0;
 		for (; *str != '\0'; ++str)

+ 22 - 97
src/Util/Scanner.cpp → src/Util/Scanner/Scanner.cpp

@@ -10,90 +10,12 @@
 #include "Assert.h"
 
 
+namespace Scanner {
+
 #define SCANNER_EXCEPTION(x) \
 	EXCEPTION("Scanner exception (" + scriptName + ':' + boost::lexical_cast<std::string>(lineNmbr) + "): " + x)
 
 
-//======================================================================================================================
-// Constructor [Token]                                                                                                 =
-//======================================================================================================================
-Scanner::Token::Token(const Token& b): code(b.code), dataType(b.dataType)
-{
-	switch(b.dataType)
-	{
-		case Scanner::DT_FLOAT:
-			value.float_ = b.value.float_;
-			break;
-		case Scanner::DT_INT:
-			value.int_ = b.value.int_;
-			break;
-		case Scanner::DT_CHAR:
-			value.char_ = b.value.char_;
-			break;
-		case Scanner::DT_STR:
-			value.string = b.value.string;
-			break;	
-	}
-	memcpy(asString, b.asString, Scanner::MAX_SCRIPT_LINE_LEN * sizeof(char));
-}
-
-
-//======================================================================================================================
-// getInfoStr                                                                                                          =
-//======================================================================================================================
-std::string Scanner::Token::getInfoStr() const
-{
-	char tokenInfoStr[512];
-	switch(code)
-	{
-		case TC_COMMENT:
-			return "comment";
-		case TC_NEWLINE:
-			return "newline";
-		case TC_EOF:
-			return "end of file";
-		case TC_STRING:
-			sprintf(tokenInfoStr, "string \"%s\"", value.string);
-			break;
-		case TC_CHAR:
-			sprintf(tokenInfoStr, "char '%c' (\"%s\")", value.char_, asString);
-			break;
-		case TC_NUMBER:
-			if(dataType == DT_FLOAT)
-				sprintf(tokenInfoStr, "float %f or %e (\"%s\")", value.float_, value.float_, asString);
-			else
-				sprintf(tokenInfoStr, "int %lu (\"%s\")", value.int_, asString);
-			break;
-		case TC_IDENTIFIER:
-			sprintf(tokenInfoStr, "identifier \"%s\"", value.string);
-			break;
-		case TC_ERROR:
-			return "scanner error";
-			break;
-		default:
-			if(code>=TC_KE && code<=TC_KEYWORD)
-			{
-				sprintf(tokenInfoStr, "reserved word \"%s\"", value.string);
-			}
-			else if(code>=TC_SCOPERESOLUTION && code<=TC_ASSIGNOR)
-			{
-				sprintf(tokenInfoStr, "operator no %d", code - TC_SCOPERESOLUTION);
-			}
-	}
-
-	return tokenInfoStr;
-}
-
-
-//======================================================================================================================
-// print                                                                                                               =
-//======================================================================================================================
-void Scanner::Token::print() const
-{
-	std::cout << "Token: " << getInfoStr() << std::endl;
-}
-
-
 //======================================================================================================================
 // statics                                                                                                             =
 //======================================================================================================================
@@ -173,7 +95,7 @@ void Scanner::initAsciiMap()
 	asciiLookupTable['\n'] = AC_ERROR; // newline is unacceptable char
 
 	asciiLookupTable['@'] = asciiLookupTable['`'] = asciiLookupTable['$'] = AC_ACCEPTABLE_IN_COMMENTS;
-	                   
+
 	asciiLookupTable['\"']         = AC_DOUBLEQUOTE;
 	asciiLookupTable['\'']         = AC_QUOTE;
 	asciiLookupTable[(int)eofChar] = AC_EOF;
@@ -278,13 +200,13 @@ void Scanner::getAllPrintAll()
 // loadFile                                                                                                            =
 //======================================================================================================================
 void Scanner::loadFile(const char* filename_)
-{	
+{
 	inFstream.open(filename_);
 	if(!inFstream.is_open())
 	{
 		throw EXCEPTION("Cannot open file \"" + filename_ + '\"');
 	}
-	
+
 	loadIstream(inFstream, filename_);
 }
 
@@ -323,7 +245,7 @@ void Scanner::unload()
 //======================================================================================================================
 // getNextToken                                                                                                        =
 //======================================================================================================================
-const Scanner::Token& Scanner::getNextToken()
+const Token& Scanner::getNextToken()
 {
 	start:
 
@@ -343,7 +265,7 @@ const Scanner::Token& Scanner::getNextToken()
 			putBackChar();
 			int line = getLineNumber();
 			checkComment();
-			
+
 			commentedLines = getLineNumber() - line; // update commentedLines
 			lineNmbr -= commentedLines; // part of the ultimate hack
 		}
@@ -421,7 +343,7 @@ const Scanner::Token& Scanner::getNextToken()
 	{
 		goto start;
 	}
-	
+
 	return crntToken;
 }
 
@@ -430,7 +352,7 @@ const Scanner::Token& Scanner::getNextToken()
 //======================================================================================================================
 void Scanner::checkWord()
 {
-	char* tmpStr = crntToken.asString;
+	char* tmpStr = &crntToken.asString[0];
 	char ch = *pchar;
 
 	//build the string
@@ -443,9 +365,9 @@ void Scanner::checkWord()
 	*tmpStr = '\0'; // finalize it
 
 	//check if reserved
-	int len = tmpStr-crntToken.asString;
+	int len = tmpStr - &crntToken.asString[0];
 	crntToken.code = TC_IDENTIFIER;
-	crntToken.value.string = crntToken.asString;
+	crntToken.value.string = &crntToken.asString[0];
 	crntToken.dataType = DT_STR; // not important
 
 	if(len <= 7 && len >= 2)
@@ -458,7 +380,7 @@ void Scanner::checkWord()
 				break;
 			}
 
-			if(strcmp(rwTable[len][x].string, crntToken.asString) == 0)
+			if(strcmp(rwTable[len][x].string, &crntToken.asString[0]) == 0)
 			{
 				crntToken.code = rwTable[len][x].code;
 				break;
@@ -552,7 +474,7 @@ void Scanner::checkNumber()
 	long dad = 0;     // digits after dot (for floats)
 	bool expSign = 0; // exponent sign in case float is represented in mant/exp format. 0 means positive and 1 negative
 	long exp = 0;     // the exponent in case float is represented in mant/exp format
-	char* tmpStr = crntToken.asString;
+	char* tmpStr = &crntToken.asString[0];
 	crntToken.dataType = DT_INT;
 	uint asc;
 
@@ -841,7 +763,7 @@ void Scanner::checkNumber()
 		}
 
 		*tmpStr = '\0';
-		throw SCANNER_EXCEPTION("Bad number suffix \"" + crntToken.asString + '\"');
+		throw SCANNER_EXCEPTION("Bad number suffix \"" + &crntToken.asString[0] + '\"');
 }
 
 
@@ -850,7 +772,7 @@ void Scanner::checkNumber()
 //======================================================================================================================
 void Scanner::checkString()
 {
-	char* tmpStr = crntToken.asString;
+	char* tmpStr = &crntToken.asString[0];
 	char ch = getNextChar();
 
 	for(;;)
@@ -860,7 +782,7 @@ void Scanner::checkString()
 		{
 			crntToken.code = TC_ERROR;
 			*tmpStr = '\0';
-			throw SCANNER_EXCEPTION("Incorrect string ending \"" + crntToken.asString + '\"');
+			throw SCANNER_EXCEPTION("Incorrect string ending \"" + &crntToken.asString[0] + '\"');
 			return;
 		}
 		// Escape Codes
@@ -871,7 +793,7 @@ void Scanner::checkString()
 			{
 				crntToken.code = TC_ERROR;
 				*tmpStr = '\0';
-				throw SCANNER_EXCEPTION("Incorrect string ending \"" + crntToken.asString + '\"');
+				throw SCANNER_EXCEPTION("Incorrect string ending \"" + &crntToken.asString[0] + '\"');
 				return;
 			}
 
@@ -919,7 +841,7 @@ void Scanner::checkString()
 		{
 			*tmpStr = '\0';
 			crntToken.code = TC_STRING;
-			crntToken.value.string = crntToken.asString;
+			crntToken.value.string = &crntToken.asString[0];
 			getNextChar();
 			return;
 		}
@@ -941,7 +863,7 @@ void Scanner::checkChar()
 {
 	char ch = getNextChar();
 	char ch0 = ch;
-	char* tmpStr = crntToken.asString;
+	char* tmpStr = &crntToken.asString[0];
 
 	crntToken.code = TC_ERROR;
 	*tmpStr++ = ch;
@@ -1293,3 +1215,6 @@ void Scanner::checkSpecial()
 	getNextChar();
 	crntToken.code = code;
 }
+
+
+} // end namesapce

+ 34 - 130
src/Util/Scanner.h → src/Util/Scanner/Scanner.h

@@ -2,7 +2,10 @@
 #define SCANNER_H
 
 #include <fstream>
-#include "StdTypes.h"
+#include "ScannerToken.h"
+
+
+namespace Scanner {
 
 
 /// C++ Tokenizer
@@ -11,132 +14,9 @@
 /// The class does not make any kind of memory allocations so it can be fast.
 class Scanner
 {
-	//====================================================================================================================
-	// Pre-nested                                                                                                        =
-	//====================================================================================================================
-	protected:
-		static const int MAX_SCRIPT_LINE_LEN = 1024; ///< The max allowed length of a script line
-
-	//====================================================================================================================
-	// Nested                                                                                                            =
-	//====================================================================================================================
-	public:
-		/// The TokenCode is an enum that defines the Token type
-		enum TokenCode
-		{
-			// general codes
-			TC_ERROR, TC_EOF, TC_COMMENT, TC_NUMBER, TC_CHAR, TC_STRING, TC_IDENTIFIER, TC_NEWLINE,
-
-			// keywords listed by strlen (dummy keywords at the moment)
-			TC_KE,
-			TC_KEY,
-			TC_KEYW,
-			TC_KEYWO,
-			TC_KEYWOR,
-			TC_KEYWORD,
-
-			// operators (in 5s)
-			TC_SCOPERESOLUTION, TC_LSQBRACKET, TC_RSQBRACKET, TC_LPAREN, TC_RPAREN,
-			TC_DOT, TC_POINTERTOMEMBER, TC_LBRACKET, TC_RBRACKET, TC_COMMA,
-			TC_PERIOD, TC_UPDOWNDOT, TC_QUESTIONMARK, TC_SHARP, TC_EQUAL,
-			TC_NOTEQUAL, TC_LESS, TC_GREATER, TC_LESSEQUAL, TC_GREATEREQUAL,
-			TC_LOGICALOR, TC_LOGICALAND, TC_PLUS, TC_MINUS, TC_STAR,
-			TC_BSLASH, TC_NOT, TC_BITWISEAND, TC_BITWISEOR, TC_ONESCOMPLEMENT,
-			TC_MOD, TC_XOR, TC_INC, TC_DEC, TC_SHL,
-			TC_SHR, TC_ASSIGN, TC_ASSIGNADD, TC_ASSIGNSUB, TC_ASSIGNMUL,
-			TC_ASSIGNDIV, TC_ASSIGNMOD, TC_ASSIGNSHL, TC_ASSIGNSHR, TC_ASSIGNAND,
-			TC_ASSIGNXOR, TC_ASSIGNOR
-		}; // end enum TokenCode
-
-
-		/// The value of Token::dataType
-		enum TokenDataType
-		{
-			DT_FLOAT,
-			DT_INT,
-			DT_CHAR,
-			DT_STR
-		};
-
-		/// Used inside the Token, its a variant that holds the data of the Token
-		class TokenDataVal
-		{
-			friend class Scanner;
-			friend class Token;
-
-			private:
-				/// The data as unamed union
-				union
-				{
-					char   char_;
-					ulong  int_;
-					double float_;
-					char*  string; ///< points to @ref Token::asString if the token is string or identifier
-				};
-
-			public:
-				/// @name Accessors
-				/// @{
-				char getChar() const {return char_;} ///< Access the data as C char
-				ulong getInt() const {return int_;} ///< Access the data as unsigned int
-				double getFloat() const {return float_;} ///< Access the data as double
-				const char* getString() const {return string;} ///< Access the data as C string
-				/// @}
-		}; // end class TokenDataVal
-
-
-		/// The Token class
-		struct Token
-		{
-			friend class Scanner;
-
-			public:
-				Token(): code(TC_ERROR) {}
-				Token(const Token& b);
-				std::string getInfoStr() const; ///< Get a string with the info of the token
-				void print() const; ///< Print info of the token
-
-				/// @name accessors
-				/// @{
-				const char* getString() const {return asString;}
-				TokenCode getCode() const {return code;}
-				TokenDataType getDataType() const {return dataType;}
-				const TokenDataVal& getValue() const {return value;}
-				/// @}
-
-			private:
-				char asString[1024];
-				TokenCode code; ///< The first thing you should know about a token
-				TokenDataType dataType; ///< Additional info in case @ref code is @ref TC_NUMBER
-				TokenDataVal value; ///< A value variant
-		}; // end class Token
-
-
-	protected:
-		/// Every char in the Ascii table is binded with one characteristic code type. This helps the scanning
-		enum AsciiFlag
-		{
-			AC_ERROR = 0,
-			AC_EOF = 1,
-			AC_LETTER = 2,
-			AC_DIGIT = 4,
-			AC_SPECIAL = 8,
-			AC_WHITESPACE = 16,
-			AC_QUOTE = 32,
-			AC_DOUBLEQUOTE = 64,
-			AC_ACCEPTABLE_IN_COMMENTS = 128 ///< Only accepted in comments
-		};
-
-		/// Reserved words like "int" "const" etc. Currently the reserved words list is being populated with dummy data
-		struct ResWord
-		{
-			const char* string;
-			TokenCode   code;
-		};
-
-	//====================================================================================================================
-	// Public                                                                                                            =
-	//====================================================================================================================
+	//==================================================================================================================
+	// Public                                                                                                          =
+	//==================================================================================================================
 	public:
 		/// Constructor #1
 		/// @param newlinesAsWhitespace @see newlinesAsWhitespace
@@ -186,10 +66,31 @@ class Scanner
 		/// Get the current line the Scanner is processing
 		int getLineNumber() const {return lineNmbr;}
 
-	//====================================================================================================================
-	// Protected                                                                                                         =
-	//====================================================================================================================
+	//==================================================================================================================
+	// Protected                                                                                                       =
+	//==================================================================================================================
 	protected:
+		/// Every char in the Ascii table is binded with one characteristic code type. This helps the scanning
+		enum AsciiFlag
+		{
+			AC_ERROR = 0,
+			AC_EOF = 1,
+			AC_LETTER = 2,
+			AC_DIGIT = 4,
+			AC_SPECIAL = 8,
+			AC_WHITESPACE = 16,
+			AC_QUOTE = 32,
+			AC_DOUBLEQUOTE = 64,
+			AC_ACCEPTABLE_IN_COMMENTS = 128 ///< Only accepted in comments
+		};
+
+		/// Reserved words like "int" "const" etc. Currently the reserved words list is being populated with dummy data
+		struct ResWord
+		{
+			const char* string;
+			TokenCode   code;
+		};
+
 		static char eofChar; ///< Special end of file character
 
 		static AsciiFlag asciiLookupTable[]; ///< The array contains one AsciiFlag for every symbol of the ASCII table
@@ -270,4 +171,7 @@ inline Scanner::Scanner(std::istream& istream_, const char* scriptName_, bool ne
 }
 
 
+} // end namespace
+
+
 #endif

+ 12 - 0
src/Util/Scanner/ScannerCommon.h

@@ -0,0 +1,12 @@
+#ifndef SCANNER_COMMON_H
+#define SCANNER_COMMON_H
+
+
+namespace Scanner {
+
+const int MAX_SCRIPT_LINE_LEN = 1024; ///< The max allowed length of a script line
+
+}
+
+
+#endif

+ 93 - 0
src/Util/Scanner/ScannerToken.cpp

@@ -0,0 +1,93 @@
+#include <cstring>
+#include <cstdio>
+#include <iostream>
+#include <boost/lexical_cast.hpp>
+#include "ScannerToken.h"
+
+
+namespace Scanner {
+
+
+//======================================================================================================================
+// Copy constructor                                                                                                    =
+//======================================================================================================================
+Token::Token(const Token& b):
+	code(b.code),
+	dataType(b.dataType)
+{
+	switch(b.dataType)
+	{
+		case Scanner::DT_FLOAT:
+			value.float_ = b.value.float_;
+			break;
+		case Scanner::DT_INT:
+			value.int_ = b.value.int_;
+			break;
+		case Scanner::DT_CHAR:
+			value.char_ = b.value.char_;
+			break;
+		case Scanner::DT_STR:
+			value.string = b.value.string;
+			break;
+	}
+	memcpy(&asString[0], &b.asString[0], sizeof(asString));
+}
+
+
+//======================================================================================================================
+// getInfoStr                                                                                                          =
+//======================================================================================================================
+std::string Token::getInfoStr() const
+{
+	char tokenInfoStr[512];
+	switch(code)
+	{
+		case TC_COMMENT:
+			return "comment";
+		case TC_NEWLINE:
+			return "newline";
+		case TC_EOF:
+			return "end of file";
+		case TC_STRING:
+			sprintf(tokenInfoStr, "string \"%s\"", value.string);
+			break;
+		case TC_CHAR:
+			sprintf(tokenInfoStr, "char '%c' (\"%s\")", value.char_, &asString[0]);
+			break;
+		case TC_NUMBER:
+			if(dataType == DT_FLOAT)
+				sprintf(tokenInfoStr, "float %f or %e (\"%s\")", value.float_, value.float_, &asString[0]);
+			else
+				sprintf(tokenInfoStr, "int %lu (\"%s\")", value.int_, &asString[0]);
+			break;
+		case TC_IDENTIFIER:
+			sprintf(tokenInfoStr, "identifier \"%s\"", value.string);
+			break;
+		case TC_ERROR:
+			return "scanner error";
+			break;
+		default:
+			if(code >= TC_KE && code <= TC_KEYWORD)
+			{
+				sprintf(tokenInfoStr, "reserved word \"%s\"", value.string);
+			}
+			else if(code>=TC_SCOPERESOLUTION && code<=TC_ASSIGNOR)
+			{
+				sprintf(tokenInfoStr, "operator no %d", code - TC_SCOPERESOLUTION);
+			}
+	}
+
+	return tokenInfoStr;
+}
+
+
+//======================================================================================================================
+// print                                                                                                               =
+//======================================================================================================================
+void Token::print() const
+{
+	std::cout << "Token: " << getInfoStr() << std::endl;
+}
+
+
+} // end namespace

+ 108 - 0
src/Util/Scanner/ScannerToken.h

@@ -0,0 +1,108 @@
+#ifndef SCANNER_TOKEN_H
+#define SCANNER_TOKEN_H
+
+#include <string>
+#include <boost/array.hpp>
+#include "ScannerCommon.h"
+#include "StdTypes.h"
+
+
+namespace Scanner {
+
+
+/// The TokenCode is an enum that defines the Token type
+enum TokenCode
+{
+	// general codes
+	TC_ERROR, TC_EOF, TC_COMMENT, TC_NUMBER, TC_CHAR, TC_STRING, TC_IDENTIFIER, TC_NEWLINE,
+
+	// keywords listed by strlen (dummy keywords at the moment)
+	TC_KE,
+	TC_KEY,
+	TC_KEYW,
+	TC_KEYWO,
+	TC_KEYWOR,
+	TC_KEYWORD,
+
+	// operators (in 5s)
+	TC_SCOPERESOLUTION, TC_LSQBRACKET, TC_RSQBRACKET, TC_LPAREN, TC_RPAREN,
+	TC_DOT, TC_POINTERTOMEMBER, TC_LBRACKET, TC_RBRACKET, TC_COMMA,
+	TC_PERIOD, TC_UPDOWNDOT, TC_QUESTIONMARK, TC_SHARP, TC_EQUAL,
+	TC_NOTEQUAL, TC_LESS, TC_GREATER, TC_LESSEQUAL, TC_GREATEREQUAL,
+	TC_LOGICALOR, TC_LOGICALAND, TC_PLUS, TC_MINUS, TC_STAR,
+	TC_BSLASH, TC_NOT, TC_BITWISEAND, TC_BITWISEOR, TC_ONESCOMPLEMENT,
+	TC_MOD, TC_XOR, TC_INC, TC_DEC, TC_SHL,
+	TC_SHR, TC_ASSIGN, TC_ASSIGNADD, TC_ASSIGNSUB, TC_ASSIGNMUL,
+	TC_ASSIGNDIV, TC_ASSIGNMOD, TC_ASSIGNSHL, TC_ASSIGNSHR, TC_ASSIGNAND,
+	TC_ASSIGNXOR, TC_ASSIGNOR
+}; // end enum TokenCode
+
+
+/// The value of Token::dataType
+enum TokenDataType
+{
+	DT_FLOAT,
+	DT_INT,
+	DT_CHAR,
+	DT_STR
+};
+
+
+/// Used inside the Token, its a variant that holds the data of the Token
+class TokenDataVal
+{
+	friend class Scanner;
+	friend class Token;
+
+	public:
+		/// @name Accessors
+		/// @{
+		char getChar() const {return char_;} ///< Access the data as C char
+		ulong getInt() const {return int_;} ///< Access the data as unsigned int
+		double getFloat() const {return float_;} ///< Access the data as double
+		const char* getString() const {return string;} ///< Access the data as C string
+		/// @}
+
+	private:
+		/// The data as unamed union
+		union
+		{
+			char char_;
+			ulong int_;
+			double float_;
+			char* string; ///< points to @ref Token::asString if the token is string or identifier
+		};
+}; // end class TokenDataVal
+
+
+/// The Token class
+struct Token
+{
+	friend class Scanner;
+
+	public:
+		Token(): code(TC_ERROR) {}
+		Token(const Token& b);
+		std::string getInfoStr() const; ///< Get a string with the info of the token
+		void print() const; ///< Print info of the token
+
+		/// @name accessors
+		/// @{
+		const char* getString() const {return &asString[0];}
+		TokenCode getCode() const {return code;}
+		TokenDataType getDataType() const {return dataType;}
+		const TokenDataVal& getValue() const {return value;}
+		/// @}
+
+	private:
+		boost::array<char, MAX_SCRIPT_LINE_LEN> asString;
+		TokenCode code; ///< The first thing you should know about a token
+		TokenDataType dataType; ///< Additional info in case @ref code is @ref TC_NUMBER
+		TokenDataVal value; ///< A value variant
+}; // end class Token
+
+
+} // end namespace
+
+
+#endif

部分文件因为文件数量过多而无法显示