Skip to content

Commit 2722500

Browse files
authored
Merge pull request #1043 from gruenich/feature/replace-c-style-casts
Replace C-style casts
2 parents 36ff404 + b5e767a commit 2722500

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

xmltest.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ int main( int argc, const char ** argv )
324324

325325
printf( "Test file '%s' loaded. ErrorID=%d\n", argv[1], errorID );
326326
if ( !errorID ) {
327-
printf( "Load time=%u\n", (unsigned)(loadTime - startTime) );
328-
printf( "Delete time=%u\n", (unsigned)(deleteTime - loadTime) );
329-
printf( "Total time=%u\n", (unsigned)(deleteTime - startTime) );
327+
printf( "Load time=%u\n", static_cast<unsigned>(loadTime - startTime) );
328+
printf( "Delete time=%u\n", static_cast<unsigned>(deleteTime - loadTime) );
329+
printf( "Total time=%u\n", static_cast<unsigned>(deleteTime - startTime) );
330330
}
331331
exit(0);
332332
}
@@ -595,8 +595,8 @@ int main( int argc, const char ** argv )
595595

596596
result = ele->QueryDoubleAttribute( "attr0", &dVal );
597597
XMLTest( "Query attribute: int as double", XML_SUCCESS, result);
598-
XMLTest( "Query attribute: int as double", 1, (int)dVal );
599-
XMLTest( "Query attribute: int as double", 1, (int)ele->DoubleAttribute("attr0"));
598+
XMLTest( "Query attribute: int as double", 1, static_cast<int>(dVal) );
599+
XMLTest( "Query attribute: int as double", 1, static_cast<int>(ele->DoubleAttribute("attr0")));
600600

601601
result = ele->QueryDoubleAttribute( "attr1", &dVal );
602602
XMLTest( "Query attribute: double as double", XML_SUCCESS, result);
@@ -648,17 +648,17 @@ int main( int argc, const char ** argv )
648648

649649
{
650650
XMLError queryResult = ele->QueryAttribute( "int", &iVal2 );
651-
XMLTest( "Query int attribute generic", (int)XML_SUCCESS, queryResult);
651+
XMLTest( "Query int attribute generic", static_cast<int>(XML_SUCCESS), queryResult);
652652
}
653653
{
654654
XMLError queryResult = ele->QueryAttribute( "double", &dVal2 );
655-
XMLTest( "Query double attribute generic", (int)XML_SUCCESS, queryResult);
655+
XMLTest( "Query double attribute generic", static_cast<int>(XML_SUCCESS), queryResult);
656656
}
657657

658658
XMLTest( "Attribute match test", "strValue", ele->Attribute( "str", "strValue" ) );
659659
XMLTest( "Attribute round trip. c-string.", "strValue", cStr );
660660
XMLTest( "Attribute round trip. int.", 1, iVal );
661-
XMLTest( "Attribute round trip. double.", -1, (int)dVal );
661+
XMLTest( "Attribute round trip. double.", -1, static_cast<int>(dVal) );
662662
XMLTest( "Alternate query", true, iVal == iVal2 );
663663
XMLTest( "Alternate query", true, dVal == dVal2 );
664664
XMLTest( "Alternate query", true, iVal == ele->IntAttribute("int") );
@@ -675,15 +675,15 @@ int main( int argc, const char ** argv )
675675
const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
676676
0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
677677

678-
XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) );
678+
XMLTest( "UTF-8: Russian value.", reinterpret_cast<const char*>(correctValue), element->Attribute( "value" ) );
679679

680680
const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U,
681681
0xd1U, 0x81U, 0xd1U, 0x81U,
682682
0xd0U, 0xbaU, 0xd0U, 0xb8U,
683683
0xd0U, 0xb9U, 0 };
684684
const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>";
685685

686-
XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( (const char*) russianElementName )->FirstChild()->ToText();
686+
XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( reinterpret_cast<const char*>(russianElementName) )->FirstChild()->ToText();
687687
XMLTest( "UTF-8: Browsing russian element name.",
688688
russianText,
689689
text->Value() );
@@ -824,7 +824,7 @@ int main( int argc, const char ** argv )
824824
{
825825
int v = 0;
826826
XMLError queryResult = element->QueryAttribute("attrib", &v);
827-
XMLTest("Attribute: int", (int)XML_SUCCESS, queryResult, true);
827+
XMLTest("Attribute: int", static_cast<int>(XML_SUCCESS), queryResult, true);
828828
XMLTest("Attribute: int", -100, v, true);
829829
}
830830
XMLTest("Attribute: int", -100, element->IntAttribute("attrib"), true);
@@ -840,7 +840,7 @@ int main( int argc, const char ** argv )
840840
{
841841
unsigned v = 0;
842842
XMLError queryResult = element->QueryAttribute("attrib", &v);
843-
XMLTest("Attribute: unsigned", (int)XML_SUCCESS, queryResult, true);
843+
XMLTest("Attribute: unsigned", static_cast<int>(XML_SUCCESS), queryResult, true);
844844
XMLTest("Attribute: unsigned", unsigned(100), v, true);
845845
}
846846
{
@@ -864,7 +864,7 @@ int main( int argc, const char ** argv )
864864
{
865865
int64_t v = 0;
866866
XMLError queryResult = element->QueryAttribute("attrib", &v);
867-
XMLTest("Attribute: int64_t", (int)XML_SUCCESS, queryResult, true);
867+
XMLTest("Attribute: int64_t", static_cast<int>(XML_SUCCESS), queryResult, true);
868868
XMLTest("Attribute: int64_t", BIG, v, true);
869869
}
870870
XMLTest("Attribute: int64_t", BIG, element->Int64Attribute("attrib"), true);
@@ -880,7 +880,7 @@ int main( int argc, const char ** argv )
880880
{
881881
uint64_t v = 0;
882882
XMLError queryResult = element->QueryAttribute("attrib", &v);
883-
XMLTest("Attribute: uint64_t", (int)XML_SUCCESS, queryResult, true);
883+
XMLTest("Attribute: uint64_t", static_cast<int>(XML_SUCCESS), queryResult, true);
884884
XMLTest("Attribute: uint64_t", BIG_POS, v, true);
885885
}
886886
XMLTest("Attribute: uint64_t", BIG_POS, element->Unsigned64Attribute("attrib"), true);
@@ -896,7 +896,7 @@ int main( int argc, const char ** argv )
896896
{
897897
bool v = false;
898898
XMLError queryResult = element->QueryAttribute("attrib", &v);
899-
XMLTest("Attribute: bool", (int)XML_SUCCESS, queryResult, true);
899+
XMLTest("Attribute: bool", static_cast<int>(XML_SUCCESS), queryResult, true);
900900
XMLTest("Attribute: bool", true, v, true);
901901
}
902902
XMLTest("Attribute: bool", true, element->BoolAttribute("attrib"), true);
@@ -924,7 +924,7 @@ int main( int argc, const char ** argv )
924924
{
925925
double v = 0;
926926
XMLError queryResult = element->QueryAttribute("attrib", &v);
927-
XMLTest("Attribute: bool", (int)XML_SUCCESS, queryResult, true);
927+
XMLTest("Attribute: bool", static_cast<int>(XML_SUCCESS), queryResult, true);
928928
XMLTest("Attribute: double", 100.0, v, true);
929929
}
930930
XMLTest("Attribute: double", 100.0, element->DoubleAttribute("attrib"), true);
@@ -940,7 +940,7 @@ int main( int argc, const char ** argv )
940940
{
941941
float v = 0;
942942
XMLError queryResult = element->QueryAttribute("attrib", &v);
943-
XMLTest("Attribute: float", (int)XML_SUCCESS, queryResult, true);
943+
XMLTest("Attribute: float", static_cast<int>(XML_SUCCESS), queryResult, true);
944944
XMLTest("Attribute: float", 100.0f, v, true);
945945
}
946946
XMLTest("Attribute: float", 100.0f, element->FloatAttribute("attrib"), true);
@@ -1068,15 +1068,15 @@ int main( int argc, const char ** argv )
10681068

10691069
unsigned unsigned_value;
10701070
unsigned_value = root->FirstChildElement("unsigned")->UnsignedText();
1071-
XMLTest("PushText( unsigned value ) test", (unsigned)12, unsigned_value);
1071+
XMLTest("PushText( unsigned value ) test", static_cast<unsigned>(12), unsigned_value);
10721072

10731073
int64_t int64_t_value;
10741074
int64_t_value = root->FirstChildElement("int64_t")->Int64Text();
1075-
XMLTest("PushText( int64_t value ) test", (int64_t) 13, int64_t_value);
1075+
XMLTest("PushText( int64_t value ) test", static_cast<int64_t>(13), int64_t_value);
10761076

10771077
uint64_t uint64_t_value;
10781078
uint64_t_value = root->FirstChildElement("uint64_t")->Unsigned64Text();
1079-
XMLTest("PushText( uint64_t value ) test", (uint64_t) 14, uint64_t_value);
1079+
XMLTest("PushText( uint64_t value ) test", static_cast<uint64_t>(14), uint64_t_value);
10801080

10811081
float float_value;
10821082
float_value = root->FirstChildElement("float")->FloatText();
@@ -1397,7 +1397,7 @@ int main( int argc, const char ** argv )
13971397
buf[61] = 0;
13981398

13991399
XMLDocument doc;
1400-
doc.Parse( (const char*)buf);
1400+
doc.Parse( reinterpret_cast<const char*>(buf) );
14011401
XMLTest( "Broken CDATA", true, doc.Error() );
14021402
}
14031403

@@ -1753,7 +1753,7 @@ int main( int argc, const char ** argv )
17531753
unsigned unsignedValue = 0;
17541754
XMLError queryResult = pointElement->FirstChildElement( "y" )->QueryUnsignedText( &unsignedValue );
17551755
XMLTest( "QueryUnsignedText result", XML_SUCCESS, queryResult, false );
1756-
XMLTest( "QueryUnsignedText", (unsigned)1, unsignedValue, false );
1756+
XMLTest( "QueryUnsignedText", static_cast<unsigned>(1), unsignedValue, false );
17571757
}
17581758

17591759
{
@@ -2779,9 +2779,9 @@ int main( int argc, const char ** argv )
27792779
#endif
27802780

27812781
#if defined( _MSC_VER )
2782-
const double duration = 1000.0 * (double)(end - start) / ((double)freq * (double)COUNT);
2782+
const double duration = 1000.0 * static_cast<double>(end - start) / (static_cast<double>(freq) * static_cast<double>(COUNT));
27832783
#else
2784-
const double duration = (double)(cend - cstart) / (double)COUNT;
2784+
const double duration = static_cast<double>(cend - cstart) / static_cast<double>(COUNT);
27852785
#endif
27862786
printf("\nParsing dream.xml (%s): %.3f milli-seconds\n", note, duration);
27872787
}

0 commit comments

Comments
 (0)