简介
主要对Open CASCADE中的工具包(ToolKits)、包(Packages)、类(Classes)和方法(Methods)的命名规则进行介绍,同时对其代码编写的规则进行简单介绍。
命名规则
1.Prefix for toolkit name:
工具包一般被TK所修饰,后面跟着对于该工具包具有解释作用的词语,例如:TKOpenGl
2.Packages
包一般是具有相同功能的类的集合,例如,Geom、Geom2d表示geomtrical data and operations,TopoDS表示topological data and operations。
3.Name of public types--public classes and other types(structs、enums、typedefs)
公共类或数据结构的表示一般是:包名_类名(<package-mane_class-name>)
例如:Adaptor2d_Curve2d :它属于Adaptor2d这个包,其头文件定义在Adaptor2d_Curve2d.hxx,实现的源码在Adaptor2d_Curve2d.cxx文件中。
4.Name of functions
定义方法时,其一般将公共方法以大写字符开头,私有方法以小写字符开头。
class MyPackage_MyClass
{
public:
Standard_Integer Value();
void SetValue(const Standard_Integer theValue);
private:
void setIntegerValue(const Standard_Integer theValue);
};
5.Name of varialbes
对于局部变量,命名时以小写字母开头,后面的词以大写字符开头,如:Standard_Integer aGp=0;
对于全局变量(一般不建议使用),命名时以类或包名为开头,修饰所定义的全局变量,其余与局部变量一样。如:Standard_Integer MyPackage_myGlobalVariable=0;
OCC中变量类型与C++之间的对应关系
OCC库中的各个类型在Standard_TypeDef.hxx头文件中被定义,其与c++中的对应关系如下所示:
C++ | Open Cascade |
---|---|
int | Standard_Integer |
double | Standard_Real |
float | Standard_ShortReal |
bool | Standard_Boolean |
char | Standard_Character |
unsigned char | Standard_Byte |
void * | Standard_Address |
size_t | Standard_Size |
false/true | Standard_False/True |