Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satisfy Misra C++ quality rules #1362

Merged
merged 17 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ build_script:
- if "%TARGET%"=="mingw" cmake --build . --config %configuration% --target install -- -j2
- if "%TARGET%"=="mingw" dir C:\projects\visp\build\install
- if "%TARGET%"=="mingw" dir %VISP_DLL_DIR%
- if "%TARGET%"=="mingw" ctest --output-on-failure
- if "%TARGET%"=="mingw" ctest --output-on-failure -V

# msvc case
- if "%TARGET%"=="msvc" dir %OpenCV_DLL_DIR%
- if "%TARGET%"=="msvc" cmake -G "Visual Studio 15 2017" -A %platform% ..\visp
- if "%TARGET%"=="msvc" cmake --build . --config %configuration% --target install -- /m:2
- if "%TARGET%"=="msvc" dir C:\projects\visp\build\install
- if "%TARGET%"=="msvc" dir %VISP_DLL_DIR%
- if "%TARGET%"=="msvc" ctest --output-on-failure
- if "%TARGET%"=="msvc" ctest --output-on-failure -V

# uwp case
- if "%TARGET%"=="uwp" cmake -G "Visual Studio 15 2017" -A %platform% -DCMAKE_SYSTEM_NAME="WindowsStore" -DCMAKE_SYSTEM_VERSION="10.0" -DBUILD_DEMOS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_TUTORIALS=OFF ..\visp
Expand Down
27 changes: 16 additions & 11 deletions example/device/framegrabber/grab1394Two.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool read_options(int argc, const char **argv, bool &multi, unsigned int &camera
case '?':
usage(argv[0], nullptr, camera, nframes, opath, roi_left, roi_top, roi_width, roi_height, ringbuffersize,
panControl);
exit(0);
return false;
break;
}
}
Expand Down Expand Up @@ -376,10 +376,9 @@ int main(int argc, const char **argv)
if (read_options(argc, argv, multi, camera, nframes, verbose_info, verbose_settings, videomode_is_set, videomode,
framerate_is_set, framerate, colorcoding_is_set, colorcoding, ringbuffersize_is_set,
ringbuffersize, display, save, opath, roi_left, roi_top, roi_width, roi_height, reset, panControl,
panControl_is_set)) {
panControl_is_set) == false) {
return EXIT_FAILURE;
}

// Create a grabber
vp1394TwoGrabber g(reset);

Expand Down Expand Up @@ -465,11 +464,13 @@ int main(int argc, const char **argv)
for (it_lmode = lmode.begin(); it_lmode != lmode.end(); ++it_lmode) {
// Parse the list of supported modes
vp1394TwoGrabber::vp1394TwoVideoModeType supmode = *it_lmode;
std::stringstream ss;
ss << (int)supmode;
if (curmode == supmode)
std::cout << " * " << vp1394TwoGrabber::videoMode2string(supmode) << " (-v " << (int)supmode << ")"
std::cout << " * " << vp1394TwoGrabber::videoMode2string(supmode) << " (-v " << ss.str() << ")"
<< std::endl;
else
std::cout << " " << vp1394TwoGrabber::videoMode2string(supmode) << " (-v " << (int)supmode << ")"
std::cout << " " << vp1394TwoGrabber::videoMode2string(supmode) << " (-v " << ss.str() << ")"
<< std::endl;

if (g.isVideoModeFormat7(supmode)) {
Expand All @@ -479,25 +480,29 @@ int main(int argc, const char **argv)
for (it_lcoding = lcoding.begin(); it_lcoding != lcoding.end(); ++it_lcoding) {
vp1394TwoGrabber::vp1394TwoColorCodingType supcoding;
supcoding = *it_lcoding;
std::stringstream ss;
ss << (int)supcoding;
if ((curmode == supmode) && (supcoding == curcoding))
std::cout << " * " << vp1394TwoGrabber::colorCoding2string(supcoding) << " (-g " << (int)supcoding
std::cout << " * " << vp1394TwoGrabber::colorCoding2string(supcoding) << " (-g " << ss.str()
<< ")" << std::endl;
else
std::cout << " " << vp1394TwoGrabber::colorCoding2string(supcoding) << " (-g " << (int)supcoding
std::cout << " " << vp1394TwoGrabber::colorCoding2string(supcoding) << " (-g " << ss.str()
<< ")" << std::endl;
}
}
else {

// Parse the list of supported framerates for a supported mode
// Parse the list of supported framerates for a supported mode
g.getFramerateSupported(supmode, lfps);
for (it_lfps = lfps.begin(); it_lfps != lfps.end(); ++it_lfps) {
vp1394TwoGrabber::vp1394TwoFramerateType supfps = *it_lfps;
std::stringstream ss;
ss << (int)supfps;
if ((curmode == supmode) && (supfps == curfps))
std::cout << " * " << vp1394TwoGrabber::framerate2string(supfps) << " (-f " << (int)supfps << ")"
std::cout << " * " << vp1394TwoGrabber::framerate2string(supfps) << " (-f " << ss.str() << ")"
<< std::endl;
else
std::cout << " " << vp1394TwoGrabber::framerate2string(supfps) << " (-f " << (int)supfps << ")"
std::cout << " " << vp1394TwoGrabber::framerate2string(supfps) << " (-f " << ss.str() << ")"
<< std::endl;
}
}
Expand All @@ -520,7 +525,7 @@ int main(int argc, const char **argv)
g.setVideoMode(videomode);
}
else {
// get The actual video mode
// get The actual video mode
g.setCamera(camera);
g.getVideoMode(videomode);
}
Expand Down
60 changes: 30 additions & 30 deletions modules/core/include/visp3/core/vpArray2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
* a[1][0] = 4; a[1][1] = 5.5; a[1][2] = 6;
*
* std::cout << "a:" << std::endl;
* for (unsigned int i = 0; i < a.getRows(); i++) {
* for (unsigned int j = 0; j < a.getCols(); j++) {
* for (unsigned int i = 0; i < a.getRows(); ++i) {
* for (unsigned int j = 0; j < a.getCols(); ++j) {
* std::cout << a[i][j] << " ";
* }
* std::cout << std::endl;
Expand Down Expand Up @@ -475,7 +475,7 @@ template <class Type> class vpArray2D
memcpy(data + r * colNum, A.data, sizeof(Type) * A.size());
}
else if (data != nullptr && A.data != nullptr && A.data != data) {
for (unsigned int i = r; i < (r + A.getRows()); i++) {
for (unsigned int i = r; i < (r + A.getRows()); ++i) {
memcpy(data + i * colNum + c, A.data + (i - r) * A.colNum, sizeof(Type) * A.colNum);
}
}
Expand Down Expand Up @@ -592,8 +592,8 @@ template <class Type> class vpArray2D
std::ios_base::fmtflags original_flags = s.flags();

s.precision(10);
for (unsigned int i = 0; i < A.getRows(); i++) {
for (unsigned int j = 0; j < A.getCols() - 1; j++) {
for (unsigned int i = 0; i < A.getRows(); ++i) {
for (unsigned int j = 0; j < A.getCols() - 1; ++j) {
s << A[i][j] << " ";
}
// We don't add " " after the last row element
Expand Down Expand Up @@ -698,8 +698,8 @@ template <class Type> class vpArray2D
A.resize(rows, cols);

Type value;
for (unsigned int i = 0; i < rows; i++) {
for (unsigned int j = 0; j < cols; j++) {
for (unsigned int i = 0; i < rows; ++i) {
for (unsigned int j = 0; j < cols; ++j) {
file >> value;
A[i][j] = value;
}
Expand Down Expand Up @@ -728,8 +728,8 @@ template <class Type> class vpArray2D
A.resize(rows, cols);

Type value;
for (unsigned int i = 0; i < rows; i++) {
for (unsigned int j = 0; j < cols; j++) {
for (unsigned int i = 0; i < rows; ++i) {
for (unsigned int j = 0; j < cols; ++j) {
file.read((char *)&value, sizeof(Type));
A[i][j] = value;
}
Expand Down Expand Up @@ -881,8 +881,8 @@ template <class Type> class vpArray2D
matrixSize = A.getCols();
file.write((char *)&matrixSize, sizeof(unsigned int));
Type value;
for (unsigned int i = 0; i < A.getRows(); i++) {
for (unsigned int j = 0; j < A.getCols(); j++) {
for (unsigned int i = 0; i < A.getRows(); ++i) {
for (unsigned int j = 0; j < A.getCols(); ++j) {
value = A[i][j];
file.write((char *)&value, sizeof(Type));
}
Expand Down Expand Up @@ -1068,7 +1068,7 @@ template <class Type> Type vpArray2D<Type>::getMinValue() const
Type *dataptr = data;
Type min = *dataptr;
dataptr++;
for (unsigned int i = 0; i < dsize - 1; i++) {
for (unsigned int i = 0; i < dsize - 1; ++i) {
if (*dataptr < min) {
min = *dataptr;
}
Expand All @@ -1085,7 +1085,7 @@ template <class Type> Type vpArray2D<Type>::getMaxValue() const
Type *dataptr = data;
Type max = *dataptr;
dataptr++;
for (unsigned int i = 0; i < dsize - 1; i++) {
for (unsigned int i = 0; i < dsize - 1; ++i) {
if (*dataptr > max) {
max = *dataptr;
}
Expand All @@ -1109,7 +1109,7 @@ template <class Type> vpArray2D<Type> vpArray2D<Type>::hadamard(const vpArray2D<
vpArray2D<Type> out;
out.resize(rowNum, colNum, false);

for (unsigned int i = 0; i < dsize; i++) {
for (unsigned int i = 0; i < dsize; ++i) {
out.data[i] = data[i] * m.data[i];
}

Expand All @@ -1119,8 +1119,8 @@ template <class Type> vpArray2D<Type> vpArray2D<Type>::hadamard(const vpArray2D<
template <class Type> vpArray2D<Type> vpArray2D<Type>::t() const
{
vpArray2D<Type> At(colNum, rowNum);
for (unsigned int i = 0; i < rowNum; i++) {
for (unsigned int j = 0; j < colNum; j++) {
for (unsigned int i = 0; i < rowNum; ++i) {
for (unsigned int j = 0; j < colNum; ++j) {
At[j][i] = (*this)[i][j];
}
}
Expand Down Expand Up @@ -1169,10 +1169,10 @@ template <class Type> void vpArray2D<Type>::conv2(const vpArray2D<Type> &M, cons
}

if (mode == "same") {
for (unsigned int i = 0; i < res_same.getRows(); i++) {
for (unsigned int j = 0; j < res_same.getCols(); j++) {
for (unsigned int k = 0; k < kernel.getRows(); k++) {
for (unsigned int l = 0; l < kernel.getCols(); l++) {
for (unsigned int i = 0; i < res_same.getRows(); ++i) {
for (unsigned int j = 0; j < res_same.getCols(); ++j) {
for (unsigned int k = 0; k < kernel.getRows(); ++k) {
for (unsigned int l = 0; l < kernel.getCols(); ++l) {
res_same[i][j] += M_padded[i + k][j + l] * kernel[kernel.getRows() - k - 1][kernel.getCols() - l - 1];
}
}
Expand All @@ -1181,16 +1181,16 @@ template <class Type> void vpArray2D<Type>::conv2(const vpArray2D<Type> &M, cons

const unsigned int start_i = kernel.getRows() / 2;
const unsigned int start_j = kernel.getCols() / 2;
for (unsigned int i = 0; i < M.getRows(); i++) {
for (unsigned int i = 0; i < M.getRows(); ++i) {
memcpy(res.data + i * M.getCols(), res_same.data + (i + start_i) * res_same.getCols() + start_j,
sizeof(Type) * M.getCols());
}
}
else {
for (unsigned int i = 0; i < res.getRows(); i++) {
for (unsigned int j = 0; j < res.getCols(); j++) {
for (unsigned int k = 0; k < kernel.getRows(); k++) {
for (unsigned int l = 0; l < kernel.getCols(); l++) {
for (unsigned int i = 0; i < res.getRows(); ++i) {
for (unsigned int j = 0; j < res.getCols(); ++j) {
for (unsigned int k = 0; k < kernel.getRows(); ++k) {
for (unsigned int l = 0; l < kernel.getCols(); ++l) {
res[i][j] += M_padded[i + k][j + l] * kernel[kernel.getRows() - k - 1][kernel.getCols() - l - 1];
}
}
Expand All @@ -1213,8 +1213,8 @@ template<class Type> void vpArray2D<Type>::insert(const vpArray2D<Type> &A, cons
if (((r + B.getRows()) <= A.getRows()) && ((c + B.getCols()) <= A.getCols())) {
C.resize(A.getRows(), A.getCols(), false, false);

for (unsigned int i = 0; i < A.getRows(); i++) {
for (unsigned int j = 0; j < A.getCols(); j++) {
for (unsigned int i = 0; i < A.getRows(); ++i) {
for (unsigned int j = 0; j < A.getCols(); ++j) {
if (i >= r && i < (r + B.getRows()) && j >= c && j < (c + B.getCols())) {
C[i][j] = B[i - r][j - c];
}
Expand All @@ -1236,7 +1236,7 @@ template <class Type> bool vpArray2D<Type>::operator==(const vpArray2D<Type> &A)
return false;
}

for (unsigned int i = 0; i < A.size(); i++) {
for (unsigned int i = 0; i < A.size(); ++i) {
if (data[i] != A.data[i]) {
return false;
}
Expand All @@ -1254,7 +1254,7 @@ template <> inline bool vpArray2D<double>::operator==(const vpArray2D<double> &A
return false;
}

for (unsigned int i = 0; i < A.size(); i++) {
for (unsigned int i = 0; i < A.size(); ++i) {
if (fabs(data[i] - A.data[i]) > std::numeric_limits<double>::epsilon()) {
return false;
}
Expand All @@ -1272,7 +1272,7 @@ template <> inline bool vpArray2D<float>::operator==(const vpArray2D<float> &A)
return false;
}

for (unsigned int i = 0; i < A.size(); i++) {
for (unsigned int i = 0; i < A.size(); ++i) {
if (fabsf(data[i] - A.data[i]) > std::numeric_limits<float>::epsilon()) {
return false;
}
Expand Down
30 changes: 15 additions & 15 deletions modules/core/include/visp3/core/vpColVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class vpPoseVector;
* v[0] = -1; v[1] = -2.1; v[2] = -3;
*
* std::cout << "v:" << std::endl;
* for (unsigned int i = 0; i < v.size(); i++) {
* for (unsigned int i = 0; i < v.size(); ++i) {
* std::cout << v[i] << std::endl;
* }
* }
Expand Down Expand Up @@ -288,7 +288,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* int main()
* {
* vpColVector v(3);
* for (unsigned int i=0; i<v.size(); i++)
* for (unsigned int i=0; i<v.size(); ++i)
* v[i] = i;
* v.cppPrint(std::cout, "v");
* }
Expand Down Expand Up @@ -316,7 +316,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* {
* std::ofstream ofs("log.csv", std::ofstream::out);
* vpColVector v(3);
* for (unsigned int i=0; i<v.size(); i++)
* for (unsigned int i=0; i<v.size(); ++i)
* v[i] = i;
*
* v.csvPrint(ofs);
Expand Down Expand Up @@ -357,7 +357,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
*
* \code
* vpColVector v1;
* for (unsigned int i=0; i<4; i++)
* for (unsigned int i=0; i<4; ++i)
* v1.stack(i);
* // v1 is equal to [0 1 2 3]^T
* vpColVector v2 = v1.extract(1, 3);
Expand Down Expand Up @@ -429,7 +429,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* {
* vpColVector v(4);
* int val = 0;
* for(size_t i=0; i<v.getRows(); i++) {
* for(size_t i=0; i<v.getRows(); ++i) {
* v[i] = val++;
* }
* std::cout << "v: " << v.t() << std::endl;
Expand Down Expand Up @@ -459,12 +459,12 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* int main()
* {
* vpColVector v(4);
* for (unsigned int i=0; i < v.size(); i++)
* for (unsigned int i=0; i < v.size(); ++i)
* v[i] = i;
* std::cout << "v: " << v.t() << std::endl;
*
* vpColVector w(2);
* for (unsigned int i=0; i < w.size(); i++)
* for (unsigned int i=0; i < w.size(); ++i)
* w[i] = i+10;
* std::cout << "w: " << w.t() << std::endl;
*
Expand All @@ -491,7 +491,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* int main()
* {
* vpColVector v(3);
* for (unsigned int i=0; i<v.size(); i++)
* for (unsigned int i=0; i<v.size(); ++i)
* v[i] = i;
* std::cout << "v = "; v.maplePrint(std::cout);
* }
Expand Down Expand Up @@ -520,7 +520,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* int main()
* {
* vpColVector v(3);
* for (unsigned int i=0; i<v.size(); i++)
* for (unsigned int i=0; i<v.size(); ++i)
* v[i] = i;
* std::cout << "v = "; v.matlabPrint(std::cout);
* }
Expand Down Expand Up @@ -862,7 +862,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* int main()
* {
* vpColVector A, B(5);
* for (unsigned int i=0; i<B.size(); i++)
* for (unsigned int i=0; i<B.size(); ++i)
* B[i] = i;
* A << B;
* std::cout << "A: " << A.t() << std::endl;
Expand All @@ -887,7 +887,7 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* size_t n = 5;
* vpColVector A(n);
* double *B = new double [n];
* for (unsigned int i = 0; i < n; i++)
* for (unsigned int i = 0; i < n; ++i)
* B[i] = i;
* A << B;
* std::cout << "A: " << A.t() << std::endl;
Expand Down Expand Up @@ -993,8 +993,8 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* {
* int var=0;
* vpMatrix mat(3, 4);
* for (int i = 0; i < 3; i++)
* for (int j = 0; j < 4; j++)
* for (int i = 0; i < 3; ++i)
* for (int j = 0; j < 4; ++j)
* mat[i][j] = ++var;
* std::cout << "mat: \n" << mat << std::endl;
*
Expand Down Expand Up @@ -1369,12 +1369,12 @@ class VISP_EXPORT vpColVector : public vpArray2D<double>
* int main()
* {
* vpColVector v(4);
* for (unsigned int i=0; i < v.size(); i++)
* for (unsigned int i=0; i < v.size(); ++i)
* v[i] = i;
* std::cout << "v: " << v.t() << std::endl;
*
* vpColVector w(2);
* for (unsigned int i=0; i < w.size(); i++)
* for (unsigned int i=0; i < w.size(); ++i)
* w[i] = i+10;
* std::cout << "w: " << w.t() << std::endl;
*
Expand Down
Loading
Loading