Commit fd16f808 authored by GILLES Sebastien's avatar GILLES Sebastien

#1465 Utilities: reorganize a bit the files related to InputData.

parent 69bf24e1
This diff is collapsed.
......@@ -31,6 +31,7 @@
# include "Utilities/String/String.hpp"
# include "Utilities/Environment/Environment.hpp"
# include "Utilities/LuaOptionFile/LuaOptionFile.hpp"
# include "Utilities/InputData/Extract.hpp"
# include "Utilities/InputData/Exceptions/InputData.hpp"
# include "Utilities/InputData/Internal/Subtuple/Subtuple.hpp"
# include "Utilities/InputData/Internal/TupleIteration/TupleIteration.hpp"
......@@ -51,34 +52,6 @@ namespace MoReFEM
{
/*!
* \brief An enum class that will basically act as a boolean.
*
* InputData::Base class takes into account which input parameters are actually used; the
* way to do so is to set a bit in a bitset when some methods are called. However, sometimes these
* methods might be called to some purposes that do not truly mean the input parameter is used.
*
* For instance, if we check at the beginning of the program that several input vectors are the same
* length it doesn't mean all of them are actually used, hence the following enum to be able to
* specify the method not to set the bit for this specific use.
*
*/
enum class CountAsUsed
{
no,
yes
};
//! Behaviour when the folder read in the input data file doesn't exist.
enum class UnexistentFolderPolicy
{
create,
throw_exception
};
/*!
* \brief Whether a field found in the file but not referenced in the tuple yields an exception or not.
*
......@@ -357,108 +330,6 @@ namespace MoReFEM
void CreateDefaultInputFile(const std::string& path);
/*!
* \brief A convenient helper to extract information from Base class.
*
* The problem with Base class is that the syntax is really hideous; for instance a derived class
* from base (named IPL for the example below) must use the following syntax to extract a value
* named Component:
*
* \code
* using Type = InputData::BoundaryCondition::Component;
* auto component_value = this->template ReadHelper<Type>();
* \endcode
*
* This template syntax is quite unusual and many C++ developers don't know it; so the helper class
* hids that and the same quantity may be extracted with:
* \code
* using Type = InputData::BoundaryCondition::Component;
* auto component_value = Extract<Type>::Value();
* \endcode
*
* This class can also be used to read Lua functions:
* \code
* decltype(auto) fct = Extract<InputData::Force::Surfacic>::Value(input_data);
* std::cout << "Value = " << fct(0, 1, 2, 3) << std::endl;
* \endcode
*/
template<class ObjectT>
struct Extract
{
//! Convenient alias over the return type.
using return_type = typename ObjectT::return_type;
/*!
* \brief Return the value of the input parameter.
*
* \tparam InputDataT The object which holds the information about input data file content.
* \tparam CountAsUsedT At the end of the program, we may sum up the input data that have not been
* used. A call to this method tally them as used unless 'no' is specified here.
* \copydoc doxygen_hide_input_data_arg
*
* \return Value of the input parameter.
*/
template<class InputDataT, CountAsUsed CountAsUsedT = CountAsUsed::yes>
static typename ConstRefOrValue<return_type>::type Value(const InputDataT& input_data);
/*!
* \brief Return a string that stands for a path; only additional operation is to replace environment
* variables by their value.
*
* For instance "${HOME}/Codes/MoReFEM" will be resolved on a Mac in /Users/ *username* /Codes/MoReFEM.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
*
* \return Path related to \a ObjectT.
*/
template<class InputDataT>
static std::string Path(const InputDataT& input_data);
/*!
* \brief Return a string that stands for a folder; several operations might be attempted if said folder
* doesn't exist.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
*
* \return Path to the folder hold by \a ObjectT.
*/
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT = UnexistentFolderPolicy::create>
static std::string Folder(const InputDataT& input_data);
/*!
* \brief Read the number of elements when the object is a vector.
*
* If not a vector, a compilation error will occur as size() method won't be defined.
* \param[in] input_data Object which hols all relevant input data for the model considered.
*
*
* \return Number of elements hold by \a ObjectT.
*/
template<class InputDataT>
static unsigned int Number(const InputDataT& input_data);
/*!
* \brief Return the \a index -th value of a vector.
*
* If the input parameter is not a vector, subscript operator will yield an error at compile time.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
* \param[in] index Index of the element sought in the vector read in the \a input_data.
*
* \return Value of the \a index -th element of \a ObjectT.
*/
template<class InputDataT, CountAsUsed CountAsUsedT = CountAsUsed::yes>
static decltype(auto) Subscript(const InputDataT& input_data,
unsigned int index);
};
} // namespace InputDataNS
......
......@@ -204,7 +204,7 @@ namespace MoReFEM
template<class DerivedT, class TupleT>
void Base<DerivedT, TupleT>::CheckUnboundInputData(const std::string& filename,
LuaOptionFile& lua_option_file,
LuaOptionFile& lua_option_file,
DoTrackUnusedFields do_track_unused_fields) const
{
// Check there are no parameters undefined in the tuple.
......@@ -284,51 +284,6 @@ namespace MoReFEM
}
template<class ObjectT>
template<class InputDataT, CountAsUsed CountAsUsedT>
typename ConstRefOrValue<typename Extract<ObjectT>::return_type>::type
Extract<ObjectT>::Value(const InputDataT& input_data)
{
return input_data.template ReadHelper<ObjectT, CountAsUsedT>();
}
template<class ObjectT>
template<class InputDataT>
std::string Extract<ObjectT>::Path(const InputDataT& input_data)
{
return input_data.template ReadHelperPath<ObjectT>();
}
template<class ObjectT>
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT>
std::string Extract<ObjectT>
::Folder(const InputDataT& input_data)
{
return input_data.template ReadHelperFolder<ObjectT, UnexistentFolderPolicyT>();
}
template<class ObjectT>
template<class InputDataT>
unsigned int Extract<ObjectT>::Number(const InputDataT& input_data)
{
return input_data.template ReadHelperNumber<ObjectT>();
}
template<class ObjectT>
template<class InputDataT, CountAsUsed CountAsUsedT>
decltype(auto)
Extract<ObjectT>::Subscript(const InputDataT& input_data,
unsigned int index)
{
return input_data.template ReadHelper<ObjectT, CountAsUsedT>(index);
}
} // namespace InputDataNS
......
......@@ -22,7 +22,7 @@
# include "Utilities/Containers/Vector.hpp"
# include "Utilities/String/String.hpp"
# include "Utilities/InputData/LuaFunction.hpp"
# include "Utilities/InputData/Definitions.hpp"
# include "Utilities/InputData/Enum.hpp"
# include "Utilities/InputData/Internal/TupleIteration/Traits/Traits.hpp"
# include "Utilities/InputData/Internal/TupleIteration/Impl/TupleItem.hpp"
......
......@@ -16,7 +16,7 @@
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_CRTP_x_SECTION_HPP_
# include "Utilities/InputData/Definitions.hpp"
# include "Utilities/InputData/Enum.hpp"
namespace MoReFEM
......
/*!
//
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Wed, 26 Aug 2015 11:52:00 +0200
// Copyright (c) Inria. All rights reserved.
//
// \ingroup UtilitiesGroup
// \addtogroup UtilitiesGroup
// \{
*/
#include "Utilities/InputData/Definitions.hpp"
#include "Utilities/String/EmptyString.hpp"
namespace MoReFEM
{
namespace Utilities
{
namespace InputDataNS
{
const std::string& NoEnclosingSection::GetName()
{
return EmptyString();
}
const std::string& NoEnclosingSection::GetFullName()
{
return EmptyString();
}
} // namespace InputDataNS
} // namespace Utilities
} // namespace MoReFEM
/// @} // addtogroup UtilitiesGroup
/*!
//
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Tue, 18 Aug 2015 10:41:03 +0200
// Copyright (c) Inria. All rights reserved.
//
// \ingroup UtilitiesGroup
// \addtogroup UtilitiesGroup
// \{
*/
#ifndef MOREFEM_x_UTILITIES_x_INPUT_DATA_x_DEFINITIONS_HPP_
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_DEFINITIONS_HPP_
# include <string>
namespace MoReFEM
{
namespace Utilities
{
namespace InputDataNS
{
/*!
* \brief Placeholder class to use as one of the template parameter for sections and end parameters at root level.
*
* Should be used as Crtp::Section or Crtp::InputData template argument.
*/
struct NoEnclosingSection
{
//! Returns empty string.
static const std::string& GetName();
//! Returns empty string.
static const std::string& GetFullName();
};
//! Enum to tell whether current item of input parameter list is a section or an input parameter.
enum class Nature
{
section = 0,
parameter
};
} // namespace InputDataNS
} // namespace Utilities
} // namespace MoReFEM
/// @} // addtogroup UtilitiesGroup
#endif // MOREFEM_x_UTILITIES_x_INPUT_DATA_x_DEFINITIONS_HPP_
//! \file
//
//
// Enum.cpp
// MoReFEM
//
// Created by sebastien on 23/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#include "Utilities/InputData/Enum.hpp"
#include "Utilities/String/EmptyString.hpp"
namespace MoReFEM::Utilities::InputDataNS
{
const std::string& NoEnclosingSection::GetName()
{
return EmptyString();
}
const std::string& NoEnclosingSection::GetFullName()
{
return EmptyString();
}
} // namespace MoReFEM::Utilities::InputDataNS
//! \file
//
//
// Enum.hpp
// MoReFEM
//
// Created by sebastien on 23/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_INPUT_DATA_x_ENUM_HPP_
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_ENUM_HPP_
# include <memory>
# include <vector>
namespace MoReFEM::Utilities::InputDataNS
{
/*!
* \brief Placeholder class to use as one of the template parameter for sections and end parameters at root level.
*
* Should be used as Crtp::Section or Crtp::InputData template argument.
*/
struct NoEnclosingSection
{
//! Returns empty string.
static const std::string& GetName();
//! Returns empty string.
static const std::string& GetFullName();
};
//! Enum to tell whether current item of input parameter list is a section or an input parameter.
enum class Nature
{
section = 0,
parameter
};
/*!
* \brief An enum class that will basically act as a boolean.
*
* InputData::Base class takes into account which input parameters are actually used; the
* way to do so is to set a bit in a bitset when some methods are called. However, sometimes these
* methods might be called to some purposes that do not truly mean the input parameter is used.
*
* For instance, if we check at the beginning of the program that several input vectors are the same
* length it doesn't mean all of them are actually used, hence the following enum to be able to
* specify the method not to set the bit for this specific use.
*
*/
enum class CountAsUsed
{
no,
yes
};
//! Behaviour when the folder read in the input data file doesn't exist.
enum class UnexistentFolderPolicy
{
create,
throw_exception
};
} // namespace MoReFEM::Utilities::InputDataNS
#endif // MOREFEM_x_UTILITIES_x_INPUT_DATA_x_ENUM_HPP_
//! \file
//
//
// Extract.hpp
// MoReFEM
//
// Created by sebastien on 23/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_INPUT_DATA_x_EXTRACT_HPP_
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_EXTRACT_HPP_
# include "Utilities/Miscellaneous.hpp"
# include "Utilities/InputData/Enum.hpp"
namespace MoReFEM::Utilities::InputDataNS
{
/*!
* \brief A convenient helper to extract information from Base class.
*
* The problem with Base class is that the syntax is really hideous; for instance a derived class
* from base (named IPL for the example below) must use the following syntax to extract a value
* named Component:
*
* \code
* using Type = InputData::BoundaryCondition::Component;
* auto component_value = this->template ReadHelper<Type>();
* \endcode
*
* This template syntax is quite unusual and many C++ developers don't know it; so the helper class
* hids that and the same quantity may be extracted with:
* \code
* using Type = InputData::BoundaryCondition::Component;
* auto component_value = Extract<Type>::Value();
* \endcode
*
* This class can also be used to read Lua functions:
* \code
* decltype(auto) fct = Extract<InputData::Force::Surfacic>::Value(input_data);
* std::cout << "Value = " << fct(0, 1, 2, 3) << std::endl;
* \endcode
*/
template<class ObjectT>
struct Extract
{
//! Convenient alias over the return type.
using return_type = typename ObjectT::return_type;
/*!
* \brief Return the value of the input parameter.
*
* \tparam InputDataT The object which holds the information about input data file content.
* \tparam CountAsUsedT At the end of the program, we may sum up the input data that have not been
* used. A call to this method tally them as used unless 'no' is specified here.
* \copydoc doxygen_hide_input_data_arg
*
* \return Value of the input parameter.
*/
template<class InputDataT, CountAsUsed CountAsUsedT = CountAsUsed::yes>
static typename ConstRefOrValue<return_type>::type Value(const InputDataT& input_data);
/*!
* \brief Return a string that stands for a path; only additional operation is to replace environment
* variables by their value.
*
* For instance "${HOME}/Codes/MoReFEM" will be resolved on a Mac in /Users/ *username* /Codes/MoReFEM.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
*
* \return Path related to \a ObjectT.
*/
template<class InputDataT>
static std::string Path(const InputDataT& input_data);
/*!
* \brief Return a string that stands for a folder; several operations might be attempted if said folder
* doesn't exist.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
*
* \return Path to the folder hold by \a ObjectT.
*/
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT = UnexistentFolderPolicy::create>
static std::string Folder(const InputDataT& input_data);
/*!
* \brief Read the number of elements when the object is a vector.
*
* If not a vector, a compilation error will occur as size() method won't be defined.
* \param[in] input_data Object which hols all relevant input data for the model considered.
*
*
* \return Number of elements hold by \a ObjectT.
*/
template<class InputDataT>
static unsigned int Number(const InputDataT& input_data);
/*!
* \brief Return the \a index -th value of a vector.
*
* If the input parameter is not a vector, subscript operator will yield an error at compile time.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
* \param[in] index Index of the element sought in the vector read in the \a input_data.
*
* \return Value of the \a index -th element of \a ObjectT.
*/
template<class InputDataT, CountAsUsed CountAsUsedT = CountAsUsed::yes>
static decltype(auto) Subscript(const InputDataT& input_data,
unsigned int index);
};
} // namespace MoReFEM::Utilities::InputDataNS
# include "Utilities/InputData/Extract.hxx"
#endif // MOREFEM_x_UTILITIES_x_INPUT_DATA_x_EXTRACT_HPP_
//! \file
//
//
// Extract.hxx
// MoReFEM
//
// Created by sebastien on 23/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_INPUT_DATA_x_EXTRACT_HXX_
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_EXTRACT_HXX_
namespace MoReFEM::Utilities::InputDataNS
{
template<class ObjectT>
template<class InputDataT, CountAsUsed CountAsUsedT>
typename ConstRefOrValue<typename Extract<ObjectT>::return_type>::type
Extract<ObjectT>::Value(const InputDataT& input_data)
{
return input_data.template ReadHelper<ObjectT, CountAsUsedT>();
}
template<class ObjectT>
template<class InputDataT>
std::string Extract<ObjectT>::Path(const InputDataT& input_data)
{
return input_data.template ReadHelperPath<ObjectT>();
}
template<class ObjectT>
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT>
std::string Extract<ObjectT>
::Folder(const InputDataT& input_data)
{
return input_data.template ReadHelperFolder<ObjectT, UnexistentFolderPolicyT>();
}
template<class ObjectT>
template<class InputDataT>
unsigned int Extract<ObjectT>::Number(const InputDataT& input_data)
{
return input_data.template ReadHelperNumber<ObjectT>();
}
template<class ObjectT>
template<class InputDataT, CountAsUsed CountAsUsedT>
decltype(auto)
Extract<ObjectT>::Subscript(const InputDataT& input_data,
unsigned int index)
{
return input_data.template ReadHelper<ObjectT, CountAsUsedT>(index);
}
} // namespace MoReFEM::Utilities::InputDataNS
#endif // MOREFEM_x_UTILITIES_x_INPUT_DATA_x_EXTRACT_HXX_
......@@ -18,7 +18,7 @@
#include <algorithm>
#include "Utilities/String/String.hpp"
#include "Utilities/InputData/Internal/TupleIteration/Impl/PrepareDefaultEntry.hpp"
#include "Utilities/InputData/Internal/TupleIteration/Impl/Print.hpp"
namespace MoReFEM
......@@ -179,14 +179,6 @@ namespace MoReFEM