FASTDDS IDL

本文介绍了接口定义语言(IDL)的关键特性,包括基本类型、数组(一维和动态)、容器(如map和vector)、结构体与类、继承、联合、枚举和位掩码,以及如何通过头文件包含其他IDL文件。
摘要由CSDN通过智能技术生成

FASTDDS IDL

  1. IDL为接口定义语言,支持的类型有:

    • Primitive types

      IDLC++11
      charchar
      octetuint8_t
      shortint16_t
      unsigned shortuint16_t
      longint32_t
      unsigned longuint32_t
      long longint64_t
      unsigned long longuint64_t
      floatfloat
      doubledouble
      long doublelong double
      booleanbool
      stringstd::string
    • Arrays

      支持一维和多维数组。

      IDLC++11
      char a[5]std::array<char,5> a
      octet a[5]std::array<uint8_t,5> a
      short a[5]std::array<int16_t,5> a
      unsigned short a[5]std::array<uint16_t,5> a
      long a[5]std::array<int32_t,5> a
      unsigned long a[5]std::array<uint32_t,5> a
      long long a[5]std::array<int64_t,5> a
      unsigned long long a[5]std::array<uint64_t,5> a
      float a[5]std::array<float,5> a
      double a[5]std::array<double,5> a
    • Sequences

      支持动态数组,对应C++中的std::vector

      IDLC++11
      sequencestd::vector<char>
      sequencestd::vector<uint8_t>
      sequencestd::vector<int16_t>
      sequencestd::vector<uint16_t>
      sequencestd::vector<int32_t>
      sequencestd::vector<uint32_t>
      sequencestd::vector<int64_t>
      sequencestd::vector<uint64_t>
      sequencestd::vector<float>
      sequencestd::vector<double>
    • Maps

      支持容器,对应C++中的std::map

      IDLC++11
      map<char, unsigned long long>std::map<char, uint64_T>
    • Structures

      将多种类型的变量定义在一个结构体,最后每个结构体将被转换成为一个类,为类中的每个变量定义set和get方法

      struct Structure
      {
          octet octet_value;
          long long_value;
          string string_value;
      };
      
      class Structure
      {
      public:
          Structure();
          ~Structure();
          Structure(const Structure &x);
          Structure(Structure &&x);
          Structure& operator=(const Structure &x);
          Structure& operator=(Structure &&x);
      
          void octet_value(uint8_t _octet_value);
          uint8_t octet_value() const;
          uint8_t& octet_value();
          void long_value(int64_t _long_value);
          int64_t long_value() const;
          int64_t& long_value();
          void string_value(const std::string
              &_string_value);
          void string_value(std::string &&_string_value);
          const std::string& string_value() const;
          std::string& string_value();
      
      private:
          uint8_t m_octet_value;
          int64_t m_long_value;
          std::string m_string_value;
      };
      

      结构体可以继承

      struct ParentStruct
      {
          octet parent_member;
      };
      
      struct ChildStruct : ParentStruct
      {
          long child_member;
      };
      
    • Unions

      union Union switch(long)
      {
         case 1:
          octet octet_value;
        case 2:
          long long_value;
        case 3:
          string string_value;
      };
      
    • Bitsets

      bitset MyBitset
      {
          bitfield<3> a;
          bitfield<10> b;
          bitfield<12, long> c;
      };
      

      共25bits(3+10+12)

    • Enumerations

      enum Enumeration
      {
          RED,
          GREEN,
          BLUE
      };
      
    • Bitmasks

      @bit_bound(8)
      bitmask MyBitMask
      {
          @position(0) flag0,
          @position(1) flag1,
          @position(4) flag4,
          @position(6) flag6,
          flag7
      };
      

      转换后

      enum MyBitMask : uint8_t
      {
          flag0 = 0x01 << 0,
          flag1 = 0x01 << 1,
          flag4 = 0x01 << 4,
          flag6 = 0x01 << 6,
          flag7 = 0x01 << 7
      };
      

      bit_bound设置范围1-64,不设置默认为32bits,使用position定义flag,如果不定义,position将从最后一次flag自动递增,从0开始。

    • Data types with a key

      struct MyType
      {
          @Key long id;
          @Key string type;
          long positionX;
          long positionY;
      };
      

    IDL可以包含别的IDL文件

    #include "OtherFile.idl"
    #include <AnotherFile.idl>
    
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值