[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / IOStream.h
blob8a135a5e4262d376952c633592ba7d1486ca2a38
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file IOStream.h
7 * $Id: IOStream.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author James CE Johnson <jcej@lads.com>
10 * @author Jim Crossley <jim@lads.com>
12 //=============================================================================
14 #ifndef ACE_IOSTREAM_H
15 #define ACE_IOSTREAM_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/ACE_export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 // Needed on Windows for streambuf
25 // FUZZ: disable check_for_streams_include
26 #include "ace/streams.h"
28 // This is a temporary restriction - ACE_IOStream is only enabled if the
29 // compiler does not supply the standard C++ library (and standard iostreams)
30 // or, if it does, the platform is explicitly set to use old iostreams
31 // by its config.h file.
32 // This restriction is recorded in Bugzilla entry 857.
33 #if defined (ACE_HAS_STANDARD_CPP_LIBRARY) && (ACE_HAS_STANDARD_CPP_LIBRARY == 1)
34 # if !defined (ACE_USES_OLD_IOSTREAMS) && !defined (ACE_LACKS_ACE_IOSTREAM)
35 # define ACE_LACKS_ACE_IOSTREAM
36 # endif /* !ACE_USES_OLD_IOSTREAMS && !ACE_LACKS_ACE_IOSTREAM */
37 #endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
39 #if !defined (ACE_LACKS_ACE_IOSTREAM)
41 # if defined (ACE_HAS_STRING_CLASS)
42 # if defined (ACE_WIN32) && defined (_MSC_VER)
43 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
44 typedef CString ACE_IOStream_String;
45 ACE_END_VERSIONED_NAMESPACE_DECL
46 # else
47 # if !defined (ACE_HAS_STDCPP_STL_INCLUDES)
48 #include /**/ <String.h>
49 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
50 typedef String ACE_IOStream_String;
51 ACE_END_VERSIONED_NAMESPACE_DECL
52 # else
53 # include /**/ <string>
55 # if defined(ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
56 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
57 typedef std::string ACE_IOStream_String;
58 ACE_END_VERSIONED_NAMESPACE_DECL
59 # else
60 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
61 typedef string ACE_IOStream_String;
62 ACE_END_VERSIONED_NAMESPACE_DECL
63 # endif /* ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB */
64 # endif /* ! ACE_HAS_STDCPP_STL_INCLUDES */
65 # endif /* ACE_WIN32 && defined (_MSC_VER) */
67 # if defined (__DECCXX_VER)
68 # if __DECCXX_VER < 50700000
69 # include /**/ <stl_macros>
70 # else
71 # include /**/ <stdcomp>
72 # endif /* __DECCXX_VER < 50700000 */
73 # endif /* __DECCXX_VER */
75 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
77 class ACE_Export ACE_Quoted_String : public ACE_IOStream_String
79 public:
80 inline ACE_Quoted_String (void) { *this = ""; }
81 inline ACE_Quoted_String (const char *c) { *this = ACE_IOStream_String (c); }
82 inline ACE_Quoted_String (const ACE_IOStream_String &s) { *this = s; }
83 inline ACE_Quoted_String &operator= (const ACE_IOStream_String& s)
85 return (ACE_Quoted_String &) ACE_IOStream_String::operator= (s);
87 inline ACE_Quoted_String &operator = (const char c) {
88 return (ACE_Quoted_String &) ACE_IOStream_String::operator= (c);
90 inline ACE_Quoted_String &operator = (const char *c) {
91 return (ACE_Quoted_String &) ACE_IOStream_String::operator= (c);
93 inline bool operator < (const ACE_Quoted_String &s) const {
94 return *(ACE_IOStream_String *) this < (ACE_IOStream_String) s;
96 # if defined (ACE_WIN32) && defined (_MSC_VER)
97 inline int length (void) { return this->GetLength (); }
98 # endif /* ACE_WIN32 && defined (_MSC_VER) */
101 ACE_END_VERSIONED_NAMESPACE_DECL
103 # endif /* ACE_HAS_STRING_CLASS */
105 # include "ace/Time_Value.h"
106 # include "ace/os_include/sys/os_types.h"
108 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
111 * @class ACE_Streambuf
113 * @brief Create your custom streambuf by providing and ACE_*_Stream
114 * object to this template. I have tested it with
115 * ACE_SOCK_Stream and it should work fine for others as well.
117 * For any iostream object, the real work is done by the
118 * underlying streambuf class. That is what we create here.
119 * A streambuf has an internal buffer area into which data is
120 * read and written as the iostream requests and provides data.
121 * At some point during the read process, the iostream will
122 * realize that the streambuf has no more data. The underflow
123 * function of the streambuf is then called.
124 * Likewise, during the write process, the iostream will
125 * eventually notice that the streabuf's buffer has become full
126 * and will invoke the overflow function.
127 * The empty/full state of the read/write "buffers" are
128 * controled by two sets pointers. One set is dedicated to
129 * read, the other to write. These pointers, in turn, reference
130 * a common buffer that is to be shared by both read and write
131 * operations. It is this common buffer to which data is
132 * written and from which it is read.
133 * The common buffer is used by functions of the streambuf as
134 * well as the iostream. Because of this and the fact that it
135 * is "shared" by both read and write operators, there is a
136 * danger of data corruption if read and write operations are
137 * allowed to take place "at the same time".
138 * To prevent data corruption, we manipulate the read and write
139 * pointer sets so that the streambuf is in either a read-mode
140 * or write-mode at all times and can never be in both modes at
141 * the same time.
142 * In the constructor: set the read and write sets to NULL This
143 * causes the underflow or overflow operators to be invoked at
144 * the first IO activity of the iostream.
145 * In the underflow function we arrange for the common buffer to
146 * reference our read buffer and for the write pointer set to be
147 * disabled. If a write operation is performed by the iostream
148 * this will cause the overflow function to be invoked.
149 * In the overflow function we arrange for the common buffer to
150 * reference our write buffer and for the read pointer set to be
151 * disabled. This causes the underflow function to be invoked
152 * when the iostream "changes our mode".
153 * The overflow function will also invoke the send_n function to
154 * flush the buffered data to our peer. Similarly, the sync and
155 * syncout functions will cause send_n to be invoked to send the
156 * data.
157 * Since socket's and the like do not support seeking, there can
158 * be no method for "syncing" the input. However, since we
159 * maintain separate read/write buffers, no data is lost by
160 * "syncing" the input. It simply remains buffered.
162 class ACE_Export ACE_Streambuf : public streambuf
164 public:
167 * If the default allocation strategey were used the common buffer
168 * would be deleted when the object destructs. Since we are
169 * providing separate read/write buffers, it is up to us to manage
170 * their memory.
172 virtual ~ACE_Streambuf (void);
174 /// Get the current Time_Value pointer and provide a new one.
175 ACE_Time_Value *recv_timeout (ACE_Time_Value *tv = 0);
178 * Use this to allocate a new/different buffer for put operations.
179 * If you do not provide a buffer pointer, one will be allocated.
180 * That is the preferred method. If you do provide a buffer, the
181 * size must match that being used by the get buffer. If
182 * successful, you will receive a pointer to the current put buffer.
183 * It is your responsibility to delete this memory when you are done
184 * with it.
186 char *reset_put_buffer (char *newBuffer = 0,
187 u_int _streambuf_size = 0,
188 u_int _pptr = 0 );
190 /// Return the number of bytes to be 'put' onto the stream media.
191 /// pbase + put_avail = pptr
192 u_int put_avail (void);
195 * Use this to allocate a new/different buffer for get operations.
196 * If you do not provide a buffer pointer, one will be allocated.
197 * That is the preferred method. If you do provide a buffer, the
198 * size must match that being used by the put buffer. If
199 * successful, you will receive a pointer to the current get buffer.
200 * It is your responsibility to delete this memory when you are done
201 * with it.
203 char *reset_get_buffer (char *newBuffer = 0,
204 u_int _streambuf_size = 0,
205 u_int _gptr = 0,
206 u_int _egptr = 0);
208 /// Return the number of bytes not yet gotten. eback + get_waiting =
209 /// gptr
210 u_int get_waiting (void);
212 /// Return the number of bytes in the get area (includes some already
213 /// gotten); eback + get_avail = egptr
214 u_int get_avail (void);
216 /// Query the streambuf for the size of its buffers.
217 u_int streambuf_size (void);
219 /// Did we take an error because of an IO operation timeout?
220 /// @note Invoking this resets the flag.
221 u_char timeout (void);
223 protected:
224 ACE_Streambuf (u_int streambuf_size,
225 int io_mode);
227 /// Sync both input and output. See syncin/syncout below for
228 /// descriptions.
229 virtual int sync (void);
231 // = Signatures for the underflow/overflow discussed above.
232 virtual int underflow (void);
234 /// The overflow function receives the character which caused the
235 /// overflow.
236 virtual int overflow (int c = EOF);
238 /// Resets the <base> pointer and streambuf mode. This is used
239 /// internally when get/put buffers are allocatd.
240 void reset_base (void);
242 protected:
243 // = Two pointer sets for manipulating the read/write areas.
244 char *eback_saved_;
245 char *gptr_saved_;
246 char *egptr_saved_;
247 char *pbase_saved_;
248 char *pptr_saved_;
249 char *epptr_saved_;
251 // = With cur_mode_ we keep track of our current IO mode.
253 // This helps us to optimize the underflow/overflow functions.
254 u_char cur_mode_;
255 const u_char get_mode_;
256 const u_char put_mode_;
258 /// mode tells us if we're working for an istream, ostream, or
259 /// iostream.
260 int mode_;
262 /// This defines the size of the input and output buffers. It can be
263 /// set by the object constructor.
264 const u_int streambuf_size_;
266 /// Did we take an error because of an IO operation timeout?
267 u_char timeout_;
269 /// We want to allow the user to provide Time_Value pointers to
270 /// prevent infinite blocking while waiting to receive data.
271 ACE_Time_Value recv_timeout_value_;
272 ACE_Time_Value *recv_timeout_;
275 * syncin is called when the input needs to be synced with the
276 * source file. In a filebuf, this results in the <seek> system
277 * call being used. We can't do that on socket-like connections, so
278 * this does basically nothing. That's safe because we have a
279 * separate read buffer to maintain the already-read data. In a
280 * filebuf, the single common buffer is used forcing the <seek>
281 * call.
283 int syncin (void);
285 /// syncout is called when the output needs to be flushed. This is
286 /// easily done by calling the peer's send_n function.
287 int syncout (void);
289 /// flushbuf is the worker of syncout. It is a separate function
290 /// because it gets used sometimes in different context.
291 int flushbuf (void);
294 * fillbuf is called in a couple of places. This is the worker of
295 * underflow. It will attempt to fill the read buffer from the
296 * peer.
298 int fillbuf (void);
301 * Used by fillbuf and others to get exactly one byte from the peer.
302 * recv_n is used to be sure we block until something is available.
303 * It is virtual because we really need to override it for
304 * datagram-derived objects.
306 virtual int get_one_byte (void);
309 * Stream connections and "unconnected connections" (ie --
310 * datagrams) need to work just a little differently. We derive
311 * custom Streambuf objects for them and provide these functions at
312 * that time.
314 virtual ssize_t send (char *buf,
315 ssize_t len) = 0;
316 virtual ssize_t recv (char *buf,
317 ssize_t len,
318 ACE_Time_Value *tv = 0) = 0;
319 virtual ssize_t recv (char *buf,
320 ssize_t len,
321 int flags,
322 ACE_Time_Value *tv = 0) = 0;
323 virtual ssize_t recv_n (char *buf,
324 ssize_t len,
325 int flags = 0,
326 ACE_Time_Value *tv = 0) = 0;
328 virtual ACE_HANDLE get_handle (void);
330 # if defined (ACE_HAS_STANDARD_CPP_LIBRARY) && (ACE_HAS_STANDARD_CPP_LIBRARY != 0) && !defined (ACE_USES_OLD_IOSTREAMS)
331 char *base (void) const
333 return cur_mode_ == get_mode_ ? eback_saved_
334 : cur_mode_ == put_mode_ ? pbase_saved_
335 : 0;
337 char *ebuf (void) const
339 return cur_mode_ == 0 ? 0 : base () + streambuf_size_;
342 int blen (void) const
344 return streambuf_size_;
347 void setb (char* b, char* eb, int /* a */=0)
349 setbuf (b, (eb - b));
352 int out_waiting (void)
354 return pptr () - pbase ();
356 # endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
359 ACE_END_VERSIONED_NAMESPACE_DECL
361 ///////////////////////////////////////////////////////////////////////////
363 // These typedefs are provided by G++ (on some systems?) without the
364 // trailing '_'. Since we can't count on 'em, I've defined them to
365 // what GNU wants here.
367 typedef ios& (*__manip_)(ios&);
368 typedef istream& (*__imanip_)(istream&);
369 typedef ostream& (*__omanip_)(ostream&);
371 // Trying to do something like is shown below instead of using the
372 // __*manip typedefs causes Linux do segfault when "<<endl" is done.
374 // virtual MT& operator<<(ios& (*func)(ios&)) { (*func)(*this); return *this; }
376 // This macro defines the get operator for class MT into datatype DT.
377 // We will use it below to quickly override most (all?) iostream get
378 // operators. Notice how the <ipfx> and <isfx> functions are used.
380 #define GET_SIG(MT,DT) inline virtual MT& operator>> (DT v)
381 # if (defined (__SUNPRO_CC) && __SUNPRO_CC > 0x510)
382 #define GET_CODE { \
383 if (ipfx (0)) \
385 (*((istream*)this)) >> (v); \
387 isfx (); \
388 return *this; \
390 # else
391 #define GET_CODE { \
392 if (ipfx (0)) \
394 iostream::operator>> (v); \
396 isfx (); \
397 return *this; \
399 # endif
400 #define GET_PROT(MT,DT,CODE) GET_SIG(MT,DT) CODE
401 #define GET_FUNC(MT,DT) GET_PROT(MT,DT,GET_CODE)
403 // This macro defines the put operator for class MT into datatype DT.
404 // We will use it below to quickly override most (all?) iostream put
405 // operators. Notice how the <opfx> and <osfx> functions are used.
407 #define PUT_SIG(MT,DT) inline virtual MT& operator<< (DT v)
408 # if (defined (__SUNPRO_CC) && __SUNPRO_CC > 0x510)
409 #define PUT_CODE { \
410 if (opfx ()) \
412 (*((ostream *) this)) << (v); \
414 osfx (); \
415 return *this; \
417 # else
418 #define PUT_CODE { \
419 if (opfx ()) \
421 iostream::operator<< (v); \
423 osfx (); \
424 return *this; \
426 # endif
427 #define PUT_PROT(MT,DT,CODE) PUT_SIG(MT,DT) CODE
428 #define PUT_FUNC(MT,DT) PUT_PROT(MT,DT,PUT_CODE)
431 // These are necessary in case somebody wants to derive from us and
432 // override one of these with a custom approach.
434 # if defined (ACE_LACKS_CHAR_RIGHT_SHIFTS)
435 #define GET_FUNC_SET0(MT,CODE,CODE2) \
436 GET_PROT(MT,short &,CODE) \
437 GET_PROT(MT,u_short &,CODE) \
438 GET_PROT(MT,int &,CODE) \
439 GET_PROT(MT,u_int &,CODE) \
440 GET_PROT(MT,long &,CODE) \
441 GET_PROT(MT,u_long &,CODE) \
442 GET_PROT(MT,float &,CODE) \
443 GET_PROT(MT,double &,CODE) \
444 inline virtual MT& operator>>(__omanip_ func) CODE2 \
445 inline virtual MT& operator>>(__manip_ func) CODE2
446 # else
447 #define GET_FUNC_SET0(MT,CODE,CODE2) \
448 GET_PROT(MT,short &,CODE) \
449 GET_PROT(MT,u_short &,CODE) \
450 GET_PROT(MT,int &,CODE) \
451 GET_PROT(MT,u_int &,CODE) \
452 GET_PROT(MT,long &,CODE) \
453 GET_PROT(MT,u_long &,CODE) \
454 GET_PROT(MT,float &,CODE) \
455 GET_PROT(MT,double &,CODE) \
456 GET_PROT(MT,char &,CODE) \
457 GET_PROT(MT,u_char &,CODE) \
458 GET_PROT(MT,char *,CODE) \
459 GET_PROT(MT,u_char *,CODE) \
460 inline virtual MT& operator>>(__omanip_ func) CODE2 \
461 inline virtual MT& operator>>(__manip_ func) CODE2
462 # endif
464 #define PUT_FUNC_SET0(MT,CODE,CODE2) \
465 PUT_PROT(MT,short,CODE) \
466 PUT_PROT(MT,u_short,CODE) \
467 PUT_PROT(MT,int,CODE) \
468 PUT_PROT(MT,u_int,CODE) \
469 PUT_PROT(MT,long,CODE) \
470 PUT_PROT(MT,u_long,CODE) \
471 PUT_PROT(MT,float,CODE) \
472 PUT_PROT(MT,double,CODE) \
473 PUT_PROT(MT,char,CODE) \
474 PUT_PROT(MT,u_char,CODE) \
475 PUT_PROT(MT,const char *,CODE) \
476 PUT_PROT(MT,u_char *,CODE) \
477 PUT_PROT(MT,void *,CODE) \
478 inline virtual MT& operator<<(__omanip_ func) CODE2 \
479 inline virtual MT& operator<<(__manip_ func) CODE2
481 # if defined (ACE_LACKS_SIGNED_CHAR)
482 #define GET_FUNC_SET1(MT,CODE,CODE2) GET_FUNC_SET0(MT,CODE,CODE2)
483 #define PUT_FUNC_SET1(MT,CODE,CODE2) PUT_FUNC_SET0(MT,CODE,CODE2)
484 # else
485 #define GET_FUNC_SET1(MT,CODE,CODE2) \
486 GET_PROT(MT,signed char &,CODE) \
487 GET_PROT(MT,signed char *,CODE) \
488 GET_FUNC_SET0(MT,CODE,CODE2)
490 #define PUT_FUNC_SET1(MT,CODE,CODE2) \
491 PUT_FUNC(MT,signed char) \
492 PUT_FUNC(MT,const signed char *) \
493 PUT_FUNC_SET0(MT,CODE,CODE2)
494 # endif /* ACE_LACKS_SIGNED_CHAR */
496 #define GET_MANIP_CODE { if (ipfx ()) { (*func) (*this); } isfx (); return *this; }
497 #define PUT_MANIP_CODE { if (opfx ()) { (*func) (*this); } osfx (); return *this; }
499 #define GET_FUNC_SET(MT) GET_FUNC_SET1(MT,GET_CODE,GET_MANIP_CODE)
500 #define PUT_FUNC_SET(MT) PUT_FUNC_SET1(MT,PUT_CODE,PUT_MANIP_CODE)
501 #define GETPUT_FUNC_SET(MT) GET_FUNC_SET(MT) PUT_FUNC_SET(MT)
503 #define GET_SIG_SET(MT) GET_FUNC_SET1(MT,= 0;,= 0;)
504 #define PUT_SIG_SET(MT) PUT_FUNC_SET1(MT,= 0;,= 0;)
505 #define GETPUT_SIG_SET(MT) GET_SIG_SET(MT) PUT_SIG_SET(MT)
507 // Include the templates here.
508 # include "ace/IOStream_T.h"
509 #endif /* !ACE_LACKS_ACE_IOSTREAM && ACE_USES_OLD_IOSTREAMS */
511 #include /**/ "ace/post.h"
512 #endif /* ACE_IOSTREAM_H */