Arcane  v4.1.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
arcane/src/arcane/utils/Convert.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/* Convert.cc (C) 2000-2025 */
9/* */
10/* Fonctions pour convertir un type en un autre. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14//#include "arcane/utils/Convert.h"
15
16#include "arcane/utils/ValueConvert.h"
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20/*!
21 * \brief Fonctions pour convertir un type en un autre.
22 * \namespace Arcane::Convert
23 */
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33static char global_hexa[16] = {'0','1', '2', '3', '4', '5', '6', '7', '8', '9',
34 'a', 'b', 'c', 'd', 'e', 'f' };
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace
40{
42_toHexaString(Span<const std::byte> input)
43{
44 UniqueArray<Byte> out_buf;
45 Int64 len = input.size();
46 out_buf.resize((len*2)+1);
47 for( Int64 i=0; i<len; ++i ){
48 int v = std::to_integer<int>(input[i]);
49 out_buf[(i*2)] = global_hexa[v/16];
50 out_buf[(i*2)+1] = global_hexa[v%16];
51 }
52 out_buf[len*2] = '\0';
53 return String(out_buf);
54}
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
62{
63 return _toHexaString(input);
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
71{
72 return _toHexaString(asBytes(Span<const Byte>(input)));
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
79toHexaString(Int64 input,Span<Byte> output)
80{
81 for (Integer i=0; i<8; ++i ){
82 Byte v = (Byte)(input % 256);
83 output[(i*2)] = global_hexa[v/16];
84 output[(i*2)+1] = global_hexa[v%16];
85 input = input / 256;
86 }
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93toHexaString(Real input)
94{
95 return toHexaString(ByteConstArrayView(sizeof(Real),(Byte*)&input));
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101} // End namespace Arcane
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Definition Span.h:304
Vue d'un tableau d'éléments de type T.
Definition Span.h:612
Chaîne de caractères unicode.
String toHexaString(ByteConstArrayView input)
Converti un tableau d'octet en sa représentation hexadécimale.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
double Real
Type représentant un réel.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets non modifiables.
Definition Span.h:989
ConstArrayView< Byte > ByteConstArrayView
Equivalent C d'un tableau à une dimension de caractères.
Definition UtilsTypes.h:492
unsigned char Byte
Type d'un octet.
Definition BaseTypes.h:43