Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Arcane::ServiceBuilder< InterfaceType > Class Template Reference

Utility class for instantiating a service of a given interface. More...

#include <arcane/core/ServiceBuilder.h>

Public Member Functions

 ServiceBuilder (ISubDomain *sd)
 Instantiation to create a subdomain service.
 ServiceBuilder (const MeshHandle &mesh_handle)
 Instantiation to create a subdomain service associated with the mesh_handle.
 ServiceBuilder (ISession *session)
 Instantiation to create a session service.
 ServiceBuilder (IApplication *app)
 Instantiation to create an application service.
 ServiceBuilder (IApplication *app, ICaseOptions *opt)
 Instantiation to create a dataset options service.
Ref< InterfaceType > createReference (const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the InterfaceType interface.
Ref< InterfaceType > createReference (const String &name, IMesh *mesh, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the InterfaceType interface.
UniqueArray< Ref< InterfaceType > > createAllInstances ()
 Creates an instance of every service that implements InterfaceType.
InterfaceType * getSingleton (eServiceBuilderProperties properties=SB_None)
 Singleton instance of the service implementing the InterfaceType interface.
void getServicesNames (Array< String > &names) const
 Fills names with the names of services available to instantiate this interface.
void createAllInstances (Array< InterfaceType * > &instances)
 Creates an instance of every service that implements InterfaceType.
InterfaceType * createInstance (const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the interface InterfaceType.
InterfaceType * createInstance (const String &name, IMesh *mesh, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the interface InterfaceType.

Static Public Member Functions

static Ref< InterfaceType > createReference (ISubDomain *sd, const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the InterfaceType interface.
static Ref< InterfaceType > createReference (ISession *session, const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the InterfaceType interface.
static Ref< InterfaceType > createReference (IApplication *app, const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the InterfaceType interface.
static Ref< InterfaceType > createReference (ISubDomain *sd, const String &name, IMesh *mesh, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the InterfaceType interface.
static InterfaceType * createInstance (ISubDomain *sd, const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the interface InterfaceType.
static InterfaceType * createInstance (ISession *session, const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the interface InterfaceType.
static InterfaceType * createInstance (IApplication *app, const String &name, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the interface InterfaceType.
static InterfaceType * createInstance (ISubDomain *sd, const String &name, IMesh *mesh, eServiceBuilderProperties properties=SB_None)
 Creates an instance implementing the interface InterfaceType.

Detailed Description

template<typename InterfaceType>
class Arcane::ServiceBuilder< InterfaceType >

Utility class for instantiating a service of a given interface.

This class allows searching for all available services implementing the InterfaceType interface passed as a template parameter.

This class replaces older classes that allowed service creation, namely ServiceFinderT, ServiceFinder2T, and FactoryT.

There are three constructors depending on whether you want to instantiate a subdomain, a session, or an application service. Generally, it is a subdomain service; the last two categories are rather used for internal Arcane services.

The following example creates a subdomain service implementing the IMyInterface interface with the name TOTO:

ISubDomain* sd = ...
ServiceBuilder<IMyInterface> builder(sd);
ServiceRef<IMyInterface> iservice = builder.createReference("TOTO");
...
Interface of the subdomain manager.
Definition ISubDomain.h:75

The returned instance is managed by a reference counter and is destroyed as soon as there are no more references to it. By default, createInstance() throws an exception if the service is not found, unless the SB_AllowNull property is specified. If the SB_Collective property is true, the exception thrown is of type ParallelFatalErrorException; otherwise, it is of type FatalErrorException. This is useful if you are sure that all processes will perform the same operation. In this case, this allows only one error message to be generated and the code to stop cleanly.

It is also possible to retrieve a singleton instance of a service, via getSingleton(). The available singleton instances are referenced in the code configuration file (see Code Configuration (.CONFIG)).

Definition at line 101 of file ServiceBuilder.h.

Constructor & Destructor Documentation

◆ ServiceBuilder() [1/5]

template<typename InterfaceType>
Arcane::ServiceBuilder< InterfaceType >::ServiceBuilder ( ISubDomain * sd)
inline

Instantiation to create a subdomain service.

Definition at line 106 of file ServiceBuilder.h.

Referenced by createInstance(), createInstance(), createInstance(), createReference(), createReference(), and createReference().

◆ ServiceBuilder() [2/5]

template<typename InterfaceType>
Arcane::ServiceBuilder< InterfaceType >::ServiceBuilder ( const MeshHandle & mesh_handle)
inline

Instantiation to create a subdomain service associated with the mesh_handle.

Definition at line 110 of file ServiceBuilder.h.

◆ ServiceBuilder() [3/5]

template<typename InterfaceType>
Arcane::ServiceBuilder< InterfaceType >::ServiceBuilder ( ISession * session)
inline

Instantiation to create a session service.

Definition at line 114 of file ServiceBuilder.h.

◆ ServiceBuilder() [4/5]

template<typename InterfaceType>
Arcane::ServiceBuilder< InterfaceType >::ServiceBuilder ( IApplication * app)
inline

Instantiation to create an application service.

Definition at line 118 of file ServiceBuilder.h.

◆ ServiceBuilder() [5/5]

template<typename InterfaceType>
Arcane::ServiceBuilder< InterfaceType >::ServiceBuilder ( IApplication * app,
ICaseOptions * opt )
inline

Instantiation to create a dataset options service.

Definition at line 122 of file ServiceBuilder.h.

◆ ~ServiceBuilder()

template<typename InterfaceType>
Arcane::ServiceBuilder< InterfaceType >::~ServiceBuilder ( )
inline

Definition at line 126 of file ServiceBuilder.h.

Member Function Documentation

◆ createAllInstances() [1/2]

template<typename InterfaceType>
UniqueArray< Ref< InterfaceType > > Arcane::ServiceBuilder< InterfaceType >::createAllInstances ( )
inline

Creates an instance of every service that implements InterfaceType.

The created instances are stored in instances. The caller must destroy them using the delete operator once they are no longer useful.

Definition at line 184 of file ServiceBuilder.h.

Referenced by createAllInstances().

◆ createAllInstances() [2/2]

template<typename InterfaceType>
void Arcane::ServiceBuilder< InterfaceType >::createAllInstances ( Array< InterfaceType * > & instances)
inline

Creates an instance of every service that implements InterfaceType.

The created instances are stored in instances. The caller must destroy them using the delete operator once they are no longer needed.

Deprecated
Use the overload that returns an array of references.

Definition at line 285 of file ServiceBuilder.h.

References createAllInstances().

◆ createInstance() [1/6]

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::createInstance ( const String & name,
eServiceBuilderProperties properties = SB_None )
inline

Creates an instance implementing the interface InterfaceType.

The instance is created using the factory registered under the name name. The returned pointer must be deallocated using delete.

By default, an exception is thrown if the specified service is not found. It is possible to change this behavior by specifying SB_AllowNull in properties in which case the function returns a null pointer if the specified service does not exist.

Deprecated
Use createReference() instead.

Definition at line 303 of file ServiceBuilder.h.

References createInstance(), Arcane::SB_AllowNull, and Arcane::SB_None.

Referenced by createInstance(), createInstance(), createInstance(), createInstance(), createInstance(), and createInstance().

◆ createInstance() [2/6]

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::createInstance ( const String & name,
IMesh * mesh,
eServiceBuilderProperties properties = SB_None )
inline

Creates an instance implementing the interface InterfaceType.

The instance is created using the factory registered under the name name. The returned pointer must be deallocated using delete.

It is possible to specify the mesh mesh on which the service will rely. This is only useful for subdomain services. For session or application services, this argument is not used.

By default, an exception is thrown if the specified service is not found. It is possible to change this behavior by specifying SB_AllowNull in properties in which case the function returns a null pointer if the specified service does not exist.

Deprecated
Use createReference() instead.

Definition at line 344 of file ServiceBuilder.h.

References createInstance(), Arcane::SB_AllowNull, and Arcane::SB_None.

◆ createInstance() [3/6]

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::createInstance ( IApplication * app,
const String & name,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the interface InterfaceType.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 377 of file ServiceBuilder.h.

References createInstance(), Arcane::SB_None, and ServiceBuilder().

◆ createInstance() [4/6]

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::createInstance ( ISession * session,
const String & name,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the interface InterfaceType.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 361 of file ServiceBuilder.h.

References createInstance(), Arcane::SB_None, and ServiceBuilder().

◆ createInstance() [5/6]

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::createInstance ( ISubDomain * sd,
const String & name,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the interface InterfaceType.

See also
createInstance(const String& name,eServiceBuilderProperties properties)
Deprecated
Use createReference() instead.

Definition at line 321 of file ServiceBuilder.h.

References createInstance(), and Arcane::SB_None.

◆ createInstance() [6/6]

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::createInstance ( ISubDomain * sd,
const String & name,
IMesh * mesh,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the interface InterfaceType.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 393 of file ServiceBuilder.h.

References createInstance(), Arcane::SB_None, and ServiceBuilder().

◆ createReference() [1/6]

template<typename InterfaceType>
Ref< InterfaceType > Arcane::ServiceBuilder< InterfaceType >::createReference ( const String & name,
eServiceBuilderProperties properties = SB_None )
inline

Creates an instance implementing the InterfaceType interface.

The instance is created using the factory registered under the name name.

By default, an exception is thrown if the specified service is not found. It is possible to change this behavior by specifying SB_AllowNull in properties, in which case the function returns a null pointer if the specified service does not exist.

Definition at line 140 of file ServiceBuilder.h.

References Arcane::SB_AllowNull, and Arcane::SB_None.

Referenced by createReference(), createReference(), createReference(), and createReference().

◆ createReference() [2/6]

template<typename InterfaceType>
Ref< InterfaceType > Arcane::ServiceBuilder< InterfaceType >::createReference ( const String & name,
IMesh * mesh,
eServiceBuilderProperties properties = SB_None )
inline

Creates an instance implementing the InterfaceType interface.

The instance is created using the factory registered under the name name. The returned pointer must be deallocated using delete.

It is possible to specify the mesh on which the service will reside. This is only useful for subdomain services. For session or application services, this argument is not used.

By default, an exception is thrown if the specified service is not found. It is possible to change this behavior by specifying SB_AllowNull in properties, in which case the function returns a null pointer if the specified service does not exist.

Definition at line 166 of file ServiceBuilder.h.

References Arcane::SB_AllowNull, and Arcane::SB_None.

◆ createReference() [3/6]

template<typename InterfaceType>
Ref< InterfaceType > Arcane::ServiceBuilder< InterfaceType >::createReference ( IApplication * app,
const String & name,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the InterfaceType interface.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 241 of file ServiceBuilder.h.

References createReference(), Arcane::SB_None, and ServiceBuilder().

◆ createReference() [4/6]

template<typename InterfaceType>
Ref< InterfaceType > Arcane::ServiceBuilder< InterfaceType >::createReference ( ISession * session,
const String & name,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the InterfaceType interface.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 225 of file ServiceBuilder.h.

References createReference(), Arcane::SB_None, and ServiceBuilder().

◆ createReference() [5/6]

template<typename InterfaceType>
Ref< InterfaceType > Arcane::ServiceBuilder< InterfaceType >::createReference ( ISubDomain * sd,
const String & name,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the InterfaceType interface.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 214 of file ServiceBuilder.h.

References createReference(), and Arcane::SB_None.

◆ createReference() [6/6]

template<typename InterfaceType>
Ref< InterfaceType > Arcane::ServiceBuilder< InterfaceType >::createReference ( ISubDomain * sd,
const String & name,
IMesh * mesh,
eServiceBuilderProperties properties = SB_None )
inlinestatic

Creates an instance implementing the InterfaceType interface.

See also
createInstance(const String& name,eServiceBuilderProperties properties)

Definition at line 257 of file ServiceBuilder.h.

References createReference(), Arcane::SB_None, and ServiceBuilder().

◆ getServicesNames()

template<typename InterfaceType>
void Arcane::ServiceBuilder< InterfaceType >::getServicesNames ( Array< String > & names) const
inline

Fills names with the names of services available to instantiate this interface.

Definition at line 269 of file ServiceBuilder.h.

◆ getSingleton()

template<typename InterfaceType>
InterfaceType * Arcane::ServiceBuilder< InterfaceType >::getSingleton ( eServiceBuilderProperties properties = SB_None)
inline

Singleton instance of the service implementing the InterfaceType interface.

The returned instance must not be destroyed.

By default, an exception is thrown if the specified service is not found. It is possible to change this behavior by specifying SB_AllowNull in properties, in which case the function returns a null pointer if the specified service does not exist.

Definition at line 198 of file ServiceBuilder.h.

References Arcane::SB_AllowNull, and Arcane::SB_None.


The documentation for this class was generated from the following file: