Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
BasicDataType.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* BasicDataType.cc (C) 2000-2023 */
9/* */
10/* Définition des types liés aux données. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15#include "arccore/base/String.h"
16#include "arccore/base/ArgumentException.h"
17#include "arccore/base/FatalErrorException.h"
18
19#include <limits>
20#include <string>
21#include <iostream>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arccore
35{
36namespace
37{
38const char* N_BYTE = "Byte";
39const char* N_BFLOAT16 = "BFloat16";
40const char* N_FLOAT16 = "Float16";
41const char* N_FLOAT32 = "Float32";
42const char* N_FLOAT64 = "Float64";
43const char* N_FLOAT128 = "Float128";
44const char* N_INT8 = "Int8";
45const char* N_INT16 = "Int16";
46const char* N_INT32 = "Int32";
47const char* N_INT64 = "Int64";
48const char* N_INT128 = "Int128";
49const char* N_UNKNOWN = "Unknown";
50const char* N_INVALID = "Invalid";
51
53const char* N_ALL_NAMES[NB_BASIC_DATA_TYPE] =
54 {
55 N_UNKNOWN, N_BYTE,
56 N_FLOAT16, N_FLOAT32, N_FLOAT64, N_FLOAT128,
57 N_INT16, N_INT32, N_INT64, N_INT128,
58 N_BFLOAT16, N_INT8
59 };
60
62int ALL_SIZEOF[NB_BASIC_DATA_TYPE] =
63 {
64 0, 1,
65 2, 4, 8, 16,
66 2, 4, 8, 16,
67 2, 1
68 };
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74extern "C++" const char*
76{
77 Byte b = (Byte)type;
78 if (b>=NB_BASIC_DATA_TYPE)
79 return N_INVALID;
80 return N_ALL_NAMES[b];
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86extern "C++" std::ostream&
87operator<< (std::ostream& ostr,eBasicDataType data_type)
88{
89 ostr << basicDataTypeName(data_type);
90 return ostr;
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96extern "C++" eBasicDataType
97basicDataTypeFromName(const char* name,bool& has_error)
98{
99 has_error = true;
100 std::string_view buf(name);
101 for( int i=0; i<NB_BASIC_DATA_TYPE; ++i ){
102 if (buf==std::string_view(N_ALL_NAMES[i])){
103 has_error = false;
104 return (eBasicDataType)i;
105 }
106 }
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113extern "C++" Integer
115{
116 Byte b = (Byte)type;
117 if (b>=NB_BASIC_DATA_TYPE)
118 throw ArgumentException("basicDataTypeSize()","Invalid datatype");
119 return ALL_SIZEOF[b];
120}
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
126extern "C++" eBasicDataType
127basicDataTypeFromName(const char* name)
128{
129 bool has_error = true;
130 eBasicDataType data_type = basicDataTypeFromName(name,has_error);
131 if (has_error)
132 ARCCORE_FATAL("Bad DataType '{0}'",name);
133 return data_type;
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139extern "C++" std::istream&
140operator>> (std::istream& istr,eBasicDataType& data_type)
141{
142 std::string buf;
143 istr >> buf;
144 bool has_error = true;
145 data_type = basicDataTypeFromName(buf.c_str(),has_error);
146 if (has_error){
147 data_type = eBasicDataType::Unknown;
148 istr.setstate(std::ios_base::failbit);
149 }
150 return istr;
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156} // End namespace Arccore
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
Fichier contenant les définitions des types de données basiques gérés par Arccore.
Exception lorsqu'un argument est invalide.
Espace de nom de Arccore.
Definition ArcaneTypes.h:24
eBasicDataType basicDataTypeFromName(const char *name, bool &has_error)
Trouve le type associé à name.
Int32 Integer
Type représentant un entier.
Integer basicDataTypeSize(eBasicDataType type)
Taille du type de donnée type.
const char * basicDataTypeName(eBasicDataType type)
Nom du type de donnée.
constexpr unsigned char NB_BASIC_DATA_TYPE
Nombre de types de base supportés.
eBasicDataType
Type d'une donnée de base.
@ Unknown
Donnée de type inconnu ou non initialisé
unsigned char Byte
Type d'un octet.
Definition BaseTypes.h:43