XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
buffer_server.cpp
Aller à la documentation de ce fichier.
1 #include "xios_spl.hpp"
2 #include "exception.hpp"
3 #include "buffer_server.hpp"
4 
5 
6 namespace xios
7 {
8 
10  {
11  size = 3 * buffSize;
12  first = 0;
13  current = 1;
14  end = size;
15  buffer = new char[size]; // use MPI_ALLOC_MEM later?
16  }
17 
19  {
20  delete [] buffer ;
21  }
22 
23 
25  {
26  bool ret ;
27 
28  if (count==0) return true ;
29 
30  if (current>first)
31  {
32  if (current+count<size)
33  {
34  ret=true ;
35  }
36  else if (current+count==size)
37  {
38  if (first>0)
39  {
40  ret=true ;
41  }
42  else
43  {
44  ret=false ;
45  }
46  }
47  else
48  {
49  if (count<first)
50  {
51  ret=true ;
52  }
53  else
54  {
55  ret=false ;
56  }
57  }
58  }
59  else
60  {
61  if (current+count<first)
62  {
63  ret=true ;
64  }
65  else
66  {
67  ret=false ;
68  }
69  }
70 
71  return ret ;
72  }
73 
74 
76  {
77  char* ret ;
78 
79  if (count==0) return buffer+current ;
80 
81  if (current>first)
82  {
83  if (current+count<size)
84  {
85  ret=buffer+current ;
86  current+=count ;
87  }
88  else if (current+count==size)
89  {
90  if (first>0)
91  {
92  ret=buffer+current ;
93  current=0 ;
94  }
95  else
96  {
97  ERROR("void* CServerBuffer::getBuffer(size_t count)",
98  <<"cannot allocate required size in buffer") ;
99  }
100  }
101  else
102  {
103  end=current ;
104  if (count<first)
105  {
106  ret=buffer ;
107  current=count ;
108  }
109  else
110  {
111  ERROR("void* CServerBuffer::getBuffer(size_t count)",
112  <<"cannot allocate required size in buffer") ;
113  }
114  }
115  }
116  else
117  {
118  if (current+count<first)
119  {
120  ret=buffer+current ;
121  current+=count ;
122  }
123  else
124  {
125  ERROR("void* CServerBuffer::getBuffer(size_t count)",
126  <<"cannot allocate required size in buffer") ;
127  }
128  }
129 
130  return ret ;
131  }
132 
134  {
135  if (count==0) return ;
136 
137  if (first==end-1)
138  {
139  first=0 ;
140  count-- ;
141  end=size ;
142  }
143 
144  if (first<=current)
145  {
146  if (first+count <current)
147  {
148  first+=count ;
149  }
150  else
151  {
152  ERROR("void CServerBuffer::freeBuffer(size_t count)",
153  <<"cannot free required size in buffer") ;
154  }
155 
156  }
157  else
158  {
159  if (first+count<end)
160  {
161  first+=count ;
162  }
163  else
164  {
165  ERROR("void CServerBuffer::freeBuffer(size_t count)",
166  <<"cannot free required size in buffer") ;
167  }
168  }
169  }
170 
171 }
int count
Definition: tracer.cpp:26
void freeBuffer(size_t count)
CServerBuffer(StdSize bufSize)
#define xios(arg)
CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar *scalarDestination, CScalar *scalarSource, CReduceScalarToScalar *algo ERROR)("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)",<< "Operation must be defined."<< "Scalar source "<< scalarSource->getId()<< std::endl<< "Scalar destination "<< scalarDestination->getId())
void * getBuffer(size_t count)
bool isBufferFree(size_t count)
std::size_t StdSize
Definition: xios_spl.hpp:49