TrioCFD 1.9.9_beta
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 @brief Forces writing of buffered data to disk. Uses the ofstream implementation.
45 *
46 * @return *this
47 */
49{
50 return *this;
51}
52
53/*! @brief Appends a null character at the end of the buffer to make it a valid C string.
54 *
55 * len() returns the buffer length including the null terminator.
56 * See EcrFicPartage::syncfile().
57 *
58 */
60{
61 assert(! bin_); // Makes no sense in binary mode
62 buf_->put('\0');
63}
64
65/*! @brief Returns a pointer to the beginning of the 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// Returns the number of bytes in the 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()
Returns a pointer to the beginning of the buffer.
Definition OBuffer.cpp:68
Sortie & flush() override
Forces writing of buffered data to disk. Uses the ofstream implementation.
Definition OBuffer.cpp:48
void put_null_char()
Appends a null character at the end of the buffer to make it a valid C string.
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