diff --git a/modules/c++/mem/CMakeLists.txt b/modules/c++/mem/CMakeLists.txt index 590f1a012..297850c3b 100644 --- a/modules/c++/mem/CMakeLists.txt +++ b/modules/c++/mem/CMakeLists.txt @@ -3,7 +3,7 @@ set(MODULE_NAME mem) coda_add_module( ${MODULE_NAME} VERSION 1.0 - DEPS sys-c++ gsl-c++ std-c++) + DEPS sys-c++ gsl-c++ coda_oss-c++ std-c++) coda_add_tests( MODULE_NAME ${MODULE_NAME} diff --git a/modules/c++/mem/include/mem/ComplexView.h b/modules/c++/mem/include/mem/ComplexView.h new file mode 100644 index 000000000..0f76d244d --- /dev/null +++ b/modules/c++/mem/include/mem/ComplexView.h @@ -0,0 +1,58 @@ +/* ========================================================================= + * This file is part of mem-c++ + * ========================================================================= + * + * (C) Copyright 2013 - 2014, MDA Information Systems LLC + * (C) Copyright 2023, Maxar Technologies, Inc. + * + * mem-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, + * see . + * + */ + +#ifndef CODA_OSS_mem_ComplexView_h_INCLUDED_ +#define CODA_OSS_mem_ComplexView_h_INCLUDED_ +#pragma once + +#include +#include +#include +#include + +#include "coda_oss/span.h" + +namespace mem +{ +/*! + * \class ComplexView + * \brief This class provides a read-only view onto a collection of complex numbers. + * For the simple case, it's std::span>. However, sometimes + * the data is in two parallel arrays: + * const float* reals; + * const float* imags; + * This class sets things up so that clients can always use the same + * access routines, regardless of how the underlying data is actually stored. + */ +template +struct ComplexView +{ + ComplexView() = default; + ~ComplexView() = default; + ComplexView(const ComplexView&) = default; + ComplexView& operator=(const ComplexView&) = default; + ComplexView(ComplexView&&) = default; + ComplexView& operator=(ComplexView&&) = default; +}; + +#endif // CODA_OSS_mem_ComplexView_h_INCLUDED_ diff --git a/modules/c++/mem/unittests/test_vector_pointers.cpp b/modules/c++/mem/unittests/test_vector_pointers.cpp index a4d5da5d1..f73fd9d55 100644 --- a/modules/c++/mem/unittests/test_vector_pointers.cpp +++ b/modules/c++/mem/unittests/test_vector_pointers.cpp @@ -20,6 +20,10 @@ * */ +#include +#include +#include + #include #include "TestCase.h" @@ -112,10 +116,28 @@ TEST_CASE(testVecOfSharedPointers) { std::vector> myVec2 = std_vector_shared_ptr_int(); // copy } +} +TEST_CASE(testSpanCxFloat) +{ + const std::vector> data{{1, 2}, {3, 4}, {5, 6}, {7, 8}}; + const std::span> view(data.data(), data.size()); + + TEST_ASSERT_EQ(data.size(), view.size()); + + TEST_ASSERT_EQ(view[0].real(), 1); + TEST_ASSERT_EQ(view[0].imag(), 2); + TEST_ASSERT_EQ(view[1].real(), 3); + TEST_ASSERT_EQ(view[1].imag(), 4); + TEST_ASSERT_EQ(view[2].real(), 5); + TEST_ASSERT_EQ(view[2].imag(), 6); + TEST_ASSERT_EQ(view[3].real(), 7); + TEST_ASSERT_EQ(view[3].imag(), 8); } TEST_MAIN( TEST_CHECK(testVecOfRawPointers); TEST_CHECK(testVecOfSharedPointers); + + TEST_CHECK(testSpanCxFloat); ) diff --git a/modules/c++/mem/wscript b/modules/c++/mem/wscript index 112f2edde..044f80abb 100644 --- a/modules/c++/mem/wscript +++ b/modules/c++/mem/wscript @@ -1,6 +1,6 @@ NAME = 'mem' VERSION = '1.0' -MODULE_DEPS = 'sys gsl std' +MODULE_DEPS = 'sys gsl coda_oss std' TEST_DEPS = 'cli std' UNITTEST_DEPS = 'std'