web idl 接口定义语言数据类型与 C++绑定关系



Modules

Every IDL module corresponds to a C++ namespace. The name of that namespace is based on module's prefixed name.

IDL
 module dom {
  };

C++
 namespace org {
    namespace w3c {
      namespace dom {

IDL
 [Prefix=::com]
  module getfirebug {

C++
 namespace com {
    namespace getfirebug {

Note: Historically each W3C specification introduced its own module name. However, the recent specifications tend to omit the module specification in the IDL definition. At least it seems one module name per spec doesn't make sense any more.

cf. http://lists.w3.org/Archives/Public/public-webapps/2009AprJun/1380.html

Primitive types

IDL C++
boolean bool
byte signed char
octet unsigned char
short short
unsigned short unsigned short
long int
unsigned long unsigned int
long long long long
unsigned long long unsigned long long
float float
double double

Any

The any type is the union of all other possible types.

IDL
 any
C++
 class Any {
   public:
    Any();
    Any(const Any& value);
    template <typename T>
    Any(const T& x);
    Any& operator=(const Any& x);
    template<typename T>
    Any& operator=(const T& x);
    template<typename T>
    operator T() const;
    // snip
  };

Example

IDL
 interface CanvasRenderingContext2D {
    attribute any fillStyle;
  };

C++
 class CanvasRenderingContext2D : public Object {
  public:
    Any getFillStyle();
    void setFillStyle(Any fillStyle);
  };

  canvasRenderingContext2D->setFillStyle("black");

DOMString

The DOMString type corresponds to the set of all possible sequences of 16 bit unsigned integer code units to be interpreted as UTF-16 encoded strings.

IDL C++
DOMString std::u16string

Date

The Date type corresponds to a 64 bit unsigned integer value. In C++ DOM API, the DOMTimeStamp type is defined as Date following Chrome's implementation as specified in DOM Level3 Core (*).

IDL C++
Date unsigned long long

(*) It appears currently Chrome is the only browser that treats the DOMTimeStamp type as the Date object in ECMAScript.

Object

The object type corresponds to the set of all possible object references, plus the special value null, which indicates no object reference.

IDL C++
object Object
null 0

Interfaces

An interface is a specification of a set of interface members, which are the constants, attributes and operations.

IDL
 interface CanvasRenderingContext2D {
  };

C++
 class CanvasRenderingContext2D : public Object {
  };

Nullable types - T?

A nullable type is an IDL type that can represent an existing type (called the inner type) values, plus an additional value null.

IDL C++
inner-type? Nullable<inner-type>

C++
 template <typename T>
  class Nullable {
   public:
    bool hasValue() const;
    T value() const;
    Nullable();
    Nullable(const T& value);
    Nullable(const Nullable<T>& nullable);
    Nullable(const Any& any);
    // snip
  };

Example

IDL
 attribute DOMString? background;

C++
 Nullable<std::string> getBackground();
  void setBackground(Nullable<std::string> background);

Sequences -sequence<T>

Thesequence<T>type is a parameterized type whose values are (possibly zero-length) sequences of values of type T.

IDL C++
sequence<T> Sequence<T>

C++
 template <typename T>
  class Sequence
  {
   public:
    Sequence();
    Sequence(const T* array, unsigned int size);
    Sequence(std::initializer_list<T> list);
    Sequence(const Sequence& value);
    ~Sequence();
    T operator[](int index) const;
    T& operator[](int index);
    unsigned int getLength() const;
    // snip
  };

IDL
 
typedef stylesheets::StyleSheetList StyleSheetList;

  readonly attribute StyleSheetList styleSheets;

C++
 typedef Sequence<StyleSheet*> StyleSheetList;

  StyleSheetList getStyleSheets();

Constants

Constants can be defined in interfaces and exceptions.

IDL
 interface MediaError {
    const unsigned short MEDIA_ERR_ABORTED = 1;
    const unsigned short MEDIA_ERR_NETWORK = 2;
    const unsigned short MEDIA_ERR_DECODE = 3;
    const unsigned short MEDIA_ERR_NONE_SUPPORTED = 4;
  };

C++
 
 class MediaError : public Object {
    public:
      static const unsigned short MEDIA_ERR_ABORTED = 1;
      static const unsigned short MEDIA_ERR_NETWORK = 2;
      static const unsigned short MEDIA_ERR_DECODE = 3;
      static const unsigned short MEDIA_ERR_NONE_SUPPORTED = 4;
    };

Operations

Each operation defined in the IDL interface will be mapped to one or more member functions in the C++ interface class.

IDL
 interface CanvasRenderingContext2D {
    void fillRect(float x, float y, float w, float h);
  };

C++
 class CanvasRenderingContext2D : public Object {
   public:
    void fillRect(float x, float y, float w, float h);
  };

Optional argument

If the "optional" keyword appears on an operation argument, it indicates that the operation can be invoked by passing values only for the those arguments appearing before the optional argument in the operation’s argument list.

IDL
 
interface ColorCreator {
    object createColor(float v1, optional float v2, float v3, optional float alpha);
  };

C++
 class ColorCreator {
  public:
    Object createColor(float v1);
    Object createColor(float v1, float v2, float v3);
    Object createColor(float v1, float v2, float v3, float alpha);
  };  

Variadic operation

If the final argument uses the "..." terminal, it indicates that the operation is variadic, and can be passed zero or more arguments after the regular arguments. In C++, a varying number of arguments are represent as a Variadic value.

Example

IDL

  interface IntegerSet {
    readonly attribute unsigned long cardinality;

    void union(long... ints);
    void intersection(long... ints);
  };


C++
 class IntegerSet {
  public:
    unsigned int getCardinality();
    void union(Variadic<int> ints = Variadic<int>());
    void intersection(Variadic<int> ints = Variadic<int>());
  };
  template <typename T>
  class Variadic
  {
public:
    Variadic();
    Variadic(const Any* variadic, size_t length);
    Variadic(std::initializer_list<T> list);
    T operator[](int index) const;
    size_t size() const;
  };

Operations with no identifier

While it has been agreed to remove unnamed getters/setters at W3C WebApps WG (*), operations with no identifier are still in use in several W3C specifications. In C++, the default operation name as shown in the following table is used for operations with no identifier.

IDL C++
getter getElement
setter setElement
creator createElement
deleter deleteElement
stringifier toString

Example

IDL
 
interface CanvasPixelArray {
    readonly attribute unsigned long length;
    getter octet (in unsigned long index);
    setter void (in unsigned long index, in octet value);
  };

C++
 
class CanvasPixelArray : public Object {
   public:
    // CanvasPixelArray
    unsigned int getLength();
    unsigned char getElement(unsigned int index);
    void setElement(unsigned int index, unsigned char value);
    // snip
  };
(*) http://www.w3.org/2009/11/02-webapps-minutes.html#action07

Attributes

For each attribute defined on the IDL interface, a getter method is declared. For each attribute defined on the IDL interface that is not read only, a corresponding setter method is also declared.

IDL
 
interface CanvasRenderingContext2D {
    attribute float globalAlpha;
  };

C++
 class CanvasRenderingContext2D : public Object {
  public:
    float getGlobalAlpha();
    void setGlobalAlpha(float globalAlpha);
  };

Note: A getter is prefixed with "get", and the setter is prefixed with "set" following the Web IDL Java binding.

Exceptions

An exception is used to declare a type of exception that can be thrown by implementation.

IDL

 exception DOMException {
    const unsigned short INDEX_SIZE_ERR = 1;
    const unsigned short DOMSTRING_SIZE_ERR = 2;
    unsigned short code;
  };

C++
 struct DOMException {
    const unsigned short INDEX_SIZE_ERR = 1;
    const unsigned short DOMSTRING_SIZE_ERR = 2;
    unsigned short code;
  };

Note: The use of exceptions can be turned off with esidl.

Implements statements

An implements statement declares the all objects implementing an interface A (the first name) MUST also implement interface B (the second name). In C++, interface members in the mixin interface B are mixed into the primary interface A.

Example

IDL
 interface ElementTraversal {
    readonly attribute Element        firstElementChild;
    readonly attribute Element        lastElementChild;
    readonly attribute Element        previousElementSibling;
    readonly attribute Element        nextElementSibling;
  };

  Element implements ElementTraversal;

  interface Element : Node {
    // snip
  };

C++
 class Element : public Node
  {
   public:
    // snip
    Element getFirstElementChild();
    Element getLastElementChild();
    Element getPreviousElementSibling();
    Element getNextElementSibling();
    // snip

cf. http://lists.w3.org/Archives/Public/public-script-coord/2010OctDec/0071.html

Extended attributes

[Constructor],[NamedConstructor]

If the[Constructor]extended attribute appears on an interface, the corresponding C++ constructor(s) are defined.

IDL
 
[Constructor,
   Constructor(HTMLFormElement form)]
  interface FormData {
    void append(DOMString name, Blob value);
    void append(DOMString name, DOMString value);
  };

C++
 class FormData : public Object
  {
   public:
    // FormData
    void append(std::u16string name, file::Blob value);
    void append(std::u16string name, std::u16string value);

    // [Constructor]
    FormData();
    FormData(html::HTMLFormElement form);
    
    // snip
  };

Note: Unlike ECMAScript, you do not have to use the "new" operator to create an instance of the interface with the[Constructor]extended attribute.

[PutForwards]

If the[PutForwards]extended attribute appears on a read only attribute declaration whose type is an object implementing an interface, it indicates that assigning to the attribute will have specific behavior. Namely, the assignment is “forwarded” to the attribute (specified by the extended attribute argument) on the object that is currently referenced by the attribute being assigned to.

IDL
 interface Name {
    attribute DOMString full;
    attribute DOMString family;
    attribute DOMString given;
  };

  interface Person {
    [PutForwards=full] readonly attribute Name name;
  };

C++

  class Person {
  public:
    Name* getName();
    void setName(std::string name);
    // snip
  };


[Prefix]

See Modules.

[Supplemental]

cf.http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/0528.html

Example

IDL
 interface Element : Node {
    readonly attribute DOMString tagName;
    // snip
  };

  [Supplemental] interface Element {
    ClientRectList getClientRects();
    ClientRect getBoundingClientRect();
  };

C++
 class Element : public Node {
   public:
    std::string getTagName();
    // snip
    ClientRectList getClientRects();
    ClientRect getBoundingClientRect();
  };

详解 IDL(Interface Definition Language) IDL(接口定义语言)是一种标准化语言,用于描述软件接口,支持跨语言通信和分布式系统开发。其核心作用包括解耦服务与实现、标准化通信协议及自动化代码生成。常用工具如Apache Thrift、gRPC等,适用于微服务、RPC等场景。IDL通过定义接口和数据结构,生成多语言代码,简化系统集成。相比REST等技术,IDL在性能和跨语言兼容性上更具优势,但需注意版本管理和工具链统一。合理使用IDL可提升系统扩展性和开发效率。 阅读详情

相关推荐

SOME/IP序列化原理与实践:车载通信中的数据转换与安全解析

序列化是分布式系统和网络通信中的基础技术,它定义了将结构化数据转换为字节流的标准过程。其核心原理在于解决不同系统、硬件和编程语言间的数据交换难题,通过统一的编码规则确保数据的完整性和可解析性。这项技术的价值在于实现跨平台互操作,是构建可靠分布式架构的基石,广泛应用于车载网络、物联网和微服务通信等场景。在汽车电子领域,SOME/IP协议序列化机制尤为关键,它直接关系到通信效率和ECU间协同工作的可靠性。理解其对齐规则、字节序处理及代码生成工具(如CommonAPI)的使用,能有效规避数据错位和反序列化漏洞等常

weixin_34218890的博客 321

WebkitIDL(一)

Web IDL 是一门语言,用来定义WebCore的接口如何绑定外部语言比如JavaScriptCore, ObjC, GObject,C++等等。要暴露WebCore的接口给这些外部语言的话,我们需要编写IDL文件例如XMLHttpRequest.idl, Element.idl等等。Webit编译的时候,这些IDL 文件会被解析、而后生成的代码会绑定到WebCore的实现,而且会自动生成Jav

不积跬步无以至千里,不积小流无以成江海 3872

C++微服务通信:五种高效消息传递方案深度解析与实战选型

微服务架构中,服务间通信是构建分布式系统的核心技术基础,其性能与可靠性直接影响整体架构的健壮性。从原理层面看,通信效率取决于序列化协议、传输层协议及网络I/O模型的选择。在技术价值上,高效的通信机制能显著降低系统延迟、提升吞吐量,并保障服务的可扩展性。常见的应用场景包括金融交易系统、实时游戏后端、物联网数据处理等对性能有极致要求的领域。本文聚焦于C++生态,深入剖析了从底层自定义协议到高层框架的五种核心实现路径,其中gRPC凭借其强契约与跨语言特性,以及ZeroMQ提供的丰富异步模式,成为构建高性能C++微

csdndownload11123的博客 364

使用Web IDL定义Web API接口的技术详解

使用Web IDL定义Web API接口的技术详解引言Web IDL 概述什么是 Web IDL主要特点主要应用场景Web IDL 语法基本语法接口定义属性定义方法定义数据类型基本类型对象类型自定义类型扩展性异常处理示例实现步骤1. 定义接口示例2. 实现接口JavaScript 实现示例3. 测试接口测试用例示例优化策略1. 代码规范2. 性能优化3. 安全性4. 兼容性最佳实践1. 模块化设计2. 单元测试3. 文档编写4. 社区支持实际案例分析案例 1:自定义Web组件Web IDL 定义示例。

qq_36287830的博客 1381

CM02-CommonAPI与AUTOSAR AP通讯管理的异同

传送门 ==>> AutoSAR实战系列300讲「糖果Autosar」总目录CommonAPI 是由 GENIVI 开发的 C++ 框架,用于遵循 SOA 的进程间和网络通信。其目标是为不同的通信框架或协议提供统一的应用程序接口 (API)。使用 CommonAPI 的项目的基础是存在由开发人员共享的服务定义。为此,CommonAPI 使用了 Franca 接口定义语言 (Franca IDL)。这种语言允许使用方法、事件和字段定义服务,以及项目特定数据类型的规范,例如结构或枚举,然后将具有特定的在线表示。

891

ICE中间件中文编程手册详解

ICE(Internet Communication Engine)是一个开源的中间件平台,它提供了一组丰富的API和运行时组件,用于构建分布式应用程序。ICE利用面向对象的方法论将对象和服务进行抽象化,使得在不同语言编写的客户端和服务端之间进行通信变得透明而简单。IDL,即接口定义语言,是一种用于描述接口的语言规范。在ICE中,IDL用于定义服务接口,随后编译器将这些接口描述转换为特定语言的源代码。IDL文件中定义了服务接口的方法、参数、异常等信息,编译器读取这些定义,并生成对应的代码。

weixin_32389853的博客 1347

CORBA Programming with TAO - 3.IDL Data Type(数据类型与Mapping)

CORBA Programming with TAO - 3.IDL Data Type(数据类型与Mapping)摘要:简要介绍TAO支持的IDL数据类型及其C++ Mapping关系。一、简单基本数据类型(Simple Basic Types)TAO支持以下简单基本数据类型(%TAO_ROOT%/tao/Basic_Types.h):

675

webidl:IDL网站

网站IDL 这是开发规范的存储库。 贡献 良好的第一期被标记为。 除非另有说明,否则IDL通常遵循和。 标记 该规范使用编写,外加<emu> , <emu>和<emu> 。 提交其他地方的问题 应当针对以下方面进行重大更改: 渲染引擎 (由testharness.js用于运行IDL测试) 语法更改应针对以下解析器进行归档: widlparser (由Bikeshed使用) WebIDL解析器(由idlharness.js使用) TypeScript和JavaScript库生成器

Xerces-C++ DOM编程指南(一)

 原文地址:http://xerces.apache.org/xerces-c/program-dom.html设计目标    DOM的C++实现是基于阿帕奇推荐的DOM(Apache Recommended DOM C++ binding). 设计目标是为了满足如下需求:1.降低内存占用率.2.提高应用程序的性能,特别是那些服务器类型和多线程的应用程序.3.多处理系统中优异的延展性.4.比起

Ghost 7469

FreeRTOS-Plus-CLI在STM32F429上的高效移植与调试技巧

本文详细介绍了如何将FreeRTOS-Plus-CLI高效移植到STM32F429平台,并分享关键的调试技巧。内容涵盖使用HAL库进行底层驱动适配(特别是DMA+IDLE中断方案)、工程集成、自定义命令开发以及常见问题解决方案,旨在帮助开发者快速为嵌入式系统添加强大的命令行调试接口,提升开发与维护效率。

weixin_29224309的博客 338

Win10局域网内文件共享+远程桌面控制保姆级教程(含常见问题解决)

本文提供Win10局域网内文件共享和远程桌面控制的详细教程,包括环境检查、共享文件夹设置、远程桌面连接步骤及常见问题解决方案。通过内置功能实现高效办公协作,提升多设备协同工作效率,特别适合需要频繁传输文件或远程控制场景的专业人士。

rose2的博客 795

web idl 接口定义语言数据类型与 C++绑定关系(转)

转自:http://blog.csdn.net/perfectpdl/article/details/7098408 Modules Every IDL module corresponds to a C++ namespace. The name of that namespace is based on module's prefixed name. IDL [cpp] ...

weixin_30248399的博客 171

42、使用mmrotate中k3det进行旋转目标检测,并进行mnn部署和ncnn部署

基本思想:仍然是身份证分割,并进行ncnn和mnn的c++的部署开发

sxj731533730 5721

W3C Web IDL

Web IDL(Interface Definition Language,接口定义语言)该规范定义了一个OMG IDL 3.0的语法子集,用来规范定义的接口。Web IDL 是一个具有多种功能的IDL 变量,便于规范Web平台中的常用脚本对象的操作。其中包括了大量的扩展功能,以及捆绑了针对ECMAScript 3rd Edition 和Java的语言工具。 《Web IDL》工作草案,即过

scusyq的专栏 1296

无人飞行器和车辆的协同配送物资问题——附带MATLAB代码

通过建立城市地图、生成物资点和配送任务、路径规划、协同调度以及仿真和评估等步骤,可以有效地解决物资配送的优化问题。通过建立城市地图、生成物资点和配送任务、路径规划、协同调度以及仿真和评估等步骤,可以有效地解决物资配送的优化问题。我们的目标是最小化物资配送的总时间,同时确保每个物资点都被正确配送的无人飞行器或车辆所访问。我们的目标是最小化物资配送的总时间,同时确保每个物资点都被正确配送的无人飞行器或车辆所访问。我们首先需要建立一个城市地图,包括物资点、无人飞行器的起始点和车辆的起始点。

CyberJolt的博客 955

华为OD机考双机位C卷 - 手机App防沉迷系统(Java & Python& JS & C/C++ & GO )

华为OD机考双机位C卷 - 手机App防沉迷系统(OD上机考试双机位C卷)。提供在线OJ刷题。Java、C++、Python、GO语言、C语言、JavaScript题解,并提供完整思路讲解。

算法大师! 2068

C++ JSON-RPC框架libjson-rpc-cpp实战:从原理到异构系统集成

远程过程调用(RPC)是构建分布式系统和实现微服务间通信的核心技术,它允许程序像调用本地函数一样调用网络上的服务。JSON-RPC作为一种基于JSON的轻量级协议,因其文本可读、跨语言支持良好而广泛应用于异构系统集成。libjson-rpc-cpp框架封装了协议解析、网络通信和序列化等底层细节,通过桩代码生成器自动化接口绑定,显著提升了C++项目中RPC开发的效率。该框架支持HTTP、TCP Socket等多种可插拔的传输层,便于根据性能与通用性需求进行选型。在涉及C++与Python、JavaScript

weixin_33738982的博客 350

uniapp - 实现PDA扫码枪RFID批量扫描读取示例代码,uni-app APP识别RFID(射频识别)结合硬件设备进行扫描,uniApp调用RFID读写通用方案适配各种设备+完整实例源码教程!

uni-app PDA 读取RFID,基于uniapp开发PDA扫码枪APP:实现RFID批量扫描读取功能,UniApp中的RFID实现,手持机 RFID插件(uni-app集成手持设备rfid插件),uniapp自动识别RFID,uni-app调RFID模块,uni-app RFID识别插件,uniapp读取rfid,uniapp手持设备扫描rfid,uniapp超高频rfid识别,rfid标签识别,uniapp调用RFID读写,uniapp rfid扫码枪,uniapp中如何使用rfid插件,打包上线后

🏆 前端领域优质创作者 1万+

www描述语言是html,描述语言

描述语言(descriptive language)指的是为详细写出状态或始末而定义的语言,是一种允许产生新的描述方案和描述符的语言。中文名描述语言外文名descriptive language应用领域计算机特点详细,精简涉及语言接口描述语言、数据描述语言等缩写DL描述语言Web 服务描述语言编辑描述语言简介Web 服务描述语言 (Web Services Description ...

weixin_42126749的博客 2349

2023华为od机试C卷【最富裕的小家庭】C语言 实现

在一颗树中,每个节点代表一个家庭成员,节点的数字表示其个人的财富值,一个节点及其直接相连的子节点被定义为个小家庭。现给你一颗树,请计算出最富裕的小家庭的财富和。

MISAYAONE的博客 504

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Thrift简析

Thrift简析 by Elton on 二.12, 2012, under Web RPC技术及实现简介 首先思考一下分布式系统中的 RPC (Remote Procedure Call) 问题,一个完整的 RPC 模块需要可以分为三个层次 服务层(service):RPC 接口定义与实现协议层(protocol):RPC 报文格式和数据编码格式传输层(transport):

starstarstone的专栏 497

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

C++新手实战:从零构建轻量级JsonRPC框架,掌握RPC核心原理

远程过程调用(RPC)是分布式系统实现跨进程、跨机器通信的核心技术,其核心原理在于通过网络协议,使本地程序能够像调用本地函数一样调用远程服务。RPC框架通过序列化、网络传输和反序列化等技术,封装了底层通信细节,为开发者提供了透明、高效的远程调用能力,广泛应用于微服务、分布式计算等场景。JsonRPC作为一种基于JSON格式的轻量级RPC协议,因其协议简单、易于调试(如使用Postman工具)和跨语言兼容性,成为学习和理解RPC原理的绝佳切入点。本文聚焦于使用C++从零实现一个遵循JsonRPC 2.0规范的

weixin_33827590的博客 425

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Rust结构体如何安全传递给C++?深度剖析跨语言生命周期管理难题

深入解析C++ Rust数据交互中Rust结构体的安全传递方法,涵盖FFI接口设计、生命周期管理与内存安全策略,适用于跨语言高性能系统开发。有效避免悬垂指针与内存泄漏,保障程序稳定性,值得收藏。

AlgoFun的博客 794

软考——架构师笔记

该文章可作为系统架构设计师考试的参考笔记。

weixin_43930239的博客 723
上一篇: HTML5 Tutorial
下一篇: Java RMI之HelloWorld篇
piperzero
博客等级 码龄21年 1377粉丝 504原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值