Orocos Real-Time Toolkit  2.9.0
rtstreams.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon May 10 19:10:29 CEST 2004 rtstreams.cxx
3 
4  rtstreams.cxx - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 #include "os/rtstreams.hpp"
38 #include "os/fosi.h"
39 #include <cstring>
40 
41 namespace RTT
42 {namespace os
43 {
44 
46 
48  {}
49 
51  {
52  buf.sputn( c, n);
53  return *this;
54  }
55 
57  {
58  buf.sputc( c );
59  return *this;
60  }
61 
63  {
64  buf.sgetn(c,n);
65  return *this;
66  }
67 
69  {
70  return buf.sgetn(c,n);
71  }
72 
74  {
75  c = buf.sgetc();
76  return *this;
77  }
78 
80  {
81  streamsize i=0;
82  int res;
83  do {
84  res = buf.sgetc();
85  c[i++] = res;
86  } while ( res != EOF && c[i-1] != delim && i != n );
87 
88  if ( i == n)
89  c[i] = 0;
90  else
91  c[i-1] = 0;
92 
93  return *this;
94  }
95 
96  basic_istreams& basic_istreams::get( char*c, char delim)
97  {
98  streamsize i=0;
99  int res;
100  do {
101  res = buf.sgetc();
102  c[i++] = res;
103  } while ( res != EOF && c[i-1] != delim );
104 
105  c[i-1] = 0;
106 
107  return *this;
108  }
109 
111  {
112  return s << '\n';
113  }
114 
116  {
117  std::string result( int_to_string( i ) );
118  write(result.c_str(), result.length() );
119  return *this;
120  }
121 
123  {
124  std::string result( int_to_string( l ) );
125  write(result.c_str(), result.length() );
126  return *this;
127  }
128 
130  {
131  buf.sputc( c );
132  return *this;
133  }
134 
136  {
137  buf.sputn( c, strlen(c) );
138  return *this;
139  }
140 
142  {
143  return ( *f ) ( *this );
144  }
145 
147  {
148  std::string result( float_to_string( float(f) ) );
149  write( result.c_str(), result.length() );
150  return *this;
151  }
152 
154  {
155  write( s.c_str(), s.length() );
156  return *this;
157  }
158 
160  {
161  std::string result( unsigned_int_to_string( u ) );
162  write( result.c_str(), result.length() );
163  return *this;
164  }
165 
167  {
168  std::string result;
169  result.reserve(10);
170  int i_res = buf.sgetc();
171  while ( (i_res != EOF) && (i_res != ' ') )
172  {
173  result += char(i_res);
174  i_res = buf.sgetc();
175  }
176  i = string_to_int( result );
177  return *this;
178  }
179 
181  {
182  c = buf.sgetc();
183  return *this;
184  }
185 
187  {
188  std::string result;
189  result.reserve(40);
190  int i_res = buf.sgetc();
191  while ( (i_res != EOF) && (i_res != ' ') )
192  {
193  result += char(i_res);
194  i_res = buf.sgetc();
195  }
196  //f = string_to_float( result );
197  f = -1;
198  return * this;
199  }
200 
202  {
203  std::string result;
204  int i_res;
205  do {
206  i_res = buf.sgetc();
207  if (i_res == EOF )
208  break;
209  result += char(i_res);
210  } while ( i_res != ' ' );
211 
212  s = result;
213 
214  return *this;
215  }
216 
218  {
219  std::string result;
220  result.reserve(10);
221  int i_res = buf.sgetc();
222  while ( (i_res != EOF) && (i_res != ' ') )
223  {
224  result += char(i_res);
225  i_res = buf.sgetc();
226  }
227 
228  u = string_to_unsigned_int( result );
229 
230  return *this;
231  }
232 
234  {}
235 
237  {}
238 
239 
241  {}
242 
244  {}
245 
246 
247 }}
virtual basic_ostreams & write(const char *c, streamsize n)
Definition: rtstreams.cpp:50
string float_to_string(float f)
(Almost) Real-Time output streams.
An basic_ostreams is a stream which can be written to.
Definition: rtstreams.hpp:145
virtual ~basic_streams()
Definition: rtstreams.cpp:47
int string_to_int(const string &s)
converts a string to an int
string unsigned_int_to_string(unsigned int u)
unsigned int string_to_unsigned_int(const string &s)
string int_to_string(int i)
basic_ostreams & endl(basic_ostreams &s)
Flush and newline.
Definition: rtstreams.cpp:110
streambufs::streamsize streamsize
Definition: rtstreams.hpp:149
printstream cout
Console Output.
Definition: rtstreams.cpp:45
streamsize readsome(char *c, streamsize n)
Definition: rtstreams.cpp:68
basic_istreams & read(char *c, streamsize n)
Definition: rtstreams.cpp:62
streambufs::streamsize streamsize
Definition: rtstreams.hpp:118
The printstream is a stream for printing characters to the terminal window.
Definition: rtstreams.hpp:200
basic_istreams & operator>>(int &i)
Definition: rtstreams.cpp:166
virtual basic_ostreams & put(char c)
Definition: rtstreams.cpp:56
An basic_istream is a stream which can be read.
Definition: rtstreams.hpp:113
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
basic_ostreams & operator<<(int i)
Operators.
Definition: rtstreams.cpp:115
virtual ~printstream()
Definition: rtstreams.cpp:240