TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
OBuffer.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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#include <OBuffer.h>
16#include <assert.h>
17
19 precision_(8), buf_(0)
20{
21 new_buffer();
22}
23
25{
26 ostream_ = std::make_unique<std::ostringstream>();
27 // Typed view - memory is managed by Sortie:
28 buf_ = static_cast<std::ostringstream *>(ostream_.get());
29
30 buf_->setf(ios::scientific);
31 buf_->precision(precision_);
32}
33
35{
36 precision_ = i;
37 buf_->precision(i);
38}
39
41{
42 return (int)buf_->precision();
43}
44/*! @brief Force l'ecriture sur disque des donnees dans le tampon Utilise l'implementation de la classe ofstream
45 *
46 * @return (Sortie&) *this
47 */
49{
50 return *this;
51}
52
53/*! @brief ajoute le caractere nul a la fin du buffer pour en faire une chaine de caracteres valide.
54 *
55 * len() renvoie la longueur du buffer, y compris le \0
56 * Voir Ecr_Fic_Par::syncfile()
57 *
58 */
60{
61 assert(! bin_); // Ca n'a pas de sens en binaire
62 buf_->put('\0');
63}
64
65/*! @brief Renvoie un pointeur sur le debut du buffer.
66 *
67 */
68const char* OBuffer::str()
69{
70 // Need a copy:
71 string_ = std::string(buf_->str());
72 return string_.c_str();
73}
74
75// Renvoie le nombre d'octets contenus dans le buffer.
77{
78 return (int)buf_->tellp();
79}
bool bin_
Is this a binary flux?
Definition AbstractIO.h:50
int len()
Definition OBuffer.cpp:76
int get_precision()
Definition OBuffer.cpp:40
void new_buffer()
Definition OBuffer.cpp:24
const char * str()
Renvoie un pointeur sur le debut du buffer.
Definition OBuffer.cpp:68
Sortie & flush() override
Force l'ecriture sur disque des donnees dans le tampon Utilise l'implementation de la classe ofstream...
Definition OBuffer.cpp:48
void put_null_char()
ajoute le caractere nul a la fin du buffer pour en faire une chaine de caracteres valide.
Definition OBuffer.cpp:59
OBuffer()
Definition OBuffer.cpp:18
void precision(int) override
Definition OBuffer.cpp:34
Sortie()
Definition Sortie.cpp:26
std::unique_ptr< ostream > ostream_
Definition Sortie.h:116