Mercurial > octave
changeset 30489:bd67d0045e21 stable
use separate files for MArray, intNDArray, and range template forward decls
* MArray-fwd.h, intNDArray-fwd.h, range-fwd.h: New files.
* liboctave/array/module.mk: Update.
* pr-output.h, ov-range.h, MArray-C.cc, MArray-d.cc, MArray-f.cc,
MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc, MArray.h,
Range.h, dNDArray.h, fNDArray.h, idx-vector.h, intNDArray.h,
sparse-qr.h, oct-inttypes.h: Use new header files to replace inline
forward declarations of some template types.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Dec 2021 14:12:11 -0500 |
parents | abb4823df535 |
children | 34b4d993abb5 |
files | libinterp/corefcn/pr-output.h libinterp/octave-value/ov-range.h liboctave/array/MArray-C.cc liboctave/array/MArray-d.cc liboctave/array/MArray-f.cc liboctave/array/MArray-fC.cc liboctave/array/MArray-fwd.h liboctave/array/MArray-i.cc liboctave/array/MArray-s.cc liboctave/array/MArray.cc liboctave/array/MArray.h liboctave/array/Range.h liboctave/array/dNDArray.h liboctave/array/fNDArray.h liboctave/array/idx-vector.h liboctave/array/intNDArray-fwd.h liboctave/array/intNDArray.h liboctave/array/module.mk liboctave/array/range-fwd.h liboctave/numeric/sparse-qr.h liboctave/util/oct-inttypes.h |
diffstat | 21 files changed, 182 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.h Sat Dec 04 09:13:12 2021 -0500 +++ b/libinterp/corefcn/pr-output.h Mon Dec 06 14:12:11 2021 -0500 @@ -31,8 +31,10 @@ #include <iosfwd> #include "Array-fwd.h" +#include "intNDArray-fwd.h" #include "oct-cmplx.h" #include "oct-inttypes-fwd.h" +#include "range-fwd.h" #include "pr-flt-fmt.h" @@ -56,13 +58,6 @@ class Cell; class octave_value; -namespace octave -{ - template <typename T> class range; -} - -template <typename T> class intNDArray; - template <typename T> float_display_format make_format (const std::complex<T>&)
--- a/libinterp/octave-value/ov-range.h Sat Dec 04 09:13:12 2021 -0500 +++ b/libinterp/octave-value/ov-range.h Mon Dec 06 14:12:11 2021 -0500 @@ -33,6 +33,7 @@ #include <iosfwd> #include <string> +#include "Array-fwd.h" #include "Range.h" #include "lo-mappers.h"
--- a/liboctave/array/MArray-C.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-C.cc Mon Dec 06 14:12:11 2021 -0500 @@ -34,7 +34,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (Complex); +INSTANTIATE_MARRAY (Complex, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (Complex, OCTAVE_API)
--- a/liboctave/array/MArray-d.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-d.cc Mon Dec 06 14:12:11 2021 -0500 @@ -32,7 +32,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (double); +INSTANTIATE_MARRAY (double, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (double, OCTAVE_API)
--- a/liboctave/array/MArray-f.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-f.cc Mon Dec 06 14:12:11 2021 -0500 @@ -32,7 +32,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (float); +INSTANTIATE_MARRAY (float, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (float, OCTAVE_API)
--- a/liboctave/array/MArray-fC.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-fC.cc Mon Dec 06 14:12:11 2021 -0500 @@ -34,7 +34,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (FloatComplex); +INSTANTIATE_MARRAY (FloatComplex, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (FloatComplex, OCTAVE_API)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/array/MArray-fwd.h Mon Dec 06 14:12:11 2021 -0500 @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_MArray_fwd_h) +#define octave_MArray_fwd_h 1 + +#include "octave-config.h" + +template <typename T> class OCTARRAY_API MArray; + +#endif
--- a/liboctave/array/MArray-i.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-i.cc Mon Dec 06 14:12:11 2021 -0500 @@ -34,9 +34,9 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (int); +INSTANTIATE_MARRAY (int, OCTAVE_API); #if defined (OCTAVE_ENABLE_64) -INSTANTIATE_MARRAY (int64_t); +INSTANTIATE_MARRAY (int64_t, OCTAVE_API); #endif INSTANTIATE_MARRAY_FRIENDS (int, OCTAVE_API) @@ -44,20 +44,20 @@ INSTANTIATE_MARRAY_FRIENDS (int64_t, OCTAVE_API) #endif -INSTANTIATE_MARRAY (octave_int8); -INSTANTIATE_MARRAY (octave_int16); -INSTANTIATE_MARRAY (octave_int32); -INSTANTIATE_MARRAY (octave_int64); +INSTANTIATE_MARRAY (octave_int8, OCTAVE_API); +INSTANTIATE_MARRAY (octave_int16, OCTAVE_API); +INSTANTIATE_MARRAY (octave_int32, OCTAVE_API); +INSTANTIATE_MARRAY (octave_int64, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (octave_int8, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_int16, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_int32, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_int64, OCTAVE_API) -INSTANTIATE_MARRAY (octave_uint8); -INSTANTIATE_MARRAY (octave_uint16); -INSTANTIATE_MARRAY (octave_uint32); -INSTANTIATE_MARRAY (octave_uint64); +INSTANTIATE_MARRAY (octave_uint8, OCTAVE_API); +INSTANTIATE_MARRAY (octave_uint16, OCTAVE_API); +INSTANTIATE_MARRAY (octave_uint32, OCTAVE_API); +INSTANTIATE_MARRAY (octave_uint64, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (octave_uint8, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_uint16, OCTAVE_API)
--- a/liboctave/array/MArray-s.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-s.cc Mon Dec 06 14:12:11 2021 -0500 @@ -32,7 +32,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (short); +INSTANTIATE_MARRAY (short, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (short, OCTAVE_API)
--- a/liboctave/array/MArray.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray.cc Mon Dec 06 14:12:11 2021 -0500 @@ -372,8 +372,24 @@ return do_mx_unary_op<T, T> (a, mx_inline_uminus); } +template <typename T> +void MArray<T>::instantiation_guard () +{ + // This guards against accidental implicit instantiations. + // Array<T, Alloc> instances should always be explicit and use INSTANTIATE_ARRAY. + T::__xXxXx__ (); +} + #if defined (__clang__) -# define INSTANTIATE_MARRAY(T) template class OCTAVE_API MArray<T> +# define INSTANTIATE_MARRAY(T, API) \ + template <> API void \ + MArray<T>::instantiation_guard () { } \ + \ + template class API MArray<T> #else -# define INSTANTIATE_MARRAY(T) template class MArray<T> +# define INSTANTIATE_MARRAY(T, API) \ + template <> API void \ + MArray<T>::instantiation_guard () { } \ + \ + template class MArray<T> #endif
--- a/liboctave/array/MArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -29,38 +29,36 @@ #include "octave-config.h" #include "Array.h" +#include "MArray-fwd.h" #include "mx-inlines.cc" -// forward declare template with visibility attribute -template <typename T> class OCTAVE_API MArray; - -template <typename T> OCTAVE_API MArray<T>& operator += (MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T>& operator -= (MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T>& operator *= (MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T>& operator /= (MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T>& operator += (MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T>& operator -= (MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T>& product_eq (MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T>& quotient_eq (MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator + (const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator - (const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator + (const MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T> operator - (const MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T> operator * (const MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T> operator / (const MArray<T>&, const T&); -template <typename T> OCTAVE_API MArray<T> operator + (const T&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator - (const T&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator * (const T&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator / (const T&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator + (const MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> operator - (const MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> quotient (const MArray<T>&, const MArray<T>&); -template <typename T> OCTAVE_API MArray<T> product (const MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T>& operator += (MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T>& operator -= (MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T>& operator *= (MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T>& operator /= (MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T>& operator += (MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T>& operator -= (MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T>& product_eq (MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T>& quotient_eq (MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator + (const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator - (const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator + (const MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T> operator - (const MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T> operator * (const MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T> operator / (const MArray<T>&, const T&); +template <typename T> OCTARRAY_API MArray<T> operator + (const T&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator - (const T&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator * (const T&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator / (const T&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator + (const MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> operator - (const MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> quotient (const MArray<T>&, const MArray<T>&); +template <typename T> OCTARRAY_API MArray<T> product (const MArray<T>&, const MArray<T>&); //! Template for N-dimensional array classes with like-type math operators. template <typename T> class -OCTAVE_API +OCTARRAY_API MArray : public Array<T> { public: @@ -106,22 +104,25 @@ //! Performs indexed accumulative addition. //@{ - OCTAVE_API void idx_add (const octave::idx_vector& idx, T val); - OCTAVE_API void + OCTARRAY_API void idx_add (const octave::idx_vector& idx, T val); + OCTARRAY_API void idx_add (const octave::idx_vector& idx, const MArray<T>& vals); //@} - OCTAVE_API void + OCTARRAY_API void idx_min (const octave::idx_vector& idx, const MArray<T>& vals); - OCTAVE_API void + OCTARRAY_API void idx_max (const octave::idx_vector& idx, const MArray<T>& vals); - OCTAVE_API void + OCTARRAY_API void idx_add_nd (const octave::idx_vector& idx, const MArray<T>& vals, int dim = -1); - OCTAVE_API void changesign (void); + OCTARRAY_API void changesign (void); + +private: + OCTARRAY_API static void instantiation_guard (); }; // Define all the MArray forwarding functions for return type R and
--- a/liboctave/array/Range.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/Range.h Mon Dec 06 14:12:11 2021 -0500 @@ -35,13 +35,12 @@ #include "dim-vector.h" #include "lo-error.h" #include "oct-sort.h" +#include "range-fwd.h" namespace octave { template <typename T> - class - OCTAVE_API - range + class range { public:
--- a/liboctave/array/dNDArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/dNDArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -28,13 +28,12 @@ #include "octave-config.h" +#include "intNDArray-fwd.h" #include "MArray.h" #include "bsxfun-decl.h" #include "mx-defs.h" #include "mx-op-decl.h" -template <typename T> class intNDArray; - class OCTAVE_API NDArray : public MArray<double>
--- a/liboctave/array/fNDArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/fNDArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -28,13 +28,12 @@ #include "octave-config.h" +#include "intNDArray-fwd.h" #include "MArray.h" #include "bsxfun-decl.h" #include "mx-defs.h" #include "mx-op-decl.h" -template <typename T> class intNDArray; - class OCTAVE_API FloatNDArray : public MArray<float>
--- a/liboctave/array/idx-vector.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/idx-vector.h Mon Dec 06 14:12:11 2021 -0500 @@ -40,11 +40,10 @@ #include "oct-inttypes.h" #include "oct-refcount.h" #include "Sparse-fwd.h" +#include "range-fwd.h" namespace octave { - template <typename T> class range; - // Design rationale: // // idx_vector is a reference-counting, polymorphic pointer, that can
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/array/intNDArray-fwd.h Mon Dec 06 14:12:11 2021 -0500 @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_intNDArray_fwd_h) +#define octave_intNDArray_fwd_h 1 + +#include "octave-config.h" + +template <typename T> class OCTAVE_API intNDArray; + +#endif
--- a/liboctave/array/intNDArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/intNDArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -28,6 +28,7 @@ #include "octave-config.h" +#include "intNDArray-fwd.h" #include "MArray.h" #include "boolNDArray.h" @@ -35,7 +36,6 @@ template <typename T> class -OCTAVE_API intNDArray : public MArray<T> { public:
--- a/liboctave/array/module.mk Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/module.mk Mon Dec 06 14:12:11 2021 -0500 @@ -36,7 +36,9 @@ %reldir%/int32NDArray.h \ %reldir%/int64NDArray.h \ %reldir%/int8NDArray.h \ + %reldir%/intNDArray-fwd.h \ %reldir%/intNDArray.h \ + %reldir%/MArray-fwd.h \ %reldir%/MArray.h \ %reldir%/Matrix.h \ %reldir%/MatrixType.h \ @@ -44,6 +46,7 @@ %reldir%/MSparse.h \ %reldir%/PermMatrix.h \ %reldir%/Range.h \ + %reldir%/range-fwd.h \ %reldir%/Sparse-fwd.h \ %reldir%/Sparse.h \ %reldir%/uint16NDArray.h \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/array/range-fwd.h Mon Dec 06 14:12:11 2021 -0500 @@ -0,0 +1,36 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_range_fwd_h) +#define octave_range_fwd_h 1 + +#include "octave-config.h" + +namespace octave +{ + template <typename T> class OCTAVE_API range; +} + +#endif
--- a/liboctave/numeric/sparse-qr.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/numeric/sparse-qr.h Mon Dec 06 14:12:11 2021 -0500 @@ -31,13 +31,13 @@ #include <memory> #include "oct-cmplx.h" +#include "MArray-fwd.h" class Matrix; class ComplexMatrix; class SparseMatrix; class SparseComplexMatrix; class ColumnVector; -template <typename T> class MArray; namespace octave {