libcamera: Replace ARRAY_SIZE() with std::size()
C++17 has a std::size() function that returns the size of a C-style array. Use it instead of the custom ARRAY_SIZE macro. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <email@uajain.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
bd4894d259
commit
5cfbbcd207
7 changed files with 16 additions and 22 deletions
|
@ -17,8 +17,6 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
|
||||||
|
|
||||||
#ifndef __DOXYGEN__
|
#ifndef __DOXYGEN__
|
||||||
|
|
||||||
/* uClibc and uClibc-ng don't provide O_TMPFILE */
|
/* uClibc and uClibc-ng don't provide O_TMPFILE */
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -27,7 +28,6 @@
|
||||||
#include "libcamera/internal/buffer.h"
|
#include "libcamera/internal/buffer.h"
|
||||||
#include "libcamera/internal/camera_sensor.h"
|
#include "libcamera/internal/camera_sensor.h"
|
||||||
#include "libcamera/internal/log.h"
|
#include "libcamera/internal/log.h"
|
||||||
#include "libcamera/internal/utils.h"
|
|
||||||
|
|
||||||
#include <linux/bcm2835-isp.h>
|
#include <linux/bcm2835-isp.h>
|
||||||
|
|
||||||
|
@ -1092,7 +1092,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)
|
||||||
* Choose smallest cell size that won't exceed 63x48 cells.
|
* Choose smallest cell size that won't exceed 63x48 cells.
|
||||||
*/
|
*/
|
||||||
const int cellSizes[] = { 16, 32, 64, 128, 256 };
|
const int cellSizes[] = { 16, 32, 64, 128, 256 };
|
||||||
unsigned int numCells = ARRAY_SIZE(cellSizes);
|
unsigned int numCells = std::size(cellSizes);
|
||||||
unsigned int i, w, h, cellSize;
|
unsigned int i, w, h, cellSize;
|
||||||
for (i = 0; i < numCells; i++) {
|
for (i = 0; i < numCells; i++) {
|
||||||
cellSize = cellSizes[i];
|
cellSize = cellSizes[i];
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <libcamera/camera.h>
|
#include <libcamera/camera.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
@ -17,7 +18,6 @@
|
||||||
#include "libcamera/internal/log.h"
|
#include "libcamera/internal/log.h"
|
||||||
#include "libcamera/internal/pipeline_handler.h"
|
#include "libcamera/internal/pipeline_handler.h"
|
||||||
#include "libcamera/internal/thread.h"
|
#include "libcamera/internal/thread.h"
|
||||||
#include "libcamera/internal/utils.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file camera.h
|
* \file camera.h
|
||||||
|
@ -393,7 +393,7 @@ int Camera::Private::isAccessAllowed(State state, bool allowDisconnected) const
|
||||||
if (currentState == state)
|
if (currentState == state)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ASSERT(static_cast<unsigned int>(state) < ARRAY_SIZE(camera_state_names));
|
ASSERT(static_cast<unsigned int>(state) < std::size(camera_state_names));
|
||||||
|
|
||||||
LOG(Camera, Debug) << "Camera in " << camera_state_names[currentState]
|
LOG(Camera, Debug) << "Camera in " << camera_state_names[currentState]
|
||||||
<< " state trying operation requiring state "
|
<< " state trying operation requiring state "
|
||||||
|
@ -412,8 +412,8 @@ int Camera::Private::isAccessAllowed(State low, State high,
|
||||||
if (currentState >= low && currentState <= high)
|
if (currentState >= low && currentState <= high)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ASSERT(static_cast<unsigned int>(low) < ARRAY_SIZE(camera_state_names) &&
|
ASSERT(static_cast<unsigned int>(low) < std::size(camera_state_names) &&
|
||||||
static_cast<unsigned int>(high) < ARRAY_SIZE(camera_state_names));
|
static_cast<unsigned int>(high) < std::size(camera_state_names));
|
||||||
|
|
||||||
LOG(Camera, Debug) << "Camera in " << camera_state_names[currentState]
|
LOG(Camera, Debug) << "Camera in " << camera_state_names[currentState]
|
||||||
<< " state trying operation requiring state between "
|
<< " state trying operation requiring state between "
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "libcamera/internal/log.h"
|
#include "libcamera/internal/log.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#if HAVE_BACKTRACE
|
#if HAVE_BACKTRACE
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -91,7 +92,7 @@ static const char *log_severity_name(LogSeverity severity)
|
||||||
"FATAL",
|
"FATAL",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (static_cast<unsigned int>(severity) < ARRAY_SIZE(names))
|
if (static_cast<unsigned int>(severity) < std::size(names))
|
||||||
return names[severity];
|
return names[severity];
|
||||||
else
|
else
|
||||||
return "UNKWN";
|
return "UNKWN";
|
||||||
|
@ -406,7 +407,7 @@ void Logger::backtrace()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void *buffer[32];
|
void *buffer[32];
|
||||||
int num_entries = ::backtrace(buffer, ARRAY_SIZE(buffer));
|
int num_entries = ::backtrace(buffer, std::size(buffer));
|
||||||
char **strings = backtrace_symbols(buffer, num_entries);
|
char **strings = backtrace_symbols(buffer, num_entries);
|
||||||
if (!strings)
|
if (!strings)
|
||||||
return;
|
return;
|
||||||
|
@ -620,7 +621,7 @@ LogSeverity Logger::parseLogLevel(const std::string &level)
|
||||||
severity = LogInvalid;
|
severity = LogInvalid;
|
||||||
} else {
|
} else {
|
||||||
severity = LogInvalid;
|
severity = LogInvalid;
|
||||||
for (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) {
|
for (unsigned int i = 0; i < std::size(names); ++i) {
|
||||||
if (names[i] == level) {
|
if (names[i] == level) {
|
||||||
severity = i;
|
severity = i;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -31,11 +31,6 @@ namespace libcamera {
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
/**
|
|
||||||
* \def ARRAY_SIZE(array)
|
|
||||||
* \brief Determine the number of elements in the static array.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Strip the directory prefix from the path
|
* \brief Strip the directory prefix from the path
|
||||||
* \param[in] path The path to process
|
* \param[in] path The path to process
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "libcamera/internal/v4l2_videodevice.h"
|
#include "libcamera/internal/v4l2_videodevice.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -26,7 +27,6 @@
|
||||||
#include "libcamera/internal/log.h"
|
#include "libcamera/internal/log.h"
|
||||||
#include "libcamera/internal/media_device.h"
|
#include "libcamera/internal/media_device.h"
|
||||||
#include "libcamera/internal/media_object.h"
|
#include "libcamera/internal/media_object.h"
|
||||||
#include "libcamera/internal/utils.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file v4l2_videodevice.h
|
* \file v4l2_videodevice.h
|
||||||
|
@ -860,7 +860,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)
|
||||||
pix->num_planes = format->planesCount;
|
pix->num_planes = format->planesCount;
|
||||||
pix->field = V4L2_FIELD_NONE;
|
pix->field = V4L2_FIELD_NONE;
|
||||||
|
|
||||||
ASSERT(pix->num_planes <= ARRAY_SIZE(pix->plane_fmt));
|
ASSERT(pix->num_planes <= std::size(pix->plane_fmt));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < pix->num_planes; ++i) {
|
for (unsigned int i = 0; i < pix->num_planes; ++i) {
|
||||||
pix->plane_fmt[i].bytesperline = format->planes[i].bpl;
|
pix->plane_fmt[i].bytesperline = format->planes[i].bpl;
|
||||||
|
@ -1255,7 +1255,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)
|
||||||
buf.index = index;
|
buf.index = index;
|
||||||
buf.type = bufferType_;
|
buf.type = bufferType_;
|
||||||
buf.memory = V4L2_MEMORY_MMAP;
|
buf.memory = V4L2_MEMORY_MMAP;
|
||||||
buf.length = ARRAY_SIZE(v4l2Planes);
|
buf.length = std::size(v4l2Planes);
|
||||||
buf.m.planes = v4l2Planes;
|
buf.m.planes = v4l2Planes;
|
||||||
|
|
||||||
int ret = ioctl(VIDIOC_QUERYBUF, &buf);
|
int ret = ioctl(VIDIOC_QUERYBUF, &buf);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -19,7 +20,6 @@
|
||||||
#include "libcamera/internal/ipc_unixsocket.h"
|
#include "libcamera/internal/ipc_unixsocket.h"
|
||||||
#include "libcamera/internal/thread.h"
|
#include "libcamera/internal/thread.h"
|
||||||
#include "libcamera/internal/timer.h"
|
#include "libcamera/internal/timer.h"
|
||||||
#include "libcamera/internal/utils.h"
|
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ protected:
|
||||||
};
|
};
|
||||||
int fds[2];
|
int fds[2];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {
|
for (unsigned int i = 0; i < std::size(strings); i++) {
|
||||||
unsigned int len = strlen(strings[i]);
|
unsigned int len = strlen(strings[i]);
|
||||||
|
|
||||||
fds[i] = open("/tmp", O_TMPFILE | O_RDWR,
|
fds[i] = open("/tmp", O_TMPFILE | O_RDWR,
|
||||||
|
@ -333,7 +333,7 @@ protected:
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {
|
for (unsigned int i = 0; i < std::size(strings); i++) {
|
||||||
unsigned int len = strlen(strings[i]);
|
unsigned int len = strlen(strings[i]);
|
||||||
char buf[len];
|
char buf[len];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue