Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

md.h

Go to the documentation of this file.
00001 /*****************************************************************************\
00002  *  Copyright  1995  The Board of Trustees of the University of Illinois.
00003  *  All rights reserved.
00004  *
00005  *  md.h, part of the interface to the internal representation of the 
00006  *  IMPACT Meta-Description Language
00007  *  John C. Gyllenhaal, Wen-mei Hwu, and The IMPACT Research Group
00008  *  Coordinated Science Laboratory
00009  *  University of Illinois at Urbana-Champaign
00010  *
00011  *  The IMPACT Research Group may be contacted at impact@crhc.uiuc.edu.
00012  *
00013  *  md.h (part of the interface to the internal representation of the
00014  *  IMPACT Meta-Description Language software), including both binary 
00015  *  and source (hereafter, Software) is copyrighted by The Board of Trustees
00016  *  of the University of Illinois (UI), and ownership remains with the UI.
00017  *
00018  *  The UI grants you (hereafter, Licensee) a license to use the Software for
00019  *  academic, research and internal business purposes only, without a fee.
00020  *  Licensee may distribute the Software to third parties provided that the
00021  *  copyright notice and this statement appears on all copies and that no
00022  *  charge is associated with such copies.
00023  *
00024  *  Licensee may make derivative works.  However, if Licensee distributes
00025  *  any derivative work based on or derived from the Software, then Licensee
00026  *  will clearly notify users that such derivative work is a modified
00027  *  version and not the original Software distributed by the UI.
00028  *
00029  *  Any Licensee wishing to make commercial use of the Software should contact
00030  *  the UI, c/o the Research and Technology Management Office [rtmo@uiuc.edu],
00031  *  to negotiate an appropriate license for such commercial use.  Commercial
00032  *  use includes (1) integration of all or part of the source code into a
00033  *  product for sale or license by or on behalf of Licensee to third parties,
00034  *  or (2) distribution of the Software to third parties that need it to
00035  *  utilize a commercial product sold or licensed by or on behalf of Licensee.
00036  *
00037  *  UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR
00038  *  ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00039  *  THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE USERS OF THIS
00040  *  SOFTWARE.
00041  *
00042  *  By using or copying this Software, Licensee agrees to abide by the
00043  *  copyright law and all other applicable laws of the U.S. including, but
00044  *  not limited to, export control laws, and the terms of this license.
00045  *  UI shall have the right to terminate this license immediately by written
00046  *  notice upon Licensee's breach of, or non-compliance with, any of its terms.
00047  *  Licensee may be held legally responsible for any copyright infringement
00048  *  that is caused or encouraged by Licensee's failure to abide by the terms
00049  *  of this license.
00050  *
00051  *  Form approved by University Counsel, M.A.R., 05/10/93
00052 \*****************************************************************************/
00053 /*****************************************************************************\
00054  *      File:   md.h
00055  *
00056  *      Description: Header file for the interface to the internal 
00057  *                   representation of the IMPACT Meta-Description Language
00058  *
00059  *      Creation Date:  March 1995
00060  *
00061  *      Authors: John C. Gyllenhaal and Wen-mei Hwu
00062  *
00063  *      Revisions:
00064  *           Shail Aditya (HP Labs) February 1996
00065  *           Changed MD_get_xxx() arguments to be consistent with MD_set_xxx()
00066  *           Added MD_num_xxx() which returns number of sections, entries, etc.
00067  *
00068  *           John C. Gyllenhaal  May 1996
00069  *           Folded Shail's changes back into IMPACT's version
00070  *           Changed low-level representation to use hex for integers
00071  *           Added MD_rename_entry(), MD_delete_element(), MD_max_field_index()
00072  *                 MD_max_element_index(), and MD_print_md_declarations()
00073  *           Changed all error messages to uniformly use MD_punt()
00074  * 
00075  *           John C. Gyllenhaal July 1996
00076  *           Implemented Shail Aditya's suggestion of adding void pointers to
00077  *           MD_Section and MD_Entry for the user's use.  Added functions
00078  *           MD_set_section_ext(), MD_get_section_ext(), MD_set_entry_ext(), 
00079  *           and MD_get_entry_ext().
00080  * *
00081 \*****************************************************************************/
00082 
00083 #ifndef MD2_H
00084 #define MD2_H
00085 
00086 /* Stdio.h needed for prototypes */
00087 #include <stdio.h>
00088 
00089 /*
00090  * MD data types supported. 
00091  * (Use defines instead of enum to allow fitting into short int
00092  *  in MD_Element)
00093  */
00094 #define MD_INT          1
00095 #define MD_DOUBLE       2
00096 #define MD_STRING       3
00097 #define MD_LINK         4
00098 
00099 /* Field types supported */
00100 typedef enum MD_FIELD_TYPE
00101 {
00102     MD_REQUIRED_FIELD   = 1,
00103     MD_OPTIONAL_FIELD   = 2
00104 } MD_FIELD_TYPE;
00105 
00106 /* Used as index to declare optional element types */
00107 #define MD_OPTIONAL_ELEMENTS    -1
00108 
00109 
00110 /* Symbol table used for database section, entry, and field names.
00111  * Internal use only!  Not designed to be used by non-MD functions!
00112  */
00113 typedef struct MD_Symbol
00114 {
00115     char                        *name;          /* Not a copy! */
00116     unsigned int                hash_val;       /* Hashed value of name */
00117     void                        *data;          /* a MD_xxx structure */
00118     struct MD_Symbol_Table      *table;         /* For deletion of symbol */
00119     struct MD_Symbol            *next_hash;     /* For table's hash table */
00120     struct MD_Symbol            *prev_hash;
00121     struct MD_Symbol            *next_symbol;   /* For table's contents list */
00122     struct MD_Symbol            *prev_symbol;
00123     int                         symbol_id;      /* Used by MD_write_md */
00124 
00125 } MD_Symbol;
00126 
00127 typedef struct MD_Symbol_Table
00128 {
00129     struct MD           *md;            /* For error messages */
00130     char                *name;          /* For error messages */
00131     MD_Symbol           **hash;         /* Array of size hash_size */
00132     int                 hash_size;      /* Must be power of 2 */
00133     int                 hash_mask;      /* AND mask, (hash_size - 1) */
00134     int                 resize_size;    /* When reached, resize hash table */
00135     MD_Symbol           *head_symbol;   /* Contents list */
00136     MD_Symbol           *tail_symbol;
00137     int                 symbol_count;
00138 } MD_Symbol_Table;
00139 
00140 /* Types to fill out later */
00141 
00142 typedef struct MD
00143 {
00144     char                *name;          /* Name of MD */
00145     MD_Symbol_Table     *section_table; /* Sections in the MD */
00146 } MD;
00147 
00148 typedef struct MD_Section
00149 {
00150     MD                  *md;              /* MD that section is in */
00151     char                *name;            /* Name of section */
00152     MD_Symbol_Table     *field_decl_table;/* Field declared in the section */
00153     MD_Symbol_Table     *entry_table;     /* Entries in the section */
00154     int                 max_field_index;  /* Index of the max declared field */
00155     struct MD_Field_Decl **field_decl;    /* Array of field decl pointers */
00156     int                 field_array_size; /* Size of above field_decl array */
00157                                           /* and Entry's field array */
00158     MD_Symbol           *symbol;          /* In MD's section_table */
00159     void                *user_ext;        /* For user's use, NULL initially */
00160 }
00161  MD_Section;
00162 
00163 typedef struct MD_Element_Req
00164 {
00165     struct MD_Field_Decl *field_decl;   /* Field decl that element_req is in */
00166     int                 require_index;  /* Index in field_decl->require array*/
00167     short               type;           /* Type of element required */
00168     char                *desc;          /* Description (for error messages) */
00169     int                 kleene_starred; /* 1 if kleene_starred */
00170     MD_Section          **link;         /* Array of section pointers */
00171     int                 link_array_size;/* Size/links in above link array */
00172 } MD_Element_Req;
00173 
00174 typedef struct MD_Field_Decl
00175 {
00176     MD_Section          *section;           /* Section that field decl is in */
00177     int                 field_index;        /* Index in entry->field array*/
00178     char                *name;              /* Name of field being declared */
00179     MD_FIELD_TYPE       type;               /* Type of field being declared */
00180     int                 max_require_index;  /* Index of last requirement */
00181     MD_Element_Req      **require;          /* Decls of element requirements */
00182     int                 require_array_size; /* Size of above require array */
00183     MD_Element_Req      *kleene_starred_req;/* NULL if no req starred */
00184     MD_Symbol           *symbol;            /* In section->field_decl_table */
00185 } MD_Field_Decl;
00186 
00187 /* 
00188  * Each entry has an array of pointers to fields (of size field_size).
00189  * The pointers in the field array will be NULL for unspecified fields.
00190  */
00191 typedef struct MD_Entry
00192 {
00193     MD_Section          *section;       /* Section that entry is in */
00194     char                *name;          /* Name of entry */
00195     struct MD_Field     **field;        /* Array of field pointers, */
00196                                         /* of size section->field_array_size */
00197     MD_Symbol           *symbol;        /* In MD_Section's entry_table */
00198     void                *user_ext;      /* For user's use, NULL initially */
00199 } MD_Entry;
00200 
00201 
00202 /* The data in the database.  
00203  * Use macro interface routines for accessing data.
00204  */
00205 typedef struct MD_Element
00206 {
00207     struct MD_Field     *field;         /* Field element is in */
00208     unsigned short      element_index;  /* index in field->element */
00209     short               type;           /* The type of data accessed */
00210     union                               
00211     {
00212         int             i;              /* INT value */
00213         double          d;              /* DOUBLE value */
00214         char            *s;             /* STRING value */
00215         MD_Entry        *l;             /* LINK value */
00216     } value;
00217 } MD_Element;
00218 
00219 /*
00220  * Each field has an array of pointers to elements (of size array_size).
00221  * max_index is the index of the last element set to a value, -1 if
00222  * no elements have been set.
00223  * The pointers in element array will be NULL for unspecified elements.
00224  */
00225 typedef struct MD_Field
00226 {
00227     MD_Entry            *entry;            /* Entry that field is in */
00228     MD_Field_Decl       *decl;             /* Declaration of field contents */
00229     int                 max_element_index; /* max_index of last set element */
00230     MD_Element          **element;         /* Pointers to elements in field */
00231     int                 element_array_size;/* Size of above element array */
00232 } MD_Field;
00233 
00234 
00235 /*
00236  * MD prototypes/macros declarations
00237  */
00238 
00239 #ifdef __cplusplus
00240 extern "C" {
00241 #endif
00242 
00243 /* Start prototypes of MD interface functions */
00244 extern MD *MD_new_md (char *name, int num_sections);
00245 extern int MD_check_md (FILE *out, MD *md);
00246 extern void MD_delete_md (MD *md);
00247 
00248 extern MD_Section *MD_new_section (MD *md, char *name, int num_entries, 
00249                             int num_fields);
00250 
00251 extern MD_Section *MD_first_section (MD *md);
00252 extern MD_Section *MD_last_section (MD *md);
00253 extern MD_Section *MD_next_section (MD_Section *section);
00254 extern MD_Section *MD_prev_section (MD_Section *section);
00255 
00256 extern MD_Field_Decl *MD_new_field_decl (MD_Section *section, char *name, 
00257                                          MD_FIELD_TYPE field_type);
00258 
00259 extern MD_Field_Decl *MD_first_field_decl (MD_Section *section);
00260 extern MD_Field_Decl *MD_last_field_decl (MD_Section *section);
00261 extern MD_Field_Decl *MD_next_field_decl (MD_Field_Decl *field_decl);
00262 extern MD_Field_Decl *MD_prev_field_decl (MD_Field_Decl *field_decl);
00263 
00264 extern void MD_require_int (MD_Field_Decl *field_decl, int element_index);
00265 extern void MD_require_double (MD_Field_Decl *field_decl, int element_index);
00266 extern void MD_require_string (MD_Field_Decl *field_decl, int element_index);
00267 extern void MD_require_link (MD_Field_Decl *field_decl, int element_index, 
00268                       MD_Section *section);
00269 extern void MD_require_multi_target_link (MD_Field_Decl *field_decl, 
00270                                    int element_index, int section_array_size,
00271                                    MD_Section **section_array);
00272 extern void MD_kleene_star_requirement (MD_Field_Decl *field_decl, 
00273                                         int element_index);
00274 
00275 extern MD_Entry *MD_new_entry (MD_Section *section, char *name);
00276 extern void MD_rename_entry (MD_Entry *entry, char *new_name);
00277 
00278 extern MD_Entry *MD_first_entry (MD_Section *section);
00279 extern MD_Entry *MD_last_entry (MD_Section *section);
00280 extern MD_Entry *MD_next_entry (MD_Entry *entry);
00281 extern MD_Entry *MD_prev_entry (MD_Entry *entry);
00282 
00283 extern MD_Field *MD_new_field (MD_Entry *entry, MD_Field_Decl *decl, 
00284                                int num_elements);
00285 extern void MD_delete_field (MD_Field *field);
00286 extern void MD_delete_field_decl (MD_Field_Decl *field_decl);
00287 extern void MD_delete_element (MD_Field *field, int index);
00288 
00289 extern MD *MD_read_md (FILE *in, char *name);
00290 extern void MD_write_md (FILE *out, MD *md);
00291 extern void MD_print_md (FILE *out, MD *md, int page_width);
00292 extern void MD_print_md_declarations (FILE *out, MD *md, int page_width);
00293 extern void MD_print_md_template (FILE *out, MD *md);
00294 
00295 extern void MD_print_section (FILE *out, MD_Section *section, int page_width);
00296 extern void MD_print_section_template (FILE *out, MD_Section *section);
00297 extern void MD_print_field_decl (FILE *out, MD_Field_Decl *field_decl,
00298                                  int page_width);
00299 extern void MD_print_entry (FILE *out, MD_Entry *entry, int page_width);
00300 extern void MD_print_entry_template (FILE *out, MD_Entry *entry);
00301 
00302 #ifdef __cplusplus
00303 }
00304 #endif
00305 
00306 /* End prototypes of MD interface functions */
00307 
00308 /* 
00309  * MD macros.
00310  * Two versions available:
00311  *  1) macro replaced with code optimized for speed.
00312  *  2) macro replaced with function call version.
00313  *
00314  *  Version 2 is provided to aid debugging macro arguments.
00315  */
00316 #ifndef MD_DEBUG_MACROS
00317 
00318 #define MD_num_sections(md)             ((md)->section_table->symbol_count)
00319 #define MD_find_section(md, name) \
00320             ((MD_Section *)_MD_find_symbol_data((md)->section_table, name))
00321 
00322 
00323 #define MD_delete_section(section) \
00324             (MD_delete_symbol(((MD_Section *)(section))->symbol, \
00325                               (void (*)(void *))_MD_free_section))
00326 
00327 #define MD_num_entries(section)         ((section)->entry_table->symbol_count)
00328 
00329 #define MD_find_entry(section, name) \
00330             ((MD_Entry *)_MD_find_symbol_data((section)->entry_table, name))
00331 
00332 #define MD_delete_entry(entry) \
00333             (MD_delete_symbol(((MD_Entry *)(entry))->symbol, \
00334                               (void (*)(void *))_MD_free_entry))
00335 
00336 #define MD_num_field_decls(section) \
00337             ((section)->field_decl_table->symbol_count)
00338 
00339 #define MD_max_field_index(section)     ((section)->max_field_index)
00340 
00341 #define MD_find_field_decl(section, name) \
00342           ((MD_Field_Decl *)_MD_find_symbol_data((section)->field_decl_table, \
00343                                                  name))
00344 
00345 #define MD_find_field(entry, field_decl) \
00346             ((entry)->field[(field_decl)->field_index])
00347 
00348 #define MD_num_elements(field)          ((field)->max_element_index + 1)
00349 #define MD_max_element_index(field)     ((field)->max_element_index)
00350 
00351 #define MD_set_int(field, index, value) _MD_set_int(field, index, value)
00352 #define MD_get_int(field, index)        ((field)->element[index]->value.i)
00353 
00354 #define MD_set_double(field, index, value) _MD_set_double(field, index, value)
00355 #define MD_get_double(field, index)     ((field)->element[index]->value.d)
00356 
00357 #define MD_set_string(field, index, value) _MD_set_string(field, index, value)
00358 #define MD_get_string(field, index)     ((field)->element[index]->value.s)
00359 
00360 #define MD_set_link(field, index, value) _MD_set_link(field, index, value)
00361 #define MD_get_link(field, index)       ((field)->element[index]->value.l)
00362 
00363 #define MD_set_section_ext(section, ext) ((section)->user_ext = (void *)(ext))
00364 #define MD_get_section_ext(section)     ((section)->user_ext)
00365 
00366 #define MD_set_entry_ext(entry, ext)    ((entry)->user_ext = (void *)(ext))
00367 #define MD_get_entry_ext(entry)         ((entry)->user_ext)
00368 
00369 #else
00370 
00371 #define MD_num_sections(md)             _MD_num_sections(md)
00372 #define MD_find_section(md, name)       _MD_find_section(md, name)
00373 #define MD_delete_section(section)      _MD_delete_section(section)
00374 
00375 #define MD_num_entries(section)         _MD_num_entries(section)
00376 #define MD_find_entry(section, name)    _MD_find_entry(section, name)
00377 #define MD_delete_entry(entry)          _MD_delete_entry(entry)
00378 
00379 
00380 #define MD_num_field_decls(section)     _MD_num_field_decls(section)
00381 #define MD_max_field_index(section)     _MD_max_field_index(section)
00382 #define MD_find_field_decl(section, name) _MD_find_field_decl(section, name)
00383 
00384 #define MD_find_field(entry, field_decl) _MD_find_field(entry, field_decl)
00385 
00386 #define MD_num_elements(field)          _MD_num_elements(field)
00387 #define MD_max_element_index(field)     _MD_max_element_index(field)
00388 
00389 #define MD_set_int(field, index, value) \
00390             _MD_set_int_type_checking(field, index, value)
00391 #define MD_get_int(field, index)        _MD_get_int(field, index)
00392 
00393 #define MD_set_double(field, index, value) \
00394             _MD_set_double_type_checking(field, index, value)
00395 #define MD_get_double(field, index)     _MD_get_double(field, index)
00396 
00397 #define MD_set_string(field, index, value) \
00398             _MD_set_string_type_checking(field, index, value)
00399 #define MD_get_string(field, index)     _MD_get_string(field, index)
00400 
00401 #define MD_set_link(field, index, value) \
00402             _MD_set_link_type_checking(field, index, value)
00403 #define MD_get_link(field, index)       _MD_get_link(field, index)
00404 
00405 #define MD_set_section_ext(section, ext) \
00406             _MD_set_section_ext(section, (void *)(ext))
00407 #define MD_get_section_ext(section)     _MD_get_section_ext(section)
00408 
00409 #define MD_set_entry_ext(entry, ext)    _MD_set_entry_ext(entry, (void *)(ext))
00410 #define MD_get_entry_ext(entry)         _MD_get_entry_ext(entry)
00411 
00412 
00413 #endif
00414 
00415 /* MD checking macros (only one version available) */
00416 #define MD_check_section(out, section) \
00417              _MD_check_section(out, section, "MD_check_section")
00418 #define MD_check_entry(out, entry) \
00419              _MD_check_entry(out, entry, "MD_check_entry")
00420 #define MD_check_field(out, field) \
00421              _MD_check_field(out, field, "MD_check_field")
00422 
00423 
00424 
00425 
00426 
00427 
00428 /* Start prototypes of functions used by MD macros.  
00429  * DO NOT CALL THE FUNCTIONS BELOW DIRECTLY!
00430  */
00431 
00432 #ifdef __cplusplus
00433 extern "C" {
00434 #endif
00435 
00436 extern void *_MD_find_symbol_data (MD_Symbol_Table *table, char *name);
00437 
00438 extern int _MD_num_sections (MD *md);
00439 extern MD_Section *_MD_find_section (MD *md, char *name);
00440 extern void *_MD_set_section_ext(MD_Section *section, void *ext);
00441 extern void *_MD_get_section_ext(MD_Section *section);
00442 extern void _MD_free_section (MD_Section *section);
00443 extern void _MD_delete_section (MD_Section *section);
00444 extern int _MD_check_section (FILE *out, MD_Section *section, 
00445                               char *caller_name);
00446 
00447 
00448 extern int _MD_num_entries (MD_Section *section);
00449 extern MD_Entry *_MD_find_entry (MD_Section *section, char *name);
00450 extern void *_MD_set_entry_ext(MD_Entry *entry, void *ext);
00451 extern void *_MD_get_entry_ext(MD_Entry *entry);
00452 extern void _MD_free_entry (MD_Entry *entry);
00453 extern void _MD_delete_entry (MD_Entry *entry);
00454 extern int _MD_check_entry (FILE *out, MD_Entry *entry, char *caller_name);
00455 
00456 extern MD_Field_Decl *_MD_find_field_decl (MD_Section *section, char *name);
00457 extern void _MD_free_field_decl (MD_Field_Decl *field_decl);
00458 
00459 extern int _MD_num_field_decls (MD_Section *section);
00460 extern int _MD_max_field_index (MD_Section *section);
00461 
00462 extern MD_Field *_MD_find_field (MD_Entry *entry, MD_Field_Decl *field_decl);
00463 extern int _MD_check_field (FILE *out, MD_Field *field, char *caller_name);
00464 
00465 extern int _MD_num_elements (MD_Field *field);
00466 extern int _MD_max_element_index (MD_Field *field);
00467 
00468 extern void _MD_set_int (MD_Field *field, int index, int value);
00469 extern void _MD_set_int_type_checking (MD_Field *field, int index, int value);
00470 extern int _MD_get_int (MD_Field *field, int index);
00471 
00472 extern void _MD_set_double (MD_Field *field, int index, double value);
00473 extern void _MD_set_double_type_checking (MD_Field *field, int index,
00474                                           double value);
00475 extern double _MD_get_double (MD_Field *field, int index);
00476 
00477 extern void _MD_set_string (MD_Field *field, int index, char *value);
00478 extern void _MD_set_string_type_checking (MD_Field *field, int index,
00479                                           char *value);
00480 extern char *_MD_get_string (MD_Field *field, int index);
00481 
00482 extern void _MD_set_link (MD_Field *field, int index, MD_Entry *value);
00483 extern void _MD_set_link_type_checking (MD_Field *field, int index,
00484                                         MD_Entry *value);
00485 extern MD_Entry *_MD_get_link (MD_Field *field, int index);
00486 
00487 #ifdef __cplusplus
00488 }
00489 #endif
00490 /* End prototypes of functions used by MD macros.  
00491  * DO NOT CALL THE FUNCTIONS ABOVE DIRECTLY!
00492  */
00493 
00494 #endif
00495 
00496 
00497 
00498 

Generated on Mon Jul 21 20:28:01 2003 for TINKER LEGO DOC by doxygen 1.3.2