[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / CDR_Base.h
blob9c5851b220635c744dbc18f1bc9533821b001e46
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file CDR_Base.h
7 * $Id: CDR_Base.h 82088 2008-06-19 16:22:16Z shuston $
9 * ACE Common Data Representation (CDR) basic types.
11 * The current implementation assumes that the host has 1-byte,
12 * 2-byte and 4-byte integral types, and that it has single
13 * precision and double precision IEEE floats.
14 * Those assumptions are pretty good these days, with Crays being
15 * the only known exception.
18 * @author TAO version by
19 * @author Aniruddha Gokhale <gokhale@cs.wustl.edu>
20 * @author Carlos O'Ryan<coryan@cs.wustl.edu>
21 * @author ACE version by
22 * @author Jeff Parsons <parsons@cs.wustl.edu>
23 * @author Istvan Buki <istvan.buki@euronet.be>
25 //=============================================================================
28 #ifndef ACE_CDR_BASE_H
29 #define ACE_CDR_BASE_H
31 #include /**/ "ace/pre.h"
33 #include /**/ "ace/config-all.h"
35 #if !defined (ACE_LACKS_PRAGMA_ONCE)
36 # pragma once
37 #endif /* ACE_LACKS_PRAGMA_ONCE */
39 #include "ace/Basic_Types.h"
40 #include "ace/Default_Constants.h"
42 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
44 // Stuff used by the ACE CDR classes. Watch these values... they're also used
45 // in the ACE_CDR Byte_Order enum below.
46 #if defined ACE_LITTLE_ENDIAN
47 # define ACE_CDR_BYTE_ORDER 1
48 // little endian encapsulation byte order has value = 1
49 #else /* ! ACE_LITTLE_ENDIAN */
50 # define ACE_CDR_BYTE_ORDER 0
51 // big endian encapsulation byte order has value = 0
52 #endif /* ! ACE_LITTLE_ENDIAN */
54 class ACE_Message_Block;
56 /**
57 * @class ACE_CDR
59 * @brief Keep constants and some routines common to both Output and
60 * Input CDR streams.
62 class ACE_Export ACE_CDR
64 public:
65 // = Constants defined by the CDR protocol.
66 // By defining as many of these constants as possible as enums we
67 // ensure they get inlined and avoid pointless static memory
68 // allocations.
70 enum
72 // Note that some of these get reused as part of the standard
73 // binary format: unsigned is the same size as its signed cousin,
74 // float is LONG_SIZE, and double is LONGLONG_SIZE.
76 OCTET_SIZE = 1,
77 SHORT_SIZE = 2,
78 LONG_SIZE = 4,
79 LONGLONG_SIZE = 8,
80 LONGDOUBLE_SIZE = 16,
82 OCTET_ALIGN = 1,
83 SHORT_ALIGN = 2,
84 LONG_ALIGN = 4,
85 LONGLONG_ALIGN = 8,
86 /// @note the CORBA LongDouble alignment requirements do not
87 /// match its size...
88 LONGDOUBLE_ALIGN = 8,
90 /// Maximal CDR 1.1 alignment: "quad precision" FP (i.e. "CDR::Long
91 /// double", size as above).
92 MAX_ALIGNMENT = 8,
94 /// The default buffer size.
95 /**
96 * @todo We want to add options to control this
97 * default value, so this constant should be read as the default
98 * default value ;-)
100 DEFAULT_BUFSIZE = ACE_DEFAULT_CDR_BUFSIZE,
102 /// The buffer size grows exponentially until it reaches this size;
103 /// afterwards it grows linearly using the next constant
104 EXP_GROWTH_MAX = ACE_DEFAULT_CDR_EXP_GROWTH_MAX,
106 /// Once exponential growth is ruled out the buffer size increases
107 /// in chunks of this size, note that this constants have the same
108 /// value right now, but it does not need to be so.
109 LINEAR_GROWTH_CHUNK = ACE_DEFAULT_CDR_LINEAR_GROWTH_CHUNK
113 * @enum Byte_Order
115 * Defines values for the byte_order argument to ACE_OutputCDR and
116 * ACE_InputCDR.
118 enum Byte_Order
120 /// Use big-endian order (also known as network byte order).
121 BYTE_ORDER_BIG_ENDIAN = 0,
122 /// Use little-endian order.
123 BYTE_ORDER_LITTLE_ENDIAN = 1,
124 /// Use whichever byte order is native to this machine.
125 BYTE_ORDER_NATIVE = ACE_CDR_BYTE_ORDER
129 * Do byte swapping for each basic IDL type size. There exist only
130 * routines to put byte, halfword (2 bytes), word (4 bytes),
131 * doubleword (8 bytes) and quadword (16 byte); because those are
132 * the IDL basic type sizes.
134 static void swap_2 (char const *orig, char *target);
135 static void swap_4 (char const *orig, char *target);
136 static void swap_8 (char const *orig, char *target);
137 static void swap_16 (char const *orig, char *target);
138 static void swap_2_array (char const *orig,
139 char *target,
140 size_t length);
141 static void swap_4_array (char const *orig,
142 char *target,
143 size_t length);
144 static void swap_8_array (char const *orig,
145 char *target,
146 size_t length);
147 static void swap_16_array (char const *orig,
148 char *target,
149 size_t length);
151 /// Align the message block to ACE_CDR::MAX_ALIGNMENT,
152 /// set by the CORBA spec at 8 bytes.
153 static void mb_align (ACE_Message_Block *mb);
156 * Compute the size of the smallest buffer that can contain at least
157 * @a minsize bytes.
158 * To understand how a "best fit" is computed look at the
159 * algorithm in the code.
160 * Basically the buffers grow exponentially, up to a certain point,
161 * then the buffer size grows linearly.
162 * The advantage of this algorithm is that is rapidly grows to a
163 * large value, but does not explode at the end.
165 static size_t first_size (size_t minsize);
167 /// Compute not the smallest, but the second smallest buffer that
168 /// will fir @a minsize bytes.
169 static size_t next_size (size_t minsize);
172 * Increase the capacity of mb to contain at least @a minsize bytes.
173 * If @a minsize is zero the size is increased by an amount at least
174 * large enough to contain any of the basic IDL types.
175 * @retval -1 Failure
176 * @retval 0 Success.
178 static int grow (ACE_Message_Block *mb, size_t minsize);
180 /// Copy a message block chain into a single message block,
181 /// preserving the alignment of the first message block of the
182 /// original stream, not the following message blocks.
183 static void consolidate (ACE_Message_Block *dst,
184 const ACE_Message_Block *src);
186 static size_t total_length (const ACE_Message_Block *begin,
187 const ACE_Message_Block *end);
190 * @name Basic OMG IDL Types
192 * These types are for use in the CDR classes. The cleanest way to
193 * avoid complaints from all compilers is to define them all.
195 //@{
196 typedef bool Boolean;
197 typedef unsigned char Octet;
198 typedef char Char;
199 typedef ACE_WCHAR_T WChar;
200 typedef ACE_INT16 Short;
201 typedef ACE_UINT16 UShort;
202 typedef ACE_INT32 Long;
203 typedef ACE_UINT32 ULong;
204 typedef ACE_UINT64 ULongLong;
206 # if (defined (_MSC_VER)) || (defined (__BORLANDC__))
207 typedef __int64 LongLong;
208 # elif ACE_SIZEOF_LONG == 8 && !defined(_CRAYMPP)
209 typedef long LongLong;
210 # elif defined(__TANDEM)
211 typedef long long LongLong;
212 # elif ACE_SIZEOF_LONG_LONG == 8 && !defined (ACE_LACKS_LONGLONG_T)
213 # if defined (sun) && !defined (ACE_LACKS_U_LONGLONG_T)
214 // sun #defines u_longlong_t, maybe other platforms do also.
215 // Use it, at least with g++, so that its -pedantic doesn't
216 // complain about no ANSI C++ long long.
217 typedef longlong_t LongLong;
218 # else
219 // LynxOS 2.5.0 and Linux don't have u_longlong_t.
220 typedef long long LongLong;
221 # endif /* sun */
222 # else /* no native 64 bit integer type */
223 # define NONNATIVE_LONGLONG
224 struct ACE_Export LongLong
226 # if defined (ACE_BIG_ENDIAN)
227 ACE_CDR::Long h;
228 ACE_CDR::Long l;
229 # else
230 ACE_CDR::Long l;
231 ACE_CDR::Long h;
232 # endif /* ! ACE_BIG_ENDIAN */
235 * @name Overloaded Relation Operators.
237 * The canonical comparison operators.
239 //@{
240 bool operator== (const LongLong &rhs) const;
241 bool operator!= (const LongLong &rhs) const;
242 //@}
244 # endif /* no native 64 bit integer type */
246 # if defined (NONNATIVE_LONGLONG)
247 # define ACE_CDR_LONGLONG_INITIALIZER {0,0}
248 # else
249 # define ACE_CDR_LONGLONG_INITIALIZER 0
250 # endif /* NONNATIVE_LONGLONG */
252 # if ACE_SIZEOF_FLOAT == 4
253 typedef float Float;
254 # else /* ACE_SIZEOF_FLOAT != 4 */
255 struct Float
257 # if ACE_SIZEOF_INT == 4
258 // Use unsigned int to get word alignment.
259 unsigned int f;
260 # else /* ACE_SIZEOF_INT != 4 */
261 // Applications will probably have trouble with this.
262 char f[4];
263 # if defined(_UNICOS) && !defined(_CRAYMPP)
264 Float (void);
265 Float (const float &init);
266 Float & operator= (const float &rhs);
267 bool operator!= (const Float &rhs) const;
268 # endif /* _UNICOS */
269 # endif /* ACE_SIZEOF_INT != 4 */
271 # endif /* ACE_SIZEOF_FLOAT != 4 */
273 # if ACE_SIZEOF_DOUBLE == 8
274 typedef double Double;
275 # else /* ACE_SIZEOF_DOUBLE != 8 */
276 struct Double
278 # if ACE_SIZEOF_LONG == 8
279 // Use u long to get word alignment.
280 unsigned long f;
281 # else /* ACE_SIZEOF_INT != 8 */
282 // Applications will probably have trouble with this.
283 char f[8];
284 # endif /* ACE_SIZEOF_INT != 8 */
286 # endif /* ACE_SIZEOF_DOUBLE != 8 */
288 // 94-9-32 Appendix A defines a 128 bit floating point "long
289 // double" data type, with greatly extended precision and four
290 // more bits of exponent (compared to "double"). This is an IDL
291 // extension, not yet standard.
293 # if ACE_SIZEOF_LONG_DOUBLE == 16
294 typedef long double LongDouble;
295 # define ACE_CDR_LONG_DOUBLE_INITIALIZER 0
296 # define ACE_CDR_LONG_DOUBLE_ASSIGNMENT(LHS, RHS) LHS = RHS
297 # else
298 # define NONNATIVE_LONGDOUBLE
299 # define ACE_CDR_LONG_DOUBLE_INITIALIZER {{0}}
300 # define ACE_CDR_LONG_DOUBLE_ASSIGNMENT(LHS, RHS) LHS.assign (RHS)
301 struct ACE_Export LongDouble
303 // VxWorks' compiler (gcc 2.96) gets confused by the operator long
304 // double, so we avoid using long double as the NativeImpl.
305 // Linux's x86 long double format (12 or 16 bytes) is incompatible
306 // with Windows, Solaris, AIX, MacOS X and HP-UX (and probably others)
307 // long double format (8 or 16 bytes). If you need 32-bit Linux to
308 // inter-operate with 64-bit Linux you will want to define this
309 // macro to 0 so that "long double" is used. Otherwise, do not define
310 // this macro.
311 # if defined (ACE_CDR_IMPLEMENT_WITH_NATIVE_DOUBLE) && \
312 (ACE_CDR_IMPLEMENT_WITH_NATIVE_DOUBLE == 1)
313 typedef double NativeImpl;
314 # else
315 typedef long double NativeImpl;
316 # endif /* ACE_CDR_IMPLEMENT_WITH_NATIVE_DOUBLE==1 */
318 char ld[16];
320 LongDouble& assign (const NativeImpl& rhs);
321 LongDouble& assign (const LongDouble& rhs);
323 bool operator== (const LongDouble &rhs) const;
324 bool operator!= (const LongDouble &rhs) const;
326 LongDouble& operator*= (const NativeImpl rhs) {
327 return this->assign (static_cast<NativeImpl> (*this) * rhs);
329 LongDouble& operator/= (const NativeImpl rhs) {
330 return this->assign (static_cast<NativeImpl> (*this) / rhs);
332 LongDouble& operator+= (const NativeImpl rhs) {
333 return this->assign (static_cast<NativeImpl> (*this) + rhs);
335 LongDouble& operator-= (const NativeImpl rhs) {
336 return this->assign (static_cast<NativeImpl> (*this) - rhs);
338 LongDouble& operator++ () {
339 return this->assign (static_cast<NativeImpl> (*this) + 1);
341 LongDouble& operator-- () {
342 return this->assign (static_cast<NativeImpl> (*this) - 1);
344 LongDouble operator++ (int) {
345 LongDouble ldv = *this;
346 this->assign (static_cast<NativeImpl> (*this) + 1);
347 return ldv;
349 LongDouble operator-- (int) {
350 LongDouble ldv = *this;
351 this->assign (static_cast<NativeImpl> (*this) - 1);
352 return ldv;
355 operator NativeImpl () const;
357 # endif /* ACE_SIZEOF_LONG_DOUBLE != 16 */
359 //@}
361 #if !defined (ACE_CDR_GIOP_MAJOR_VERSION)
362 # define ACE_CDR_GIOP_MAJOR_VERSION 1
363 #endif /*ACE_CDR_GIOP_MAJOR_VERSION */
365 #if !defined (ACE_CDR_GIOP_MINOR_VERSION)
366 # define ACE_CDR_GIOP_MINOR_VERSION 2
367 #endif /* ACE_CDR_GIOP_MINOR_VERSION */
370 ACE_END_VERSIONED_NAMESPACE_DECL
372 #if defined (__ACE_INLINE__)
373 # include "ace/CDR_Base.inl"
374 #endif /* __ACE_INLINE__ */
377 #include /**/ "ace/post.h"
379 #endif /* ACE_CDR_BASE_H */