Skip to content

Commit

Permalink
Removed old implementation of lexical_cast_default
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 8, 2016
1 parent 10abf90 commit 8c7df93
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 294 deletions.
1 change: 0 additions & 1 deletion projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -1103,7 +1103,6 @@
<Unit filename="../../src/units/udisplay.hpp" />
<Unit filename="../../src/units/unit.cpp" />
<Unit filename="../../src/units/unit.hpp" />
<Unit filename="../../src/util.cpp" />
<Unit filename="../../src/util.hpp" />
<Unit filename="../../src/utils/const_clone.hpp" />
<Unit filename="../../src/utils/context_free_grammar_generator.cpp" />
Expand Down
1 change: 0 additions & 1 deletion projectfiles/CodeBlocks/wesnothd.cbp
Expand Up @@ -129,7 +129,6 @@
<Unit filename="../../src/server/user_handler.hpp" />
<Unit filename="../../src/tstring.cpp" />
<Unit filename="../../src/tstring.hpp" />
<Unit filename="../../src/util.cpp" />
<Unit filename="../../src/util.hpp" />
<Unit filename="../../src/version.cpp" />
<Unit filename="../../src/version.hpp" />
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -222,7 +222,6 @@ set(libwesnoth-core_STAT_SRC
mt_rng.cpp
seed_rng.cpp
tstring.cpp
util.cpp
version.cpp
serialization/binary_or_text.cpp
serialization/parser.cpp
Expand Down
1 change: 0 additions & 1 deletion src/SConscript
Expand Up @@ -40,7 +40,6 @@ libwesnoth_core_sources = Split("""
terrain/type_data.cpp
tools/schema/tag.cpp
tstring.cpp
util.cpp
version.cpp
""")

Expand Down
2 changes: 1 addition & 1 deletion src/editor/editor_preferences.cpp
Expand Up @@ -15,8 +15,8 @@
#include "editor/editor_preferences.hpp"
#include "config.hpp"
#include "game_preferences.hpp"
#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include "util.hpp"

namespace preferences {

Expand Down
2 changes: 1 addition & 1 deletion src/gui/auxiliary/typed_formula.hpp
Expand Up @@ -20,8 +20,8 @@
#include "formula/formula.hpp"
#include "gui/core/log.hpp"
#include "gui/widgets/helper.hpp"
#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include "util.hpp"
#include "tstring.hpp"

#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion src/persist_context.cpp
Expand Up @@ -15,12 +15,12 @@
#include "global.hpp"

#include "filesystem.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
#include "persist_context.hpp"
#include "persist_manager.hpp"
#include "serialization/binary_or_text.hpp"
#include "serialization/parser.hpp"
#include "util.hpp"

config pack_scalar(const std::string &name, const t_string &val)
{
Expand Down
1 change: 1 addition & 0 deletions src/preferences.cpp
Expand Up @@ -25,6 +25,7 @@
#include "filesystem.hpp"
#include "game_config.hpp"
#include "hotkey/hotkey_item.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
#include "preferences.hpp"
#include "sound.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/server/ban.cpp
Expand Up @@ -13,13 +13,13 @@
*/

#include "config.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
#include "filesystem.hpp"
#include "serialization/parser.hpp"
#include "serialization/binary_or_text.hpp"
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#include "util.hpp"

#include "server/ban.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/server/game.cpp
Expand Up @@ -16,12 +16,12 @@

#include "filesystem.hpp"
#include "game_config.hpp" // game_config::observer_team_name
#include "lexical_cast.hpp"
#include "log.hpp"

#include "server/game.hpp"
#include "server/player_network.hpp"
#include "serialization/string_utils.hpp"
#include "util.hpp"

#include <sstream>
#include <iomanip>
Expand Down
4 changes: 2 additions & 2 deletions src/server/player.cpp
Expand Up @@ -15,8 +15,8 @@
#include "global.hpp"

#include "server/player.hpp"
#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include "util.hpp"

wesnothd::player::player(const std::string& n, simple_wml::node& cfg,
bool registered, const size_t max_messages,
Expand Down Expand Up @@ -68,7 +68,7 @@ void wesnothd::player::mark_available(const int game_id,
} else {
cfg_.set_attr("available", "no");
}
cfg_.set_attr_dup("game_id", lexical_cast_default<std::string>(game_id).c_str());
cfg_.set_attr_dup("game_id", lexical_cast<std::string>(game_id).c_str());
cfg_.set_attr_dup("location", location.c_str());
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/server.cpp
Expand Up @@ -23,14 +23,14 @@

#include "config.hpp"
#include "game_config.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
#include "filesystem.hpp"
#include "multiplayer_error_codes.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#include "util.hpp"
#include "utils/iterable_pair.hpp"

#include "server/game.hpp"
Expand Down Expand Up @@ -1286,7 +1286,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
}

g.set_description(&desc);
desc.set_attr_dup("id", lexical_cast_default<std::string>(g.id()).c_str());
desc.set_attr_dup("id", lexical_cast<std::string>(g.id()).c_str());
} else {
WRN_SERVER << client_address(socket) << "\t" << player.name()
<< "\tsent scenario data in game:\t\"" << g.name() << "\" ("
Expand Down
1 change: 1 addition & 0 deletions src/settings.cpp
Expand Up @@ -19,6 +19,7 @@

#include "global.hpp"

#include "lexical_cast.hpp"
#include "settings.hpp"

#include "serialization/string_utils.hpp"
Expand Down
55 changes: 0 additions & 55 deletions src/tests/test_util.cpp
Expand Up @@ -16,67 +16,12 @@

#include <boost/test/unit_test.hpp>

#include "lexical_cast.hpp"
#include "util.hpp"

#include <cstdint>

BOOST_AUTO_TEST_SUITE( util )

BOOST_AUTO_TEST_CASE( test_lexical_cast )
{
/* First check if lexical_cast returns correct results for correct args */
int result = lexical_cast<int, const std::string&>(std::string("1"));
BOOST_CHECK( result == 1 );

int result2 = lexical_cast<int, const char*>("2");
BOOST_CHECK( result2 == 2 );

/* Check that an exception is thrown when an invalid argument is passed */
try {
lexical_cast<int, const std::string&>(std::string("iddqd"));

/* A bad_lexical_cast should have been thrown already */
BOOST_CHECK( false );
}
catch( const bad_lexical_cast &) {
// Don't do anything, we succeeded.
}

try {
lexical_cast<int, const char*>("idkfa");

/* A bad_lexical_cast should have been thrown already */
BOOST_CHECK( false );
}
catch( const bad_lexical_cast &) {
// Don't do anything, we succeeded.
}
}

BOOST_AUTO_TEST_CASE( test_lexical_cast_default )
{
/* First check if it works with correct values */
int result = lexical_cast_default<int, const std::string&>(std::string("1"));
BOOST_CHECK( result == 1 );

int result2 = lexical_cast_default<int, const char*>("2");
BOOST_CHECK( result2 == 2 );

double result3 = lexical_cast_default<double, const std::string&>(std::string("0.5"));
BOOST_CHECK( result3 >= 0.499 && result3 <= 0.511 );

/* Check if default is returned when argument is empty/invalid */
int result4 = lexical_cast_default<int, const std::string&>(std::string(), 4);
BOOST_CHECK( result4 == 4 );

int result5 = lexical_cast_default<int, const char*>("", 5);
BOOST_CHECK( result5 == 5 );

double result6 = lexical_cast_default<double, const std::string&>(std::string(), 0.5);
BOOST_CHECK( result6 >= 0.499 && result6 <= 0.511 );
}

BOOST_AUTO_TEST_CASE( test_bit_width )
{
BOOST_CHECK( bit_width<uint8_t>() == 8 );
Expand Down
11 changes: 6 additions & 5 deletions src/units/attack_type.cpp
Expand Up @@ -23,6 +23,7 @@
#include "formula/callable_objects.hpp"
#include "formula/formula.hpp"

#include "lexical_cast.hpp"
#include "log.hpp"
#include "serialization/string_utils.hpp"
#include "gettext.hpp"
Expand Down Expand Up @@ -114,13 +115,13 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil

if (!filter_attacks.empty() && !in_ranges(attack.num_attacks(), utils::parse_ranges(filter_attacks)))
return false;

if (!filter_accuracy.empty() && !in_ranges(attack.accuracy(), utils::parse_ranges(filter_accuracy)))
return false;

if (!filter_parry.empty() && !in_ranges(attack.parry(), utils::parse_ranges(filter_parry)))
return false;

if (!filter_movement.empty() && !in_ranges(attack.movement_used(), utils::parse_ranges(filter_movement)))
return false;

Expand All @@ -132,7 +133,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil

if ( !filter_special.empty() && !attack.get_special_bool(filter_special, true) )
return false;

if (!filter_formula.empty()) {
try {
const attack_type_callable callable(attack);
Expand Down Expand Up @@ -275,7 +276,7 @@ bool attack_type::apply_modification(const config& cfg)
if (num_attacks_ < 0) {
num_attacks_ = 0;
}

}

if(increase_attacks.empty() == false) {
Expand Down
1 change: 1 addition & 0 deletions src/units/unit.cpp
Expand Up @@ -30,6 +30,7 @@
#include "game_events/manager.hpp" // for add_events
#include "game_preferences.hpp" // for encountered_units
#include "gettext.hpp" // for N_
#include "lexical_cast.hpp"
#include "log.hpp" // for LOG_STREAM, logger, etc
#include "utils/make_enum.hpp" // for operator<<, operator>>
#include "map/map.hpp" // for gamemap
Expand Down

0 comments on commit 8c7df93

Please sign in to comment.