Line data Source code
1 : /* 2 : * Distributed under the OpenDDS License. 3 : * See: http://www.opendds.org/license.html 4 : */ 5 : 6 : #ifndef OPENDDS_DCPS_VALUE_WRITER_H 7 : #define OPENDDS_DCPS_VALUE_WRITER_H 8 : 9 : #include "Definitions.h" 10 : #include "XTypes/MemberDescriptorImpl.h" 11 : 12 : #include <dds/Versioned_Namespace.h> 13 : #include <FACE/Fixed.h> 14 : 15 : #include <ace/CDR_Base.h> 16 : #include <tao/String_Manager_T.h> 17 : 18 : #include <cstddef> 19 : #include <cstring> 20 : #include <cwchar> 21 : 22 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 23 : 24 : namespace OpenDDS { 25 : namespace DCPS { 26 : 27 : /// A ValueWriter receives events and values from the recitation of a 28 : /// value. Typical examples of value recitation are serializing an 29 : /// object for transmission, formatting an object for printing, or 30 : /// copying an object to another representation, e.g., C++ to v8. To 31 : /// use it, one manually or automatically, e.g., code generation in the 32 : /// IDL compiler, defines a vwrite function for a given type V. 33 : /// 34 : /// void vwrite(ValueWriter& vw, const V& value) 35 : /// 36 : /// The vwrite function should invoke the appropriate methods of the 37 : /// ValueWriter and dispatch for other vwrite functions. 38 : class OpenDDS_Dcps_Export ValueWriter { 39 : public: 40 108 : ValueWriter() {} 41 108 : virtual ~ValueWriter() {} 42 : 43 0 : virtual void begin_struct() {} 44 0 : virtual void end_struct() {} 45 0 : virtual void begin_struct_member(const DDS::MemberDescriptor& /*descriptor*/) {} 46 0 : virtual void end_struct_member() {} 47 : 48 0 : virtual void begin_union() {} 49 0 : virtual void end_union() {} 50 0 : virtual void begin_discriminator() {} 51 0 : virtual void end_discriminator() {} 52 0 : virtual void begin_union_member(const char* /*name*/) {} 53 0 : virtual void end_union_member() {} 54 : 55 0 : virtual void begin_array() {} 56 0 : virtual void end_array() {} 57 0 : virtual void begin_sequence() {} 58 0 : virtual void end_sequence() {} 59 0 : virtual void begin_element(size_t /*idx*/) {} 60 0 : virtual void end_element() {} 61 : 62 : virtual void write_boolean(ACE_CDR::Boolean /*value*/) = 0; 63 : virtual void write_byte(ACE_CDR::Octet /*value*/) = 0; 64 : #if OPENDDS_HAS_EXPLICIT_INTS 65 : virtual void write_int8(ACE_CDR::Int8 /*value*/) = 0; 66 : virtual void write_uint8(ACE_CDR::UInt8 /*value*/) = 0; 67 : #endif 68 : virtual void write_int16(ACE_CDR::Short /*value*/) = 0; 69 : virtual void write_uint16(ACE_CDR::UShort /*value*/) = 0; 70 : virtual void write_int32(ACE_CDR::Long /*value*/) = 0; 71 : virtual void write_uint32(ACE_CDR::ULong /*value*/) = 0; 72 : virtual void write_int64(ACE_CDR::LongLong /*value*/) = 0; 73 : virtual void write_uint64(ACE_CDR::ULongLong /*value*/) = 0; 74 : virtual void write_float32(ACE_CDR::Float /*value*/) = 0; 75 : virtual void write_float64(ACE_CDR::Double /*value*/) = 0; 76 : virtual void write_float128(ACE_CDR::LongDouble /*value*/) = 0; 77 : 78 : #ifdef NONNATIVE_LONGDOUBLE 79 : void write_float128(long double value); 80 : #endif 81 : 82 : virtual void write_fixed(const OpenDDS::FaceTypes::Fixed& /*value*/) = 0; 83 : virtual void write_char8(ACE_CDR::Char /*value*/) = 0; 84 : virtual void write_char16(ACE_CDR::WChar /*value*/) = 0; 85 : virtual void write_string(const ACE_CDR::Char* /*value*/, size_t /*length*/) = 0; 86 2 : void write_string(const ACE_CDR::Char* value) { write_string(value, std::strlen(value)); } 87 0 : void write_string(const std::string& value) { write_string(value.c_str(), value.length()); } 88 : virtual void write_wstring(const ACE_CDR::WChar* /*value*/, size_t /*length*/) = 0; 89 0 : void write_wstring(const ACE_CDR::WChar* value) 90 : { 91 : #ifdef DDS_HAS_WCHAR 92 0 : write_wstring(value, std::wcslen(value)); 93 : #else 94 : ACE_UNUSED_ARG(value); 95 : #endif 96 0 : } 97 : void write_wstring(const std::wstring& value) 98 : { 99 : #ifdef DDS_HAS_WCHAR 100 : write_wstring(value.c_str(), value.length()); 101 : #else 102 : ACE_UNUSED_ARG(value); 103 : #endif 104 : } 105 : 106 : virtual void write_enum(const char* /*name*/, ACE_CDR::Long /*value*/) = 0; 107 : template <typename T> 108 0 : void write_enum(const char* name, const T& value) 109 : { 110 0 : write_enum(name, static_cast<ACE_CDR::Long>(value)); 111 0 : } 112 : 113 : /// Array write operations 114 : /// Note: the portion written starts at x and ends 115 : /// at x + length. 116 : ///@{ 117 : virtual void write_boolean_array(const ACE_CDR::Boolean* x, size_t length); 118 : virtual void write_byte_array(const ACE_CDR::Octet* x, size_t length); 119 : #if OPENDDS_HAS_EXPLICIT_INTS 120 : virtual void write_int8_array(const ACE_CDR::Int8* x, size_t length); 121 : virtual void write_uint8_array(const ACE_CDR::UInt8* x, size_t length); 122 : #endif 123 : virtual void write_int16_array(const ACE_CDR::Short* x, size_t length); 124 : virtual void write_uint16_array(const ACE_CDR::UShort* x, size_t length); 125 : virtual void write_int32_array(const ACE_CDR::Long* x, size_t length); 126 : virtual void write_uint32_array(const ACE_CDR::ULong* x, size_t length); 127 : virtual void write_int64_array(const ACE_CDR::LongLong* x, size_t length); 128 : virtual void write_uint64_array(const ACE_CDR::ULongLong* x, size_t length); 129 : virtual void write_float32_array(const ACE_CDR::Float* x, size_t length); 130 : virtual void write_float64_array(const ACE_CDR::Double* x, size_t length); 131 : virtual void write_float128_array(const ACE_CDR::LongDouble* x, size_t length); 132 : virtual void write_char8_array(const ACE_CDR::Char* x, size_t length); 133 : virtual void write_char16_array(const ACE_CDR::WChar* x, size_t length); 134 : ///@} 135 : }; 136 : 137 : } // namespace DCPS 138 : } // namespace OpenDDS 139 : 140 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 141 : 142 : #endif /* OPENDDS_DCPS_VALUE_WRITER_H */