Replace more strcmp with std::string::compare or std::string::operator==.

This commit also enables TinyXML STL support.
This commit is contained in:
Tobias Loose
2013-11-23 11:10:41 +01:00
parent 5d0d130587
commit 9d5a83d588
13 changed files with 63 additions and 59 deletions

View File

@@ -31,6 +31,7 @@ HGE_OBJS = src/hge/hgecolor.o src/hge/hgeparticle.o \
CXXFLAGS = -W -Wall -Werror -Wno-unused CXXFLAGS = -W -Wall -Werror -Wno-unused
CXXFLAGS += -DTIXML_USE_STL
ifdef DEBUG ifdef DEBUG
CXXFLAGS += -ggdb3 CXXFLAGS += -ggdb3

View File

@@ -67,7 +67,7 @@ bool JAnimator::Load(const char* scriptFile)
element = script->ToElement(); element = script->ToElement();
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name")); printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
const char *type[] = string type[] =
{ {
"ANIMATION_TYPE_LOOPING", "ANIMATION_TYPE_LOOPING",
"ANIMATION_TYPE_ONCE_AND_STAY", "ANIMATION_TYPE_ONCE_AND_STAY",
@@ -76,9 +76,9 @@ bool JAnimator::Load(const char* scriptFile)
"ANIMATION_TYPE_PINGPONG" "ANIMATION_TYPE_PINGPONG"
}; };
const char* aniType = element->Attribute("type"); const char* aniType = element->Attribute("type");
for (int i=0;i<5;i++) for (int i=0;i<5;i++)
if (strcmp(type[i], aniType)==0) if (type[i] == aniType)
{ {
SetAnimationType(i); SetAnimationType(i);
break; break;
@@ -108,7 +108,7 @@ bool JAnimator::Load(const char* scriptFile)
element = param->ToElement(); element = param->ToElement();
if (element != NULL) if (element != NULL)
{ {
if (strcmp(element->Value(), "settings")==0) if (element->ValueStr() == "settings")
{ {
const char* quadName = element->Attribute("quad"); const char* quadName = element->Attribute("quad");
JQuad* quad = mResource->GetQuad(quadName); JQuad* quad = mResource->GetQuad(quadName);

View File

@@ -89,16 +89,16 @@ bool JOBJModel::Load(const char *modelName, const char *textureName)
if (count == 4) if (count == 4)
{ {
if (strcmp(s1, "vn") == 0) if (string("vn") == s1)
normalList.push_back(vert); normalList.push_back(vert);
else if (strcmp(s1, "vt") == 0) else if (string("vt") == s1)
texList.push_back(vert); texList.push_back(vert);
else if (strcmp(s1, "v") == 0) else if (string("v") == s1)
vertList.push_back(vert); vertList.push_back(vert);
} }
else if (count == 3) else if (count == 3)
{ {
if (strcmp(s1, "vt") == 0) if (string("vt") == s1)
texList.push_back(vert); texList.push_back(vert);
} }

View File

@@ -90,7 +90,7 @@ bool JParticleEffect::Load(const char* filename)
// FIELD_COUNT // FIELD_COUNT
// }; // };
const char* lifeValues[] = const string lifeValues[] =
{ {
"speed", "speed",
"size", "size",
@@ -104,7 +104,7 @@ bool JParticleEffect::Load(const char* filename)
"gravity" "gravity"
}; };
const char* typeNames[] = const string typeNames[] =
{ {
"POINT", "POINT",
"AREA", "AREA",
@@ -113,7 +113,7 @@ bool JParticleEffect::Load(const char* filename)
"CIRCLE" "CIRCLE"
}; };
const char* modeNames[] = const string modeNames[] =
{ {
"REPEAT", "REPEAT",
"ONCE", "ONCE",
@@ -149,32 +149,32 @@ bool JParticleEffect::Load(const char* filename)
{ {
element = param->ToElement(); element = param->ToElement();
if (strcmp(element->Attribute("name"), "settings")==0) if (string("settings") == element->Attribute("name"))
{ {
if (strcmp(element->Attribute("blend"), "NORMAL")==0) if (string("NORMAL") == element->Attribute("blend"))
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0) else if (string("ADDITIVE") == element->Attribute("blend"))
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE); mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++) for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
{ {
if (strcmp(element->Attribute("mode"), modeNames[i])==0) if (modeNames[i] == element->Attribute("mode"))
{ {
mParticleEmitters[mEmitterCount]->mEmitterMode = i; mParticleEmitters[mEmitterCount]->mEmitterMode = i;
#if defined (_DEBUG) #if defined (_DEBUG)
printf("emitter mode:%s\n", modeNames[i]); printf("emitter mode:%s\n", modeNames[i].c_str());
#endif #endif
break; break;
} }
} }
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++) for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
{ {
if (strcmp(element->Attribute("type"), typeNames[i])==0) if (typeNames[i] == element->Attribute("type"))
{ {
mParticleEmitters[mEmitterCount]->mType = i; mParticleEmitters[mEmitterCount]->mType = i;
#if defined (_DEBUG) #if defined (_DEBUG)
printf("emitter type:%s\n", typeNames[i]); printf("emitter type:%s\n", typeNames[i].c_str());
#endif #endif
break; break;
} }
@@ -213,7 +213,7 @@ bool JParticleEffect::Load(const char* filename)
} }
} }
else if (strcmp(element->Attribute("name"), "quantity")==0) else if (string("quantity") == element->Attribute("name"))
{ {
for (key = param->FirstChild(); key; key = key->NextSibling()) for (key = param->FirstChild(); key; key = key->NextSibling())
{ {
@@ -227,7 +227,7 @@ bool JParticleEffect::Load(const char* filename)
} }
} }
else if (strcmp(element->Attribute("name"), "lifex")==0) else if (string("lifex") == element->Attribute("name"))
{ {
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS && if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS) element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
@@ -236,7 +236,7 @@ bool JParticleEffect::Load(const char* filename)
mParticleEmitters[mEmitterCount]->mLifeMax= value; mParticleEmitters[mEmitterCount]->mLifeMax= value;
} }
} }
else if (strcmp(element->Attribute("name"), "anglex")==0) else if (string("anglex") == element->Attribute("name"))
{ {
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS && if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS) element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
@@ -245,7 +245,7 @@ bool JParticleEffect::Load(const char* filename)
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD; mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
} }
} }
else if (strcmp(element->Attribute("name"), "speedx")==0) else if (string("speedx") == element->Attribute("name"))
{ {
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS && if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS) element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
@@ -254,7 +254,7 @@ bool JParticleEffect::Load(const char* filename)
mParticleEmitters[mEmitterCount]->mSpeedMax= value; mParticleEmitters[mEmitterCount]->mSpeedMax= value;
} }
} }
else if (strcmp(element->Attribute("name"), "sizex")==0) else if (string("sizex") == element->Attribute("name"))
{ {
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS && if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS) element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
@@ -267,7 +267,7 @@ bool JParticleEffect::Load(const char* filename)
{ {
for (int i=0;i<FIELD_COUNT;i++) for (int i=0;i<FIELD_COUNT;i++)
{ {
if (strcmp(element->Attribute("name"), lifeValues[i])==0) if (lifeValues[i] == element->Attribute("name"))
{ {
for (key = param->FirstChild(); key; key = key->NextSibling()) for (key = param->FirstChild(); key; key = key->NextSibling())
{ {

View File

@@ -119,11 +119,11 @@ bool JResourceManager::LoadResource(const string& resourceName)
element = node->ToElement(); element = node->ToElement();
if (element != NULL) if (element != NULL)
{ {
if (strcmp(element->Value(), "texture")==0) if (element->ValueStr() == "texture")
{ {
CreateTexture(element->Attribute("name")); CreateTexture(element->Attribute("name"));
} }
else if (strcmp(element->Value(), "quad")==0) else if (element->ValueStr() == "quad")
{ {
string quadName = element->Attribute("name"); string quadName = element->Attribute("name");
string textureName = element->Attribute("texture"); string textureName = element->Attribute("texture");
@@ -170,7 +170,7 @@ bool JResourceManager::LoadResource(const string& resourceName)
GetQuad(id)->SetHotSpot(hotspotX, hotspotY); GetQuad(id)->SetHotSpot(hotspotX, hotspotY);
} }
} }
else if (strcmp(element->Value(), "font")==0) else if (element->ValueStr() == "font")
{ {
} }

View File

@@ -69,7 +69,7 @@ int main(int argc, char* argv[])
#endif //QT_WIDGET #endif //QT_WIDGET
if(argc >= 2 && strcmp(argv[1], "testsuite")==0) if(argc >= 2 && string(argv[1]) == "testsuite")
{ {
int result = 0; int result = 0;
result += WagicCore::runTestSuite(); result += WagicCore::runTestSuite();

View File

@@ -72,7 +72,7 @@ hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
fileSys->CloseFile(); fileSys->CloseFile();
pdesc=_get_line(desc,linebuf); pdesc=_get_line(desc,linebuf);
if(strcmp(linebuf, FNTHEADERTAG)) if(strcmp(linebuf, FNTHEADERTAG))
{ {
// hge->System_Log("Font %s has incorrect format.", szFont); // hge->System_Log("Font %s has incorrect format.", szFont);
delete[] desc; delete[] desc;

View File

@@ -1145,7 +1145,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
} }
if(strncmp(s.c_str(), "chooseacolor ", strlen("chooseacolor ")) == 0 || strncmp(s.c_str(), "chooseatype ", strlen("chooseatype ")) == 0) if(s.compare(0, strlen("chooseacolor "), "chooseacolor ") == 0 || s.compare(0, strlen("chooseatype "), "chooseatype ") == 0)
{ {
MTGAbility * choose = parseChooseActionAbility(s,card,spell,target,0,id); MTGAbility * choose = parseChooseActionAbility(s,card,spell,target,0,id);
choose = NEW GenericActivatedAbility(observer, "","",id, card,choose,NULL); choose = NEW GenericActivatedAbility(observer, "","",id, card,choose,NULL);

View File

@@ -52,28 +52,28 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
return 0; return 0;
s[i] = '\0'; s[i] = '\0';
const char* key = s.c_str(); const string key = s.substr(0, i);
const char* val = key+i+1; const char* val = s.c_str()+i+1;
switch (key[0]) switch (s[0])
{ {
case 'a': case 'a':
if (0 == strcmp("auto", key)) if (key == "auto")
{ {
if (!primitive) primitive = NEW CardPrimitive(); if (!primitive) primitive = NEW CardPrimitive();
primitive->addMagicText(val); primitive->addMagicText(val);
} }
else if (0 == strncmp("auto", key, 4)) else if (key.compare(0, strlen("auto")-1, "auto") == 0)
{ {
if (!primitive) primitive = NEW CardPrimitive(); if (!primitive) primitive = NEW CardPrimitive();
primitive->addMagicText(val, key + 4); primitive->addMagicText(val, key.substr(4));
} }
else if (0 == strcmp("alias", key)) else if (key == "alias")
{ {
if (!primitive) primitive = NEW CardPrimitive(); if (!primitive) primitive = NEW CardPrimitive();
primitive->alias = atoi(val); primitive->alias = atoi(val);
} }
else if (0 == strcmp("abilities", key)) else if (key == "abilities")
{ {
if (!primitive) primitive = NEW CardPrimitive(); if (!primitive) primitive = NEW CardPrimitive();
string value = val; string value = val;
@@ -288,21 +288,21 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
case 't': case 't':
if (!primitive) primitive = NEW CardPrimitive(); if (!primitive) primitive = NEW CardPrimitive();
if (0 == strcmp("target", key)) if (key == "target")
{ {
string value = val; string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower); std::transform(value.begin(), value.end(), value.begin(), ::tolower);
primitive->spellTargetType = value; primitive->spellTargetType = value;
} }
else if (0 == strcmp("text", key)) else if (key == "text")
primitive->setText(val); primitive->setText(val);
else if (0 == strcmp("type", key)) else if (key == "type")
{ {
vector<string> values = split(val, ' '); vector<string> values = split(val, ' ');
for (size_t values_i = 0; values_i < values.size(); ++values_i) for (size_t values_i = 0; values_i < values.size(); ++values_i)
primitive->setType(values[values_i]); primitive->setType(values[values_i]);
} }
else if (0 == strcmp("toughness", key)) primitive->setToughness(atoi(val)); else if (key == "toughness") primitive->setToughness(atoi(val));
break; break;
default: default:

View File

@@ -25,23 +25,23 @@ bool ModRules::load(string filename)
TiXmlElement* element = node->ToElement(); TiXmlElement* element = node->ToElement();
if (element != NULL) if (element != NULL)
{ {
if (strcmp(element->Value(), "menu") == 0) if (element->ValueStr() == "menu")
{ {
menu.parse(element); menu.parse(element);
} }
else if (strcmp(element->Value(), "general") == 0) else if (element->ValueStr() == "general")
{ {
general.parse(element); general.parse(element);
} }
else if (strcmp(element->Value(), "cards") == 0) else if (element->ValueStr() == "cards")
{ {
cards.parse(element); cards.parse(element);
} }
else if (strcmp(element->Value(), "game") == 0) else if (element->ValueStr() == "game")
{ {
game.parse(element); game.parse(element);
} }
else if (strcmp(element->Value(), "cardgui") == 0) else if (element->ValueStr() == "cardgui")
{ {
cardgui.parse(element); cardgui.parse(element);
} }

View File

@@ -333,15 +333,15 @@ StoryDuel::StoryDuel(TiXmlElement* root, StoryFlow * mParent) :
if (element) if (element)
{ {
const char* textC = element->GetText(); const char* textC = element->GetText();
if (strcmp(element->Value(), "onwin") == 0) if (element->ValueStr() == "onwin")
{ {
onWin = textC; onWin = textC;
} }
else if (strcmp(element->Value(), "onlose") == 0) else if (element->ValueStr() == "onlose")
{ {
onLose = textC; onLose = textC;
} }
else if (strcmp(element->Value(), "bg") == 0) else if (element->ValueStr() == "bg")
{ {
string text = textC; string text = textC;
bg = string("campaigns/").append(mParent->folder).append("/").append(text); bg = string("campaigns/").append(mParent->folder).append("/").append(text);
@@ -396,10 +396,10 @@ int StoryPage::loadElement(TiXmlElement* element)
if (!element) return 0; if (!element) return 0;
const char* textC = element->GetText(); const char* textC = element->GetText();
string text = textC; string text = textC;
if (strcmp(element->Value(), "music") == 0) if (element->ValueStr() == "music")
{ {
musicFile = string("campaigns/").append(mParent->folder).append("/").append(text); musicFile = string("campaigns/").append(mParent->folder).append("/").append(text);
if (!fileExists(musicFile.c_str())) musicFile = text; if (!FileExists(musicFile)) musicFile = text;
return 1; return 1;
} }
return 0; return 0;
@@ -434,15 +434,15 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
string sFont = safeAttribute(element, "font"); string sFont = safeAttribute(element, "font");
int font = atoi(sFont.c_str()); int font = atoi(sFont.c_str());
if (strcmp(element->Value(), "text") == 0) if (element->ValueStr() == "text")
{ {
graphics.push_back(NEW StoryText(text, x, y, align, font)); graphics.push_back(NEW StoryText(text, x, y, align, font));
} }
else if (strcmp(element->Value(), "title") == 0) else if (element->ValueStr() == "title")
{ {
graphics.push_back(NEW StoryText(text, x, y, "center", Fonts::MENU_FONT)); graphics.push_back(NEW StoryText(text, x, y, "center", Fonts::MENU_FONT));
} }
else if (strcmp(element->Value(), "img") == 0) else if (element->ValueStr() == "img")
{ {
//special case to force center //special case to force center
if (sX.compare("") == 0) if (sX.compare("") == 0)
@@ -452,7 +452,7 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
string img = string("campaigns/").append(mParent->folder).append("/").append(text); string img = string("campaigns/").append(mParent->folder).append("/").append(text);
graphics.push_back(NEW StoryImage(img, x, y)); graphics.push_back(NEW StoryImage(img, x, y));
} }
else if (strcmp(element->Value(), "answer") == 0) else if (element->ValueStr() == "answer")
{ {
string id = element->Attribute("goto"); string id = element->Attribute("goto");
if (!align.size()) align = "center"; if (!align.size()) align = "center";
@@ -461,7 +461,7 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
graphics.push_back(sc); graphics.push_back(sc);
Add(sc); Add(sc);
} }
else if (strcmp(element->Value(), "reward") == 0) else if (element->ValueStr() == "reward")
{ {
string type = safeAttribute(element, "type"); string type = safeAttribute(element, "type");
string value = safeAttribute(element, "value"); string value = safeAttribute(element, "value");
@@ -553,7 +553,7 @@ StoryPage * StoryFlow::loadPage(TiXmlElement* element)
if (!typeNode) return NULL; if (!typeNode) return NULL;
StoryPage * result = NULL; StoryPage * result = NULL;
const char* type = typeNode->ToElement()->GetText(); const char* type = typeNode->ToElement()->GetText();
if (strcmp(type, "duel") == 0) if (string("duel") == type)
{ {
result = NEW StoryDuel(element, this); result = NEW StoryDuel(element, this);
} }
@@ -615,7 +615,7 @@ bool StoryFlow::parse(string path)
TiXmlElement* element = node->ToElement(); TiXmlElement* element = node->ToElement();
if (element != NULL) if (element != NULL)
{ {
if (strcmp(element->Value(), "page") == 0) if (element->ValueStr() == "page")
{ {
string id = element->Attribute("id"); string id = element->Attribute("id");

View File

@@ -18,6 +18,7 @@ CONFIG(debug, debug|release):DEFINES += _DEBUG
#DEFINES += QT_CONFIG #DEFINES += QT_CONFIG
#DEFINES += NETWORK_SUPPORT #DEFINES += NETWORK_SUPPORT
DEFINES += SDL_CONFIG DEFINES += SDL_CONFIG
DEFINES += TIXML_USE_STL
macx:DEFINES += USE_PHONON macx:DEFINES += USE_PHONON
maemo5: { maemo5: {
DEFINES += USE_PHONON DEFINES += USE_PHONON

View File

@@ -49,6 +49,8 @@ android:INCLUDEPATH += $$ANDROID_NDK_ROOT/platforms/android-9/arch-arm/usr/inclu
#DEFINES += QT_NO_DEBUG_OUTPUT #DEFINES += QT_NO_DEBUG_OUTPUT
DEFINES += NETWORK_SUPPORT DEFINES += NETWORK_SUPPORT
DEFINES += TIXML_USE_STL
windows:INCLUDEPATH += ../../JGE/Dependencies/include windows:INCLUDEPATH += ../../JGE/Dependencies/include
windows{ windows{
*-g++* { *-g++* {