Skip to content

Commit

Permalink
refactor: EnumStrings.hpp from codingUtilities to common/format (#3267)
Browse files Browse the repository at this point in the history
* todos

* DataTypes.hpp now only manage static types
- no runtime types nor Mpi constants
- DataTypes.cpp is not useful anymore.

* removing common -> fileIO

* last common->fileIO ref

* removing common->codingUtilities

* logger has now a dedicated folder for upcoming files (future PRs)

* 📝 missed docs (where not previously catched by the CI)

* Moving EnumStrings.hpp from codingUtilities to common/format

* moving the regex in codingUtilities as it is related to rtTypes / regexes

* removing dependency with TypeName<T>
  • Loading branch information
MelReyCG authored Nov 13, 2024
1 parent 1c89619 commit 73d86e8
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 56 deletions.
1 change: 0 additions & 1 deletion src/coreComponents/codingUtilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Specify all headers
#
set( codingUtilities_headers
EnumStrings.hpp
RTTypes.hpp
Parsing.hpp
SFINAE_Macros.hpp
Expand Down
26 changes: 25 additions & 1 deletion src/coreComponents/codingUtilities/RTTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define GEOS_CODINGUTILITIES_RTTYPES_HPP

#include "common/DataTypes.hpp"
#include "common/format/EnumStrings.hpp"
#include "common/format/Format.hpp"
#include "common/logger/Logger.hpp"

Expand Down Expand Up @@ -232,7 +233,30 @@ struct TypeName
}
};

}
/**
* @brief Base types TypeRegex specializations
*/
///@{

/**
* @brief Specialization of TypeRegex for enumeration types with strings attached (pun intended).
* @tparam ENUM the type of enumeration
*/
template< typename ENUM >
struct TypeRegex< ENUM, std::enable_if_t< internal::HasEnumStrings< ENUM > > >
{
/**
* @brief @return Regex for validating enumeration inputs for @p ENUM type.
*/
static Regex get()
{
return Regex( EnumStrings< ENUM >::concat( "|" ),
"Input value must be one of { " + EnumStrings< ENUM >::concat( ", " ) + " }." );
}
};

///@}

}

#endif /* GEOS_CODINGUTILITIES_RTTYPES_HPP */
1 change: 1 addition & 0 deletions src/coreComponents/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set( common_headers
format/table/TableLayout.hpp
format/table/TableFormatter.hpp
format/table/TableData.hpp
format/EnumStrings.hpp
format/Format.hpp
format/StringUtilities.hpp
logger/Logger.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* of these strings, like stream insertion/extraction operators.
*/

#ifndef GEOS_CODINGUTILITIES_ENUMSTRINGS_HPP
#define GEOS_CODINGUTILITIES_ENUMSTRINGS_HPP
#ifndef GEOS_COMMON_FORMAT_ENUMSTRINGS_HPP
#define GEOS_COMMON_FORMAT_ENUMSTRINGS_HPP

#include "common/format/StringUtilities.hpp"
#include "codingUtilities/RTTypes.hpp"
// #include "codingUtilities/RTTypes.hpp"
#include "common/DataTypes.hpp"
#include "common/logger/Logger.hpp"
#include "common/format/Format.hpp"
Expand Down Expand Up @@ -66,6 +66,15 @@ constexpr int countArgs( ARGS ... )
* may be used to get access to strings at runtime. While not strictly necessary,
* it is recommended that macro call immediately follows the enum definition
* (or the class definition, if enum is defined inside a class).
*
* enum struct VTKOutputMode
* {
* BINARY,
* ASCII
* };
* ENUM_STRINGS( VTKOutputMode,
* "binary",
* "ascii" );
*/
#define ENUM_STRINGS( ENUM, ... ) \
inline auto const & getEnumStrings( ENUM const ) \
Expand All @@ -74,6 +83,11 @@ constexpr int countArgs( ARGS ... )
return ss; \
} \
\
inline auto const & getEnumTypeNameString( ENUM const ) \
{ \
return #ENUM; \
} \
\
inline std::ostream & operator<<( std::ostream & os, ENUM const e ) \
{ \
os << EnumStrings< ENUM >::toString( e ); \
Expand Down Expand Up @@ -139,7 +153,7 @@ struct EnumStrings
std::size_t size = std::distance( std::begin( strings ), std::end( strings ) );
base_type const index = static_cast< base_type >( e );
GEOS_THROW_IF( index >= LvArray::integerConversion< base_type >( size ),
"Invalid value " << index << " of type " << TypeName< ENUM >::brief() << ". Valid range is 0.." << size - 1,
"Invalid value " << index << " of type " << getEnumTypeNameString( enum_type{} ) << ". Valid range is 0.." << size - 1,
InputError );
return strings[ index ];
}
Expand All @@ -154,7 +168,7 @@ struct EnumStrings
auto const & strings = get();
auto const it = std::find( std::begin( strings ), std::end( strings ), s );
GEOS_THROW_IF( it == std::end( strings ),
"Invalid value '" << s << "' of type " << TypeName< enum_type >::brief() << ". Valid options are: " << concat( ", " ),
"Invalid value '" << s << "' of type " << getEnumTypeNameString( enum_type{} ) << ". Valid options are: " << concat( ", " ),
InputError );
enum_type const e = static_cast< enum_type >( LvArray::integerConversion< base_type >( std::distance( std::begin( strings ), it ) ) );
return e;
Expand All @@ -166,23 +180,6 @@ namespace internal
IS_VALID_EXPRESSION( HasEnumStrings, ENUM, getEnumStrings( std::declval< ENUM >() ) );
}

/**
* @brief Specialization of TypeRegex for enumeration types with strings attached (pun intended).
* @tparam ENUM the type of enumeration
*/
template< typename ENUM >
struct TypeRegex< ENUM, std::enable_if_t< internal::HasEnumStrings< ENUM > > >
{
/**
* @brief @return Regex for validating enumeration inputs for @p ENUM type.
*/
static Regex get()
{
return Regex( EnumStrings< ENUM >::concat( "|" ),
"Input value must be one of { " + EnumStrings< ENUM >::concat( ", " ) + " }." );
}
};

} // namespace geos

// Formatter specialization for enums
Expand All @@ -209,4 +206,4 @@ struct GEOS_FMT_NS::formatter< Enum, std::enable_if_t< std::is_enum< Enum >::val
}
};

#endif //GEOS_CODINGUTILITIES_ENUMSTRINGS_HPP
#endif //GEOS_COMMON_FORMAT_ENUMSTRINGS_HPP
2 changes: 1 addition & 1 deletion src/coreComponents/constitutive/ExponentialRelation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define GEOS_CONSITUTIVE_EXPONENTIALRELATION_HPP_

#include "common/DataTypes.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

#include <cmath>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp"

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "functions/TableFunction.hpp"

namespace geos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_CO2BRINEFLUID_HPP_
#define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_CO2BRINEFLUID_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "constitutive/fluid/multifluid/MultiFluidBase.hpp"
#include "constitutive/fluid/multifluid/MultiFluidUtils.hpp"
#include "constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "ModelParameters.hpp"
#include "constitutive/fluid/multifluid/MultiFluidBase.hpp"
#include "dataRepository/InputFlags.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "FunctionBase.hpp"

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_CONSTITUTIVE_FLUID_REACTIVEBRINEFLUID_HPP_
#define GEOS_CONSTITUTIVE_FLUID_REACTIVEBRINEFLUID_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "constitutive/fluid/multifluid/reactive/ReactiveMultiFluid.hpp"
#include "constitutive/fluid/multifluid/MultiFluidUtils.hpp"
#include "constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_REACTIVE_REACTIVEMULTIFLUID_HPP_


#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "constitutive/fluid/multifluid/MultiFluidBase.hpp"
#include "constitutive/fluid/multifluid/reactive/chemicalReactions/EquilibriumReactions.hpp"
#include "constitutive/fluid/multifluid/reactive/chemicalReactions/KineticReactions.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_CONSTITUTIVE_FLUID_SINGLEFLUID_PARTICLEFLUID_HPP_
#define GEOS_CONSTITUTIVE_FLUID_SINGLEFLUID_PARTICLEFLUID_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "constitutive/fluid/singlefluid/ParticleFluidBase.hpp"

namespace geos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "constitutive/ConstitutiveBase.hpp"
#include "constitutive/relativePermeability/layouts.hpp"
#include "common/GEOS_RAJA_Interface.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/dataRepository/ExecutableGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_DATAREPOSITORY_EXECUTABLEGROUP_HPP_
#define GEOS_DATAREPOSITORY_EXECUTABLEGROUP_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "common/DataTypes.hpp"
#include "Group.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <gtest/gtest.h>

#include "dataRepository/xmlWrapper.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

using namespace geos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "dataRepository/Wrapper.hpp"
#include "fileIO/vtk/VTKPVDWriter.hpp"
#include "fileIO/vtk/VTKVTMWriter.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

class vtkUnstructuredGrid;
class vtkPointData;
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/finiteElement/PDEUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_FINITEELEMENT_PDEUTILITIES_HPP_
#define GEOS_FINITEELEMENT_PDEUTILITIES_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "FunctionBase.hpp"

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "LvArray/src/tensorOps.hpp"

namespace geos
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/functions/TableFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "FunctionBase.hpp"

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "LvArray/src/tensorOps.hpp"
#include "common/format/table/TableFormatter.hpp"
#include "common/Units.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_LINEARALGEBRA_UTILITIES_LINEARSOLVERPARAMETERS_HPP_
#define GEOS_LINEARALGEBRA_UTILITIES_LINEARSOLVERPARAMETERS_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/ElementType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_MESH_ELEMENTTYPE_HPP
#define GEOS_MESH_ELEMENTTYPE_HPP

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/MeshObjectPath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define GEOS_MESH_MESHOBJECTPATH_HPP_


#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "MeshLevel.hpp"

namespace geos
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/ParticleType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_MESH_PARTICLETYPE_HPP
#define GEOS_MESH_PARTICLETYPE_HPP

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/SurfaceElementRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define GEOS_MESH_SURFACEELEMENTREGION_HPP_

#include "ElementRegionBase.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_MESH_GENERATORS_INTERNALMESHGENERATOR_HPP
#define GEOS_MESH_GENERATORS_INTERNALMESHGENERATOR_HPP

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "mesh/generators/MeshGeneratorBase.hpp"
#include "mesh/generators/CellBlockManager.hpp"
#include "mesh/mpiCommunications/SpatialPartition.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_MESHUTILITIES_INTERNALWELLBOREGENERATOR_HPP
#define GEOS_MESHUTILITIES_INTERNALWELLBOREGENERATOR_HPP

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "dataRepository/Group.hpp"
#include "InternalMeshGenerator.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "mesh/generators/MeshGeneratorBase.hpp"

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef GEOS_PHYSICSSOLVERS_NONLINEARSOLVERPARAMETERS_HPP_
#define GEOS_PHYSICSSOLVERS_NONLINEARSOLVERPARAMETERS_HPP_

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "dataRepository/Group.hpp"
#include "physicsSolvers/PhysicsSolverBaseKernels.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef GEOS_PHYSICSSOLVERS_SOLVERBASEKERNELS_HPP
#define GEOS_PHYSICSSOLVERS_SOLVERBASEKERNELS_HPP

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "common/DataTypes.hpp"
#include "common/MpiWrapper.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define GEOS_PHYSICSSOLVERS_CONTACT_CONTACTFIELDS_HPP_

#include "mesh/MeshFields.hpp"
#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"

namespace geos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLCONTROLS_HPP
#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_WELLCONTROLS_HPP

#include "codingUtilities/EnumStrings.hpp"
#include "common/format/EnumStrings.hpp"
#include "dataRepository/Group.hpp"
#include "functions/TableFunction.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef GEOS_PHYSICSSOLVERS_SIMPLEPDE_LAPLACE_BASE_HPP
#define GEOS_PHYSICSSOLVERS_SIMPLEPDE_LAPLACE_BASE_HPP

#include "codingUtilities/EnumStrings.hpp" // facilities for enum-string conversion (for reading enum values from XML input)
#include "common/format/EnumStrings.hpp" // facilities for enum-string conversion (for reading enum values from XML input)
#include "physicsSolvers/PhysicsSolverBase.hpp" // an abstraction class shared by all physics solvers
#include "fieldSpecification/FieldSpecificationManager.hpp" // a manager that can access and set values on the discretized domain

Expand Down
Loading

0 comments on commit 73d86e8

Please sign in to comment.