LCOV - code coverage report
Current view: top level - DCPS - ValueReader.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 27 92.6 %
Date: 2023-04-30 01:32:43 Functions: 9 28 32.1 %

          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_READER_H
       7             : #define OPENDDS_DCPS_VALUE_READER_H
       8             : 
       9             : #include "Definitions.h"
      10             : #include "XTypes/TypeObject.h"
      11             : 
      12             : #include <FACE/Fixed.h>
      13             : #include <dds/Versioned_Namespace.h>
      14             : 
      15             : #include <ace/CDR_Base.h>
      16             : 
      17             : #include <cstddef>
      18             : 
      19             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      20             : 
      21             : namespace OpenDDS {
      22             : namespace DCPS {
      23             : 
      24             : /// A ValueReader produces events and values for the recitation of a
      25             : /// value.  To use it, one manually or automatically, e.g., code
      26             : /// generation in the IDL compiler, defines a vread function for a
      27             : /// given type V.
      28             : ///
      29             : ///   bool vread(ValueReader& vw, V& value)
      30             : ///
      31             : /// The vread function should invoke the appropriate methods of the
      32             : /// ValueReader and dispatch to other vread functions.
      33             : class MemberHelper {
      34             : public:
      35           1 :   virtual ~MemberHelper() {}
      36             :   virtual bool get_value(XTypes::MemberId& value,
      37             :                          const char* name) const = 0;
      38             : };
      39             : 
      40             : class ListMemberHelper : public MemberHelper {
      41             : public:
      42             :   struct Pair {
      43             :     const char* name;
      44             :     XTypes::MemberId value;
      45             :   };
      46             : 
      47           1 :   ListMemberHelper(const Pair* pairs)
      48           1 :     : pairs_(pairs)
      49           1 :   {}
      50             : 
      51          32 :   bool get_value(XTypes::MemberId& value,
      52             :                  const char* name) const
      53             :   {
      54         232 :     for (const Pair* ptr = pairs_; ptr->name; ++ptr) {
      55         230 :       if (std::strcmp(ptr->name, name) == 0) {
      56          30 :         value = ptr->value;
      57          30 :         return true;
      58             :       }
      59             :     }
      60             : 
      61           2 :     return false;
      62             :   }
      63             : 
      64             : private:
      65             :   const Pair* pairs_;
      66             : };
      67             : 
      68             : class EnumHelper {
      69             : public:
      70           1 :   virtual ~EnumHelper() {}
      71             :   virtual bool get_value(ACE_CDR::Long& value,
      72             :                          const char* name) const = 0;
      73             : };
      74             : 
      75             : class ListEnumHelper : public EnumHelper {
      76             : public:
      77             :   struct Pair {
      78             :     const char* name;
      79             :     ACE_CDR::Long value;
      80             :   };
      81             : 
      82           1 :   ListEnumHelper(const Pair* pairs)
      83           1 :     : pairs_(pairs)
      84           1 :   {}
      85             : 
      86           3 :   bool get_value(ACE_CDR::Long& value,
      87             :                  const char* name) const
      88             :   {
      89           4 :     for (const Pair* ptr = pairs_; ptr->name; ++ptr) {
      90           4 :       if (std::strcmp(ptr->name, name) == 0) {
      91           3 :         value = ptr->value;
      92           3 :         return true;
      93             :       }
      94             :     }
      95             : 
      96           0 :     return false;
      97             :   }
      98             : 
      99             : private:
     100             :   const Pair* pairs_;
     101             : };
     102             : 
     103             : class OpenDDS_Dcps_Export ValueReader {
     104             : public:
     105          13 :   ValueReader() {}
     106          13 :   virtual ~ValueReader() {}
     107             : 
     108             :   virtual bool begin_struct() = 0;
     109             :   virtual bool end_struct() = 0;
     110             :   virtual bool begin_struct_member(XTypes::MemberId& member_id, const MemberHelper& helper) = 0;
     111             :   virtual bool end_struct_member() = 0;
     112             : 
     113             :   virtual bool begin_union() = 0;
     114             :   virtual bool end_union() = 0;
     115             :   virtual bool begin_discriminator() = 0;
     116             :   virtual bool end_discriminator() = 0;
     117             :   virtual bool begin_union_member() = 0;
     118             :   virtual bool end_union_member() = 0;
     119             : 
     120             :   virtual bool begin_array() = 0;
     121             :   virtual bool end_array() = 0;
     122             :   virtual bool begin_sequence() = 0;
     123             :   virtual bool elements_remaining() = 0;
     124             :   virtual bool end_sequence() = 0;
     125             :   virtual bool begin_element() = 0;
     126             :   virtual bool end_element() = 0;
     127             : 
     128             :   virtual bool read_boolean(ACE_CDR::Boolean& value) = 0;
     129             :   virtual bool read_byte(ACE_CDR::Octet& value) = 0;
     130             : #if OPENDDS_HAS_EXPLICIT_INTS
     131             :   virtual bool read_int8(ACE_CDR::Int8& value) = 0;
     132             :   virtual bool read_uint8(ACE_CDR::UInt8& value) = 0;
     133             : #endif
     134             :   virtual bool read_int16(ACE_CDR::Short& value) = 0;
     135             :   virtual bool read_uint16(ACE_CDR::UShort& value) = 0;
     136             :   virtual bool read_int32(ACE_CDR::Long& value) = 0;
     137             :   virtual bool read_uint32(ACE_CDR::ULong& value) = 0;
     138             :   virtual bool read_int64(ACE_CDR::LongLong& value) = 0;
     139             :   virtual bool read_uint64(ACE_CDR::ULongLong& value) = 0;
     140             :   virtual bool read_float32(ACE_CDR::Float& value) = 0;
     141             :   virtual bool read_float64(ACE_CDR::Double& value) = 0;
     142             :   virtual bool read_float128(ACE_CDR::LongDouble& value) = 0;
     143             : 
     144             : #ifdef NONNATIVE_LONGDOUBLE
     145             :   bool read_float128(long double& value);
     146             : #endif
     147             : 
     148             :   virtual bool read_fixed(OpenDDS::FaceTypes::Fixed& value) = 0;
     149             :   virtual bool read_char8(ACE_CDR::Char& value) = 0;
     150             :   virtual bool read_char16(ACE_CDR::WChar& value) = 0;
     151             :   virtual bool read_string(String& value) = 0;
     152             :   virtual bool read_wstring(WString& value) = 0;
     153             : 
     154             :   virtual bool read_long_enum(ACE_CDR::Long& value, const EnumHelper& helper) = 0;
     155             :   template <typename T>
     156           3 :   bool read_enum(T& value, const EnumHelper& helper)
     157             :   {
     158             :     ACE_CDR::Long lvalue;
     159           3 :     if (!read_long_enum(lvalue, helper)) {
     160           0 :       return false;
     161             :     }
     162           3 :     value = static_cast<T>(lvalue);
     163           3 :     return true;
     164             :   }
     165             : 
     166             :   /// Array read operations
     167             :   ///@{
     168             :   virtual bool read_boolean_array(ACE_CDR::Boolean* value, size_t length);
     169             :   virtual bool read_byte_array(ACE_CDR::Octet* value, size_t length);
     170             : #if OPENDDS_HAS_EXPLICIT_INTS
     171             :   virtual bool read_int8_array(ACE_CDR::Int8* value, size_t length);
     172             :   virtual bool read_uint8_array(ACE_CDR::UInt8* value, size_t length);
     173             : #endif
     174             :   virtual bool read_int16_array(ACE_CDR::Short* value, size_t length);
     175             :   virtual bool read_uint16_array(ACE_CDR::UShort* value, size_t length);
     176             :   virtual bool read_int32_array(ACE_CDR::Long* value, size_t length);
     177             :   virtual bool read_uint32_array(ACE_CDR::ULong* value, size_t length);
     178             :   virtual bool read_int64_array(ACE_CDR::LongLong* value, size_t length);
     179             :   virtual bool read_uint64_array(ACE_CDR::ULongLong* value, size_t length);
     180             :   virtual bool read_float32_array(ACE_CDR::Float* value, size_t length);
     181             :   virtual bool read_float64_array(ACE_CDR::Double* value, size_t length);
     182             :   virtual bool read_float128_array(ACE_CDR::LongDouble* value, size_t length);
     183             :   virtual bool read_char8_array(ACE_CDR::Char* value, size_t length);
     184             :   virtual bool read_char16_array(ACE_CDR::WChar* value, size_t length);
     185             :   ///@}
     186             : };
     187             : 
     188             : } // namespace DCPS
     189             : } // namespace OpenDDS
     190             : 
     191             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     192             : 
     193             : #endif  /* OPENDDS_DCPS_VALUE_READER_H */

Generated by: LCOV version 1.16