ODM 示例代码和输出

下面的 Fictional_Characters、Friend_Table 和 Enemy_Table 对象类和关系表列示了本节的示例代码创建的对象类和对象。

表 1. Fictional_Characters
Story_Star (char) Birthday (char) Age (short) Friends_of (link) 灌肠 (链接) Do_This (method)
Cinderella Once upon a time 19 Cinderella Cinderella echo Cleans House
Snow White Once upon a time 18 Snow White Snow White echo Cleans House
表 2。 Friend_Table
Friend_of (char) Friend (char)
Cinderella Fairy Godmother
Cinderella mice
Snow White Sneezy
Snow White Sleepy
Cinderella Prince
Snow White Happy
表 3。 Enemy_Table
灌肠 (char) 敌人 (字符)
Cinderella midnight
Cinderella Mean Stepmother
Snow White Mean Stepmother

用于创建对象类的 ODM 示例输入代码

使用 odmcreate 命令作为输入文件时, MyObjects.cre 文件中的以下示例代码将创建三个对象类:

*      MyObjects.cre
*       An input file for ODM create utilities.
*       Creates three object classes:
*               Friend_Table
*               Enemy_Table
*               Fictional_Characters
class   Friend_Table {
        char    Friend_of[20];
        char    Friend[20];
};
class   Enemy_Table {
        char    Enemy_of[20];
        char    Enemy[20];
};
class   Fictional_Characters {
        char    Story_Star[20];
        char    Birthday[20];
        short   Age;
        link    Friend_Table Friend_Table Friend_of Friends_of;
        link    Enemy_Table Enemy_Table Enemy_of Enemies_of;
        method  Do_This;
};
* End of MyObjects.cre input file for ODM create utilities. *

Fictional_Characters对象类包含六个描述符:

  • Story_StarBirthday,每个都具有描述符类型 char 和 20 个字符的最大长度。
  • Age描述符类型为 short。
  • Friends_ofEnemies_of同时来自链接类和指向两个先前定义的对象类的链接。
    注: 对象类链接重复两次。
  • Do_This具有描述符类型的方法。

要生成 ODM 所需的对象类文件,包含此代码的文件必须用 odmcreate 命令处理。

用于对象类定义的 ODM 示例输出

使用 odmcreate 命令处理 MyObjects.cre 文件中的代码在 .h 文件中生成下面的结构:

* MyObjects.h
* The file output from ODM processing of the MyObjects.cre input
* file. Defines structures for the three object classes:
*       Friend_Table
*       Enemy_Table
*       Fictional_Characters
#include <odmi.h>

struct  Friend_Table {
       long     _id;     * unique object id within object class *
       long     _reserved;  * reserved field *
       long     _scratch;   * extra field for application use *
       char     Friend_of[20];
       char     Friend[20];
};
#define Friend_Table_Descs 2
extern struct Class Friend_Table_CLASS[];
#define get_Friend_Table_list(a,b,c,d,e) (struct Friend_Table * )odm_get_list (a,b,c,d,e)
struct  Enemy_Table {
        long    _id;
        long    _reserved;
        long    _scratch;
        char    Enemy_of[20];
        char    Enemy[20];
};
#define Enemy_Table_Descs 2
extern struct Class Enemy_Table_CLASS[];
#define get_Enemy_Table_list(a,b,c,d,e) (struct Enemy_Table * )odm_get_list (a,b,c,d,e)
struct  Fictional_Characters {
        long    _id;
        long    _reserved;
        long    _scratch;
        char    Story_Star[20];
        char    Birthday[20];
        short   Age;
       struct  Friend_Table *Friends_of;    * link *
        struct  listinfo *Friends_of_info;   * link *
        char    Friends_of_Lvalue[20];       * link *
        struct  Enemy_Table *Enemies_of;     * link *
        struct  listinfo *Enemies_of_info;   * link *
        char    Enemies_of_Lvalue[20];       * link *
        char    Do_This[256];                * method *
};
#define Fictional_Characters_Descs 6
 
extern struct Class Fictional_Characters_CLASS[];
#define get_Fictional_Characters_list(a,b,c,d,e) (struct Fictional_Characters * )odm_get_list (a,b,c,d,e)
* End of MyObjects.h structure definition file output from ODM    * processing.

用于将对象添加到对象类的 ODM 示例代码

以下代码可由 odmadd 命令处理,以填充由处理 MyObjects.cre 输入文件创建的对象类:

* MyObjects.add
* An input file for ODM add utilities.
* Populates three created object classes:
*       Friend_Table
*       Enemy_Table
*       Fictional_Characters
Fictional_Characters:
Story_Star = "Cinderella" #a comment for the  MyObjects.add file.
Birthday        =       "Once upon a time"
Age             =       19
Friends_of      =       "Cinderella"
Enemies_of      =       "Cinderella"
Do_This =               "echo Cleans house"
Fictional_Characters:
Story_Star      =       "Snow White"
Birthday        =       "Once upon a time"
Age             =       18
Friends_of      =       "Snow White"
Enemies_of      =       "Snow White"
Do_This   =              "echo Cleans house"
Friend_Table:
Friend_of       =       "Cinderella"
Friend          =       "Fairy Godmother"
Friend_Table:
Friend_of       =       "Cinderella"
Friend          =       "mice"
Friend_Table:
Friend_of       =       "Snow White"
Friend          =       "Sneezy"
Friend_Table:
Friend_of       =       "Snow White"
Friend          =       "Sleepy"
Friend_Table:
Friend_of       =       "Cinderella"
Friend          =       "Prince"
Friend_Table:
Friend_of       =       "Snow White"
Friend          =       "Happy"
Enemy_Table:
Enemy_of        =       "Cinderella"
Enemy           =       "midnight"
Enemy_Table:
Enemy_of        =       "Cinderella"
Enemy           =       "Mean Stepmother"
Enemy_Table:
Enemy_of        =       "Snow White"
Enemy           =       "Mean Stepmother"
* End of MyObjects.add input file for ODM add utilities. *

注: 先前示例代码中的 * (星号) 或 # (井号) 注释将不会进入对象文件。 如果行的起始内容使得该行为注释,那么命令不会进入对象文件。 如果注释包含在 " "(双引号)中,它会被包含在文件中并被作为字符串处理。