TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
InputCommBuffer.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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 <InputCommBuffer.h>
17#include <OutputCommBuffer.h>
18#include <assert.h>
19
21{
23 bin_ = 1;
24 // Communication buffer should never try to convert int into long:
25 avoid_conversion_ = true;
26 memorysize_ = 16;
27 size_ = 0;
28 // On alloue toujours quelque chose (create_stream a besoin d'un octet au moins
29 // pour creer un stream de taille nulle)
30 buffer_ = new char[memorysize_]();
31 stream_ = 0;
32}
33
35{
36 assert(stream_ == 0);
37 delete[] buffer_;
38 buffer_ = 0;
39 size_ = 0;
40 memorysize_ = 0;
41}
42
44{
45 assert(stream_ == 0);
46 size_ = bufsize;
47 if (size_ > memorysize_)
48 {
49 delete[] buffer_;
50 memorysize_ = size_ * 2;
51 buffer_ = new char[memorysize_]();
52 }
53 return buffer_;
54}
55
57{
58 assert(stream_ == 0);
59 assert(size_ >= 0);
60 // (Voir documentation de istrstream) :
61 // Si size_ > 0 istrstream(buf, size_) cree un buffer de taille size_.
62 // Si size_ = 0, istrstream(buf, size_) suppose que buf est une chaine
63 // de caracteres terminee par zero. Pour creer un stream de taille nulle,
64 // il faut donc faire ceci:
65 if (size_ == 0)
66 buffer_[0] = 0;
67 stream_ = new istringstream(std::string(buffer_, size_));
68 set_istream(stream_);
69}
70
72{
73 assert(stream_ == 0);
74 const char nullchar = 0;
75 const char * buffer = output_buf.get_buffer();
76 const int size = output_buf.get_buffer_size();
77 // (Voir documentation de istrstream) :
78 // Si size_ > 0 istrstream(buf, size_) cree un buffer de taille size_.
79 // Si size_ = 0, istrstream(buf, size_) suppose que buf est une chaine
80 // de caracteres terminee par zero. Pour creer un stream de taille nulle,
81 // il faut donc faire ceci:
82 if (size == 0)
83 buffer = &nullchar;
84 stream_ = new istringstream(std::string(buffer, size));
85 set_istream(stream_);
86}
87
89{
90 assert(stream_);
91#ifndef TRUST_USE_UVM // ToDo bug ?
92 delete stream_;
93#endif
94 stream_ = 0;
95 set_istream(stream_);
96 size_ = -1;
97}
bool bin_
Is this a binary flux?
Definition AbstractIO.h:50
bool avoid_conversion_
Definition AbstractIO.h:57
@ ERROR_CONTINUE
Definition Entree.h:93
virtual void set_error_action(Error_Action)
Change le comportement en cas d'erreur de l'entree, voir error_handle_() et get_error_action().
Definition Entree.cpp:382
void set_istream(istream *is)
Definition Entree.cpp:50
char * reserve_buffer(int bufsize)
~InputCommBuffer() override
void create_stream_from_output_stream(OutputCommBuffer &)
: Classe outil utilisee exclusivement par Schema_Comm.
const char * get_buffer()