CN109840093A - A kind of arbitrary function adapter implementation method - Google Patents
A kind of arbitrary function adapter implementation method Download PDFInfo
- Publication number
- CN109840093A CN109840093A CN201811579835.1A CN201811579835A CN109840093A CN 109840093 A CN109840093 A CN 109840093A CN 201811579835 A CN201811579835 A CN 201811579835A CN 109840093 A CN109840093 A CN 109840093A
- Authority
- CN
- China
- Prior art keywords
- function
- type
- std
- parameter
- template subclass
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Withdrawn
Links
Landscapes
- Stored Programmes (AREA)
Abstract
A kind of arbitrary function adapter implementation method, comprising: defined function adapter base class;Define the template subclass of the function adaptation base class;Compile the template subclass;Obtain the return type and parameter type and number of parameters of the function;It runs the template subclass and calls Invoke function;The Invoke parameter is converted according to the parameter type of template subclass record and assignment saves;Real function call is carried out using the template subclass.Arbitrary function adapter implementation method of the invention can be used same type of object and store different types of function object, and adaptation arbitrary function returns harmonic function message informing.
Description
Technical field
The present invention relates to computer program development technique fields, more particularly to a kind of arbitrary function adapter realization side
Method.
Background technique
In carrying out C++ program development, in order to realize the height multiplexing and intermodule decoupling of code, often can all it make
The basic development technique such as function readjustment and message informing are used, however since C++ is a kind of strongly-typed program development language,
Same type of function object can only be all used in defined function readjustment and message informing function, this is in complicated program development
In have some limitations, in present technology or be each type if necessary to a plurality of types of function message informings
The function message informing of type defines a message informing manager or is one species by the type definition of message informing function
Type uses void* as parameter, implements function and go to parse void* parameter again, this clearly increases programs to open
The workload of hair and the readability for reducing development efficiency and program.
Summary of the invention
In order to solve the shortcomings of the prior art, the purpose of the present invention is to provide a kind of realizations of arbitrary function adapter
Method can be used same type of object and store different types of function object, and adaptation arbitrary function returns harmonic function and disappears
Breath notice.
To achieve the above object, arbitrary function adapter implementation method provided by the invention, comprising:
Defined function adapter base class;
Define the template subclass of the function adaptation base class;
Compile the template subclass;
Obtain the return type and parameter type and number of parameters of the function;
It runs the template subclass and calls Invoke function;
The Invoke parameter is converted according to the parameter type of template subclass record and assignment saves;
Real function call is carried out using the template subclass.
Further, the function adaptation base class includes member function, and function prototype is as follows:
std::any Invoke(const std::vector<std::any>&)。
Further, the return type of the member function and parameter type are all based on std::any.
Further, using the pointer of the function adaptation base class as final function adaptation pointer.
Further, the template subclass covers the Invoke function in the function adaptation base class
Further, the template subclass further includes the function object and std::tuple type of std::function type
Parameter list object.
To achieve the above object, the present invention also provides a kind of computer readable storage mediums, are stored thereon with computer and refer to
It enables, which is characterized in that the computer instruction executes arbitrary function adapter implementation method step as described above when running.
Arbitrary function adapter implementation method of the invention, has the advantages that
1) it is able to use same type of object and stores different types of function object, adaptation arbitrary function returns harmonic function and disappears
Breath notice.
2) program development efficiency, lower coupling, Gao Fuyong are promoted, program development cost is reduced.
Other features and advantages of the present invention will be illustrated in the following description, also, partly becomes from specification
It obtains it is clear that understand through the implementation of the invention.
Detailed description of the invention
Attached drawing is used to provide further understanding of the present invention, and constitutes part of specification, and with it is of the invention
Embodiment together, is used to explain the present invention, and is not construed as limiting the invention.In the accompanying drawings:
Fig. 1 is arbitrary function adapter implementation method flow chart according to the present invention.
Specific embodiment
Hereinafter, preferred embodiments of the present invention will be described with reference to the accompanying drawings, it should be understood that preferred reality described herein
Apply example only for the purpose of illustrating and explaining the present invention and is not intended to limit the present invention.
Fig. 1 is arbitrary function adapter implementation method flow chart according to the present invention, below with reference to Fig. 1, to the present invention
Arbitrary function adapter implementation method be described in detail.
Firstly, in step 101, defined function adapter base class, wherein the function adaptation base class is properly termed as
AnyFunctionBase。
Preferably, the function adaptation base class includes member function.In the step, function adaptation base class
AnyFunctionBase includes a member function, and the possible prototype of function is as follows:
Std::any Invoke (const std::vector<std::any>&),
Preferably, the return type of the member function and parameter type are all based on the member function.The return of the function
Type and parameter type are all based on std::any, are because when doing so this function of calling using the reason of std::any
Wait the type of the return and parameter that can wipe real function.
Preferably, using the pointer of the function adaptation base class as final function adaptation pointer.In the step, function
The pointer of adapter base class AnyFunctionBase type will also be used as final function adaptation pointer.
In step 102, the template subclass of the function adaptation base class is defined.In the step, definition is inherited from
The template subclass AnyFunction of AnyFunctionBase.
Preferably, using the template subclass as the real realization of function call.In the step, AnyFunction template
Class is by the real realization as function call.
In step 103, the template subclass is compiled, in the step, the possibility prototype of AnyFunction are as follows:
template<typename _Ft, size_t ArgsNum>
class AnyFunction : public AnyFunctionBase{}
Specialization prototype is
template<typename _Ft, 0>
class AnyFunction : public AnyFunctionBase
Wherein, template parameter _ Ft is that can call object or function;ArgsNum is that can call the parameter of object or function
Number.
Preferably, the template subclass covers the Invoke function in the function adaptation base class.In the step,
AnyFunction covers the Invoke function in AnyFunctionBase.
In step 104, the return type and parameter type and number of parameters of the function are obtained.In the step, extraction _
The return type of Ft, parameter type and number of parameters, and general _ Ft type is converted to std::function function object.The step
In, using C++ mould plate technique extraction _ Ft return type, parameter type and number of parameters, and general _ Ft type is converted to std::
Function function object.
Preferably, the template subclass further includes the function object and std::tuple type of std::function type
Parameter list object.In the step, there are two member variable, the letters of a std::function type in AnyFunction
Number objects, one be std::tuple type parameter list object.
In step 105, runs the template subclass and call Invoke function.
In step 106, the Invoke parameter is converted according to the parameter type of template subclass record and assignment saves.
In the step, when the runtime calling Invoke function, it will remember according in the std::tuple subtype member of AnyFunction
Invoke Parameter Switch is that simultaneously assignment is saved in std::tuple corresponding type in std::tuple by the parameter type of record.
In step 107, real function call is carried out using the template subclass.In the step, when creation one
When AnyFunction object, compiling duration AnyFunction just have been able to know return type and the parameter type of function with
And number of parameters.When the runtime calling Invoke function, it will according in the std::tuple subtype member of AnyFunction
Invoke Parameter Switch is that simultaneously assignment is saved in std::tuple to corresponding type in std::tuple by the parameter type of record
In.Then real function call is carried out using std::apply.
Preferably, the present invention also provides a kind of computer readable storage mediums, are stored thereon with computer instruction, feature
It is, the computer instruction executes arbitrary function adapter implementation method step as described above when running.
Those of ordinary skill in the art will appreciate that: the foregoing is only a preferred embodiment of the present invention, and does not have to
In the limitation present invention, although the present invention is described in detail referring to the foregoing embodiments, for those skilled in the art
For, still can to foregoing embodiments record technical solution modify, or to part of technical characteristic into
Row equivalent replacement.All within the spirits and principles of the present invention, any modification, equivalent replacement, improvement and so on should all include
Within protection scope of the present invention.
Claims (7)
1. a kind of arbitrary function adapter implementation method, which comprises the following steps:
Defined function adapter base class;
Define the template subclass of the function adaptation base class;
Compile the template subclass;
Obtain the return type and parameter type and number of parameters of the function;
It runs the template subclass and calls Invoke function;
The Invoke parameter is converted according to the parameter type of template subclass record and assignment saves;
Real function call is carried out using the template subclass.
2. the method according to claim 1, wherein the function adaptation base class includes member function, function
Prototype is as follows:
std::any Invoke(const std::vector<std::any>&)。
3. according to the method described in claim 2, it is characterized in that, the member function, return type and parameter type base
In std::any.
4. the method according to claim 1, wherein using the pointer of the function adaptation base class as final letter
Number adapter pointer.
5. the method according to claim 1, wherein the template subclass covers the function adaptation base class
In Invoke function.
6. the method according to claim 1, wherein the template subclass further includes std::function type
Function object and std::tuple type parameter list object.
7. a kind of computer readable storage medium, is stored thereon with computer instruction, which is characterized in that the computer instruction fortune
Perform claim requires 1 to 6 described in any item arbitrary function adapter implementation method steps when row.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811579835.1A CN109840093A (en) | 2018-12-24 | 2018-12-24 | A kind of arbitrary function adapter implementation method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811579835.1A CN109840093A (en) | 2018-12-24 | 2018-12-24 | A kind of arbitrary function adapter implementation method |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109840093A true CN109840093A (en) | 2019-06-04 |
Family
ID=66883312
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811579835.1A Withdrawn CN109840093A (en) | 2018-12-24 | 2018-12-24 | A kind of arbitrary function adapter implementation method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109840093A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111552638A (en) * | 2020-04-23 | 2020-08-18 | 北京奇艺世纪科技有限公司 | Code detection method and device |
CN113971019A (en) * | 2021-10-19 | 2022-01-25 | 深圳市元征科技股份有限公司 | Data type creating method, device, server and medium |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6237134B1 (en) * | 1997-03-12 | 2001-05-22 | International Business Machines Corporation | Method of, system for, and article of manufacture for providing a generic adaptor for converting from a non-future function pointer to a future function object |
CN102375825A (en) * | 2010-08-13 | 2012-03-14 | 捷达世软件(深圳)有限公司 | Process integration server and method for realizing system integration by utilizing same |
CN103109549A (en) * | 2010-06-25 | 2013-05-15 | 艾奥森诺有限公司 | Apparatus for changing an audio scene and an apparatus for generating a directional function |
CN104331368A (en) * | 2014-11-18 | 2015-02-04 | 合肥康捷信息科技有限公司 | Method for performing static analysis on C++ virtual function call upon cfg (configuration) files |
CN107832056A (en) * | 2017-12-14 | 2018-03-23 | 苏州蜗牛数字科技股份有限公司 | JAVA function calling methods in C++ based on JNI |
-
2018
- 2018-12-24 CN CN201811579835.1A patent/CN109840093A/en not_active Withdrawn
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6237134B1 (en) * | 1997-03-12 | 2001-05-22 | International Business Machines Corporation | Method of, system for, and article of manufacture for providing a generic adaptor for converting from a non-future function pointer to a future function object |
CN103109549A (en) * | 2010-06-25 | 2013-05-15 | 艾奥森诺有限公司 | Apparatus for changing an audio scene and an apparatus for generating a directional function |
CN102375825A (en) * | 2010-08-13 | 2012-03-14 | 捷达世软件(深圳)有限公司 | Process integration server and method for realizing system integration by utilizing same |
CN104331368A (en) * | 2014-11-18 | 2015-02-04 | 合肥康捷信息科技有限公司 | Method for performing static analysis on C++ virtual function call upon cfg (configuration) files |
CN107832056A (en) * | 2017-12-14 | 2018-03-23 | 苏州蜗牛数字科技股份有限公司 | JAVA function calling methods in C++ based on JNI |
Non-Patent Citations (1)
Title |
---|
SIMBA888888: "函数适配器bind2nd 、mem_fun_ref 源码分析、函数适配器应用举例", 《HTTPS://WWW.IT610.COM/ARTICLE/3844325.HTM》 * |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111552638A (en) * | 2020-04-23 | 2020-08-18 | 北京奇艺世纪科技有限公司 | Code detection method and device |
CN111552638B (en) * | 2020-04-23 | 2023-08-18 | 北京奇艺世纪科技有限公司 | Code detection method and device |
CN113971019A (en) * | 2021-10-19 | 2022-01-25 | 深圳市元征科技股份有限公司 | Data type creating method, device, server and medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106598579B (en) | Method and apparatus for integrating dynamic type programming language on blockchain | |
CN107979508B (en) | Micro-service test method and device | |
CN109729149A (en) | A kind of micro services framework implementation method based on note | |
US8713514B2 (en) | Heterogeneous language data typing without executable regeneration | |
US10635408B2 (en) | Method and apparatus for enabling agile development of services in cloud computing and traditional environments | |
CN109840093A (en) | A kind of arbitrary function adapter implementation method | |
CN106547567A (en) | Interprocess communication system and its implementation under multi-service in a kind of Android system | |
JP2000504868A (en) | Management interworking unit and method of forming such a unit | |
CN110233946B (en) | Method for executing outbound service, electronic device and computer readable storage medium | |
CN106681718A (en) | Toolkit-based desktop side plugin frame and implementation method thereof | |
CN102208081A (en) | Method for making business process management (BPM) application to be suitable for being used by multi-tenancy (MT) usages and apparatus thereof | |
CN105975277A (en) | Template-based mixed cloud elastic telescoping set building method | |
CN111158800B (en) | Method and device for constructing task DAG based on mapping relation | |
CN104978170B (en) | A kind of multi-agent system generation method based on graph-based | |
CN104063219B (en) | The form development approach and system of a kind of WEB systems | |
CN109614096B (en) | Method for converting use cases and activities in modeling process based on UML (unified modeling language) requirements | |
CN105933887B (en) | Apply the adaptation method and device between different dual-card intelligent mobile phones | |
CN105786509A (en) | Graphical display method for business process | |
CN108694040B (en) | Call processing method and device and communication system | |
CN110515677A (en) | A method of based on the customized timed task of cloudy platform | |
Vallejos et al. | Predicated generic functions: enabling context-dependent method dispatch | |
CN113722045B (en) | Cluster application deployment method and device | |
US20090265682A1 (en) | Method for transforming data from a model into a secondary model to optimize code generation | |
CN115629976A (en) | Kernel testing method and device and storage medium | |
CN112631696B (en) | Service arranging method, arranging device, processor and service arranging system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20190604 |
|
WW01 | Invention patent application withdrawn after publication |