Commit f1ab5f2a authored by GILLES Sebastien's avatar GILLES Sebastien

#1465 Pave the way to the extension that will enable writing the content of a...

#1465 Pave the way to the extension that will enable writing the content of a built object rather than the default values.
parent fd16f808
......@@ -176,7 +176,6 @@ namespace MoReFEM
}
template<class TupleT>
void CreateDefaultInputFile(const std::string& path)
{
......@@ -190,6 +189,20 @@ namespace MoReFEM
}
template<class InputData>
void Write(const InputData& input_data,
const std::string& path)
{
std::ofstream out;
FilesystemNS::File::Create(out, path, __FILE__, __LINE__);
out << "-- Comment lines are introduced by \"--\".\n";
out << "-- In a section (i.e. within braces), all entries must be separated by a comma.\n\n";
Internal::InputDataNS::PrintContent(input_data, out);
}
template<class DerivedT, class TupleT>
void Base<DerivedT, TupleT>::CheckNoDuplicateKeysInTuple() const
{
......
......@@ -43,6 +43,9 @@ namespace MoReFEM
{
enum class print_default_value { yes, no };
//! Convenient alias to avoid repeating endlessly namespaces.
using Nature = Utilities::InputDataNS::Nature;
......@@ -132,8 +135,10 @@ namespace MoReFEM
*
* \param[in,out] parameter_block_per_identifier List of key/default value for input data items.
*/
template<print_default_value DoPrintDefaultValueT, class InputDataT>
static void PrepareEntry(std::vector<std::pair<std::string, std::string>>&
parameter_block_per_identifier);
parameter_block_per_identifier,
const InputDataT* input_data);
/*!
* \brief Print the list of keys found in the tuple.
......@@ -230,8 +235,10 @@ namespace MoReFEM
static void Fill(const InputDataT* input_data, LuaOptionFile& , TupleT& );
template<print_default_value DoPrintDefaultValueT, class InputDataT>
static void PrepareEntry(std::vector<std::pair<std::string, std::string>>&
parameter_block_per_identifier);
parameter_block_per_identifier,
const InputDataT* input_data);
static void PrintKeys(std::ostream& stream);
......@@ -339,7 +346,9 @@ namespace MoReFEM
static bool DoMatchIdentifier(std::string_view, std::string_view);
static void PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier);
template<print_default_value DoPrintDefaultValueT, class InputDataT>
static void PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier,
const InputDataT* input_data);
using tuple_iteration = TupleIteration<section_tuple, 0, std::tuple_size<section_tuple>::value>;
......@@ -384,7 +393,9 @@ namespace MoReFEM
static bool DoMatchIdentifier(std::string_view, std::string_view);
static void PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier);
template<print_default_value DoPrintDefaultValueT, class InputDataT>
static void PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier,
const InputDataT* input_data);
/*!
* \copydoc doxygen_hide_cplusplus_variadic_args
......
......@@ -276,15 +276,38 @@ namespace MoReFEM
// Extract all input parameters from \a TupleT (including those enclosed in sections) and
// generate their content which is stored in a map.
TupleIteration<TupleT, 0, size>::PrepareEntry(parameter_block_per_identifier);
TupleIteration<TupleT, 0, size>
::template PrepareEntry<print_default_value::yes, std::nullptr_t>(parameter_block_per_identifier,
nullptr);
Impl::PrintInFile(parameter_block_per_identifier, out);
}
template<class InputDataT>
void PrintContent(const InputDataT& input_data,
std::ostream& stream)
{
using tuple = typename InputDataT::Tuple;
constexpr auto size = std::tuple_size<tuple>::value;
std::vector<std::pair<std::string, std::string>> parameter_block_per_identifier;
// Extract all input parameters from \a TupleT (including those enclosed in sections) and
// generate their content which is stored in a map.
TupleIteration<tuple, 0, size>::template
PrepareEntry<print_default_value::no>(parameter_block_per_identifier,
&input_data);
Impl::PrintInFile(parameter_block_per_identifier, stream);
}
template<class TupleEltTypeT>
template<print_default_value DoPrintDefaultValueT, class InputDataT>
void SectionOrParameter<TupleEltTypeT, Nature::parameter>
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier)
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier,
const InputDataT* input_data)
{
std::ostringstream oconv;
......@@ -314,20 +337,33 @@ namespace MoReFEM
oconv << indent << TupleEltTypeT::NameInFile() << " = ";
if (TupleEltTypeT::DefaultValue().empty())
oconv << "No default value was provided!";
if constexpr (DoPrintDefaultValueT == print_default_value::yes)
{
assert(input_data == nullptr);
static_cast<void>(input_data);
if (TupleEltTypeT::DefaultValue().empty())
oconv << "No default value was provided!";
else
oconv << TupleEltTypeT::DefaultValue();
}
else
oconv << TupleEltTypeT::DefaultValue();
{
assert(input_data != nullptr);
oconv << "TMP BLAH BLAH BLAH";
}
parameter_block_per_identifier.emplace_back(std::make_pair(TupleEltTypeT::GetIdentifier(), oconv.str()));
}
template<class TupleEltTypeT>
template<print_default_value DoPrintDefaultValueT, class InputDataT>
void SectionOrParameter<TupleEltTypeT, Nature::section>
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier)
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier,
const InputDataT* input_data)
{
tuple_iteration::PrepareEntry(parameter_block_per_identifier);
tuple_iteration::template PrepareEntry<DoPrintDefaultValueT>(parameter_block_per_identifier,
input_data);
}
......@@ -337,24 +373,30 @@ namespace MoReFEM
unsigned int Index,
unsigned int Length
>
template<print_default_value DoPrintDefaultValueT, class InputDataT>
void TupleIteration<TupleT, Index, Length>
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier)
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier,
const InputDataT* input_data)
{
section_or_parameter::PrepareEntry(parameter_block_per_identifier);
section_or_parameter::template PrepareEntry<DoPrintDefaultValueT>(parameter_block_per_identifier,
input_data);
// Recursion.
next_item::PrepareEntry(parameter_block_per_identifier);
next_item::template PrepareEntry<DoPrintDefaultValueT>(parameter_block_per_identifier,
input_data);
}
template<class TupleT, unsigned int Length>
template<print_default_value DoPrintDefaultValueT, class InputDataT>
void TupleIteration<TupleT, Length, Length>
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier)
::PrepareEntry(std::vector<std::pair<std::string, std::string>>& parameter_block_per_identifier,
const InputDataT* input_data)
{
// Do nothing.
static_cast<void>(parameter_block_per_identifier);
static_cast<void>(input_data);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment