MD5: Use C++11 range-based for loop

pull/898/head
Turo Lamminen 2016-05-21 23:43:01 +03:00
parent b9fbfbc18a
commit ac676d4d3c
1 changed files with 21 additions and 21 deletions

View File

@ -193,13 +193,13 @@ bool MD5Parser::ParseSection(Section& out)
// skip all spaces ... handle EOL correctly // skip all spaces ... handle EOL correctly
#define AI_MD5_SKIP_SPACES() if(!SkipSpaces(&sz)) \ #define AI_MD5_SKIP_SPACES() if(!SkipSpaces(&sz)) \
MD5Parser::ReportWarning("Unexpected end of line",(*eit).iLineNumber); MD5Parser::ReportWarning("Unexpected end of line",elem.iLineNumber);
// read a triple float in brackets: (1.0 1.0 1.0) // read a triple float in brackets: (1.0 1.0 1.0)
#define AI_MD5_READ_TRIPLE(vec) \ #define AI_MD5_READ_TRIPLE(vec) \
AI_MD5_SKIP_SPACES(); \ AI_MD5_SKIP_SPACES(); \
if ('(' != *sz++) \ if ('(' != *sz++) \
MD5Parser::ReportWarning("Unexpected token: ( was expected",(*eit).iLineNumber); \ MD5Parser::ReportWarning("Unexpected token: ( was expected",elem.iLineNumber); \
AI_MD5_SKIP_SPACES(); \ AI_MD5_SKIP_SPACES(); \
sz = fast_atoreal_move<float>(sz,(float&)vec.x); \ sz = fast_atoreal_move<float>(sz,(float&)vec.x); \
AI_MD5_SKIP_SPACES(); \ AI_MD5_SKIP_SPACES(); \
@ -208,7 +208,7 @@ bool MD5Parser::ParseSection(Section& out)
sz = fast_atoreal_move<float>(sz,(float&)vec.z); \ sz = fast_atoreal_move<float>(sz,(float&)vec.z); \
AI_MD5_SKIP_SPACES(); \ AI_MD5_SKIP_SPACES(); \
if (')' != *sz++) \ if (')' != *sz++) \
MD5Parser::ReportWarning("Unexpected token: ) was expected",(*eit).iLineNumber); MD5Parser::ReportWarning("Unexpected token: ) was expected",elem.iLineNumber);
// parse a string, enclosed in quotation marks or not // parse a string, enclosed in quotation marks or not
#define AI_MD5_PARSE_STRING(out) \ #define AI_MD5_PARSE_STRING(out) \
@ -220,7 +220,7 @@ bool MD5Parser::ParseSection(Section& out)
szStart++; \ szStart++; \
if ('\"' != *(szEnd-=1)) { \ if ('\"' != *(szEnd-=1)) { \
MD5Parser::ReportWarning("Expected closing quotation marks in string", \ MD5Parser::ReportWarning("Expected closing quotation marks in string", \
(*eit).iLineNumber); \ elem.iLineNumber); \
continue; \ continue; \
} \ } \
} \ } \
@ -244,11 +244,11 @@ MD5MeshParser::MD5MeshParser(SectionList& mSections)
} }
else if ((*iter).mName == "joints") { else if ((*iter).mName == "joints") {
// "origin" -1 ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000000 0.707107 ) // "origin" -1 ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000000 0.707107 )
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit){ for (const auto & elem : (*iter).mElements){
mJoints.push_back(BoneDesc()); mJoints.push_back(BoneDesc());
BoneDesc& desc = mJoints.back(); BoneDesc& desc = mJoints.back();
const char* sz = (*eit).szStart; const char* sz = elem.szStart;
AI_MD5_PARSE_STRING(desc.mName); AI_MD5_PARSE_STRING(desc.mName);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
@ -263,8 +263,8 @@ MD5MeshParser::MD5MeshParser(SectionList& mSections)
mMeshes.push_back(MeshDesc()); mMeshes.push_back(MeshDesc());
MeshDesc& desc = mMeshes.back(); MeshDesc& desc = mMeshes.back();
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit){ for (const auto & elem : (*iter).mElements){
const char* sz = (*eit).szStart; const char* sz = elem.szStart;
// shader attribute // shader attribute
if (TokenMatch(sz,"shader",6)) { if (TokenMatch(sz,"shader",6)) {
@ -297,14 +297,14 @@ MD5MeshParser::MD5MeshParser(SectionList& mSections)
VertexDesc& vert = desc.mVertices[idx]; VertexDesc& vert = desc.mVertices[idx];
if ('(' != *sz++) if ('(' != *sz++)
MD5Parser::ReportWarning("Unexpected token: ( was expected",(*eit).iLineNumber); MD5Parser::ReportWarning("Unexpected token: ( was expected",elem.iLineNumber);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
sz = fast_atoreal_move<float>(sz,(float&)vert.mUV.x); sz = fast_atoreal_move<float>(sz,(float&)vert.mUV.x);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
sz = fast_atoreal_move<float>(sz,(float&)vert.mUV.y); sz = fast_atoreal_move<float>(sz,(float&)vert.mUV.y);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
if (')' != *sz++) if (')' != *sz++)
MD5Parser::ReportWarning("Unexpected token: ) was expected",(*eit).iLineNumber); MD5Parser::ReportWarning("Unexpected token: ) was expected",elem.iLineNumber);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
vert.mFirstWeight = ::strtoul10(sz,&sz); vert.mFirstWeight = ::strtoul10(sz,&sz);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
@ -357,11 +357,11 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections)
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end();iter != iterEnd;++iter) { for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end();iter != iterEnd;++iter) {
if ((*iter).mName == "hierarchy") { if ((*iter).mName == "hierarchy") {
// "sheath" 0 63 6 // "sheath" 0 63 6
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit) { for (const auto & elem : (*iter).mElements) {
mAnimatedBones.push_back ( AnimBoneDesc () ); mAnimatedBones.push_back ( AnimBoneDesc () );
AnimBoneDesc& desc = mAnimatedBones.back(); AnimBoneDesc& desc = mAnimatedBones.back();
const char* sz = (*eit).szStart; const char* sz = elem.szStart;
AI_MD5_PARSE_STRING(desc.mName); AI_MD5_PARSE_STRING(desc.mName);
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
@ -371,7 +371,7 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections)
// flags (highest is 2^6-1) // flags (highest is 2^6-1)
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
if(63 < (desc.iFlags = ::strtoul10(sz,&sz))){ if(63 < (desc.iFlags = ::strtoul10(sz,&sz))){
MD5Parser::ReportWarning("Invalid flag combination in hierarchy section",(*eit).iLineNumber); MD5Parser::ReportWarning("Invalid flag combination in hierarchy section",elem.iLineNumber);
} }
AI_MD5_SKIP_SPACES(); AI_MD5_SKIP_SPACES();
@ -381,8 +381,8 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections)
} }
else if((*iter).mName == "baseframe") { else if((*iter).mName == "baseframe") {
// ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000242 0.707107 ) // ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000242 0.707107 )
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit) { for (const auto & elem : (*iter).mElements) {
const char* sz = (*eit).szStart; const char* sz = elem.szStart;
mBaseFrames.push_back ( BaseFrameDesc () ); mBaseFrames.push_back ( BaseFrameDesc () );
BaseFrameDesc& desc = mBaseFrames.back(); BaseFrameDesc& desc = mBaseFrames.back();
@ -407,8 +407,8 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections)
} }
// now read all elements (continuous list of floats) // now read all elements (continuous list of floats)
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){ for (const auto & elem : (*iter).mElements){
const char* sz = (*eit).szStart; const char* sz = elem.szStart;
while (SkipSpacesAndLineEnd(&sz)) { while (SkipSpacesAndLineEnd(&sz)) {
float f;sz = fast_atoreal_move<float>(sz,f); float f;sz = fast_atoreal_move<float>(sz,f);
desc.mValues.push_back(f); desc.mValues.push_back(f);
@ -455,13 +455,13 @@ MD5CameraParser::MD5CameraParser(SectionList& mSections)
cuts.reserve(strtoul10((*iter).mGlobalValue.c_str())); cuts.reserve(strtoul10((*iter).mGlobalValue.c_str()));
} }
else if ((*iter).mName == "cuts") { else if ((*iter).mName == "cuts") {
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){ for (const auto & elem : (*iter).mElements){
cuts.push_back(strtoul10((*eit).szStart)+1); cuts.push_back(strtoul10(elem.szStart)+1);
} }
} }
else if ((*iter).mName == "camera") { else if ((*iter).mName == "camera") {
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){ for (const auto & elem : (*iter).mElements){
const char* sz = (*eit).szStart; const char* sz = elem.szStart;
frames.push_back(CameraAnimFrameDesc()); frames.push_back(CameraAnimFrameDesc());
CameraAnimFrameDesc& cur = frames.back(); CameraAnimFrameDesc& cur = frames.back();