Console: Implement short-option and non-option parsing
[senf.git] / Socket / FileHandle.cci
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief FileHandle inline non-template implementation
25  */
26
27 //#include "FileHandle.ih"
28
29 // Custom includes
30 #include "../Utils/senfassert.hh"
31 #include <errno.h>
32 #include "../Utils/Exception.hh"
33
34 #define prefix_ inline
35 ///////////////////////////////cci.p///////////////////////////////////////
36
37 ///////////////////////////////////////////////////////////////////////////
38 // senf::FileBody
39
40 prefix_ senf::FileBody::FileBody(int fd)
41     : fd_(fd)
42 {}
43
44 prefix_ senf::FileHandle senf::FileBody::handle()
45 {
46     return FileHandle(ptr(this));
47 }
48
49 prefix_ int senf::FileBody::fd()
50     const
51 {
52     return fd_;
53 }
54
55 prefix_ void senf::FileBody::fd(int fd)
56 {
57     fd_ = fd;
58 }
59
60 prefix_ bool senf::FileBody::eof()
61     const
62 {
63     return v_eof();
64 }
65
66 prefix_ bool senf::FileBody::valid()
67     const
68 {
69     return fd_!=-1 && v_valid();
70 }
71
72 prefix_ bool senf::FileBody::readable()
73     const
74 {
75     return pollCheck(fd(),true);
76 }
77
78 prefix_ void senf::FileBody::waitReadable()
79     const
80 {
81     pollCheck(fd(),true,true);
82 }
83
84 prefix_ bool senf::FileBody::writeable()
85     const
86 {
87     return pollCheck(fd(),false);
88 }
89
90 prefix_ void senf::FileBody::waitWriteable()
91     const
92 {
93     pollCheck(fd(),false,true);
94 }
95
96 ///////////////////////////////////////////////////////////////////////////
97 // senf::FileHandle
98
99 prefix_ senf::FileBody & senf::FileHandle::body()
100 {
101     SENF_ASSERT(body_);
102     return *body_;
103 }
104
105 prefix_ senf::FileBody const & senf::FileHandle::body()
106     const
107 {
108     SENF_ASSERT(body_);
109     return *body_;
110 }
111
112 prefix_ void senf::FileHandle::close()
113 {
114     body().close();
115 }
116
117 prefix_ void senf::FileHandle::terminate()
118 {
119     body().terminate();
120 }
121
122 prefix_ bool senf::FileHandle::readable()
123     const
124 {
125     return body().readable();
126 }
127
128 prefix_ void senf::FileHandle::waitReadable()
129     const
130 {
131     body().waitReadable();
132 }
133
134 prefix_ bool senf::FileHandle::writeable()
135     const
136 {
137     return body().writeable();
138 }
139
140 prefix_ void senf::FileHandle::waitWriteable()
141     const
142 {
143     body().waitWriteable();
144 }
145
146 prefix_ bool senf::FileHandle::blocking()
147     const
148 {
149     return body().blocking();
150 }
151
152 prefix_ void senf::FileHandle::blocking(bool status)
153 {
154     body().blocking(status);
155 }
156
157 prefix_ bool senf::FileHandle::eof()
158     const
159 {
160     return body().eof();
161 }
162
163 prefix_ bool senf::FileHandle::valid()
164     const
165 {
166     return body_ && body().valid();
167 }
168
169 prefix_ bool senf::FileHandle::boolean_test()
170     const
171 {
172     return valid() && !eof();
173 }
174
175 prefix_ int senf::FileHandle::fd()
176     const
177 {
178     return body().fd();
179 }
180
181 prefix_ senf::FileHandle::FileHandle()
182     : body_(0)
183 {}
184
185 prefix_ senf::FileHandle::~FileHandle()
186 {
187     if (body_ && ! body().is_shared())
188         body().destroyClose();
189 }
190
191 prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
192     : body_(body.release())
193 {}
194
195 prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
196     : body_(body)
197 {}
198
199 prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle)
200 {
201     return handle.body();
202 }
203
204 prefix_ senf::FileBody const &
205 senf::FileHandle::body(FileHandle const & handle)
206 {
207     return handle.body();
208 }
209
210 prefix_ void senf::FileHandle::fd(int fd)
211 {
212     body().fd(fd);
213 }
214
215 prefix_ senf::FileHandle::FileHandle
216 senf::FileHandle::cast_static(FileHandle handle)
217 {
218     return handle;
219 }
220
221 prefix_ senf::FileHandle
222 senf::FileHandle::cast_dynamic(FileHandle handle)
223 {
224     return handle;
225 }
226
227 prefix_ int senf::retrieve_filehandle(FileHandle handle)
228 {
229     return handle.fd();
230 }
231
232 ///////////////////////////////cci.e///////////////////////////////////////
233 #undef prefix_
234
235 \f
236 // Local Variables:
237 // mode: c++
238 // fill-column: 100
239 // c-file-style: "senf"
240 // indent-tabs-mode: nil
241 // ispell-local-dictionary: "american"
242 // compile-command: "scons -u test"
243 // comment-column: 40
244 // End: