Annotator

zhaozj2021-02-16  48

Attachment

Entrusted code generator

Liu Qiang

Cambest@sohu.com

April 2, 2004

In order to solve the discomfort when customization, I deliberately prepare this gadget, which is convenient to convert the delegate statement into the code as described above. Here is its basic usage.

In your header file, such as Test.h, declare a commission in __dlegate keyword:

__dlegate void WinHandler (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM);

Then go to the command line mode, enter the directory of Test.h, but the key is as follows:

Delegate.exe test.h / out test.hxx

It will generate Test.hxx files. You can include this file to your source to use the delegate you are defined. For example, it can be like this: #include "test.hxx"

You can define multiple delegates in a file or define multiple delegates in multiple files. But you can only specify an output file. If you don't use the / OUT option to specify an output file, the default output is delegate.h. Such as:

Delegate.exe test.h test1.h test2.h / out test.hxx

Use the / HELP option to get help, use the / version option to get version information.

Among the code generated by the commissioned code, the ADD / RemoveFunction accepts the parameter type default is 'void *', which is not conducive to the compiler to do a function matching check for us. / PTM option Forced parameter types for our defined delegate type.

Use delegate.exe / help to find more information:

Delegate Generator Version 1.1.0

Copyright Cambest (Tcliuqiang, Liuqiang, Lewis Li).

2004 - 3-31, all rights reserved.

/ OUT [OUTPUT FILE] Specify The Output File.

/ PTM force the add / removefunction parameter type match. default is 'void *'.

/ keyword specify the keyword. Default is '__dlegate'.

/ include Remove Delegate Declaration from Source File, And Include The Generated File to Your Source File.

/ HELP Print this message.

/ version Print Version of Delegate.exe

Please feed@sohu.com

The following is a specific example:

[Example 1]

//test.h:

#include

#include

Using namespace std;

ENUM STATUS

{

Finding,

Found,

PROCESS

}

__delegate void handlewnd (HWND HWND, DWORD LPARAM, WROD WPARAM, UINT TYPE);

ENUM TYPE

{

Normal,

Separator

}

__dlegate void WinAPI Callback WinProc (HWND HWND, DWORD LPARAM); Bool ISseParator (Char CH);

Void Process (String T);

Void Parse (ISTREAM IN, OSTREAM OUT);

//test1.h:

#define WinAPI 0

/ * The following is a delegation * /

__dlegate void WinHandler (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM);

/ * Do not comment in the definition * /

The following is the code generated by delegate.exe test.h test1.h / out test.hxx:

//test.hxx

#include

Using namespace std;

/ *

Generated by delegate.exe.

Please don't modify this file.

If You Encountered Any Problems, please feedback to cambest@sohu.com.

* /

Typedef unsigned int __nativeptr

Typedef void (* __handle_winhandler) (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM);

Class WinHandler

{

Private:

List <__ nativeptr> ftns;

PUBLIC:

Void AddFunction (void *)

{

__Nativeptr np = (__ nativeptr) ftn;

FTNS.PUSH_BACK (NP);

}

Void RemoveFunction (void * ftn)

{

__Nativeptr np = (__ nativeptr) ftn;

FTNS.Remove (NP);

}

Void Operator = (Void * ftn)

{

this-> addfunction (ftn);

}

Void Operator - = (void * ftn)

{

This-> RemoveFunction (FTN);

}

INT Invoke (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM)

{

__Handle_WinHandler Handle;

List <__ nativeptr> :: item 特r = ftns.begin ();

Try

{

For (; itr! = ftns.end (); ITR )

{

Handle = (__ Handle_WinHandler) * ITR;

Handle (hwnd, message, wparam, lparam);

}

}

Catch (int * _e)

{

Return 0;

}

Return 1;

}

Int Operator () (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM)

{

Return Invoke (HWND, MESSAGE, WPARAM, LPARAM);

}

}

/ *

Generated by delegate.exe.

Please don't modify this file.

If You Encountered Any Problems, please feedback to cambest@sohu.com.

* /

Typedef void (* __handle_handlewnd) (HWND HWND, DWORD LPARAM, WROD WPARAM, UINT TYPE); Class Handlewnd

{

Private:

List <__ nativeptr> ftns;

PUBLIC:

Void AddFunction (void *)

{

__Nativeptr np = (__ nativeptr) ftn;

FTNS.PUSH_BACK (NP);

}

Void RemoveFunction (void * ftn)

{

__Nativeptr np = (__ nativeptr) ftn;

FTNS.Remove (NP);

}

Void Operator = (Void * ftn)

{

this-> addfunction (ftn);

}

Void Operator - = (void * ftn)

{

This-> RemoveFunction (FTN);

}

Int Invoke (HWND HWND, DWORD LPARAM, WROD WPARAM, UINT TYPE)

{

__Handle_handlewnd handle;

List <__ nativeptr> :: item 特r = ftns.begin ();

Try

{

For (; itr! = ftns.end (); ITR )

{

Handle = (__ handle_handlewnd) * ITR;

Handle (HWND, LPARAM, WPARAM, TYPE);

}

}

Catch (int * _e)

{

Return 0;

}

Return 1;

}

Int Operator () (HWND HWND, DWORD LPARAM, WROD WPARAM, UINT TYPE)

{

Return Invoke (HWND, LPARAM, WPARAM, TYPE);

}

}

/ *

Generated by delegate.exe.

Please don't modify this file.

If You Encountered Any Problems, please feedback to cambest@sohu.com.

* /

TypedEf void WinAPI Callback (* __handle_winproc) (HWND HWND, DWORD LPARAM);

Class WinProc

{

Private:

List <__ nativeptr> ftns;

PUBLIC:

Void AddFunction (void *)

{

__Nativeptr np = (__ nativeptr) ftn;

FTNS.PUSH_BACK (NP);

}

Void RemoveFunction (void * ftn)

{

__Nativeptr np = (__ nativeptr) ftn;

FTNS.Remove (NP);

}

Void Operator = (Void * ftn)

{

this-> addfunction (ftn);

}

Void Operator - = (void * ftn)

{

This-> RemoveFunction (FTN);

}

Int Invoke (HWND HWND, DWORD LPARAM)

{

__Handle_WinProc Handle;

List <__ nativeptr> :: item 特r = ftns.begin ();

Try

{

For (; itr! = ftns.end (); ITR )

{

Handle = (__ handle_winproc) * iTr;

Handle (hwnd, lparam);

}

Catch (int * _e)

{

Return 0;

}

Return 1;

}

Int Operator () (HWND HWND, DWORD LPARAM)

{

Return Invoke (HWND, LPARAM);

}

}

Note: The latest Visual C .NET version has supported the same name keyword __delegate, which is Microsoft to add a new keyword added to Visual C to .NET, only Visual C .NET support, other Visual C 6.0, Borland C Builder, GNU C is not supported. But there is no connection at all. Fortunately, the Delegate gadget supports the / keyword option, which can specify the keyword you define your own, such as __dlegate__. In this way, the Delegate tool can look for the delegation definition starting with __dlegate__ in your source code, not the default __dlegate.

Another point is / include option to delete the delegate declaration in your source code and add a statement containing the output file accordingly. For example, Test1.h has such a statement:

__delegate__void WinProchandler (HWND HWND, LPARAM LPARAM, WPARA WPARAM);

Execute command delegate test1.h / ptm / include / out ptxx.h

The statement in Test1.h is replaced:

#include "ptxx.h"

Doing so can make you minimal maintenance.

[Example 2]

// Hello. CPP

#include

Using namespace std;

__dlegate void sho (char * s);

Void Print (Char * STR)

{

Cout << "IT IS in Print: << Str << endl;

}

Void Good (Char * STR)

{

Cout << "it is in good, say good to you:" << str << Endl;

}

void main ()

{

SHO S;

S = print;

s = good;

S ("I am the best!");

}

/ / Generate a delegate code: delegate.exe hello.cpp / fpm / include / out sho.h

#include

Using namespace std;

#include "sho.h"

Void Print (Char * STR)

{

Cout << "IT IS in Print: << Str << endl;

}

Void Good (Char * STR)

{

Cout << "it is in good, say good to you:" << str << Endl;

}

void main ()

{

SHO S;

S = print;

s = good;

S ("I am the best!");

S- = print;

S ("JJJ KKK LLL TTT");

Compile: (use Microsoft C compiler)

CL Hello.cpp / EHSC

Since the code generated by Delegate contains an exception handling, you need to specify the / eHSC option when compiling hello.cpp, otherwise the warning message will be given, but do not hinder compilation success.

Output:

IT IS in Print: I am the Best!

IT is in good, say good to you :: i am the best!

IT is in good, say good to you :: jjj kkk lll ttt

You can open SHO. H files see how it is defined.

Since it is just a test version, this gadget is not very strong. For example, you cannot have a comment in the middle of the delegate statement, but only before or after declaration or declaration. In addition, due to the time relationship, I did not do very good to deal with the delegate return value. I hope this problem will soon solve. What comments and suggestions, please feedback to my email: cambest@sohu.com.

转载请注明原文地址:https://www.9cbs.com/read-25620.html

New Post(0)