Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestAutoRef.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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#include <gtest/gtest.h>
9
10#include "arcane/utils/AutoRef.h"
11
12#include <iostream>
13
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17using namespace Arcane;
18
20{
21 public:
22
23 explicit MyClass(Int32 x)
24 : m_value(x)
25 {
26 std::cout << "CREATE_REF value=" << m_value << "\n";
27 }
28 ~MyClass()
29 {
30 std::cout << "DESTROY_REF value=" << m_value << "\n";
31 }
32
33 void addRef()
34 {
35 ++m_nb_ref;
36 std::cout << "ADD_REF n=" << m_nb_ref << " value=" << m_value << "\n";
37 }
38
39 void removeRef()
40 {
41 --m_nb_ref;
42 std::cout << "REMOVE_REF n=" << m_nb_ref << " value=" << m_value << "\n";
43 if (m_nb_ref == 0) {
44 delete this;
45 }
46 }
47
48 private:
49
50 Int32 m_value = 0;
51 Int32 m_nb_ref = 0;
52};
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
57AutoRef2<MyClass> _buildOne(Int32 v)
58{
59 return AutoRef2<MyClass>(new MyClass(v));
60}
61
62AutoRef2<MyClass> _buildTwo(Int32 v1, Int32 v2)
63{
66 ref_v1 = ref_v2;
67 return ref_v1;
68}
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73TEST(TestAutoRef, Misc)
74{
77 ref1 = _buildOne(46);
78 AutoRef2<MyClass> ref3(_buildOne(17));
79 AutoRef2<MyClass> ref4(std::move(_buildTwo(57, 16)));
81 std::cout << "END_OF_TEST\n";
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int32_t Int32
Type entier signé sur 32 bits.