Using ccb in C ++, binding call and member variables makes it a headache and easy to make mistakes.
I wrote a small program using pythong and directly generated C ++ code through the ccb file.
I am not using python much, and I am doing it casually. The quality of the code is very poor. Let's be more inclusive.
It consists of three files: codeGen. py, myCommon. py, and genCpp. py.
Run codeGen. py.
MyCommon. py contains some configuration information, which can be modified based on the specific project.
Class projectinfo: def _ init _ (self): self. projectName = 'fishingjoyforccb' # project name self. customSubclass = {# This is the parent class defined by myself. This information is not contained in the ccb file, so we have to add it here. The first key is the subclass value is the parent class # sample 'coin ': 'giameobject' subclassName: superclassName # 'coin ': 'giameobject'} self. ownerClass = {# When the members and callback methods are of the owner type, you can specify the owner class here, in this way, the methods and member variables defined in ccb will be declared in the owner class # sample 'ownerclass': [className1, className2...] # 'coin ': ['matf8level']} # self. ccbPath = '/Users/dev/cocos2d-x-2.2.3/projects/FishingJoyForCcb/ccb_source' # self. classPath = '/Users/dev/cocos2d-x-2.2.3/projects/FishingJoyForCcb/Classes' self. ccbPath = '. /'# The Directory of the ccb file is the same as that in the command line path. The command line takes precedence. The default value is the current directory self. classPath = '. /'# The Directory of the cpp file is the same as that in the command line path. The command line takes precedence. The default value is the current directory self. ccbTargetType = ['none', 'rootdocument', 'owner'] self. ccbCustomPropertiesType = ['int', 'float', 'bool ', 'std: string'] # className: classInfo self. classDictionary = {}
Command Line
Python codeGen. py-c./-o./Coin Fish
-C,-ccbpath: ccb file path
-O,-outputpath, -- generator cpp file path
It is the same as the meaning defined in myCommon. py.
Finally, you can keep up with the name of the class to be generated. Without any class name, all classes under the ccb directory will be generated.
I am used to adding the m _ prefix to the member variables. Due to poor program writing, this place is not very easy to change.
Because I automatically add a prefix to the member variables, so that no prefix is required for the ccb definition. The variable names starting with uppercase can be used.
Example: Type
This will generate
Int m_Type member variable
And int getType () and void setType (int value) Methods
It is easy to use the code generated automatically in the initial stage of the project, and it is difficult to maintain the code in the later stage. Make plans when using the code.
If the extended attributes of ccb are of the string type, I have some problems here. Please be careful.
Code