ODM コードおよび出力の例

次の「Fictional_Characters」、「Friend_Table」、および「Enemy_Table」のオブジェクト・クラスと関係の表は、ここのセクションのコード例で作成したオブジェクト・クラスおよびオブジェクト を示しています。

表 1. Fictional_Characters
Story_Star (char) Birthday (char) Age (short) Friends_of (link) Enemies_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
Enemy_of (char) エネミー (Char)
Cinderella midnight
Cinderella Mean Stepmother
Snow White Mean Stepmother

オブジェクト・クラスを作成するための ODM 入力コード例

MyObjects.cre ファイル内の以下のサンプル・コードは、 odmcreate コマンドで入力ファイルとして使用されると、3 つのオブジェクト・クラスを作成します。

*      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オブジェクト・クラスには、次の 6 つの記述子

  • Story_StarおよびBirthday,それぞれの記述子タイプは char で、最大長は 20 文字です。
  • Ageshort 型の記述子型を使用します。
  • Friends_ofおよびEnemies_ofリンク・クラスと、以前に定義された 2 つのオブジェクト・クラスへのリンクの両方です。
    注: オブジェクト・クラス・リンクは 2 回繰り返されます。
  • Do_Thisメソッドの記述子タイプを指定します。

ODM で必要なオブジェクト・クラス・ファイルを作成するには、 odmcreate コマンドを用いて、このコードの入ったファイルを処理しなければなりません。

オブジェクト・クラス定義のための ODM 出力例

MyObjects.cre ファイルのコードを odmcreate コマンドで処理すると、.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. *

注: 前のコード例の * (アスタリスク) または # (ポンド記号) コメントは、オブジェクト・ファイルには入りません。 行の先頭に原因があってその行がコメント化された場合、そのコマンドはオブジェクト・ファイルには入りません。 コメントは、ファイルに組み込まれ、 " " (二重引用符) で囲まれた場合は、文字列として扱われます。