Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / CDR_Size.h
blobd29a1a3975d2e645c759b5318fc493f1f85c4250
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file CDR_Size.h
7 * ACE Common Data Representation (CDR) size-calculating stream.
9 * The current implementation assumes that the host has 1-byte,
10 * 2-byte and 4-byte integral types, and that it has single
11 * precision and double precision IEEE floats.
12 * Those assumptions are pretty good these days, with Crays being
13 * the only known exception.
15 * @author Boris Kolpackov <boris@kolpackov.net>
17 //=============================================================================
19 #ifndef ACE_CDR_SIZE_H
20 #define ACE_CDR_SIZE_H
22 #include /**/ "ace/pre.h"
24 #include "ace/CDR_Base.h"
25 #include "ace/CDR_Stream.h" // for ACE_OutputCDR::from_*
27 #if !defined (ACE_LACKS_PRAGMA_ONCE)
28 # pragma once
29 #endif /* ACE_LACKS_PRAGMA_ONCE */
31 #include "ace/SStringfwd.h"
33 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 /**
36 * @class ACE_SizeCDR
38 * @brief A CDR stream for calculating size of the representation.
40 class ACE_Export ACE_SizeCDR
42 public:
43 /// Default constructor.
44 ACE_SizeCDR (ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
45 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION);
47 /// Returns @c false if an error has occurred.
48 bool good_bit () const;
50 /// Reset current size.
51 void reset ();
53 /// Return current size.
54 size_t total_length () const;
56 // Return 0 on failure and 1 on success.
57 //@{ @name Size-calculating pseudo-write operations
58 ACE_CDR::Boolean write_boolean (ACE_CDR::Boolean x);
59 ACE_CDR::Boolean write_char (ACE_CDR::Char x);
60 ACE_CDR::Boolean write_wchar (ACE_CDR::WChar x);
61 ACE_CDR::Boolean write_octet (ACE_CDR::Octet x);
62 ACE_CDR::Boolean write_short (ACE_CDR::Short x);
63 ACE_CDR::Boolean write_ushort (ACE_CDR::UShort x);
64 ACE_CDR::Boolean write_long (ACE_CDR::Long x);
65 ACE_CDR::Boolean write_ulong (ACE_CDR::ULong x);
66 ACE_CDR::Boolean write_longlong (const ACE_CDR::LongLong &x);
67 ACE_CDR::Boolean write_ulonglong (const ACE_CDR::ULongLong &x);
68 ACE_CDR::Boolean write_float (ACE_CDR::Float x);
69 ACE_CDR::Boolean write_double (const ACE_CDR::Double &x);
70 ACE_CDR::Boolean write_longdouble (const ACE_CDR::LongDouble &x);
71 ACE_CDR::Boolean write_fixed (const ACE_CDR::Fixed &x);
73 /// For string we offer methods that accept a precomputed length.
74 ACE_CDR::Boolean write_string (const ACE_CDR::Char *x);
75 ACE_CDR::Boolean write_string (ACE_CDR::ULong len,
76 const ACE_CDR::Char *x);
77 ACE_CDR::Boolean write_string (const ACE_CString &x);
78 ACE_CDR::Boolean write_wstring (const ACE_CDR::WChar *x);
79 ACE_CDR::Boolean write_wstring (ACE_CDR::ULong length,
80 const ACE_CDR::WChar *x);
81 ACE_CDR::Boolean write_string (const std::string &x);
82 #if !defined(ACE_LACKS_STD_WSTRING)
83 ACE_CDR::Boolean write_wstring (const std::wstring &x);
84 #endif
85 //@}
87 /// @note the portion written starts at <x> and ends
88 /// at <x + length>.
89 /// The length is *NOT* stored into the CDR stream.
90 //@{ @name Array write operations
91 ACE_CDR::Boolean write_boolean_array (const ACE_CDR::Boolean *x,
92 ACE_CDR::ULong length);
93 ACE_CDR::Boolean write_char_array (const ACE_CDR::Char *x,
94 ACE_CDR::ULong length);
95 ACE_CDR::Boolean write_wchar_array (const ACE_CDR::WChar* x,
96 ACE_CDR::ULong length);
97 ACE_CDR::Boolean write_octet_array (const ACE_CDR::Octet* x,
98 ACE_CDR::ULong length);
99 ACE_CDR::Boolean write_short_array (const ACE_CDR::Short *x,
100 ACE_CDR::ULong length);
101 ACE_CDR::Boolean write_ushort_array (const ACE_CDR::UShort *x,
102 ACE_CDR::ULong length);
103 ACE_CDR::Boolean write_long_array (const ACE_CDR::Long *x,
104 ACE_CDR::ULong length);
105 ACE_CDR::Boolean write_ulong_array (const ACE_CDR::ULong *x,
106 ACE_CDR::ULong length);
107 ACE_CDR::Boolean write_longlong_array (const ACE_CDR::LongLong* x,
108 ACE_CDR::ULong length);
109 ACE_CDR::Boolean write_ulonglong_array (const ACE_CDR::ULongLong *x,
110 ACE_CDR::ULong length);
111 ACE_CDR::Boolean write_float_array (const ACE_CDR::Float *x,
112 ACE_CDR::ULong length);
113 ACE_CDR::Boolean write_double_array (const ACE_CDR::Double *x,
114 ACE_CDR::ULong length);
115 ACE_CDR::Boolean write_longdouble_array (const ACE_CDR::LongDouble* x,
116 ACE_CDR::ULong length);
119 /// Adjust to @a size and count @a size octets.
120 void adjust (size_t size);
122 /// As above, but now the size and alignment requirements may be
123 /// different.
124 void adjust (size_t size,
125 size_t align);
127 private:
128 ACE_SizeCDR (const ACE_SizeCDR&) = delete;
129 ACE_SizeCDR& operator= (const ACE_SizeCDR&) = delete;
130 ACE_SizeCDR (ACE_SizeCDR&&) = delete;
131 ACE_SizeCDR& operator= (ACE_SizeCDR&&) = delete;
133 ACE_CDR::Boolean write_1 (const ACE_CDR::Octet *x);
134 ACE_CDR::Boolean write_2 (const ACE_CDR::UShort *x);
135 ACE_CDR::Boolean write_4 (const ACE_CDR::ULong *x);
136 ACE_CDR::Boolean write_8 (const ACE_CDR::ULongLong *x);
137 ACE_CDR::Boolean write_16 (const ACE_CDR::LongDouble *x);
140 * write an array of @a length elements, each of @a size bytes and the
141 * start aligned at a multiple of <align>. The elements are assumed
142 * to be packed with the right alignment restrictions. It is mostly
143 * designed for buffers of the basic types.
145 * This operation uses <memcpy>; as explained above it is expected
146 * that using assignment is faster that <memcpy> for one element,
147 * but for several elements <memcpy> should be more efficient, it
148 * could be interesting to find the break even point and optimize
149 * for that case, but that would be too platform dependent.
151 ACE_CDR::Boolean write_array (const void *x,
152 size_t size,
153 size_t align,
154 ACE_CDR::ULong length);
157 ACE_CDR::Boolean write_wchar_array_i (const ACE_CDR::WChar* x,
158 ACE_CDR::ULong length);
160 private:
161 /// Set to false when an error occurs.
162 bool good_bit_;
164 /// Current size.
165 size_t size_;
167 protected:
168 /// GIOP version information
169 ACE_CDR::Octet major_version_;
170 ACE_CDR::Octet minor_version_;
173 // @@ This operator should not be inlined since they force SString.h
174 // to be included in this header.
175 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
176 const ACE_CString &x);
178 ACE_END_VERSIONED_NAMESPACE_DECL
180 #if defined (__ACE_INLINE__)
181 # include "ace/CDR_Size.inl"
182 #else /* __ACE_INLINE__ */
184 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
186 // Not used by CORBA or TAO
187 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
188 ACE_CDR::Char x);
190 // CDR size-calculating output operators for primitive types
192 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
193 ACE_CDR::Short x);
194 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
195 ACE_CDR::UShort x);
196 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
197 ACE_CDR::Long x);
198 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
199 ACE_CDR::ULong x);
200 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
201 ACE_CDR::LongLong x);
202 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
203 ACE_CDR::ULongLong x);
204 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR& ss,
205 ACE_CDR::LongDouble x);
206 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
207 ACE_CDR::Float x);
208 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
209 ACE_CDR::Double x);
210 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
211 const ACE_CDR::Fixed &x);
213 // CDR size-calculating output operator from helper classes
215 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
216 ACE_OutputCDR::from_boolean x);
217 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
218 ACE_OutputCDR::from_char x);
219 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
220 ACE_OutputCDR::from_wchar x);
221 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
222 ACE_OutputCDR::from_octet x);
223 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
224 ACE_OutputCDR::from_string x);
225 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
226 ACE_OutputCDR::from_wstring x);
227 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
228 const ACE_CDR::Char* x);
229 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
230 const ACE_CDR::WChar* x);
231 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
232 const std::string& x);
233 #if !defined(ACE_LACKS_STD_WSTRING)
234 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
235 const std::wstring& x);
236 #endif
238 ACE_END_VERSIONED_NAMESPACE_DECL
240 #endif /* __ACE_INLINE__ */
243 #include /**/ "ace/post.h"
245 #endif /* ACE_CDR_SIZE_H */