Arcane  v3.16.8.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ServiceInstance.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ServiceInstance.h (C) 2000-2025 */
9/* */
10/* Instance de service. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_SERVICEINSTANCE_H
13#define ARCANE_CORE_SERVICEINSTANCE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Ref.h"
18#include "arcane/core/IService.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28/*!
29 * \brief Référence sur une instance de service.
30 *
31 * Cette classe est gérée via un compteur de référence à la manière
32 * de la classe std::shared_ptr.
33 */
34class ARCANE_CORE_EXPORT ServiceInstanceRef
35{
36 typedef Ref<IServiceInstance> RefType;
37 private:
38 ServiceInstanceRef(const RefType& r) : m_instance(r){}
39 public:
40 ServiceInstanceRef() = default;
41 public:
42 static ServiceInstanceRef createRef(IServiceInstance* p)
43 {
44 return ServiceInstanceRef(RefType::create(p));
45 }
46 static ServiceInstanceRef createRefNoDestroy(IServiceInstance* p)
47 {
48 return ServiceInstanceRef(RefType::_createNoDestroy(p));
49 }
50 static ServiceInstanceRef createWithHandle(IServiceInstance* p,Internal::ExternalRef handle)
51 {
52 return ServiceInstanceRef(RefType::createWithHandle(p,handle));
53 }
54 public:
55 IServiceInstance* get() const { return m_instance.get(); }
56 void reset() { m_instance.reset(); }
57 private:
58 RefType m_instance;
59};
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64inline bool operator==(const ServiceInstanceRef& a,const ServiceInstanceRef& b)
65{
66 return a.get()==b.get();
67}
68
69inline bool operator!=(const ServiceInstanceRef& a,const ServiceInstanceRef& b)
70{
71 return a.get()!=b.get();
72}
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77} // End namespace Arcane
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82#endif
Interface d'une instance d'un service.
Definition IService.h:67
Référence à une instance.
Référence sur une instance de service.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-