TCPMP之node

typedef struct datadef
{
    int    No;       
    int    Type;
    int    Flags;
    int    Format1; // DF_MINMAX:min, DF_ENUMSRING:string class, DF_ENUMCLASS:node class, nodeclass
    int    Format2; // DF_MINMAX:max
    const tchar_t* Name;
    int Class;           
    int Size;
} datadef;
其中:
int NO  数据唯一标识。通过定义一个有意义的宏来表明用途。比如player.h中:
// buffer size in KB (int)
#define PLAYER_BUFFER_SIZE    0x20
// microdrive buffer size in KB (int)
#define PLAYER_MD_BUFFER_SIZE 0x80

int Type    数据类型标识。
#define TYPE_BOOL            1
#define TYPE_INT
#deinfe TYPE_RECT

int Flags    数据特性的标志。可以“并”在一起使用。根据不同的Type,可以使用不同的Flags.
#define DF_RDONLY            0x00000001
#define DF_SETUP            0x00000002
#define DF_HIDDEN            0x00000004
#define DF_MINMAX            0x00000008

datatable都是用来定义数组的元素。在数组的最后都要添加宏DATATABLE_END(Class)。这样,数组中的datatable类型的元素中,如果Type==-1,那么就表示数组结束了。而-1前面的值则是这个数组中每项数据所属的class(node)。
typedef struct datatable
{
    int    No;
    int    Type;
    int Flags;
    int Format1;
    int    Format2;
} datatable;
#define DATATABLE_END(Class) { Class, -1 }
在player.c中定义了PlayerParams[],这个数组可以看作是所有与Player相关的各种参数。
static const datatable PlayerParams[] =
{
    { PLAYER_AUTOPREROTATE,    TYPE_BOOL, DF_SETUP },
    { PLAYER_REPEAT,        TYPE_BOOL, DF_SETUP|DF_HIDDEN },
    { PLAYER_SHUFFLE,        TYPE_BOOL, DF_SETUP|DF_HIDDEN },
    { PLAYER_KEEPPLAY_AUDIO,TYPE_BOOL, DF_SETUP },
    ...
}
在player.c中定义的BufferParams[]则是与缓冲区相关的各种参数。
static const datatable BufferParams[] =
{
    { PLAYER_BUFFER_SIZE,    TYPE_INT, DF_SETUP|DF_KBYTE|DF_GAP, 512, 128*1024 },
    { PLAYER_UNDERRUN,        TYPE_INT, DF_SETUP|DF_PERCENT,0,PERCENT_ONE },

在node.h中定义的关于node的部分。其中VMT_NODE是用于扩展node的宏。node则定义了node的标识Class、获取node所有属性的函数指针Enum、设置和读取node属性的函数指针Get, Set。相对于nodedef,node可以理解为一个数据实体。而nodedef则定义了node的类型Flags、创建、销毁、优先级,以及node之间的关系(通过ParentClass)。node与nodedef的关联是通过node Class。node class是一个int, 其中4个字节存放的是四个ascii字母。比如,DMO_CLASS='ADMO'。
#define VMT_NODE   \
 int   Class;  \
 nodeenum Enum;  \
 nodeget  Get;  \
 nodeset  Set;

typedef struct node
{
 int   Class;
 nodeenum Enum;
 nodeget  Get;
 nodeset  Set;
} node;

typedef struct nodedef
{
 int    Flags;
 int    Class;
 int    ParentClass;
 int    Priority;
 nodecreate  Create;
 nodedelete  Delete;
} nodedef;

Player Node. 通过扩展VMT_NODE,添加Player特有的函数定义了,Player节点。
typedef struct player_t
{
 VMT_NODE
 playerpaint  Paint;
 playercomment CommentByName;
 playerswap  ListSwap;
 playerprocess Process;

} player;

你可能感兴趣的:(C++,c,C#)