Replace use of deprecated C Standard library headers in C++ code.
Change-Id: I9fa6630c7e4bdb2897df34d417635d8c7d8253bc
Signed-off-by: Tyler Chatow <tchatow@gmail.com>
diff --git a/y2016/actors/autonomous_actor.cc b/y2016/actors/autonomous_actor.cc
index 0b11bdd..c35612f 100644
--- a/y2016/actors/autonomous_actor.cc
+++ b/y2016/actors/autonomous_actor.cc
@@ -1,13 +1,11 @@
#include "y2016/actors/autonomous_actor.h"
-#include <inttypes.h>
-
#include <chrono>
+#include <cinttypes>
#include <cmath>
#include "aos/logging/logging.h"
#include "aos/util/phased_loop.h"
-
#include "y2016/control_loops/drivetrain/drivetrain_base.h"
#include "y2016/control_loops/shooter/shooter_goal_generated.h"
#include "y2016/control_loops/shooter/shooter_status_generated.h"
@@ -63,8 +61,7 @@
vision_align_actor_factory_(
actors::VisionAlignActor::MakeFactory(event_loop)),
vision_status_fetcher_(
- event_loop->MakeFetcher<::y2016::vision::VisionStatus>(
- "/vision")),
+ event_loop->MakeFetcher<::y2016::vision::VisionStatus>("/vision")),
ball_detector_fetcher_(
event_loop->MakeFetcher<::y2016::sensors::BallDetector>(
"/superstructure")),
@@ -971,7 +968,7 @@
if (!WaitForDriveDone()) return true;
AOS_LOG(INFO, "Done %f\n",
- ::aos::time::DurationInSeconds(monotonic_now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_now() - start_time));
::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
monotonic_now(),
diff --git a/y2016/actors/autonomous_actor_main.cc b/y2016/actors/autonomous_actor_main.cc
index b422faf..4dc2721 100644
--- a/y2016/actors/autonomous_actor_main.cc
+++ b/y2016/actors/autonomous_actor_main.cc
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#include <cstdio>
#include "aos/events/shm_event_loop.h"
#include "aos/init.h"
diff --git a/y2016/actors/superstructure_actor_main.cc b/y2016/actors/superstructure_actor_main.cc
index 4cc65a1..46c3b55 100644
--- a/y2016/actors/superstructure_actor_main.cc
+++ b/y2016/actors/superstructure_actor_main.cc
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#include <cstdio>
#include "aos/events/shm_event_loop.h"
#include "aos/init.h"
diff --git a/y2016/actors/vision_align_actor_main.cc b/y2016/actors/vision_align_actor_main.cc
index 518b405..37c3183 100644
--- a/y2016/actors/vision_align_actor_main.cc
+++ b/y2016/actors/vision_align_actor_main.cc
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#include <cstdio>
#include "aos/events/shm_event_loop.h"
#include "aos/init.h"
diff --git a/y2016/constants.cc b/y2016/constants.cc
index 1f4ae9e..363ef26 100644
--- a/y2016/constants.cc
+++ b/y2016/constants.cc
@@ -1,9 +1,8 @@
#include "y2016/constants.h"
-#include <inttypes.h>
-#include <math.h>
-#include <stdint.h>
-
+#include <cinttypes>
+#include <cmath>
+#include <cstdint>
#include <map>
#if __has_feature(address_sanitizer)
@@ -14,7 +13,6 @@
#include "aos/logging/logging.h"
#include "aos/network/team_number.h"
#include "aos/stl_mutex/stl_mutex.h"
-
#include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
#include "y2016/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
diff --git a/y2016/constants.h b/y2016/constants.h
index 3cbb895..f332e37 100644
--- a/y2016/constants.h
+++ b/y2016/constants.h
@@ -1,17 +1,17 @@
#ifndef Y2016_CONSTANTS_H_
#define Y2016_CONSTANTS_H_
-#include <stdint.h>
+#include <cstdint>
+#include "frc971/constants.h"
#include "frc971/control_loops/state_feedback_loop.h"
#include "frc971/shifter_hall_effect.h"
-#include "frc971/constants.h"
namespace y2016 {
namespace constants {
-using ::frc971::constants::ShifterHallEffect;
using ::frc971::constants::PotAndIndexPulseZeroingConstants;
+using ::frc971::constants::ShifterHallEffect;
// Has all of the numbers that change for both robots and makes it easy to
// retrieve the values for the current one.
diff --git a/y2016/joystick_reader.cc b/y2016/joystick_reader.cc
index 7a2ce81..974adf7 100644
--- a/y2016/joystick_reader.cc
+++ b/y2016/joystick_reader.cc
@@ -1,8 +1,9 @@
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
#include <unistd.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+
#include "aos/actions/actions.h"
#include "aos/init.h"
#include "aos/logging/logging.h"
diff --git a/y2016/vision/debug_receiver.cc b/y2016/vision/debug_receiver.cc
index d3c527c..e89e9d8 100644
--- a/y2016/vision/debug_receiver.cc
+++ b/y2016/vision/debug_receiver.cc
@@ -1,24 +1,23 @@
-#include <stdio.h>
-#include <stdlib.h>
+#include <gtk/gtk.h>
#include <netdb.h>
#include <unistd.h>
-#include <vector>
+#include <cstdio>
+#include <cstdlib>
#include <memory>
+#include <vector>
-#include <gtk/gtk.h>
-#include "aos/vision/image/image_types.h"
-#include "aos/vision/image/jpeg_routines.h"
+#include "aos/vision/blob/codec.h"
+#include "aos/vision/blob/range_image.h"
+#include "aos/vision/blob/stream_view.h"
+#include "aos/vision/events/epoll_events.h"
#include "aos/vision/events/socket_types.h"
#include "aos/vision/events/tcp_client.h"
-#include "aos/vision/events/epoll_events.h"
-#include "aos/vision/blob/range_image.h"
-#include "aos/vision/blob/codec.h"
-#include "aos/vision/blob/stream_view.h"
-
-#include "y2016/vision/vision_data.pb.h"
-#include "y2016/vision/stereo_geometry.h"
+#include "aos/vision/image/image_types.h"
+#include "aos/vision/image/jpeg_routines.h"
#include "y2016/vision/blob_filters.h"
+#include "y2016/vision/stereo_geometry.h"
+#include "y2016/vision/vision_data.pb.h"
using namespace aos::vision;
@@ -69,9 +68,9 @@
private:
void DrawCross(PixelLinesOverlay &overlay, Vector<2> center, PixelRef color) {
overlay.AddLine(Vector<2>(center.x() - 50, center.y()),
- Vector<2>(center.x() + 50, center.y()), color);
+ Vector<2>(center.x() + 50, center.y()), color);
overlay.AddLine(Vector<2>(center.x(), center.y() - 50),
- Vector<2>(center.x(), center.y() + 50), color);
+ Vector<2>(center.x(), center.y() + 50), color);
}
// where we darw for debugging
@@ -128,6 +127,7 @@
img_read_ = -1;
}
}
+
private:
data_len len_;
int num_read_;
diff --git a/y2016/vision/target_receiver.cc b/y2016/vision/target_receiver.cc
index cc9f41b..a762e4f 100644
--- a/y2016/vision/target_receiver.cc
+++ b/y2016/vision/target_receiver.cc
@@ -1,10 +1,10 @@
#include <netdb.h>
-#include <stdlib.h>
#include <unistd.h>
#include <array>
#include <atomic>
#include <chrono>
+#include <cstdlib>
#include <limits>
#include <memory>
#include <thread>
diff --git a/y2016/vision/target_sender.cc b/y2016/vision/target_sender.cc
index bc2a695..a0a0dc7 100644
--- a/y2016/vision/target_sender.cc
+++ b/y2016/vision/target_sender.cc
@@ -1,6 +1,7 @@
-#include <stdio.h>
-#include <stdlib.h>
#include <sys/stat.h>
+
+#include <cstdio>
+#include <cstdlib>
#include <fstream>
#include <iostream>
#include <memory>
@@ -19,22 +20,22 @@
namespace y2016 {
namespace vision {
-using aos::vision::ImageStreamEvent;
-using aos::vision::DataRef;
-using aos::events::TCPServer;
-using aos::vision::BlobLRef;
-using aos::vision::Vector;
-using aos::vision::Int32Codec;
-using aos::vision::BlobList;
-using aos::vision::RangeImage;
-using aos::vision::PixelRef;
-using aos::vision::ImageValue;
-using aos::vision::HistogramBlobFilter;
-using aos::vision::CornerFinder;
-using aos::vision::Int64Codec;
-using aos::events::TXUdpSocket;
using aos::events::DataSocket;
+using aos::events::TCPServer;
+using aos::events::TXUdpSocket;
+using aos::vision::BlobList;
+using aos::vision::BlobLRef;
+using aos::vision::CornerFinder;
+using aos::vision::DataRef;
+using aos::vision::HistogramBlobFilter;
using aos::vision::ImageFormat;
+using aos::vision::ImageStreamEvent;
+using aos::vision::ImageValue;
+using aos::vision::Int32Codec;
+using aos::vision::Int64Codec;
+using aos::vision::PixelRef;
+using aos::vision::RangeImage;
+using aos::vision::Vector;
::aos::vision::CameraParams GetCameraParams(const Calibration &calibration) {
::aos::vision::CameraParams params;
diff --git a/y2016/vision/tools/blob_stream_replay.cc b/y2016/vision/tools/blob_stream_replay.cc
index acf4d4b..847f654 100644
--- a/y2016/vision/tools/blob_stream_replay.cc
+++ b/y2016/vision/tools/blob_stream_replay.cc
@@ -1,20 +1,20 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <vector>
-#include <memory>
#include <endian.h>
-#include <sys/stat.h>
-#include <fstream>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
+#include <sys/stat.h>
-#include "aos/vision/image/reader.h"
-#include "aos/vision/image/jpeg_routines.h"
-#include "aos/vision/image/image_stream.h"
+#include <cstdio>
+#include <cstdlib>
+#include <fstream>
+#include <memory>
+#include <vector>
+
+#include "aos/vision/blob/stream_view.h"
#include "aos/vision/events/epoll_events.h"
#include "aos/vision/events/tcp_server.h"
-#include "aos/vision/blob/stream_view.h"
+#include "aos/vision/image/image_stream.h"
+#include "aos/vision/image/jpeg_routines.h"
+#include "aos/vision/image/reader.h"
#include "y2016/vision/blob_filters.h"
// #include "y2016/vision/process_targets.h"
@@ -22,7 +22,8 @@
namespace vision {
using namespace aos::vision;
-::aos::vision::Vector<2> CreateCenterFromTarget(double lx, double ly, double rx, double ry) {
+::aos::vision::Vector<2> CreateCenterFromTarget(double lx, double ly, double rx,
+ double ry) {
return ::aos::vision::Vector<2>((lx + rx) / 2.0, (ly + ry) / 2.0);
}
@@ -32,8 +33,8 @@
return ::std::hypot(dx, dy);
}
-void SelectTargets(std::vector<std::pair<Vector<2>, Vector<2>>>& left_target,
- std::vector<std::pair<Vector<2>, Vector<2>>>&right_target,
+void SelectTargets(std::vector<std::pair<Vector<2>, Vector<2>>> &left_target,
+ std::vector<std::pair<Vector<2>, Vector<2>>> &right_target,
::aos::vision::Vector<2> *center_left,
::aos::vision::Vector<2> *center_right) {
// No good targets. Let the caller decide defaults.
@@ -43,12 +44,12 @@
// Only one option, we have to go with it.
if (right_target.size() == 1 && left_target.size() == 1) {
- *center_left =
- CreateCenterFromTarget(left_target[0].first.x(), left_target[0].first.y(),
- left_target[0].second.x(), left_target[0].second.y());
+ *center_left = CreateCenterFromTarget(
+ left_target[0].first.x(), left_target[0].first.y(),
+ left_target[0].second.x(), left_target[0].second.y());
*center_right = CreateCenterFromTarget(
- right_target[0].first.x(), right_target[0].first.y(), right_target[0].second.x(),
- right_target[0].second.y());
+ right_target[0].first.x(), right_target[0].first.y(),
+ right_target[0].second.x(), right_target[0].second.y());
return;
}
@@ -57,12 +58,10 @@
int left_index = 0;
// First pick the widest target from the left.
for (size_t i = 0; i < left_target.size(); i++) {
- const double h = left_target[i].first.y() -
- left_target[i].second.y();
- const double wid1 = TargetWidth(left_target[i].first.x(),
- left_target[i].first.y(),
- left_target[i].second.x(),
- left_target[i].second.y());
+ const double h = left_target[i].first.y() - left_target[i].second.y();
+ const double wid1 =
+ TargetWidth(left_target[i].first.x(), left_target[i].first.y(),
+ left_target[i].second.x(), left_target[i].second.y());
const double angle = h / wid1;
if (min_angle == -1.0 || ::std::abs(angle) < ::std::abs(min_angle)) {
min_angle = angle;
@@ -70,21 +69,20 @@
}
}
// Calculate the angle of the bottom edge for the left.
- double h = left_target[left_index].first.y() -
- left_target[left_index].second.y();
+ double h =
+ left_target[left_index].first.y() - left_target[left_index].second.y();
double good_ang = min_angle;
double min_ang_err = -1.0;
int right_index = -1;
- // Now pick the bottom edge angle from the right that lines up best with the left.
+ // Now pick the bottom edge angle from the right that lines up best with the
+ // left.
for (size_t j = 0; j < right_target.size(); j++) {
- double wid2 = TargetWidth(right_target[j].first.x(),
- right_target[j].first.y(),
- right_target[j].second.x(),
- right_target[j].second.y());
- h = right_target[j].first.y() -
- right_target[j].second.y();
- double ang = h/ wid2;
+ double wid2 =
+ TargetWidth(right_target[j].first.x(), right_target[j].first.y(),
+ right_target[j].second.x(), right_target[j].second.y());
+ h = right_target[j].first.y() - right_target[j].second.y();
+ double ang = h / wid2;
double ang_err = ::std::abs(good_ang - ang);
if (min_ang_err == -1.0 || min_ang_err > ang_err) {
min_ang_err = ang_err;
@@ -92,19 +90,15 @@
}
}
- *center_left =
- CreateCenterFromTarget(left_target[left_index].first.x(),
- left_target[left_index].first.y(),
- left_target[left_index].second.x(),
- left_target[left_index].second.y());
- *center_right =
- CreateCenterFromTarget(right_target[right_index].first.x(),
- right_target[right_index].first.y(),
- right_target[right_index].second.x(),
- right_target[right_index].second.y());
+ *center_left = CreateCenterFromTarget(
+ left_target[left_index].first.x(), left_target[left_index].first.y(),
+ left_target[left_index].second.x(), left_target[left_index].second.y());
+ *center_right = CreateCenterFromTarget(right_target[right_index].first.x(),
+ right_target[right_index].first.y(),
+ right_target[right_index].second.x(),
+ right_target[right_index].second.y());
}
-
long GetFileSize(std::string filename) {
struct stat stat_buf;
int rc = stat(filename.c_str(), &stat_buf);
@@ -152,9 +146,10 @@
prev_ = buf_;
buf_ += sizeof(uint32_t);
*timestamp = Int64Codec::Read(&buf_);
-// auto* buf_tmp = buf_;
+ // auto* buf_tmp = buf_;
buf_ = ParseBlobList(blob_list, buf_);
-// fprintf(stderr, "read frame: %lu, buf_size: %lu\n", *timestamp, buf_ - buf_tmp);
+ // fprintf(stderr, "read frame: %lu, buf_size: %lu\n", *timestamp, buf_ -
+ // buf_tmp);
return true;
}
@@ -217,8 +212,8 @@
ifs2_(fname2),
blob_filt_(fmt, 40, 750, 250000),
finder_(0.25, 35) {
- text_overlay_.draw_fn =
- [this](RenderInterface *render, double /*width*/, double /*height*/) {
+ text_overlay_.draw_fn = [this](RenderInterface *render, double /*width*/,
+ double /*height*/) {
render->SetSourceRGB(1.0, 1.0, 1.0);
if (hud_text) render->Text(20, 20, 0, 0, kHudText);
};
@@ -418,12 +413,14 @@
void UpdateNewTime(int new_delta) {
if (new_delta != ms_event_delta_) {
ms_event_delta_ = new_delta;
- SetTime(::std::chrono::milliseconds(ms_event_delta_) + aos::monotonic_clock::now());
+ SetTime(::std::chrono::milliseconds(ms_event_delta_) +
+ aos::monotonic_clock::now());
}
}
void Done() override {
- SetTime(::std::chrono::milliseconds(ms_event_delta_) + aos::monotonic_clock::now());
+ SetTime(::std::chrono::milliseconds(ms_event_delta_) +
+ aos::monotonic_clock::now());
if (paused && !single_step) return;
single_step = false;
frame_count_++;
@@ -481,7 +478,8 @@
if (seeking_target_) {
if (play_forward) {
- // Go back to the last time we didn't see a target and play from there.
+ // Go back to the last time we didn't see a target and play from
+ // there.
TickBackFrame(nano_step);
seeking_target_ = false;
} else if (seeking_target_) {
@@ -525,9 +523,9 @@
void DrawCross(PixelLinesOverlay &overlay, Vector<2> center, PixelRef color) {
overlay.AddLine(Vector<2>(center.x() - 25, center.y()),
- Vector<2>(center.x() + 25, center.y()), color);
+ Vector<2>(center.x() + 25, center.y()), color);
overlay.AddLine(Vector<2>(center.x(), center.y() - 25),
- Vector<2>(center.x(), center.y() + 25), color);
+ Vector<2>(center.x(), center.y() + 25), color);
}
void AddTo(aos::events::EpollLoop *loop) {
@@ -542,6 +540,7 @@
private:
int ms_event_delta_ = 200;
+
public:
// basic image size
ImageFormat fmt_;
@@ -574,8 +573,8 @@
// count how many frames we miss in a row.
int missed_count_ = 16;
};
-}
-} // namespace y2016::vision
+} // namespace vision
+} // namespace y2016
int main(int argc, char *argv[]) {
using namespace y2016::vision;
@@ -597,8 +596,8 @@
printf("file (%s) dbg_lvl (%d)\n", file.c_str(), dbg);
std::string fname_path = file;
- NetworkForwardingImageStream strm1(
- fmt, dbg, fname_path + "_0.dat", fname_path + "_1.dat");
+ NetworkForwardingImageStream strm1(fmt, dbg, fname_path + "_0.dat",
+ fname_path + "_1.dat");
fprintf(stderr, "staring main\n");
strm1.AddTo(&loop);
diff --git a/y2016/wpilib_interface.cc b/y2016/wpilib_interface.cc
index e8ad2f6..e3d367c 100644
--- a/y2016/wpilib_interface.cc
+++ b/y2016/wpilib_interface.cc
@@ -1,10 +1,10 @@
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
#include <unistd.h>
#include <array>
#include <chrono>
+#include <cinttypes>
+#include <cstdio>
+#include <cstring>
#include <functional>
#include <mutex>
#include <thread>
@@ -53,8 +53,8 @@
#include "y2016/control_loops/superstructure/superstructure_position_generated.h"
#include "y2016/queues/ball_detector_generated.h"
-using std::make_unique;
using ::frc971::wpilib::LoopOutputHandler;
+using std::make_unique;
namespace shooter = ::y2016::control_loops::shooter;
namespace superstructure = ::y2016::control_loops::superstructure;