COMP: remove explicit specialisations for CSV reading (fixes #2764)
- can use traits to distinguish label vs scalar types and setComponents to properly index into single or multi-component types without needing template specialisations for the task. This avoids the need for a concrete translation unit and the reported problem of multiply-defined specialisations when the header is included in different places.
This commit is contained in:
parent
e967305ef2
commit
287025d2df
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -66,41 +66,26 @@ Foam::labelList Foam::csvTableReader<Type>::getComponentColumns
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
label csvTableReader<label>::readValue
|
||||
(
|
||||
const List<string>& strings
|
||||
) const
|
||||
{
|
||||
return readLabel(strings[componentColumns_[0]]);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
scalar csvTableReader<scalar>::readValue
|
||||
(
|
||||
const List<string>& strings
|
||||
) const
|
||||
{
|
||||
return readScalar(strings[componentColumns_[0]]);
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::csvTableReader<Type>::readValue
|
||||
(
|
||||
const List<string>& strings
|
||||
const UList<string>& strings
|
||||
) const
|
||||
{
|
||||
Type result;
|
||||
|
||||
for (label i = 0; i < pTraits<Type>::nComponents; ++i)
|
||||
if (std::is_integral<Type>::value)
|
||||
{
|
||||
result[i] = readScalar(strings[componentColumns_[i]]);
|
||||
// nComponents == 1
|
||||
setComponent(result, 0) = readLabel(strings[componentColumns_[0]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||
{
|
||||
setComponent(result, cmpt) =
|
||||
readScalar(strings[componentColumns_[cmpt]]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -144,7 +129,7 @@ void Foam::csvTableReader<Type>::operator()
|
||||
// Skip header
|
||||
if (headerLine_)
|
||||
{
|
||||
is.getLine(line);
|
||||
is.getLine(nullptr);
|
||||
++lineNo;
|
||||
}
|
||||
|
||||
@ -171,12 +156,12 @@ void Foam::csvTableReader<Type>::operator()
|
||||
|
||||
if (nPos == std::string::npos)
|
||||
{
|
||||
strings.append(line.substr(pos));
|
||||
strings.push_back(line.substr(pos));
|
||||
pos = nPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
strings.append(line.substr(pos, nPos-pos));
|
||||
strings.push_back(line.substr(pos, nPos-pos));
|
||||
pos = nPos + 1;
|
||||
}
|
||||
}
|
||||
@ -198,7 +183,7 @@ void Foam::csvTableReader<Type>::operator()
|
||||
scalar x = readScalar(strings[refColumn_]);
|
||||
Type value = readValue(strings);
|
||||
|
||||
values.append(Tuple2<scalar,Type>(x, value));
|
||||
values.emplace_back(x, value);
|
||||
}
|
||||
|
||||
data.transfer(values);
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -35,8 +35,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef csvTableReader_H
|
||||
#define csvTableReader_H
|
||||
#ifndef Foam_csvTableReader_H
|
||||
#define Foam_csvTableReader_H
|
||||
|
||||
#include "tableReader.H"
|
||||
#include "labelList.H"
|
||||
@ -81,7 +81,7 @@ class csvTableReader
|
||||
);
|
||||
|
||||
//- Read component values from the split string
|
||||
Type readValue(const List<string>& strings) const;
|
||||
Type readValue(const UList<string>& strings) const;
|
||||
|
||||
|
||||
public:
|
||||
@ -133,14 +133,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Template specialisations
|
||||
template<>
|
||||
label csvTableReader<label>::readValue(const List<string>& strings) const;
|
||||
|
||||
template<>
|
||||
scalar csvTableReader<scalar>::readValue(const List<string>& strings) const;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -64,37 +64,26 @@ Foam::labelList Foam::Function1Types::CSV<Type>::getComponentColumns
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<>
|
||||
Foam::label Foam::Function1Types::CSV<Foam::label>::readValue
|
||||
(
|
||||
const List<string>& strings
|
||||
) const
|
||||
{
|
||||
return readLabel(strings[componentColumns_[0]]);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
Foam::scalar Foam::Function1Types::CSV<Foam::scalar>::readValue
|
||||
(
|
||||
const List<string>& strings
|
||||
) const
|
||||
{
|
||||
return readScalar(strings[componentColumns_[0]]);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::Function1Types::CSV<Type>::readValue
|
||||
(
|
||||
const List<string>& strings
|
||||
const UList<string>& strings
|
||||
) const
|
||||
{
|
||||
Type result;
|
||||
|
||||
for (label i = 0; i < pTraits<Type>::nComponents; ++i)
|
||||
if (std::is_integral<Type>::value)
|
||||
{
|
||||
result[i] = readScalar(strings[componentColumns_[i]]);
|
||||
// nComponents == 1
|
||||
setComponent(result, 0) = readLabel(strings[componentColumns_[0]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||
{
|
||||
setComponent(result, cmpt) =
|
||||
readScalar(strings[componentColumns_[cmpt]]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -124,7 +113,7 @@ void Foam::Function1Types::CSV<Type>::read()
|
||||
// Skip header
|
||||
for (label i = 0; i < nHeaderLine_; ++i)
|
||||
{
|
||||
is.getLine(line);
|
||||
is.getLine(nullptr);
|
||||
++lineNo;
|
||||
}
|
||||
|
||||
@ -169,12 +158,12 @@ void Foam::Function1Types::CSV<Type>::read()
|
||||
|
||||
if (nPos == std::string::npos)
|
||||
{
|
||||
strings.append(line.substr(pos));
|
||||
strings.push_back(line.substr(pos));
|
||||
pos = nPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
strings.append(line.substr(pos, nPos - pos));
|
||||
strings.push_back(line.substr(pos, nPos - pos));
|
||||
pos = nPos + 1;
|
||||
}
|
||||
}
|
||||
@ -196,7 +185,7 @@ void Foam::Function1Types::CSV<Type>::read()
|
||||
scalar x = readScalar(strings[refColumn_]);
|
||||
Type value = readValue(strings);
|
||||
|
||||
values.append(Tuple2<scalar,Type>(x, value));
|
||||
values.emplace_back(x, value);
|
||||
}
|
||||
|
||||
this->table_.transfer(values);
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -53,8 +53,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Function1Types_CSV_H
|
||||
#define Function1Types_CSV_H
|
||||
#ifndef Foam_Function1Types_CSV_H
|
||||
#define Foam_Function1Types_CSV_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "TableBase.H"
|
||||
@ -111,14 +111,17 @@ class CSV
|
||||
void read();
|
||||
|
||||
//- Read component values from the split string
|
||||
Type readValue(const List<string>& strings) const;
|
||||
Type readValue(const UList<string>& strings) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const CSV<Type>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Declare type-name, virtual type (with debug switch)
|
||||
TypeName("csvFile");
|
||||
|
||||
@ -161,14 +164,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Template specialisations
|
||||
template<>
|
||||
label CSV<label>::readValue(const List<string>& strings) const;
|
||||
|
||||
template<>
|
||||
scalar CSV<scalar>::readValue(const List<string>& strings) const;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Function1Types
|
||||
|
Loading…
Reference in New Issue
Block a user