summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-02 20:41:01 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-02 20:41:01 +0300
commit1dab21b236d76900f3ddd2be32f9590aef394c2d (patch)
tree9ff63d2bf544a440c5d8de41faa401e900898012
parentf4f16b2fd6c455cd38e089a97db374c5ee3ea9fd (diff)
downloadManaVerse-1dab21b236d76900f3ddd2be32f9590aef394c2d.tar.gz
ManaVerse-1dab21b236d76900f3ddd2be32f9590aef394c2d.tar.bz2
ManaVerse-1dab21b236d76900f3ddd2be32f9590aef394c2d.tar.xz
ManaVerse-1dab21b236d76900f3ddd2be32f9590aef394c2d.zip
Remove most C casts.
-rw-r--r--src/being.cpp3
-rw-r--r--src/configuration.cpp17
-rw-r--r--src/debug/debug_new.cpp77
-rw-r--r--src/resources/emotedb.cpp8
-rw-r--r--src/resources/mapreader.cpp2
-rw-r--r--src/utils/xml.cpp14
-rw-r--r--src/utils/xml.h15
7 files changed, 78 insertions, 58 deletions
diff --git a/src/being.cpp b/src/being.cpp
index b08e95e96..1f637ef06 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -2271,7 +2271,8 @@ void Being::recalcSpritesOrder()
mSpriteHide[remSprite] = repIt->second;
if (repIt->second != 1)
{
- if ((unsigned)remSprite != hairSlot)
+ if (static_cast<unsigned>(remSprite)
+ != hairSlot)
{
setSprite(remSprite, repIt->second,
mSpriteColors[remSprite],
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 9055642a3..3b8aa6a92 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -733,12 +733,9 @@ void ConfigurationObject::writeToXML(const XmlTextWriterPtr writer)
logger->log("unused configuration option: " + i->first);
}
#endif
- xmlTextWriterStartElement(writer, BAD_CAST "option");
- xmlTextWriterWriteAttribute(writer,
- BAD_CAST "name", BAD_CAST i->first.c_str());
-
- xmlTextWriterWriteAttribute(writer,
- BAD_CAST "value", BAD_CAST i->second.c_str());
+ XmlTextWriterStartElement(writer, "option");
+ XmlTextWriterWriteAttribute(writer,"name", i->first.c_str());
+ XmlTextWriterWriteAttribute(writer,"value", i->second.c_str());
xmlTextWriterEndElement(writer);
}
@@ -748,14 +745,14 @@ void ConfigurationObject::writeToXML(const XmlTextWriterPtr writer)
{
const char *const name = it->first.c_str();
- xmlTextWriterStartElement(writer, BAD_CAST "list");
- xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST name);
+ XmlTextWriterStartElement(writer, "list");
+ XmlTextWriterWriteAttribute(writer, "name", name);
// recurse on all elements
for (ConfigurationList::const_iterator elt_it = it->second.begin(),
elt_it_end = it->second.end(); elt_it != elt_it_end; ++elt_it)
{
- xmlTextWriterStartElement(writer, BAD_CAST name);
+ XmlTextWriterStartElement(writer, name);
if (*elt_it)
(*elt_it)->writeToXML(writer);
xmlTextWriterEndElement(writer);
@@ -794,7 +791,7 @@ void Configuration::write()
xmlTextWriterSetIndent(writer, 1);
xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
// xmlTextWriterStartDocument(writer, nullptr, "utf8", nullptr);
- xmlTextWriterStartElement(writer, BAD_CAST "configuration");
+ XmlTextWriterStartElement(writer, "configuration");
writeToXML(writer);
diff --git a/src/debug/debug_new.cpp b/src/debug/debug_new.cpp
index b64fc684b..ee4573132 100644
--- a/src/debug/debug_new.cpp
+++ b/src/debug/debug_new.cpp
@@ -338,12 +338,12 @@ static bool print_position_from_addr(const void* addr)
#else
const char ignore_err[] = "";
#endif
- char* cmd = (char*)alloca(strlen(new_progname)
- + exeext_len
- + sizeof addr2line_cmd - 1
- + sizeof ignore_err - 1
- + sizeof(void*) * 2
- + 4 /* SP + "0x" + null */);
+ char* cmd = static_cast<char*>(alloca(strlen(new_progname)
+ + exeext_len
+ + sizeof addr2line_cmd - 1
+ + sizeof ignore_err - 1
+ + sizeof(void*) * 2
+ + 4 /* SP + "0x" + null */));
strcpy(cmd, addr2line_cmd);
strcpy(cmd + sizeof addr2line_cmd - 1, new_progname);
size_t len = strlen(cmd);
@@ -416,7 +416,7 @@ static void print_position(const void* ptr, int line)
{
if (line != 0) // Is file/line information present?
{
- fprintf(new_output_fp, "%s:%d", (const char*)ptr, line);
+ fprintf(new_output_fp, "%s:%d", static_cast<const char*>(ptr), line);
}
else if (ptr != nullptr) // Is caller address present?
{
@@ -468,7 +468,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array)
Alignment_must_be_power_of_two);
STATIC_ASSERT(M_DEBUG_NEW_TAILCHECK >= 0, Invalid_tail_check_length);
size_t s = size + ALIGNED_LIST_ITEM_SIZE + M_DEBUG_NEW_TAILCHECK;
- new_ptr_list_t* ptr = (new_ptr_list_t*)malloc(s);
+ new_ptr_list_t* ptr = static_cast<new_ptr_list_t*>(malloc(s));
if (ptr == nullptr)
{
#if M_DEBUG_NEW_STD_OPER_NEW
@@ -482,7 +482,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array)
M_DEBUG_NEW_ERROR_ACTION;
#endif
}
- void* pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE;
+ void* pointer = reinterpret_cast<char*>(ptr) + ALIGNED_LIST_ITEM_SIZE;
#if M_DEBUG_NEW_FILENAME_LEN == 0
ptr->file = file;
#else
@@ -493,7 +493,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array)
}
else
{
- ptr->addr = (void*)file;
+ ptr->addr = reinterpret_cast<void*>(const_cast<char*>(file));
}
#endif
ptr->line = line;
@@ -518,7 +518,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array)
fprintf(new_output_fp,
"new%s: allocated %p (size %u, ",
is_array ? "[]" : "",
- pointer, (unsigned)size);
+ pointer, static_cast<unsigned>(size));
if (line != 0)
print_position(ptr->file, ptr->line);
else
@@ -541,8 +541,8 @@ static void free_pointer(void* pointer, void* addr, bool is_array)
{
if (pointer == nullptr)
return;
- new_ptr_list_t* ptr =
- (new_ptr_list_t*)((char*)pointer - ALIGNED_LIST_ITEM_SIZE);
+ new_ptr_list_t* ptr = reinterpret_cast<new_ptr_list_t*>(
+ static_cast<char*>(pointer) - ALIGNED_LIST_ITEM_SIZE);
if (ptr->magic != MAGIC)
{
{
@@ -567,8 +567,8 @@ static void free_pointer(void* pointer, void* addr, bool is_array)
fprintf(new_output_fp,
"%s: pointer %p (size %u)\n\tat ",
msg,
- (char*)ptr + ALIGNED_LIST_ITEM_SIZE,
- (unsigned)ptr->size);
+ reinterpret_cast<char*>(ptr) + ALIGNED_LIST_ITEM_SIZE,
+ static_cast<unsigned>(ptr->size));
print_position(addr, 0);
fprintf(new_output_fp, "\n\toriginally allocated at ");
if (ptr->line != 0)
@@ -598,10 +598,11 @@ static void free_pointer(void* pointer, void* addr, bool is_array)
{
fast_mutex_autolock lock(new_output_lock);
fprintf(new_output_fp,
- "delete%s: freed %p (size %u, %u bytes still allocated)\n",
- is_array ? "[]" : "",
- (char*)ptr + ALIGNED_LIST_ITEM_SIZE,
- (unsigned)ptr->size, (unsigned)total_mem_alloc);
+ "delete%s: freed %p (size %u, %u bytes still allocated)\n",
+ is_array ? "[]" : "",
+ reinterpret_cast<char*>(ptr) + ALIGNED_LIST_ITEM_SIZE,
+ static_cast<unsigned>(ptr->size),
+ static_cast<unsigned>(total_mem_alloc));
}
free(ptr);
return;
@@ -625,7 +626,8 @@ int check_leaks()
while (ptr != &new_ptr_list)
{
- const char* const pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE;
+ const char* const pointer = reinterpret_cast<const char *const>(ptr)
+ + ALIGNED_LIST_ITEM_SIZE;
if (ptr->magic != MAGIC)
{
fprintf(new_output_fp,
@@ -646,14 +648,14 @@ int check_leaks()
{
fprintf(new_output_fp,
"Leaked object at %p (size %u, dump %u, ",
- pointer, (unsigned)ptr->size, ptr->dumped);
+ pointer, static_cast<unsigned>(ptr->size), ptr->dumped);
if (ptr->line != 0)
print_position(ptr->file, ptr->line);
else
print_position(ptr->addr, ptr->line);
fprintf(new_output_fp, ")\n");
++ new_cnt;
- new_size += (unsigned long)ptr->size;
+ new_size += static_cast<unsigned long>(ptr->size);
}
if (ptr->dumped)
++ dumped_cnt;
@@ -687,7 +689,8 @@ int check_mem_corruption()
ptr != &new_ptr_list;
ptr = ptr->next)
{
- const char* const pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE;
+ const char* const pointer = reinterpret_cast<char*>(ptr)
+ + ALIGNED_LIST_ITEM_SIZE;
if (ptr->magic == MAGIC
#if M_DEBUG_NEW_TAILCHECK
&& check_tail(ptr)
@@ -701,9 +704,9 @@ int check_mem_corruption()
{
#endif
fprintf(new_output_fp,
- "Heap data corrupt near %p (size %u, ",
- pointer,
- (unsigned)ptr->size);
+ "Heap data corrupt near %p (size %u, ",
+ pointer,
+ static_cast<unsigned>(ptr->size));
#if M_DEBUG_NEW_TAILCHECK
}
else
@@ -730,8 +733,8 @@ void __debug_new_recorder::_M_process(void* pointer)
{
if (pointer == nullptr)
return;
- new_ptr_list_t* ptr =
- (new_ptr_list_t*)((char*)pointer - ALIGNED_LIST_ITEM_SIZE);
+ new_ptr_list_t* ptr = reinterpret_cast<new_ptr_list_t*>(
+ static_cast<char*>(pointer) - ALIGNED_LIST_ITEM_SIZE);
if (ptr->magic != MAGIC || ptr->line != 0)
{
fast_mutex_autolock lock(new_output_lock);
@@ -777,23 +780,27 @@ void* operator new [](size_t size, const char* file, int line)
void* operator new (size_t size) //throw(std::bad_alloc)
{
- return operator new (size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0);
+ return operator new (size, static_cast<char*>(
+ M_DEBUG_NEW_CALLER_ADDRESS), 0);
}
void* operator new [](size_t size) //throw(std::bad_alloc)
{
- return operator new [](size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0);
+ return operator new [](size, static_cast<char*>(
+ M_DEBUG_NEW_CALLER_ADDRESS), 0);
}
#if !defined(__BORLANDC__) || __BORLANDC__ > 0x551
void* operator new (size_t size, const std::nothrow_t&) throw()
{
- return alloc_mem(size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0, false);
+ return alloc_mem(size, static_cast<char*>(
+ M_DEBUG_NEW_CALLER_ADDRESS), 0, false);
}
void* operator new [](size_t size, const std::nothrow_t&) throw()
{
- return alloc_mem(size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0, true);
+ return alloc_mem(size, static_cast<char*>(
+ M_DEBUG_NEW_CALLER_ADDRESS), 0, true);
}
#endif
@@ -838,12 +845,14 @@ void operator delete [](void* pointer, const char* file, int line) throw()
void operator delete (void* pointer, const std::nothrow_t&) throw()
{
- operator delete (pointer, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0);
+ operator delete (pointer, static_cast<char*>(
+ M_DEBUG_NEW_CALLER_ADDRESS), 0);
}
void operator delete [](void* pointer, const std::nothrow_t&) throw()
{
- operator delete [](pointer, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0);
+ operator delete [](pointer, static_cast<char*>(
+ M_DEBUG_NEW_CALLER_ADDRESS), 0);
}
#endif // HAVE_PLACEMENT_DELETE
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 14e3a96b5..1098243ac 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -91,8 +91,8 @@ void EmoteDB::load()
{
EmoteSprite *const currentSprite = new EmoteSprite;
std::string file = paths.getStringValue("sprites")
- + (std::string) reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
+ + std::string(reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content));
currentSprite->sprite = AnimatedSprite::load(file,
XML::getProperty(spriteNode, "variant", 0));
currentSprite->name = XML::langProperty(
@@ -147,8 +147,8 @@ void EmoteDB::load()
{
EmoteSprite *const currentSprite = new EmoteSprite;
std::string file = paths.getStringValue("sprites")
- + (std::string) reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
+ + std::string(reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content));
currentSprite->sprite = AnimatedSprite::load(file,
XML::getProperty(spriteNode, "variant", 0));
currentSprite->name = XML::langProperty(
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index ede630d0c..51d762569 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -705,7 +705,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
std::string pathDir(path);
std::map<std::string, std::string> props;
- if (xmlHasProp(node, BAD_CAST "source"))
+ if (XmlHasProp(node, "source"))
{
std::string filename = XML::getProperty(node, "source", "");
filename = resolveRelativePath(path, filename);
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index f25d867a6..73418cc60 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -110,7 +110,7 @@ namespace XML
{
int &ret = def;
- xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = XmlGetProp(node, name);
if (prop)
{
ret = atoi(reinterpret_cast<char*>(prop));
@@ -125,7 +125,7 @@ namespace XML
{
int &ret = def;
- xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = XmlGetProp(node, name);
if (prop)
{
ret = atoi(reinterpret_cast<char*>(prop));
@@ -143,7 +143,7 @@ namespace XML
{
double &ret = def;
- xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = XmlGetProp(node, name);
if (prop)
{
ret = atof(reinterpret_cast<char*>(prop));
@@ -156,7 +156,7 @@ namespace XML
std::string getProperty(const XmlNodePtr node, const char *const name,
const std::string &def)
{
- xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = XmlGetProp(node, name);
if (prop)
{
std::string val = reinterpret_cast<char*>(prop);
@@ -180,11 +180,11 @@ namespace XML
bool getBoolProperty(const XmlNodePtr node, const char *const name,
const bool def)
{
- const xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
+ const xmlChar *const prop = XmlGetProp(node, name);
- if (xmlStrEqual(prop, BAD_CAST "true" ))
+ if (XmlStrEqual(prop, "true"))
return true;
- if (xmlStrEqual(prop, BAD_CAST "false"))
+ if (XmlStrEqual(prop, "false"))
return false;
return def;
}
diff --git a/src/utils/xml.h b/src/utils/xml.h
index e72d72070..ad54f4b28 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -32,9 +32,22 @@
#include "localconsts.h"
#define XmlNodePtr xmlNodePtr
-#define xmlNameEqual(node, str) xmlStrEqual((node)->name, BAD_CAST (str))
+#define XmlStrEqual(str1, str2) xmlStrEqual(str1, \
+ reinterpret_cast<const xmlChar*>(str2))
+#define xmlNameEqual(node, str) xmlStrEqual((node)->name, \
+ reinterpret_cast<const xmlChar*>(str))
#define XmlTextWriterPtr xmlTextWriterPtr
#define xmlTypeEqual(node, typ) ((node)->type == (typ))
+#define XmlHasProp(node, name) xmlHasProp(node, \
+ reinterpret_cast<const xmlChar*>(name))
+#define XmlGetProp(node, name) xmlGetProp(node, \
+ reinterpret_cast<const xmlChar*>(name))
+#define XmlTextWriterStartElement(writer, name) \
+ xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>(name))
+#define XmlTextWriterWriteAttribute(writer, name, content) \
+ xmlTextWriterWriteAttribute(writer, \
+ reinterpret_cast<const xmlChar*>(name), \
+ reinterpret_cast<const xmlChar*>(content))
/**
* XML helper functions.