TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
AbstractIO.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <AbstractIO.h>
17#include <arch.h>
18#include <type_traits>
19
21#ifdef INT_is_64_ // in 64b, we write 64b integers by default. But sometimes (save/restart files for example) we might want to still write 32b.
22 is_64b_(true)
23#else
24 is_64b_(false)
25#endif
26{ }
27
28
29/*! @brief Whether to convert an int into a long when reading/writing out data.
30 *
31 * The rules are:
32 * - for 32 files, everything is read/written as 'int', even if _TYPE_ 'long' (or trustIdType) was requested - overflow is checked
33 * in Entree/Sortie classes
34 * - for 64 files, everything is read/written as 'long', even if _TYPE_ 'int' (or trustIdType) was requested
35 * This is for historical reasons: in the former 64b version of TRUST all int were replaced by long, we need to
36 * keep backward compatibility. When we read a former .sauv file written prior to 1.9.5 for example, all integer values are 'long'.
37 * But we might need to load them in an 'int' variable (for example this is the case with the 'format_sauvegarde'
38 * value in Probleme_base).
39 *
40 * Note however that we can force the file to written in 32b even when running the 64b executable, thanks to the is_64b
41 * flag. This is what we do in Problem_base, save/restart logic.
42 */
43template<typename _TYPE_>
45{
46 static constexpr bool IS_INTEG = std::is_integral<_TYPE_>::value;
47
48 if (!IS_INTEG || avoid_conversion_)
49 return false;
50 else
51 {
52 const bool SAME_BITNESS = (std::is_same<_TYPE_, std::int64_t>::value && is_64b_) // The file being read is 64b and _TYPE_ is 64b (long)
53 || (std::is_same<_TYPE_, std::int32_t>::value && !is_64b_); // The file being read is 32b and _TYPE_ is 32b (int)
54 return !SAME_BITNESS;
55 }
56}
57
58template bool AbstractIO::must_convert<int>() const;
59template bool AbstractIO::must_convert<unsigned>() const;
60template bool AbstractIO::must_convert<unsigned long>() const;
61template bool AbstractIO::must_convert<long>() const;
62template bool AbstractIO::must_convert<long long>() const;
63template bool AbstractIO::must_convert<float>() const;
64template bool AbstractIO::must_convert<double>() const;
65
66
67
bool is_64b_
Will we be reading/writing in 64b? (Init in ctor to avoid including arch.h probably).
Definition AbstractIO.h:51
bool avoid_conversion_
Definition AbstractIO.h:57
bool must_convert() const
Whether to convert an int into a long when reading/writing out data.