Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / ace / CDR_Size.h
blob1668bba36132e8df508c4b09884e0980d3cf2b07
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 ACE_CDR::Boolean write_string_view (const std::string_view &x);
83 #if !defined(ACE_LACKS_STD_WSTRING)
84 ACE_CDR::Boolean write_wstring (const std::wstring &x);
85 #endif
86 //@}
88 /// @note the portion written starts at <x> and ends
89 /// at <x + length>.
90 /// The length is *NOT* stored into the CDR stream.
91 //@{ @name Array write operations
92 ACE_CDR::Boolean write_boolean_array (const ACE_CDR::Boolean *x,
93 ACE_CDR::ULong length);
94 ACE_CDR::Boolean write_char_array (const ACE_CDR::Char *x,
95 ACE_CDR::ULong length);
96 ACE_CDR::Boolean write_wchar_array (const ACE_CDR::WChar* x,
97 ACE_CDR::ULong length);
98 ACE_CDR::Boolean write_octet_array (const ACE_CDR::Octet* x,
99 ACE_CDR::ULong length);
100 ACE_CDR::Boolean write_short_array (const ACE_CDR::Short *x,
101 ACE_CDR::ULong length);
102 ACE_CDR::Boolean write_ushort_array (const ACE_CDR::UShort *x,
103 ACE_CDR::ULong length);
104 ACE_CDR::Boolean write_long_array (const ACE_CDR::Long *x,
105 ACE_CDR::ULong length);
106 ACE_CDR::Boolean write_ulong_array (const ACE_CDR::ULong *x,
107 ACE_CDR::ULong length);
108 ACE_CDR::Boolean write_longlong_array (const ACE_CDR::LongLong* x,
109 ACE_CDR::ULong length);
110 ACE_CDR::Boolean write_ulonglong_array (const ACE_CDR::ULongLong *x,
111 ACE_CDR::ULong length);
112 ACE_CDR::Boolean write_float_array (const ACE_CDR::Float *x,
113 ACE_CDR::ULong length);
114 ACE_CDR::Boolean write_double_array (const ACE_CDR::Double *x,
115 ACE_CDR::ULong length);
116 ACE_CDR::Boolean write_longdouble_array (const ACE_CDR::LongDouble* x,
117 ACE_CDR::ULong length);
120 /// Adjust to @a size and count @a size octets.
121 void adjust (size_t size);
123 /// As above, but now the size and alignment requirements may be
124 /// different.
125 void adjust (size_t size,
126 size_t align);
128 private:
129 ACE_SizeCDR (const ACE_SizeCDR&) = delete;
130 ACE_SizeCDR& operator= (const ACE_SizeCDR&) = delete;
131 ACE_SizeCDR (ACE_SizeCDR&&) = delete;
132 ACE_SizeCDR& operator= (ACE_SizeCDR&&) = delete;
134 ACE_CDR::Boolean write_1 (const ACE_CDR::Octet *x);
135 ACE_CDR::Boolean write_2 (const ACE_CDR::UShort *x);
136 ACE_CDR::Boolean write_4 (const ACE_CDR::ULong *x);
137 ACE_CDR::Boolean write_8 (const ACE_CDR::ULongLong *x);
138 ACE_CDR::Boolean write_16 (const ACE_CDR::LongDouble *x);
141 * write an array of @a length elements, each of @a size bytes and the
142 * start aligned at a multiple of <align>. The elements are assumed
143 * to be packed with the right alignment restrictions. It is mostly
144 * designed for buffers of the basic types.
146 * This operation uses <memcpy>; as explained above it is expected
147 * that using assignment is faster that <memcpy> for one element,
148 * but for several elements <memcpy> should be more efficient, it
149 * could be interesting to find the break even point and optimize
150 * for that case, but that would be too platform dependent.
152 ACE_CDR::Boolean write_array (const void *x,
153 size_t size,
154 size_t align,
155 ACE_CDR::ULong length);
158 ACE_CDR::Boolean write_wchar_array_i (const ACE_CDR::WChar* x,
159 ACE_CDR::ULong length);
161 private:
162 /// Set to false when an error occurs.
163 bool good_bit_;
165 /// Current size.
166 size_t size_;
168 protected:
169 /// GIOP version information
170 ACE_CDR::Octet major_version_;
171 ACE_CDR::Octet minor_version_;
174 // @@ This operator should not be inlined since they force SString.h
175 // to be included in this header.
176 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
177 const ACE_CString &x);
179 ACE_END_VERSIONED_NAMESPACE_DECL
181 #if defined (__ACE_INLINE__)
182 # include "ace/CDR_Size.inl"
183 #else /* __ACE_INLINE__ */
185 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
187 // Not used by CORBA or TAO
188 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
189 ACE_CDR::Char x);
191 // CDR size-calculating output operators for primitive types
193 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
194 ACE_CDR::Short x);
195 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
196 ACE_CDR::UShort x);
197 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
198 ACE_CDR::Long x);
199 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
200 ACE_CDR::ULong x);
201 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
202 ACE_CDR::LongLong x);
203 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
204 ACE_CDR::ULongLong x);
205 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR& ss,
206 ACE_CDR::LongDouble x);
207 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
208 ACE_CDR::Float x);
209 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
210 ACE_CDR::Double x);
211 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
212 const ACE_CDR::Fixed &x);
214 // CDR size-calculating output operator from helper classes
216 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
217 ACE_OutputCDR::from_boolean x);
218 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
219 ACE_OutputCDR::from_char x);
220 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
221 ACE_OutputCDR::from_wchar x);
222 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
223 ACE_OutputCDR::from_octet x);
224 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
225 ACE_OutputCDR::from_string x);
226 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
227 ACE_OutputCDR::from_wstring x);
228 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
229 const ACE_CDR::Char* x);
230 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
231 const ACE_CDR::WChar* x);
232 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
233 const std::string& x);
234 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
235 const std::string_view& x);
236 #if !defined(ACE_LACKS_STD_WSTRING)
237 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_SizeCDR &ss,
238 const std::wstring& x);
239 #endif
241 ACE_END_VERSIONED_NAMESPACE_DECL
243 #endif /* __ACE_INLINE__ */
246 #include /**/ "ace/post.h"
248 #endif /* ACE_CDR_SIZE_H */