mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -66,41 +66,26 @@ Foam::labelList Foam::csvTableReader<Type>::getComponentColumns
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * 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>
|
template<class Type>
|
||||||
Type Foam::csvTableReader<Type>::readValue
|
Type Foam::csvTableReader<Type>::readValue
|
||||||
(
|
(
|
||||||
const List<string>& strings
|
const UList<string>& strings
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
Type result;
|
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;
|
return result;
|
||||||
@ -144,7 +129,7 @@ void Foam::csvTableReader<Type>::operator()
|
|||||||
// Skip header
|
// Skip header
|
||||||
if (headerLine_)
|
if (headerLine_)
|
||||||
{
|
{
|
||||||
is.getLine(line);
|
is.getLine(nullptr);
|
||||||
++lineNo;
|
++lineNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,12 +156,12 @@ void Foam::csvTableReader<Type>::operator()
|
|||||||
|
|
||||||
if (nPos == std::string::npos)
|
if (nPos == std::string::npos)
|
||||||
{
|
{
|
||||||
strings.append(line.substr(pos));
|
strings.push_back(line.substr(pos));
|
||||||
pos = nPos;
|
pos = nPos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strings.append(line.substr(pos, nPos-pos));
|
strings.push_back(line.substr(pos, nPos-pos));
|
||||||
pos = nPos + 1;
|
pos = nPos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,7 +183,7 @@ void Foam::csvTableReader<Type>::operator()
|
|||||||
scalar x = readScalar(strings[refColumn_]);
|
scalar x = readScalar(strings[refColumn_]);
|
||||||
Type value = readValue(strings);
|
Type value = readValue(strings);
|
||||||
|
|
||||||
values.append(Tuple2<scalar,Type>(x, value));
|
values.emplace_back(x, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.transfer(values);
|
data.transfer(values);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2020 OpenCFD Ltd.
|
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -35,8 +35,8 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef csvTableReader_H
|
#ifndef Foam_csvTableReader_H
|
||||||
#define csvTableReader_H
|
#define Foam_csvTableReader_H
|
||||||
|
|
||||||
#include "tableReader.H"
|
#include "tableReader.H"
|
||||||
#include "labelList.H"
|
#include "labelList.H"
|
||||||
@ -81,7 +81,7 @@ class csvTableReader
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Read component values from the split string
|
//- Read component values from the split string
|
||||||
Type readValue(const List<string>& strings) const;
|
Type readValue(const UList<string>& strings) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
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
|
} // End namespace Foam
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -64,37 +64,26 @@ Foam::labelList Foam::Function1Types::CSV<Type>::getComponentColumns
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * 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>
|
template<class Type>
|
||||||
Type Foam::Function1Types::CSV<Type>::readValue
|
Type Foam::Function1Types::CSV<Type>::readValue
|
||||||
(
|
(
|
||||||
const List<string>& strings
|
const UList<string>& strings
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
Type result;
|
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;
|
return result;
|
||||||
@ -124,7 +113,7 @@ void Foam::Function1Types::CSV<Type>::read()
|
|||||||
// Skip header
|
// Skip header
|
||||||
for (label i = 0; i < nHeaderLine_; ++i)
|
for (label i = 0; i < nHeaderLine_; ++i)
|
||||||
{
|
{
|
||||||
is.getLine(line);
|
is.getLine(nullptr);
|
||||||
++lineNo;
|
++lineNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,12 +158,12 @@ void Foam::Function1Types::CSV<Type>::read()
|
|||||||
|
|
||||||
if (nPos == std::string::npos)
|
if (nPos == std::string::npos)
|
||||||
{
|
{
|
||||||
strings.append(line.substr(pos));
|
strings.push_back(line.substr(pos));
|
||||||
pos = nPos;
|
pos = nPos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strings.append(line.substr(pos, nPos - pos));
|
strings.push_back(line.substr(pos, nPos - pos));
|
||||||
pos = nPos + 1;
|
pos = nPos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +185,7 @@ void Foam::Function1Types::CSV<Type>::read()
|
|||||||
scalar x = readScalar(strings[refColumn_]);
|
scalar x = readScalar(strings[refColumn_]);
|
||||||
Type value = readValue(strings);
|
Type value = readValue(strings);
|
||||||
|
|
||||||
values.append(Tuple2<scalar,Type>(x, value));
|
values.emplace_back(x, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->table_.transfer(values);
|
this->table_.transfer(values);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -53,8 +53,8 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Function1Types_CSV_H
|
#ifndef Foam_Function1Types_CSV_H
|
||||||
#define Function1Types_CSV_H
|
#define Foam_Function1Types_CSV_H
|
||||||
|
|
||||||
#include "Function1.H"
|
#include "Function1.H"
|
||||||
#include "TableBase.H"
|
#include "TableBase.H"
|
||||||
@ -111,14 +111,17 @@ class CSV
|
|||||||
void read();
|
void read();
|
||||||
|
|
||||||
//- Read component values from the split string
|
//- 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
|
//- No copy assignment
|
||||||
void operator=(const CSV<Type>&) = delete;
|
void operator=(const CSV<Type>&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//- Declare type-name, virtual type (with debug switch)
|
//- Declare type-name, virtual type (with debug switch)
|
||||||
TypeName("csvFile");
|
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
|
} // End namespace Function1Types
|
||||||
|
|||||||
Reference in New Issue
Block a user