Skip to content

Commit

Permalink
Fix has_format_to by renaming to sc_format_to
Browse files Browse the repository at this point in the history
I wasn't able to get the enable_if working so that it doesn't pick up fmt internal format_to function and fails there trying to create a reference to void*.

I assume that since this whole thing is a convenience function to simplify writing custom fmt formatters, we can just use a different name.
  • Loading branch information
scamille committed Oct 17, 2021
1 parent 7505b1c commit 30c605d
Show file tree
Hide file tree
Showing 31 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion engine/action/dot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct dot_t : private noncopyable
void last_tick();
bool channel_interrupt();

friend void format_to( const dot_t&, fmt::format_context::iterator );
friend void sc_format_to( const dot_t&, fmt::format_context::iterator );

void reschedule_tick();
private:
Expand Down
2 changes: 1 addition & 1 deletion engine/action/sc_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4497,7 +4497,7 @@ double action_t::last_tick_factor(const dot_t* /* d */, timespan_t time_to_tick,
return std::min(1.0, duration / time_to_tick);
}

void format_to( const action_t& action, fmt::format_context::iterator out )
void sc_format_to( const action_t& action, fmt::format_context::iterator out )
{
if ( action.sim->log_spell_id )
{
Expand Down
2 changes: 1 addition & 1 deletion engine/action/sc_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ struct action_t : private noncopyable
return( r == BLOCK_RESULT_BLOCKED || r == BLOCK_RESULT_CRIT_BLOCKED );
}

friend void format_to( const action_t&, fmt::format_context::iterator );
friend void sc_format_to( const action_t&, fmt::format_context::iterator );
};

struct call_action_list_t : public action_t
Expand Down
2 changes: 1 addition & 1 deletion engine/action/sc_dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ void dot_t::dot_end_event_t::execute()
dot->last_tick();
}

void format_to( const dot_t& dot, fmt::format_context::iterator out )
void sc_format_to( const dot_t& dot, fmt::format_context::iterator out )
{
fmt::format_to( out, "Dot {}", dot.name_str );
}
2 changes: 1 addition & 1 deletion engine/buff/sc_buff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,7 @@ void buff_t::update_stack_uptime_array( timespan_t current_time, int old_stacks
uptime_array.add( end_time, end_partial.total_seconds() * mul );
}

void format_to( const buff_t& buff, fmt::format_context::iterator out )
void sc_format_to( const buff_t& buff, fmt::format_context::iterator out )
{
if ( buff.sim->log_spell_id )
{
Expand Down
2 changes: 1 addition & 1 deletion engine/buff/sc_buff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ struct buff_t : private noncopyable
virtual buff_t* apply_affecting_conduit( const conduit_data_t& conduit, int effect_num = 1 );
virtual buff_t* apply_affecting_conduit_effect( const conduit_data_t& conduit, size_t effect_num );

friend void format_to( const buff_t&, fmt::format_context::iterator );
friend void sc_format_to( const buff_t&, fmt::format_context::iterator );
private:
void update_trigger_calculations();
void adjust_haste();
Expand Down
2 changes: 1 addition & 1 deletion engine/item/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ std::string item_t::socket_bonus_stats_str() const
return str;
}

void format_to( const item_t& item, fmt::format_context::iterator out )
void sc_format_to( const item_t& item, fmt::format_context::iterator out )
{
fmt::format_to( out, "name={} id={}", item.name_str, item.parsed.data.id );
if ( item.slot != SLOT_INVALID )
Expand Down
2 changes: 1 addition & 1 deletion engine/item/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,5 @@ struct item_t
const special_effect_t* special_effect( special_effect_source_e source = SPECIAL_EFFECT_SOURCE_NONE, special_effect_e type = SPECIAL_EFFECT_NONE ) const;
const special_effect_t* special_effect_with_name( util::string_view name, special_effect_source_e source = SPECIAL_EFFECT_SOURCE_NONE, special_effect_e type = SPECIAL_EFFECT_NONE ) const;

friend void format_to( const item_t&, fmt::format_context::iterator );
friend void sc_format_to( const item_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/item/special_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ std::string special_effect_t::name() const
return n;
}

void format_to( const special_effect_t& se, fmt::format_context::iterator out )
void sc_format_to( const special_effect_t& se, fmt::format_context::iterator out )
{
fmt::format_to( out, "{}", se.name() );
fmt::format_to( out, " type={}", se.type );
Expand Down
2 changes: 1 addition & 1 deletion engine/item/special_effect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ struct special_effect_t
timespan_t duration() const;
timespan_t tick_time() const;

friend void format_to( const special_effect_t&, fmt::format_context::iterator );
friend void sc_format_to( const special_effect_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/player/gear_stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ struct gear_stats_t
double get_stat( stat_e stat ) const;
static double stat_mod( stat_e stat );

friend void format_to( const gear_stats_t&, fmt::format_context::iterator );
friend void sc_format_to( const gear_stats_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/player/pet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ struct pet_t : public player_t

void acquire_target( retarget_source /* event */, player_t* /* context */ = nullptr ) override;

friend void format_to( const pet_t&, fmt::format_context::iterator );
friend void sc_format_to( const pet_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/player/rating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void rating_t::init(dbc_t& dbc, int level)
}
}

void format_to( const rating_t& r, fmt::format_context::iterator out )
void sc_format_to( const rating_t& r, fmt::format_context::iterator out )
{
for (rating_e i = static_cast<rating_e>(0); i < RATING_MAX; ++i)
fmt::format_to( out, "{}{}={}", i ? " " : "", cache_from_rating(i), r.get(i) ); // hacky
Expand Down
2 changes: 1 addition & 1 deletion engine/player/rating.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ struct rating_t

void init(dbc_t& dbc, int level);

friend void format_to( const rating_t&, fmt::format_context::iterator );
friend void sc_format_to( const rating_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/player/sc_pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void pet_t::acquire_target( retarget_source event, player_t* context )
}
}

void format_to( const pet_t& pet, fmt::format_context::iterator out )
void sc_format_to( const pet_t& pet, fmt::format_context::iterator out )
{
fmt::format_to( out, "Pet '{}'", pet.full_name_str );
}
4 changes: 2 additions & 2 deletions engine/player/sc_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ player_t::base_initial_current_t::base_initial_current_t() :
range::fill( attribute_multiplier, 1.0 );
}

void format_to( const player_t::base_initial_current_t& s, fmt::format_context::iterator out )
void sc_format_to( const player_t::base_initial_current_t& s, fmt::format_context::iterator out )
{
fmt::format_to( out, "{}", s.stats );
fmt::format_to( out, " spell_power_per_intellect={}", s.spell_power_per_intellect );
Expand Down Expand Up @@ -13176,7 +13176,7 @@ void player_t::init_distance_targeting()
}
}

void format_to( const player_t& player, fmt::format_context::iterator out )
void sc_format_to( const player_t& player, fmt::format_context::iterator out )
{
fmt::format_to( out, "Player '{}'", player.name() );
}
Expand Down
4 changes: 2 additions & 2 deletions engine/player/sc_player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ struct player_t : public actor_t
double spell_power_multiplier, attack_power_multiplier, base_armor_multiplier, armor_multiplier;
position_e position;

friend void format_to( const base_initial_current_t&, fmt::format_context::iterator );
friend void sc_format_to( const base_initial_current_t&, fmt::format_context::iterator );
}
base, // Base values, from some database or overridden by user
initial, // Base + Passive + Gear (overridden or items) + Player Enchants + Global Enchants
Expand Down Expand Up @@ -1246,7 +1246,7 @@ struct player_t : public actor_t
spawner::base_actor_spawner_t* find_spawner( util::string_view id ) const;
int nth_iteration() const;

friend void format_to( const player_t&, fmt::format_context::iterator );
friend void sc_format_to( const player_t&, fmt::format_context::iterator );

// Indicates whether the player uses PTR dbc data
bool is_ptr() const;
Expand Down
2 changes: 1 addition & 1 deletion engine/player/sc_set_bonus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ std::string set_bonus_t::to_string() const
}


void format_to( const set_bonus_t& sb, fmt::format_context::iterator out )
void sc_format_to( const set_bonus_t& sb, fmt::format_context::iterator out )
{
int i = 0;
for ( size_t idx = 0; idx < sb.set_bonus_spec_data.size(); idx++ )
Expand Down
2 changes: 1 addition & 1 deletion engine/player/set_bonus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ struct set_bonus_t
std::string to_profile_string(const std::string & = "\n") const;
std::string generate_set_bonus_options() const;

friend void format_to( const set_bonus_t&, fmt::format_context::iterator );
friend void sc_format_to( const set_bonus_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/sim/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct event_t : private noncopyable
}
static void cancel( event_t*& e );

friend void format_to( const event_t&, fmt::format_context::iterator );
friend void sc_format_to( const event_t&, fmt::format_context::iterator );

protected:
template <typename Event, typename... Args>
Expand Down
2 changes: 1 addition & 1 deletion engine/sim/raid_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ struct raid_event_t : private noncopyable
event_t* start_event;
event_t* end_event;

friend void format_to( const raid_event_t&, fmt::format_context::iterator );
friend void sc_format_to( const raid_event_t&, fmt::format_context::iterator );
};
2 changes: 1 addition & 1 deletion engine/sim/sc_cooldown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ void cooldown_t::adjust_max_charges( int charge_change )
set_max_charges( new_charges );
}

void format_to( const cooldown_t& cooldown, fmt::format_context::iterator out )
void sc_format_to( const cooldown_t& cooldown, fmt::format_context::iterator out )
{
fmt::format_to( out, "Cooldown {}", cooldown.name_str );
}
2 changes: 1 addition & 1 deletion engine/sim/sc_cooldown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct cooldown_t
void set_max_charges( int new_max_charges );
void adjust_max_charges( int charge_change );

friend void format_to( const cooldown_t&, fmt::format_context::iterator );
friend void sc_format_to( const cooldown_t&, fmt::format_context::iterator );

private:
void adjust_remaining_duration( double delta ); // Modify the remaining duration of an ongoing cooldown.
Expand Down
2 changes: 1 addition & 1 deletion engine/sim/sc_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void event_t::cancel( event_t*& e )
e = nullptr;
}

void format_to( const event_t& e, fmt::format_context::iterator out )
void sc_format_to( const event_t& e, fmt::format_context::iterator out )
{
fmt::format_to( out, "{}(#{})", e.name(), e.id );
}
2 changes: 1 addition & 1 deletion engine/sim/sc_gear_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ double gear_stats_t::stat_mod( stat_e stat )
}
}

void format_to( const gear_stats_t& s, fmt::format_context::iterator out )
void sc_format_to( const gear_stats_t& s, fmt::format_context::iterator out )
{
for ( stat_e i = STAT_STRENGTH; i < STAT_MAX; i++ )
{
Expand Down
2 changes: 1 addition & 1 deletion engine/sim/sc_option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ opts::parse_status option_t::parse( sim_t* sim, util::string_view name, util::st
}
}

void format_to( const option_t& option, fmt::format_context::iterator out )
void sc_format_to( const option_t& option, fmt::format_context::iterator out )
{
option.do_format_to( out );
}
Expand Down
6 changes: 3 additions & 3 deletions engine/sim/sc_option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct option_t
util::string_view name() const
{ return _name; }

friend void format_to( const option_t&, fmt::format_context::iterator );
friend void sc_format_to( const option_t&, fmt::format_context::iterator );
protected:
virtual opts::parse_status do_parse( sim_t*, util::string_view name, util::string_view value ) const = 0;
virtual void do_format_to( fmt::format_context::iterator ) const = 0;
Expand All @@ -67,9 +67,9 @@ parse_status parse( sim_t*, util::span<const std::unique_ptr<option_t>>, util::s
void parse( sim_t*, util::string_view context, util::span<const std::unique_ptr<option_t>>, util::string_view options_str, const parse_status_fn_t& fn = nullptr );
}

inline void format_to( const std::unique_ptr<option_t>& option, fmt::format_context::iterator out )
inline void sc_format_to( const std::unique_ptr<option_t>& option, fmt::format_context::iterator out )
{
format_to(*option, out);
sc_format_to(*option, out);
}

std::unique_ptr<option_t> opt_string( util::string_view n, std::string& v );
Expand Down
2 changes: 1 addition & 1 deletion engine/sim/sc_raid_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ double raid_event_t::evaluate_raid_event_expression( sim_t* s, util::string_view
;
}

void format_to( const raid_event_t& raid_event, fmt::format_context::iterator out )
void sc_format_to( const raid_event_t& raid_event, fmt::format_context::iterator out )
{
fmt::format_to( out, "Raid event (type={} name={})", raid_event.type, raid_event.name );
}
6 changes: 3 additions & 3 deletions engine/util/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ template <typename...> using void_t = void;
template <typename T, typename = void> struct has_format_to : std::false_type {};
template <typename T>
struct has_format_to<T,
void_t<decltype( format_to( std::declval<const T&>(),
void_t<decltype( sc_format_to( std::declval<const T&>(),
std::declval<::fmt::format_context::iterator>() ) ) > > : std::true_type {};
} } // namespace util::fmt_detail

namespace fmt {

/**
* Generic fmt::formatter that supports any type T that has adl-discoverable
* format_to( const T&, fmt::format_context::iterator )
* sc_format_to( const T&, fmt::format_context::iterator )
* overload.
*/
template <typename T>
struct formatter<T, char, std::enable_if_t<::util::fmt_detail::has_format_to<T>::value>> {
constexpr auto parse( format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const T& v, format_context& ctx ) {
auto out = ctx.out();
format_to( v, out );
sc_format_to( v, out );
return out;
}
};
Expand Down
2 changes: 1 addition & 1 deletion engine/util/timespan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace simc
{
void format_to( timespan_t x, fmt::format_context::iterator out )
void sc_format_to( timespan_t x, fmt::format_context::iterator out )
{
fmt::format_to( out, "{:.3f}", x.total_seconds() );
}
Expand Down
2 changes: 1 addition & 1 deletion engine/util/timespan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace simc
return timespan_t( std::numeric_limits<time_t>::min() );
}

friend void format_to( timespan_t, fmt::format_context::iterator );
friend void sc_format_to( timespan_t, fmt::format_context::iterator );
};

} // namespace simc
Expand Down

0 comments on commit 30c605d

Please sign in to comment.