Skip to content

Commit

Permalink
Merge pull request #1799 from arcaneframework/dev/gg-decouply-propert…
Browse files Browse the repository at this point in the history
…y-instance-from-setter

Decouple the type of the property setter class from the type of the instance set
  • Loading branch information
grospelliergilles authored Nov 27, 2024
2 parents efa1529 + 5538107 commit 4cf87ed
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 38 deletions.
14 changes: 9 additions & 5 deletions arcane/src/arcane/launcher/ArcaneLauncher.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ArcaneLauncher.cc (C) 2000-2023 */
/* ArcaneLauncher.cc (C) 2000-2024 */
/* */
/* Classe gérant le lancement de l'exécution. */
/*---------------------------------------------------------------------------*/
Expand All @@ -26,6 +26,8 @@
#include "arcane/utils/ParameterList.h"
#include "arcane/utils/Ref.h"
#include "arcane/utils/ConcurrencyUtils.h"
#include "arcane/utils/internal/ParallelLoopOptionsProperties.h"
#include "arcane/utils/internal/ApplicationInfoProperties.h"

#include "arcane/impl/ArcaneMain.h"
#include "arcane/impl/ArcaneSimpleExecutor.h"
Expand Down Expand Up @@ -102,7 +104,7 @@ _checkReadConfigFile(StringView config_file_name)
if (config.null())
return;
std::cout << "READING CONFIG\n";
properties::readFromJSON(config,app_info);
properties::readFromJSON<ApplicationInfo,ApplicationInfoProperties>(config,app_info);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -322,20 +324,22 @@ init(const CommandLineArguments& args)
if (global_has_init_done)
ARCANE_FATAL("ArcaneLauncher::init() has already been called");
global_has_init_done = true;
applicationInfo().setCommandLineArguments(args);
auto& application_info = applicationInfo();
application_info.setCommandLineArguments(args);
bool do_list = false;
if (do_list)
_listPropertySettings();
const CommandLineArguments& cargs = applicationInfo().commandLineArguments();
String runtime_config_file_name = cargs.getParameter("RuntimeConfigFile");
if (!runtime_config_file_name.empty())
_checkReadConfigFile(runtime_config_file_name);
properties::readFromParameterList<ApplicationInfo,ApplicationInfoProperties>(args.parameters(),application_info);
auto& dotnet_info = ArcaneLauncher::dotNetRuntimeInitialisationInfo();
properties::readFromParameterList(args.parameters(),dotnet_info);
auto& accelerator_info = ArcaneLauncher::acceleratorRuntimeInitialisationInfo();
properties::readFromParameterList(args.parameters(),accelerator_info);
ParallelLoopOptions loop_options;
properties::readFromParameterList(args.parameters(),loop_options);
properties::readFromParameterList<ParallelLoopOptions,ParallelLoopOptionsProperties>(args.parameters(),loop_options);
TaskFactory::setDefaultParallelLoopOptions(loop_options);
}
catch(const Exception& ex){
Expand Down
12 changes: 8 additions & 4 deletions arcane/src/arcane/utils/ApplicationInfo.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ApplicationInfo.cc (C) 2000-2020 */
/* ApplicationInfo.cc (C) 2000-2024 */
/* */
/* Informations sur une application. */
/*---------------------------------------------------------------------------*/
Expand All @@ -17,6 +17,7 @@
#include "arcane/utils/PlatformUtils.h"
#include "arcane/utils/List.h"
#include "arcane/utils/Property.h"
#include "arcane/utils/internal/ApplicationInfoProperties.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -443,7 +444,10 @@ addParameterLine(const String& line)
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

template<typename V> void ApplicationInfo::
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

template<typename V> void ApplicationInfoProperties::
_applyPropertyVisitor(V& p)
{
auto b = p.builder();
Expand Down Expand Up @@ -486,7 +490,7 @@ _applyPropertyVisitor(V& p)
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

ARCANE_REGISTER_PROPERTY_CLASS(ApplicationInfo,());
ARCANE_REGISTER_PROPERTY_CLASS(ApplicationInfoProperties,());

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand Down
6 changes: 2 additions & 4 deletions arcane/src/arcane/utils/ApplicationInfo.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ApplicationInfo.h (C) 2000-2020 */
/* ApplicationInfo.h (C) 2000-2024 */
/* */
/* Informations sur une application. */
/*---------------------------------------------------------------------------*/
Expand All @@ -17,7 +17,6 @@
#include "arcane/utils/VersionInfo.h"
#include "arcane/utils/String.h"
#include "arcane/utils/UtilsTypes.h"
#include "arcane/utils/PropertyDeclarations.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand All @@ -38,7 +37,6 @@ class CommandLineArguments;
*/
class ARCANE_UTILS_EXPORT ApplicationInfo
{
ARCANE_DECLARE_PROPERTY_CLASS(ApplicationInfo);
public:

ApplicationInfo();
Expand Down
10 changes: 5 additions & 5 deletions arcane/src/arcane/utils/JSONPropertyReader.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* JSONPropertyReader.h (C) 2000-2020 */
/* JSONPropertyReader.h (C) 2000-2024 */
/* */
/* Lecture de propriétés au format JSON. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -59,15 +59,15 @@ class JSONPropertyReader
* Les valeurs de la propriété doivent être dans un élément fils de \a jv
* dont le nom est celui de la classe \a T.
*/
template<typename T> inline void
template<typename T, typename PropertyType = T> inline void
readFromJSON(JSONValue jv,T& instance)
{
const char* instance_property_name = T :: propertyClassName();
const char* instance_property_name = PropertyType :: propertyClassName();
JSONValue child_value = jv.child(instance_property_name);
if (child_value.null())
return;
JSONPropertyReader reader(child_value,instance);
T :: applyPropertyVisitor(reader);
PropertyType :: applyPropertyVisitor(reader);
}

/*---------------------------------------------------------------------------*/
Expand Down
9 changes: 5 additions & 4 deletions arcane/src/arcane/utils/ParallelLoopOptions.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ParallelLoopOptions.cc (C) 2000-2022 */
/* ParallelLoopOptions.cc (C) 2000-2024 */
/* */
/* Options de configuration pour les boucles parallèles en multi-thread. */
/*---------------------------------------------------------------------------*/
Expand All @@ -15,6 +15,7 @@

#include "arcane/utils/Property.h"
#include "arcane/utils/FatalErrorException.h"
#include "arcane/utils/internal/ParallelLoopOptionsProperties.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -57,7 +58,7 @@ namespace
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

template <typename V> void ParallelLoopOptions::
template <typename V> void ParallelLoopOptionsProperties::
_applyPropertyVisitor(V& p)
{
auto b = p.builder();
Expand All @@ -77,7 +78,7 @@ _applyPropertyVisitor(V& p)
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

ARCANE_REGISTER_PROPERTY_CLASS(ParallelLoopOptions, ());
ARCANE_REGISTER_PROPERTY_CLASS(ParallelLoopOptionsProperties, ());

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand Down
7 changes: 2 additions & 5 deletions arcane/src/arcane/utils/ParallelLoopOptions.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ParallelLoopOptions.h (C) 2000-2022 */
/* ParallelLoopOptions.h (C) 2000-2024 */
/* */
/* Options de configuration pour les boucles parallèles en multi-thread. */
/*---------------------------------------------------------------------------*/
Expand All @@ -15,7 +15,6 @@
/*---------------------------------------------------------------------------*/

#include "arcane/utils/UtilsTypes.h"
#include "arcane/utils/PropertyDeclarations.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand All @@ -34,8 +33,6 @@ namespace Arcane
*/
class ARCANE_UTILS_EXPORT ParallelLoopOptions
{
ARCANE_DECLARE_PROPERTY_CLASS(ParallelLoopOptions);

private:

//! Drapeau pour indiquer quels champs ont été positionnés.
Expand Down
12 changes: 6 additions & 6 deletions arcane/src/arcane/utils/ParameterListPropertyReader.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ParameterListPropertyReader.h (C) 2000-2021 */
/* ParameterListPropertyReader.h (C) 2000-2024 */
/* */
/* Lecture de propriétés au format JSON. */
/*---------------------------------------------------------------------------*/
Expand All @@ -30,7 +30,7 @@ namespace Arcane::properties
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
//! \internal
template<typename T>
template<typename T, typename PropertyType = T>
class ParameterListPropertyVisitor
: public properties::PropertyVisitor<T>
{
Expand Down Expand Up @@ -61,11 +61,11 @@ class ParameterListPropertyVisitor
/*!
* \brief Remplit les valeurs de \a instance à partir des paramètres \a args.
*/
template<typename T> inline void
template<typename T, typename PropertyType = T> inline void
readFromParameterList(const ParameterList& args,T& instance)
{
ParameterListPropertyVisitor reader(args,instance);
T :: applyPropertyVisitor(reader);
ParameterListPropertyVisitor<T,PropertyType> reader(args,instance);
PropertyType :: applyPropertyVisitor(reader);
}

/*---------------------------------------------------------------------------*/
Expand Down
11 changes: 6 additions & 5 deletions arcane/src/arcane/utils/PropertyDeclarations.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* PropertyDeclarations.h (C) 2000-2020 */
/* PropertyDeclarations.h (C) 2000-2024 */
/* */
/* Déclaration des types et macros pour la gestion des propriétés. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -57,12 +57,13 @@ class PropertyDeclaration
* class MyClass
* {
* public:
* ARCANE_DECLARE_PROPERTY_CLASS(MyClass);
* ARCANE_DECLARE_PROPERTY_CLASS(MyClass,InstanceType);
* };
* \endcode
*/
#define ARCANE_DECLARE_PROPERTY_CLASS(class_name)\
#define ARCANE_DECLARE_PROPERTY_CLASS(class_name) \
public:\
using PropertyInstanceType = class_name; \
static const char* propertyClassName() { return #class_name; }\
template<typename V> static void _applyPropertyVisitor(V& visitor);\
static void applyPropertyVisitor(Arcane::properties::PropertyVisitor<class_name>& p); \
Expand Down Expand Up @@ -109,7 +110,7 @@ namespace\
}\
}\
void aclass :: \
applyPropertyVisitor(Arcane::properties::PropertyVisitor<aclass>& p)\
applyPropertyVisitor(Arcane::properties::PropertyVisitor<typename aclass :: PropertyInstanceType >& p) \
{\
aclass :: _applyPropertyVisitor(p);\
}\
Expand Down
45 changes: 45 additions & 0 deletions arcane/src/arcane/utils/internal/ApplicationInfoProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* ApplicationInfoProperties.h (C) 2000-2024 */
/* */
/* Informations sur une application. */
/*---------------------------------------------------------------------------*/
#ifndef ARCANE_UTILS_INTERNAL_APPLICATIONINFOPROPERTIES_H
#define ARCANE_UTILS_INTERNAL_APPLICATIONINFOPROPERTIES_H
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#include "arcane/utils/ApplicationInfo.h"
#include "arcane/utils/PropertyDeclarations.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

namespace Arcane
{

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!
* \brief Informations sur une application.
*/
class ARCANE_UTILS_EXPORT ApplicationInfoProperties
: public ApplicationInfo
{
ARCANE_DECLARE_PROPERTY_CLASS(ApplicationInfo);
};

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

} // namespace Arcane

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#endif
Loading

0 comments on commit 4cf87ed

Please sign in to comment.