intfunction接口的用法
- 格式:docx
- 大小:10.58 KB
- 文档页数:1
WebApi接⼝返回值类型详解(转)使⽤过Webapi的园友应该都知道,Webapi的接⼝返回值主要有四种类型void⽆返回值IHttpActionResultHttpResponseMessage⾃定义类型此篇就围绕这四块分别来看看它们的使⽤。
⼀、void⽆返回值void关键字我们都不陌⽣,它申明⽅法没有返回值。
它的使⽤也很简单,我们来看⼀个⽰例就能明⽩。
public class ORDER{public string ID { get; set; }public string NO { get; set; }public string NAME { get; set; }public string DESC { get; set; }} public class OrderController : ApiController{[HttpPost]public void SaveOrder(ORDER name){//处理业务逻辑}}在Web⾥⾯调⽤$(function () {$.ajax({type: 'post',url: 'http://localhost:21528/api/Order/SaveOrder',data: { ID: "aaa", NAME: "test" },success: function (data, status) {alert(data);}});});得到结果可以看到,使⽤void申明的⽅法,在success⽅法⾥⾯得不到返回值,并且会返回http状态码204,告诉客户端此请求没有返回值。
⼆、IHttpActionResultIHttpActionResult类型是WebApi⾥⾯⾮常重要的⼀种返回值类型。
下⾯博主就根据平时在项⽬⾥⾯使⽤最多的⼏种⽅式来讲解下这种类型的返回值的⼀些⽤法。
system verilog中virtual的用法Virtual在SystemVerilog中是一种关键字,用于定义作为接口或基类的虚拟对象。
本文将介绍virtual的用法和功能,包括虚拟方法、虚拟类、虚拟端口和虚拟接口,并提供一些示例代码来加深理解。
我将逐步回答以下问题:1. 什么是虚拟方法?2. 如何定义和使用虚拟类?3. 虚拟端口和虚拟接口的作用是什么?4. 如何在SystemVerilog中使用virtual?1. 什么是虚拟方法?虚拟方法是一种在超类中声明但在派生类中具体实现的方法。
使用virtual关键字声明一个方法,从而能够在派生类中进行重写。
这使得派生类能够替换超类的方法实现,实现了多态。
示例代码如下:systemverilogclass Animal;virtual function void makeSound();display("Animal makes a sound");endfunctionendclassclass Dog extends Animal;virtual function void makeSound();display("Dog barks");endfunctionendclassclass Cat extends Animal;virtual function void makeSound();display("Cat meows");endfunctionendclassmodule Test;Animal a;initial begina = new Animal();a.makeSound(); 输出"Animal makes a sound"a = new Dog();a.makeSound(); 输出"Dog barks"a = new Cat();a.makeSound(); 输出"Cat meows"endendmodule在这个示例中,Animal类定义了一个虚拟方法makeSound(),它在派生类Dog和Cat中被重写。
DAME3000N驱动程序使用说明书请您务必阅读《使用纲要》,他会使您事半功倍!目录目录第一章版权信息与命名约定 (2)第一节、版权信息 (2)第二节、命名约定 (2)第二章DAME3000N设备函数接口介绍 (2)第一节、设备驱动接口函数列表(每个函数省略了前缀“DAME3000N_”) (2)第二节、设备对象管理函数原型说明 (3)第三节、AI操作函数原型说明 (6)第四节、DO操作函数原型说明 (7)第五节、DA操作函数原型说明 (11)第六节、DI操作函数原型说明 (11)第三章硬件参数结构 (14)第一节、DAME3000N设备网络配置结构介绍(_DEVICE_NET_INFO) (14)第四章软件使用说明 (19)第一节、上电及初始化 (19)第二节、上位机软件的基本用法 (19)提醒用户:通常情况下,WINDOWS系统在安装时自带的DLL库和驱动不全,所以您不管使用那种语言编程,请您最好先安装上Microsoft Visual Studio2005版本的软件,方可使我们的驱动程序有更完备的运行环境。
有关设备驱动安装和产品二次发行请参考DAME3000N.doc文档。
第一章版权信息与命名约定第一节、版权信息本软件产品及相关套件均属北京市阿尔泰科技有限公司所有,其产权受国家法律绝对保护,除非本公司书面允许,其他公司、单位及个人不得非法使用和拷贝,否则将受到国家法律的严厉制裁。
您若需要我公司产品及相关信息请及时与我们联系,我们将热情接待。
第二节、命名约定一、为简化文字内容,突出重点,本文中提到的函数名通常为基本功能名部分,其前缀设备名如DAME3000Nxxxx_则被省略。
如DAME3000N_CreateDevice则写为以上规则不局限于该产品。
第二章DAME3000N设备函数接口介绍第一节、设备驱动接口函数列表(每个函数省略了前缀“DAME3000N_”)函数名函数功能备注①设备对象操作函数CreateDevice创建设备对象ReleaseDevice释放设备对象GetNetworkConfig获得设备的网络配置信息SetNetworkConfig设置设备的网络配置信息使用需知Visual C++&C++Builder:首先将DAME3000N.h和DAME3000N.lib两个驱动库文件从相应的演示程序文件夹下复制到您的源程序文件夹中,然后在您的源程序头部添加如下语句,以便将驱动库函数接口的原型定义信息和驱动接口导入库(DAME3000N.lib)加入到您的工程中。
C#进阶系列——WebApi接⼝参数不再困惑:传参详解⼀、get请求对于取数据,我们使⽤最多的应该就是get请求了吧。
下⾯通过⼏个⽰例看看我们的get请求参数传递。
1、基础类型参数[HttpGet]public string GetAllChargingData(int id, string name){return "ChargingData" + id;}$.ajax({type: "get",url: "http://localhost:27221/api/Charging/GetAllChargingData",data: { id: 1, name: "Jim", bir: "1988-09-11"},success: function (data, status) {if (status == "success") {$("#div_test").html(data);}}});参数截图效果这是get请求最基础的参数传递⽅式,没什么特别好说的。
2、实体作为参数如果我们在get请求时想将实体对象做参数直接传递到后台,是否可⾏呢?我们来看看。
public class TB_CHARGING{/// <summary>/// 主键Id/// </summary>public string ID { get; set; }/// <summary>/// 充电设备名称/// </summary>public string NAME { get; set; }/// <summary>/// 充电设备描述/// </summary>public string DES { get; set; }/// <summary>/// 创建时间/// </summary>public DateTime CREATETIME { get; set; }}[HttpGet]public string GetByModel(TB_CHARGING oData){return "ChargingData" + oData.ID;} $.ajax({type: "get",url: "http://localhost:27221/api/Charging/GetByModel",contentType: "application/json",data: { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" },success: function (data, status) {if (status == "success") {$("#div_test").html(data);}}});测试结果由上图可知,在get请求时,我们直接将json对象当做实体传递后台,后台是接收不到的。
java的case when写法全文共四篇示例,供读者参考第一篇示例:在Java中,我们经常会用到case when语句来实现条件判断和分支选择。
虽然Java本身并没有提供专门的case when语法,但我们可以通过if-else语句或switch语句来模拟实现类似功能。
在本文中,我们将介绍几种常见的Java中的case when写法,并且讨论它们的使用场景和注意事项。
1. 使用if-else语句实现case when在Java中,最常见的一种实现case when功能的方式就是使用if-else语句。
我们可以通过一系列的if-else语句来进行条件判断,并根据不同的条件执行不同的逻辑代码。
例如:```int num = 2;if(num == 1) {System.out.println("num is 1");} else if(num == 2) {System.out.println("num is 2");} else {System.out.println("num is neither 1 nor 2");}```在这个例子中,我们通过一系列的if-else语句来判断变量num的取值,并根据不同的取值输出不同的提示信息。
虽然这种方式比较简单直观,但是当条件比较多时,代码会变得臃肿和难以维护。
除了if-else语句,Java还提供了switch语句来实现类似的功能。
switch语句更适合处理多个条件的情况,代码更加简洁、清晰。
例如:在这个例子中,我们通过switch语句根据num的取值来执行不同的分支逻辑。
每个case后面需要跟着break语句,表示执行完当前分支后跳出switch语句。
map.getOrDefault(num, () -> System.out.println("num is neither 1 nor 2")).run();```在这个例子中,我们将条件和对应逻辑代码存储在一个Map中,并使用getOrDefault方法来获取条件对应的逻辑代码并执行。
Matlab7.0.4 接口连接说明。
PSCAD使用的4.2.1教育版,网络版。
对于大小写的要求,对于系统的变量需要正常的大小写。
用户自定义的不需要注意。
切记:每个有MA TLAB的工程都需要设置一下链接,那个勾一定要勾上啊,害了我几天。
否则会报错的。
如下:不勾就会报错:下面的两个设置是一次设置就可以保存的。
1.设置fortran编译器,不能使用GUN编译器,因为它只能用在fortran77中,我用的下面的版本。
VF6.6专业版。
在PSCAD中如下设置:2.设置MA TLAB,对于7.0.4已经可以正常运行。
3.PSCAD系统设置完成后,就可以建case了,开始加模块了。
下面是我做的一个简单测试模块。
单输入单输出。
已成功运行。
testmat1.m :文件如下:function [I1]=testIO(in1)I1=in1;模块的制作如下:首先建立一个模块,这个就自己建了。
上面的三个参数是可以自己改的,第一个参数是m函数的文件名。
第二个参数是相对路径,即m函数所在的文件夹名,建议仿系统示例目录形式。
第三个参数是不一定需要的。
前面两个参数主要是用于调用m函数,表示路径和文件名。
下面是编写的脚本文件,是在DSDYN中。
#STORAGE REAL:2#LOCAL INTEGER I_CNTSTORF(NSTORF) = $INPUTCALL MLAB_INT("%:Dir\$Path", "$Name", "R" , "R")$OUTPUT = STORF(NSTORF+1)NSTORF = NSTORF + 2联合数组多输入多输出:首先建立一个INPUT,一个OUTPUT,可以是多维的,下面是一个2维输入输出。
注意,这里只有一个变量,使用数组表示,此数组下标是从1开始的。
在m文件中也是使用数组。
在main中使用数据组合和分离器。
C++回调函数用法本篇文章来源于:一回调函数我们经常在C++设计时通过使用回调函数可以使有些应用(如定时器事件回调处理、用回调函数记录某操作进度等)变得非常方便和符合逻辑,那么它的内在机制如何呢,怎么定义呢?它和其它函数(比如钩子函数)有何不同呢?使用回调函数实际上就是在调用某个函数(通常是API函数)时,将自己的一个函数(这个函数为回调函数)的地址作为参数传递给那个函数。
而那个函数在需要的时候,利用传递的地址调用回调函数,这时你可以利用这个机会在回调函数中处理消息或完成一定的操作。
至于如何定义回调函数,跟具体使用的API函数有关,一般在帮助中有说明回调函数的参数和返回值等。
C++中一般要求在回调函数前加CALLBACK(相当于FAR PASCAL),这主要是说明该函数的调用方式。
至于钩子函数,只是回调函数的一个特例。
习惯上把与SetWindowsHookEx函数一起使用的回调函数称为钩子函数。
也有人把利用VirtualQueryEx安装的函数称为钩子函数,不过这种叫法不太流行。
也可以这样,更容易理解:回调函数就好像是一个中断处理函数,系统在符合你设定的条件时自动调用。
为此,你需要做三件事:1. 声明;2. 定义;3. 设置触发条件,就是在你的函数中把你的回调函数名称转化为地址作为一个参数,以便于系统调用。
声明和定义时应注意:回调函数由系统调用,所以可以认为它属于WINDOWS系统,不要把它当作你的某个类的成员函数。
二回调函数、消息和事件例程调用(calling)机制从汇编时代起已经大量使用:准备一段现成的代码,调用者可以随时跳转至此段代码的起始地址,执行完后再返回跳转时的后续地址。
CPU为此准备了现成的调用指令,调用时可以压栈保护现场,调用结束后从堆栈中弹出现场地址,以便自动返回。
借堆栈保护现场真是一项绝妙的发明,它使调用者和被调者可以互不相识,于是才有了后来的函数和构件。
此调用机制并非完美。
金融基础件2.0接入T2SDK开发手册文档版本V2.0发布日期2013-06-27修改记录目录目录 (3)前言 (8)产品简介 (8)读者对象 (8)手册概况 (8)缩略语/术语 (8)1.开发包简介 (10)2.开发流程 (11)2.1同步开发流程 (11)2.2异步开发流程 (11)3.开发接口 (13)3.1T2SDK引出函数 (13)3.1.1取开发包版本信息(GetVersionInfo) (13)3.1.2创建配置接口(NewConfig) (13)3.1.3创建连接接口(NewConnection) (14)3.1.4创建打包器接口(NewPacker) (14)3.1.5创建解包器接口(NewUnPacker) (14)3.1.6加密接口(Encode) (15)3.1.7密码加密接口(EncodeEx) (16)3.1.8创建过滤接口(NewFilter) (16)3.1.9创建订阅参数接口(NewSubscribeParam) (16)3.1.10创建业务消息接口(NewBizMessage) (17)3.2配置接口【CConfigInterface】 (18)3.2.1读取配置文件(Load) (18)3.2.2保存配置文件(Save) (19)3.2.3获取字符型配置项值(GetString) (19)3.2.4获取整型配置项值(GetInt) (19)3.2.5设置字符型配置项值(SetString) (20)3.2.6设置整型配置项值(SetInt) (20)3.3连接回调接口【CCallbackInterface】 (21)3.3.1TCP连接成功回调(OnConnect) (21)3.3.2安全连接成功回调(OnSafeConnect) (21)3.3.3注册成功回调(OnRegister) (21)3.3.4连接断开回调(OnClose) (22)3.3.5数据发送回调(OnSent) (22)3.3.6收到消息回调(OnReceivedBiz) (23)3.3.7收到消息扩展回调(OnReceivedBizEx) (23)3.3.8收到业务消息回调(OnReceivedBizMsg) (24)3.4业务消息接口【IBizMessage】 (25)3.4.1设置功能号(SetFunction) (25)3.4.2获取功能号(GetFunction) (25)3.4.3设置包类型(SetPacketType) (26)3.4.4获取包类型(GetPacketType) (26)3.4.5设置营业部号(SetBranchNo) (26)3.4.6获取营业部号(GetBranchNo) (26)3.4.7设置系统号(SetSystemNo) (27)3.4.8获取系统号(GetSystemNo) (27)3.4.9设置子系统号(SetSubSystemNo) (27)3.4.10获取子系统号(GetSubSystemNo) (28)3.4.11设置发送者编号(SetSenderId) (28)3.4.12获取发送者编号(GetSenderId) (28)3.4.13设置包序号(SetPacketId) (28)3.4.14获取包序号(GetPacketId) (29)3.4.15设置目的地路由(SetTargetInfo) (29)3.4.16获取目的地路由(GetTargetInfo) (30)3.4.17设置发送者路由(SetSendInfo) (30)3.4.18获取发送者路由(GetSendInfo) (30)3.4.19设置错误号(SetErrorNo) (31)3.4.20获取错误号(GetErrorNo) (31)3.4.21设置错误信息(SetErrorInfo) (31)3.4.22获取错误信息(GetErrorInfo) (31)3.4.23设置返回码(SetReturnCode) (32)3.4.24获取返回码(GetReturnCode) (32)3.4.25设置业务内容(SetContent) (32)3.4.26获取业务内容(GetContent) (33)3.4.27设置订阅类型(SetIssueType) (33)3.4.28获取订阅类型(GetIssueType) (34)3.4.29设置订阅序号(SetSequeceNo) (34)3.4.30获取订阅序号(GetSequeceNo) (35)3.4.31设置订阅关键字段(SetKeyInfo) (35)3.4.32获取订阅关键字段(GetKeyInfo) (35)3.4.33设置附加数据(SetAppData) (36)3.4.34获取附加数据(GetAppData) (36)3.4.35请求转换成应答(ChangeReq2AnsMessage) (36)3.4.36消息转换成二进制流(GetBuff) (37)3.4.37二进制流转换成消息(SetBuff) (37)3.5打包器接口【IF2Packer】 (39)3.5.1设置缓存区空间(SetBuffer) (39)3.5.2开始打包(BeginPack) (39)3.5.3构造新结果集(NewDataset) (40)3.5.4添加新字段(AddField) (40)3.5.5添加string型数据(AddStr) (40)3.5.6添加int型数据(AddInt) (41)3.5.7添加double型数据(AddDouble) (41)3.5.8添加char型数据(AddChar) (41)3.5.9添加二进制数据(AddRaw) (41)3.5.10结束打包(EndPack) (42)3.5.11获取打包结果指针(GetPackBuf) (42)3.5.12获取打包结果长度(GetPackLen) (42)3.5.13获取打包缓存长度(GetPackBufSize) (43)3.5.14获取打包版本(GetVersion) (43)3.5.15设置返回码(SetReturnCode) (43)3.5.16获取解包接口(UnPack) (43)3.5.17释放打包内存(FreeMem) (44)3.5.18清空最后一个结果集数据(ClearValue) (44)3.5.19开始打包扩展接口(BeginPackEx) (44)3.5.20清空当前结果集(ClearDataSet) (45)3.6结果集接口【IF2ResultSet】 (45)3.6.1获取列个数(GetColCount) (45)3.6.2根据下标获取列名字(GetColName) (45)3.6.3获取列类型(GetColType) (46)3.6.4获取列精度(GetColScale) (46)3.6.5获取列最大长度(GetColWidth) (46)3.6.6根据列名字找到列下标(FindColIndex) (46)3.6.7根据列下标获取string类型值(GetStrByIndex) (47)3.6.8根据列名字获取string类型值(GetStr) (47)3.6.9根据列下标获取char类型值(GetCharByIndex) (47)3.6.10根据列名字获取char类型值(GetChar) (48)3.6.11根据列下标获取double类型值(GetDoubleByIndex) (48)3.6.12根据列名字获取double类型值(GetDouble) (48)3.6.13根据列下标获取int类型值(GetIntByIndex) (48)3.6.14根据列名字获取int类型值(GetInt) (49)3.6.15根据列下标获取二进制类型值(GetRawByIndex) (49)3.6.16根据列名字获取二进制类型值(GetRaw) (49)3.6.17最后一次取得值是否为空(WasNull) (50)3.6.18结果集下一条记录(Next) (50)3.6.19结果集是否到结尾(IsEOF) (50)3.6.20结果集是否为空(IsEmpty) (51)3.6.21结果集释放(Destroy) (51)3.7解包器接口【IF2UnPacker】 (51)3.7.1获取解包器版本(GetVersion) (51)3.7.2二进制转换为解包器(Open) (52)3.7.3获取结果集个数(GetDatasetCount) (52)3.7.4根据下标设置当前结果集(SetCurrentDatasetByIndex) (52)3.7.5根据结果集名字设置当前结果集(SetCurrentDataset)、 (53)3.7.6获取解包器缓存指针(GetPackBuf) (53)3.7.7获取解包器缓存长度(GetPackLen) (53)3.7.8获取当前结果集行数(GetRowCount) (53)3.7.9指向结果集第一行记录(First) (54)3.7.10指向结果集最后一行记录(Last) (54)3.7.11跳转到结果集任意行(Go) (54)3.8过滤器接口【CFilterInterface】 (56)3.8.1根据下标获取条件名字(GetFilterNameByIndex) (56)3.8.2根据下标获取条件值(GetFilterValueByIndex) (56)3.8.3根据条件名字好获取条件值(GetFilterValue) (57)3.8.4获取过滤条件个数(GetCount) (57)3.8.5设置过滤条件名字和值(SetFilter) (57)3.9订阅参数接口【CSubscribeParamInterface】 (58)3.9.1设置主题名字(SetTopicName) (58)3.9.2设置附加数据(SetAppData) (58)3.9.3设置过滤条件(SetFilter) (58)3.9.4设置返回字段(SetReturnFiled) (59)3.9.5设置补缺标志(SetFromNow) (59)3.9.6设置覆盖标志(SetReplace) (59)3.9.7设置发送间隔(SetSendInterval) (60)3.9.8获取主题名字(GetTopicName) (60)3.9.9获取附加数据(GetAppData) (60)3.9.10根据下标获取过滤字段名字(GetFilterNameByIndex) (61)3.9.11根据下标获取过滤字段值(GetFilterValueByIndex) (61)3.9.12根据过滤名字获取值(GetFilterValue) (61)3.9.13获取过滤条件个数(GetFilterCount) (62)3.9.14获取返回字段(GetReturnFiled) (62)3.9.15获取补缺标志(GetFromNow) (62)3.9.16获取覆盖标志(GetReplace) (62)3.9.17获取发送间隔(GetSendInterval) (63)3.10订阅回调接口【CSubCallbackInterface】 (63)3.10.1收到发布消息回调(OnReceived) (64)3.10.2收到剔除订阅回调(OnRecvTickMsg) (64)3.11订阅接口【CSubscribeInterface】 (65)3.11.1订阅主题 (65)3.11.2取消订阅 (66)3.11.3取消订阅扩展接口 (66)3.11.4获取已经订阅的信息 (66)3.12发布接口【CPublishInterface】 (68)3.12.1业务发包格式发送 (69)3.12.2二进制数据发送 (70)3.13连接接口【CConnectionInterface】 (73)3.13.1初始化连接对象(Create) (73)3.13.2开始连接/注册(Connect) (74)3.13.3断开连接(Close) (74)3.13.4取连接服务器地址(GetServerAddress) (74)3.13.5取连接状态(GetStatus) (75)3.13.6取服务器负载(GetServerLoad) (75)3.13.7取错误码对应的错误信息(GetErrorMsg) (76)3.13.8取连接错误号(GetConnectError) (76)3.13.9发送业务数据(SendBiz) (76)3.13.10接收业务数据(RecvBiz) (77)3.13.11发送业务数据扩展接口(SendBizEx) (78)3.13.12接收业务数据扩展接口(RecvBizEx) (79)3.13.13连接初始化的扩展接口(CreateEx) (80)3.13.14获取服务端上连接的IP和端口(GetRealAddress) (80)3.13.15获取本地连接使用的IP和端口(GetSelfAddress) (80)3.13.16获取连接使用的MAC地址(GetSelfMac) (81)3.13.17创建订阅者(NewSubscriber) (81)3.13.18获取发布者(GetPublisher) (81)3.13.19获取主题信息(GetTopic) (82)3.13.20获取消息中心的最后错误(GetMCLastError) (83)3.13.21连接用IBizMessage接口初始化(Create2BizMsg) (83)3.13.22连接发送IBizMessage业务消息(SendBizMsg) (84)3.13.23连接接收IBizMessage业务消息(RecvBizMsg) (84)4.注意事项 (88)4.1相关限制 (88)4.2调用限制 (89)4.3回调线程 (89)4.4编程建议 (89)5.示例代码 (90)5.1同步发送接收 (90)5.2异步发送接收 (94)5.3订阅 (98)5.4发布 (104)6.附录............................................................................................................错误!未定义书签。
函数大全( i开头)函数名: imagesize功能: 返回保存位图像所需的字节数用法: unsigned far imagesize(int left, int top, int right, int bottom); 程序例:#include#include#include#include#define ARROW_SIZE 10void draw_arrow(int x, int y);int main(void){/* request autodetection */int gdriver = DETECT, gmode, errorcode;void *arrow;int x, y, maxx;unsigned int size;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx();x = 0;y = getmaxy() / 2;/* draw the image to be grabbed */draw_arrow(x, y);/* calculate the size of the image */size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);/* allocate memory to hold the image */arrow = malloc(size);/* grab the image */getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);/* repeat until a key is pressed */while (!kbhit()){/* erase old image */putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);x += ARROW_SIZE;if (x >= maxx)x = 0;/* plot new image */putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);}/* clean up */free(arrow);closegraph();return 0;}void draw_arrow(int x, int y){/* draw an arrow on the screen */moveto(x, y);linerel(4*ARROW_SIZE, 0);linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);linerel(0, 2*ARROW_SIZE);linerel(2*ARROW_SIZE, -1*ARROW_SIZE);}函数名: initgraph功能: 初始化图形系统用法: void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);程序例:#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;/* initialize graphics mode */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* return with error code */}/* draw a line */line(0, 0, getmaxx(), getmaxy());/* clean up */getch();closegraph();return 0;}函数名: inport功能: 从硬件端口中输入用法: int inp(int protid);程序例:#includeint main(void){int result;int port = 0; /* serial port 0 */result = inport(port);printf("Word read from port %d = 0x%X\n", port, result);return 0;}函数名: insline功能: 在文本窗口中插入一个空行用法: void insline(void);程序例:#includeint main(void){clrscr();cprintf("INSLINE inserts an empty line in the text window\r\n"); cprintf("at the cursor position using the current text\r\n");cprintf("background color. All lines below the empty one\r\n"); cprintf("move down one line and the bottom line scrolls\r\n"); cprintf("off the bottom of the window.\r\n");cprintf("\r\nPress any key to continue:");gotoxy(1, 3);getch();insline();getch();return 0;}函数名: installuserdriver功能: 安装设备驱动程序到BGI设备驱动程序表中用法: int far installuserdriver(char far *name, int (*detect)(void));#include#include#include#include/* function prototypes */int huge detectEGA(void);void checkerrors(void);int main(void){int gdriver, gmode;/* install a user written device driver */ gdriver = installuserdriver("EGA", detectEGA);/* must force use of detection routine */ gdriver = DETECT;/* check for any installation errors */ checkerrors();/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "");/* check for any initialization errors */ checkerrors();/* draw a line */line(0, 0, getmaxx(), getmaxy());/* clean up */getch();closegraph();return 0;}/* detects EGA or VGA cards */int huge detectEGA(void){int driver, mode, sugmode = 0;detectgraph(&driver, &mode);if ((driver == EGA) || (driver == VGA))/* return suggested video mode number */return sugmode;else/* return an error code */return grError;}/* check for and report any graphics errors */void checkerrors(void){int errorcode;/* read result of last graphics operation */errorcode = graphresult();if (errorcode != grOk){printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1);}}函数名: installuserfont功能: 安装未嵌入BGI系统的字体文件(CHR)用法: int far installuserfont(char far *name);程序例:#include#include#include#include/* function prototype */void checkerrors(void);int main(void){/* request auto detection */int gdriver = DETECT, gmode;int userfont;int midx, midy;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");midx = getmaxx() / 2;midy = getmaxy() / 2;/* check for any initialization errors */checkerrors();/* install a user defined font file */userfont = installuserfont("USER.CHR");/* check for any installation errors */checkerrors();/* select the user font */settextstyle(userfont, HORIZ_DIR, 4);/* output some text */outtextxy(midx, midy, "Testing!");/* clean up */getch();closegraph();return 0;}/* check for and report any graphics errors */void checkerrors(void){int errorcode;/* read result of last graphics operation */errorcode = graphresult();if (errorcode != grOk){printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1);}}函数名: int86功能: 通用8086软中断接口用法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); 程序例:#include#include#include#define VIDEO 0x10void movetoxy(int x, int y){union REGS regs;regs.h.ah = 2; /* set cursor postion */regs.h.dh = y;regs.h.dl = x;regs.h.bh = 0; /* video page 0 */int86(VIDEO, ®s, ®s);}int main(void){clrscr();movetoxy(35, 10);printf("Hello\n");return 0;}函数名: int86x功能: 通用8086软中断接口用法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, struct SREGS *segregs);程序例:#include#include#includeint main(void){char filename[80];union REGS inregs, outregs;struct SREGS segregs;printf("Enter filename: ");gets(filename);inregs.h.ah = 0x43;inregs.h.al = 0x21;inregs.x.dx = FP_OFF(filename);segregs.ds = FP_SEG(filename);int86x(0x21, &inregs, &outregs, &segregs);printf("File attribute: %X\n", outregs.x.cx);return 0;}函数名: intdos功能: 通用DOS接口用法: int intdos(union REGS *inregs, union REGS *outregs); 程序例:#include#include/* deletes file name; returns 0 on success, nonzero on failure */ int delete_file(char near *filename){union REGS regs;int ret;regs.h.ah = 0x41; /* delete file */regs.x.dx = (unsigned) filename;ret = intdos(®s, ®s);/* if carry flag is set, there was an error */return(regs.x.cflag ? ret : 0);}int main(void){int err;err = delete_file("NOTEXIST.$$$");if (!err)printf("Able to delete NOTEXIST.$$$\n");elseprintf("Not Able to delete NOTEXIST.$$$\n");return 0;}函数名: intdosx功能: 通用DOS中断接口用法: int intdosx(union REGS *inregs, union REGS *outregs, struct SREGS *segregs);程序例:#include#include/* deletes file name; returns 0 on success, nonzero on failure */ int delete_file(char far *filename){union REGS regs; struct SREGS sregs;int ret;regs.h.ah = 0x41; /* delete file */regs.x.dx = FP_OFF(filename);sregs.ds = FP_SEG(filename);ret = intdosx(®s, ®s, &sregs);/* if carry flag is set, there was an error */return(regs.x.cflag ? ret : 0);}int main(void){int err;err = delete_file("NOTEXIST.$$$");if (!err)printf("Able to delete NOTEXIST.$$$\n");elseprintf("Not Able to delete NOTEXIST.$$$\n");return 0;函数名: intr功能: 改变软中断接口用法: void intr(int intr_num, struct REGPACK *preg); 程序例:#include#include#include#include#define CF 1 /* Carry flag */int main(void){char directory[80];struct REGPACK reg;printf("Enter directory to change to: ");gets(directory);reg.r_ax = 0x3B << 8; /* shift 3Bh into AH */reg.r_dx = FP_OFF(directory);reg.r_ds = FP_SEG(directory);intr(0x21, ®);if (reg.r_flags & CF)printf("Directory change failed\n");getcwd(directory, 80);printf("The current directory is: %s\n", directory);return 0;}函数名: ioctl功能: 控制I/O设备用法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); 程序例:#include#include#includeint main(void){int stat;/* use func 8 to determine if the default drive is removable */ stat = ioctl(0, 8, 0, 0);if (!stat)printf("Drive %c is removable.\n", getdisk() + 'A');elseprintf("Drive %c is not removable.\n", getdisk() + 'A'); return 0;}函数名: isatty功能: 检查设备类型用法: int isatty(int handle);程序例:#include#includeint main(void){int handle;handle = fileno(stdprn);if (isatty(handle))printf("Handle %d is a device type\n", handle);elseprintf("Handle %d isn't a device type\n", handle);return 0;}函数名: itoa功能: 把一整数转换为字符串用法: char *itoa(int value, char *string, int radix);程序例:#include#includeint main(void){int number = 12345;char string[25];itoa(number, string, 10);printf("integer = %d string = %s\n", number, string); return 0;}。
intfunction接口的用法
在 Kotlin 中,`IntFunction` 接口通常用于表示接受一个整数参数并返回结果的函数。这个
接口在 Kotlin 标准库中并不存在,但是你可以自己定义一个类似的接口,或者使用 Kotlin
标准库中的函数类型来实现类似的功能。
以下是一个示例,演示了如何定义一个类似 `IntFunction` 接口的函数类型,并使用它来实
现一个简单的功能:
```kotlin
// 定义一个类似 IntFunction 的函数类型
typealias IntFunction = (Int) -> Int
// 使用 IntFunction 来实现一个简单的示例
fun main() {
val square: IntFunction = { x: Int -> x * x } // 定义一个函数,计算平方
val cube: IntFunction = { x: Int -> x * x * x } // 定义一个函数,计算立方
println("Square of 5 is ${square(5)}") // 调用 square 函数,输出 25
println("Cube of 3 is ${cube(3)}") // 调用 cube 函数,输出 27
}
```
在这个示例中,我们首先使用 `typealias` 关键字定义了一个名为 `IntFunction` 的函数类型,
它接受一个整数参数并返回一个整数结果。然后我们定义了两个函数 `square` 和 `cube`,
它们都符合 `IntFunction` 的函数类型定义。最后,我们调用这两个函数并输出结果。
通过这种方式,我们可以方便地定义和使用接受整数参数并返回整数结果的函数类型,从而
实现类似于 `IntFunction` 接口的功能。