From 6cd6ee9845a904871c45d1dd11113003b04a4739 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 16 Sep 2013 12:10:00 -0700 Subject: [PATCH] Use auto more places --- aegisub/src/audio_marker.cpp | 5 ++--- aegisub/src/command/time.cpp | 4 ++-- aegisub/src/command/video.cpp | 9 ++++----- aegisub/src/dialog_manager.h | 4 ++-- aegisub/src/dialog_shift_times.cpp | 2 +- aegisub/src/font_file_lister.cpp | 2 +- aegisub/src/menu.cpp | 4 ++-- aegisub/src/spline.cpp | 14 +++++++------- aegisub/src/toolbar.cpp | 2 +- aegisub/src/video_slider.cpp | 2 +- 10 files changed, 23 insertions(+), 25 deletions(-) diff --git a/aegisub/src/audio_marker.cpp b/aegisub/src/audio_marker.cpp index 30a768920..2889314bf 100644 --- a/aegisub/src/audio_marker.cpp +++ b/aegisub/src/audio_marker.cpp @@ -78,9 +78,8 @@ void AudioMarkerProviderKeyframes::Update() { void AudioMarkerProviderKeyframes::GetMarkers(TimeRange const& range, AudioMarkerVector &out) const { // Find first and last keyframes inside the range - std::vector::const_iterator - a = lower_bound(markers.begin(), markers.end(), range.begin()), - b = upper_bound(markers.begin(), markers.end(), range.end()); + auto a = lower_bound(markers.begin(), markers.end(), range.begin()); + auto b = upper_bound(markers.begin(), markers.end(), range.end()); // Place pointers to the markers in the output vector for (; a != b; ++a) diff --git a/aegisub/src/command/time.cpp b/aegisub/src/command/time.cpp index 70c8c8461..01d5d36d6 100644 --- a/aegisub/src/command/time.cpp +++ b/aegisub/src/command/time.cpp @@ -224,7 +224,7 @@ struct time_snap_scene : public validate_video_loaded { int prev = 0; int next = 0; - const std::vector &keyframes = con->GetKeyFrames(); + auto const& keyframes = con->GetKeyFrames(); if (curFrame < keyframes.front()) next = keyframes.front(); else if (curFrame >= keyframes.back()) { @@ -232,7 +232,7 @@ struct time_snap_scene : public validate_video_loaded { next = con->GetLength(); } else { - std::vector::const_iterator kf = std::lower_bound(keyframes.begin(), keyframes.end(), curFrame); + auto kf = std::lower_bound(keyframes.begin(), keyframes.end(), curFrame); if (*kf == curFrame) { prev = *kf; next = *(kf + 1); diff --git a/aegisub/src/command/video.cpp b/aegisub/src/command/video.cpp index eb81fb2ae..15ec44aee 100644 --- a/aegisub/src/command/video.cpp +++ b/aegisub/src/command/video.cpp @@ -360,8 +360,8 @@ struct video_frame_next_keyframe : public validator_video_loaded { STR_HELP("Seek to the next keyframe") void operator()(agi::Context *c) { - std::vector const& kf = c->videoController->GetKeyFrames(); - std::vector::const_iterator pos = lower_bound(kf.begin(), kf.end(), c->videoController->GetFrameN() + 1); + auto const& kf = c->videoController->GetKeyFrames(); + auto pos = lower_bound(kf.begin(), kf.end(), c->videoController->GetFrameN() + 1); c->videoController->JumpToFrame(pos == kf.end() ? c->videoController->GetLength() - 1 : *pos); } @@ -431,14 +431,13 @@ struct video_frame_prev_keyframe : public validator_video_loaded { STR_HELP("Seek to the previous keyframe") void operator()(agi::Context *c) { - std::vector const& kf = c->videoController->GetKeyFrames(); + auto const& kf = c->videoController->GetKeyFrames(); if (kf.empty()) { c->videoController->JumpToFrame(0); return; } - std::vector::const_iterator pos = - lower_bound(kf.begin(), kf.end(), c->videoController->GetFrameN()); + auto pos = lower_bound(kf.begin(), kf.end(), c->videoController->GetFrameN()); if (pos != kf.begin()) --pos; diff --git a/aegisub/src/dialog_manager.h b/aegisub/src/dialog_manager.h index adbd471f4..a079843d1 100644 --- a/aegisub/src/dialog_manager.h +++ b/aegisub/src/dialog_manager.h @@ -102,8 +102,8 @@ public: /// @return A pointer to a DialogType or nullptr if no dialog of the given type has been created template DialogType *Get() const { - DialogMap::const_iterator it = created_dialogs.find(&typeid(DialogType)); - return it != created_dialogs.end() ? static_cast(it->second) : 0; + auto it = created_dialogs.find(&typeid(DialogType)); + return it != created_dialogs.end() ? static_cast(it->second) : nullptr; } ~DialogManager() { diff --git a/aegisub/src/dialog_shift_times.cpp b/aegisub/src/dialog_shift_times.cpp index 72974ec6d..7ee050f85 100644 --- a/aegisub/src/dialog_shift_times.cpp +++ b/aegisub/src/dialog_shift_times.cpp @@ -81,7 +81,7 @@ static wxString get_history_string(json::Object &obj) { lines = wxString::Format(_("from %d onward"), (int)(int64_t)sel.front()["start"]); else { lines += _("sel "); - for (json::Array::const_iterator it = sel.begin(); it != sel.end(); ++it) { + for (auto it = sel.begin(); it != sel.end(); ++it) { int beg = (int64_t)(*it)["start"]; int end = (int64_t)(*it)["end"]; if (beg == end) diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index 267abfd56..7c53d0aa6 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -110,7 +110,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { if (overriden) used_styles[style].lines.insert(index); std::set& chars = used_styles[style].chars; - for (wxString::const_iterator it = text.begin(); it != text.end(); ++it) { + for (auto it = text.begin(); it != text.end(); ++it) { wxUniChar cur = *it; if (cur == L'\\' && it + 1 != text.end()) { wxUniChar next = *++it; diff --git a/aegisub/src/menu.cpp b/aegisub/src/menu.cpp index a1fac9783..1d941648e 100644 --- a/aegisub/src/menu.cpp +++ b/aegisub/src/menu.cpp @@ -279,7 +279,7 @@ struct CommandMenuBar : public wxMenuBar { /// @param[out] value Output value to write to /// @return Was the requested index found bool read_entry(json::Object const& obj, const char *name, std::string *value) { - json::Object::const_iterator it = obj.find(name); + auto it = obj.find(name); if (it == obj.end()) return false; *value = static_cast(it->second); return true; @@ -313,7 +313,7 @@ menu_map const& get_menus_root() { menu_items const& get_menu(std::string const& name) { menu_map const& root = get_menus_root(); - menu_map::const_iterator it = root.find(name); + auto it = root.find(name); if (it == root.end()) throw menu::UnknownMenu("Menu named " + name + " not found"); return it->second; } diff --git a/aegisub/src/spline.cpp b/aegisub/src/spline.cpp index 2a12dd493..6be63ab71 100644 --- a/aegisub/src/spline.cpp +++ b/aegisub/src/spline.cpp @@ -69,14 +69,14 @@ std::string Spline::EncodeToAss() const { result.reserve(size() * 10); char last = 0; - for (const_iterator cur = begin(); cur != end(); ++cur) { - switch (cur->type) { + for (auto const& pt : *this) { + switch (pt.type) { case SplineCurve::POINT: if (last != 'm') { result += "m "; last = 'm'; } - result += ToScript(cur->p1).DStr(' '); + result += ToScript(pt.p1).DStr(' '); break; case SplineCurve::LINE: @@ -84,7 +84,7 @@ std::string Spline::EncodeToAss() const { result += "l "; last = 'l'; } - result += ToScript(cur->p2).DStr(' '); + result += ToScript(pt.p2).DStr(' '); break; case SplineCurve::BICUBIC: @@ -92,9 +92,9 @@ std::string Spline::EncodeToAss() const { result += "b "; last = 'b'; } - result += ToScript(cur->p2).DStr(' ') + " "; - result += ToScript(cur->p3).DStr(' ') + " "; - result += ToScript(cur->p4).DStr(' '); + result += ToScript(pt.p2).DStr(' ') + " "; + result += ToScript(pt.p3).DStr(' ') + " "; + result += ToScript(pt.p4).DStr(' '); break; default: break; diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 4ba5185e8..34ce877bb 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -101,7 +101,7 @@ namespace { /// Populate the toolbar with buttons void Populate() { json::Object const& root = get_root(); - json::Object::const_iterator root_it = root.find(name); + auto root_it = root.find(name); if (root_it == root.end()) { // Toolbar names are all hardcoded so this should never happen throw agi::InternalError("Toolbar named " + name + " not found.", 0); diff --git a/aegisub/src/video_slider.cpp b/aegisub/src/video_slider.cpp index 8844fa8f2..f86fee77a 100644 --- a/aegisub/src/video_slider.cpp +++ b/aegisub/src/video_slider.cpp @@ -127,7 +127,7 @@ void VideoSlider::OnMouse(wxMouseEvent &event) { // Shift click to snap to keyframe if (event.ShiftDown() && keyframes.size()) { int clickedFrame = GetValueAtX(x); - std::vector::const_iterator pos = lower_bound(keyframes.begin(), keyframes.end(), clickedFrame); + auto pos = lower_bound(keyframes.begin(), keyframes.end(), clickedFrame); if (pos == keyframes.end()) --pos; else if (pos + 1 != keyframes.end() && clickedFrame - *pos > (*pos + 1) - clickedFrame)