home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / FED_PLUS.EXE / SELECTS.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  44KB  |  1,372 lines

  1. /*******************************************************************
  2. ** FedEx parser output module for generating C++  class definitions
  3. ** December  5, 1989
  4. ** release 2 17-Feb-1992
  5. ** release 3 March 1993
  6. ** release 4 December 1993
  7. ** K. C. Morris
  8. **
  9. ** Development of FedEx was funded by the United States Government,
  10. ** and is not subject to copyright.
  11.  
  12. *******************************************************************
  13. The conventions used in this binding follow the proposed specification
  14. for the STEP Standard Data Access Interface as defined in document
  15. N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
  16. *******************************************************************/
  17.  
  18.  
  19. /**************************************************************************
  20. ********    The functions in this file generate C++ code for representing
  21. ********    EXPRESS SELECT types.
  22. **************************************************************************/
  23. #include "classes.h"
  24. #define BASE_SELECT "SdaiSelect"
  25.  
  26.  
  27.  
  28. #define TYPEis_primitive(t)    ( !(TYPEis_entity(t) || TYPEis_select (t) || TYPEis_aggregate(t)) )
  29.  
  30. #define TYPEis_numeric(t)   (((t)->u.type->body->type == real_) || \
  31.                   ((t)->u.type->body->type == integer_) || \
  32.                   ((t)->u.type->body->type == number_) )
  33. #define PRINT_BUG_REPORT  \
  34.      fprintf( f, "   cerr << __FILE__ << \":\" << __LINE__ <<  \":  ERROR in schema library:  \\n\" \n\t<< _POC_ << \"\\n\\n\";\n");
  35.  
  36. #define PRINT_SELECTBUG_WARNING(f) \
  37.      fprintf( (f), "\n  severity( SEVERITY_WARNING );\n" ); \
  38.      fprintf( (f), "   cerr << __FILE__ << \":\" << __LINE__ <<  \":  WARNING:  possible misuse of SELECT TYPE from schema library.\\n\";\n"); \
  39.      fprintf( (f), "  Error( \"Mismatch in underlying type.\" );\n" );
  40.  
  41. #define print_error_msg() \
  42.       fprintf( f, "\n  severity( SEVERITY_BUG );\n" ); \
  43.       PRINT_BUG_REPORT  \
  44.       fprintf( f, "  Error( \"This 'argument' is of the incorrect type\" );\n" );
  45.  
  46. #define TRUE        1
  47. #define FALSE      0
  48.  
  49. const char *
  50. SEL_ITEMget_enumtype (Type t)
  51. {
  52.   return StrToUpper(TYPEget_name (t));
  53. }
  54.  
  55.  
  56. /******************************************************************
  57.  ** Procedure:  TYPEget_utype
  58.  ** Parameters:  Type t
  59.  ** Returns:  type used to represent the underlying type in a select class
  60.  ** Description:  
  61.  ** Side Effects:  
  62.  ** Status:  
  63.  ******************************************************************/
  64.  
  65. const char *
  66. TYPEget_utype (Type t)  {
  67. /*
  68.   static char b [BUFSIZ];
  69.   strncpy (b, TYPEget_ctype (t), BUFSIZ-2);
  70.   if (TYPEis_select (t)) strcat (b, "H");
  71.   */
  72.   return (TYPEis_entity (t) ?  "STEPentityH" : TYPEget_ctype (t));
  73. }
  74.  
  75. /*******************
  76. LISTmember
  77.  
  78. determines if the given entity is a member of the list.  
  79. RETURNS the member if it is a member; otherwise 0 is returned.
  80. *******************/
  81. Generic 
  82. LISTmember (const Linked_List list, Generic e)
  83. {
  84.   Link node;
  85.   for (node = list->mark->next; node != list->mark; node = node->next) 
  86.     if (e == node -> data)  return e;
  87.   return (0);
  88. }
  89.  
  90. /*******************
  91. utype_member 
  92.  
  93. determines if the given "link's" underlying type is a member of the list.  
  94.         RETURNS the underlying type if it is a member; otherwise 0 is returned.
  95. *******************/
  96. const char *
  97. utype_member( const Linked_List list, const Type check )
  98. {
  99.   char r [BUFSIZ], *p;
  100.   LISTdo( list, t, Type )
  101.     strncpy (r, TYPEget_utype(t), BUFSIZ);
  102.     if( strcmp(r, TYPEget_utype(check)) == 0 )
  103.       return r;
  104.   LISTod;
  105.   return 0;
  106. }
  107.  
  108. /**
  109. ***  SELgetnew_dmlist (const Type type) 
  110. ***  Returns a list of types which have unique underlying types
  111. ***  The returned list includes all the types which have a data members
  112. ***  in the select type.
  113. ***
  114. ***  The list that is returned needs to be freed by the caller.
  115. ***/
  116.  
  117.  
  118. Linked_List 
  119. SELgetnew_dmlist (const Type type) 
  120. {
  121.   Linked_List complete = SEL_TYPEget_items(type);
  122.   Linked_List newlist = LISTcreate ();
  123.  
  124.   LISTdo (complete, t, Type)
  125.  
  126.     /*     if t\'s underlying type is not already in newlist, */
  127.     if ( ! utype_member (newlist, t))
  128.       LISTadd_first (newlist, t);
  129.  
  130.   LISTod; 
  131.  
  132.   return newlist;
  133.  
  134. }
  135.  
  136. const char *
  137. SEL_ITEMget_dmtype (Type t, const Linked_List l)   
  138. {
  139.   const char * r = utype_member (l, t);
  140.   return StrToLower (r ? r : TYPEget_utype (t));
  141.  
  142. }
  143.  
  144.  
  145. /**
  146. ***  SEL_ITEMget_dmname (Type t)   
  147. ***  Returns the name of the data member in the select class for 
  148. ***  the item of the select having the type t.
  149. ***
  150. ***  Note the return value is in a static buffer.
  151. ***/
  152.  
  153. #define SEL_ITEMget_dmname(t)   StrToLower (TYPEget_utype (t))
  154.  
  155. /*******************
  156. duplicate_utype_member 
  157.  
  158. determines if the given "link's" underlying type is a multiple member
  159. of the list.
  160.     RETURNS 1 if true, else 0.
  161. *******************/
  162. int
  163. duplicate_utype_member( const Linked_List list, const Type check )
  164. {
  165.   char b [BUFSIZ];
  166.  
  167.   if (TYPEis_entity (check))  return FALSE;
  168.   /*  entities are never the same  */
  169.   
  170.   LISTdo( list, t, Type )
  171.     if (t == check)  ;
  172.       /*  don\'t compare check to itself  */
  173.     else {   /*  continue looking  */
  174.       strncpy (b, TYPEget_utype (t), BUFSIZ);
  175.       if (! strcmp(b, TYPEget_utype(check)) )
  176.     /*  if the underlying types are the same  */
  177.     return TRUE;
  178.       if (! strcmp(b, "SdaiInteger") &&
  179.       (! strcmp(TYPEget_utype(check), "SdaiReal") ))
  180.     /*  integer\'s and real\'s are not unique  */
  181.     return TRUE;
  182.   }
  183.   LISTod;
  184.   return FALSE;
  185. }
  186.  
  187. /*******************
  188. any_duplicates_in_select 
  189.  
  190. determines if any of the types in a select type resolve to the same
  191. underlying Express type.  
  192. RETURNS 1 if true, else 0.
  193. *******************/
  194. int
  195. any_duplicates_in_select( const Linked_List list )
  196. {
  197.    LISTdo( list, t, Type )
  198.       if( duplicate_utype_member(list, t) )
  199.          return TRUE;
  200.    LISTod;
  201.    return FALSE;
  202. }
  203.  
  204. /*******************
  205. find_duplicate_list 
  206.  
  207. finds a instance of each kind of duplicate type found in the given list.  
  208. This list is returned as dup_list.  If a duplicate exists, the function
  209. returns TRUE, else FALSE.
  210. list should be unbound before calling, and freed afterwards.
  211. *******************/
  212. int
  213. find_duplicate_list(const Type type, Linked_List *duplicate_list )
  214. {
  215.   Linked_List temp;    /** temporary list for comparison **/
  216.  
  217.    *duplicate_list = LISTcreate();
  218.    if( any_duplicates_in_select(SEL_TYPEget_items(type)) )
  219.    {  /**  if there is a dup somewhere  **/
  220.       temp = LISTcreate();
  221.       LISTdo( SEL_TYPEget_items(type), u, Type )
  222.          if( !utype_member(*duplicate_list, u) )
  223.          {  /**  if not already a duplicate  **/
  224.             if( utype_member(temp, u) )
  225.                LISTadd_first( *duplicate_list, u );
  226.             else
  227.                LISTadd_first( temp, u );
  228.          } 
  229.       LISTod;
  230.       LISTfree( temp );
  231.       return TRUE;
  232.    } 
  233.    return FALSE;
  234. }
  235.  
  236. /******************************************************************
  237.  ** Procedure:  ATTR_LISTmember 
  238.  ** Parameters:  Linked_List l, Variable check
  239.  ** Returns:  the attribute if an attribute with the same name as "check"
  240.  **  is on the list, 0 otherwise
  241.  ** Description:  checks to see if an attribute is a member of the list
  242.  ** Side Effects:  
  243.  ** Status:  26-Oct-1993 done
  244.  ******************************************************************/
  245.  
  246. Variable
  247. ATTR_LISTmember (Linked_List l, Variable check)
  248. {
  249.   char nm [BUFSIZ];
  250.   char cur [BUFSIZ];
  251.  
  252.   generate_attribute_name (check, nm);
  253.   LISTdo (l, a, Variable) 
  254.     generate_attribute_name (a, cur);
  255.     if (! strcmp (nm, cur) )
  256.        return check;
  257.   LISTod;
  258.   return (0);
  259. }
  260.  
  261.  
  262. /******************************************************************
  263.  ** Procedure:  SEL_TYPEgetnew_attribute_list 
  264.  ** Parameters:  const Type type
  265.  ** Returns:  Returns a list of all the attributes for a select type.
  266.  **   The list is the union of all the attributes of the underlying types.
  267.  ** Description:  
  268.  ** Side Effects:  
  269. ***  The list that is returned needs to be freed by the caller.
  270.  ** Status:  
  271.  ******************************************************************/
  272.  
  273. Linked_List 
  274. SEL_TYPEgetnew_attribute_list (const Type type) 
  275. {
  276.   Linked_List complete = SEL_TYPEget_items(type);
  277.   Linked_List newlist = LISTcreate ();
  278.   Linked_List attrs;
  279.   Entity cur;
  280.  
  281.   LISTdo (complete, t, Type)
  282.     if( TYPEis_entity(t) )
  283.       {  
  284.     cur = ENT_TYPEget_entity (t);
  285.     attrs = ENTITYget_all_attributes (cur);
  286.     LISTdo (attrs, a, Variable)
  287.       if (! ATTR_LISTmember (newlist, a))
  288.         LISTadd_first (newlist, a);
  289.     LISTod; 
  290.       }
  291.   LISTod;
  292.   return newlist;
  293. }
  294.  
  295. /*******************
  296. TYPEselect_inc_print_vars prints the class 'definition', that is, the objects
  297.     and the constructor(s)/destructor for a select class.
  298. *******************/
  299. void
  300. TYPEselect_inc_print_vars( const Type type, FILE *f, Linked_List dups)
  301. {
  302.   char buffer [BUFSIZ],
  303.     *buf = buffer;
  304.   int result;
  305.   Linked_List data_members = SELgetnew_dmlist (type);
  306.   char dmname [BUFSIZ];
  307.   char classnm [BUFSIZ];
  308.   buffer[0] = '\0';
  309.   
  310.   strncpy (classnm, SelectName (TYPEget_name (type)), BUFSIZ);
  311.   fprintf (f, "\n//////////  SELECT TYPE %s\n", TYPEget_name (type));
  312.   fprintf( f, "class %s;\n"
  313.        "typedef %s * %sH;\n\n",
  314.        classnm, classnm, classnm);
  315.   fprintf( f, "class %s  :  public "  BASE_SELECT " {\n", classnm);
  316.    fprintf( f, "  protected:\n" );
  317. /*   fprintf( f, "  \tunion {  \n" );  */
  318.    fprintf( f, "/*  \tunion {  */\n" );  
  319.    fprintf( f, "\t//  types in SELECT \n" );  
  320.    LISTdo( SEL_TYPEget_items(type), t, Type )
  321.      fprintf( f, "\t//   %s\t--  %s\n", 
  322.           SEL_ITEMget_enumtype (t), FundamentalType (t,0));
  323.    LISTod;
  324.  
  325.    LISTdo (data_members, t, Type)
  326.      strncpy (dmname, SEL_ITEMget_dmname (t), BUFSIZ);
  327.      fprintf( f, "\t   %s _%s;\n", 
  328.           TYPEget_utype (t), dmname
  329.           );
  330.    LISTod;
  331.  
  332. /*   fprintf( f, "  \t}  ;" );*/
  333.   fprintf( f, "/*  \t} ;  */" );
  334.   fprintf( f, "  /* unnamed union of select items */\n" );
  335.  
  336.   fprintf (f, "\n  public:\n"
  337.        "\tvirtual const TypeDescriptor * AssignEntity (STEPentity * se);\n"
  338.        "\tvirtual SdaiSelect * NewSelect ();\n"
  339.        );
  340.  
  341.   fprintf (f, "\n\n// STEP Part 21\n");
  342.   fprintf (f, "\tvirtual void STEPwrite_content (ostream& out =cout) const;\n");
  343.   fprintf (f, "\tvirtual Severity STEPread_content "
  344.        "(istream& in =cin, InstMgr * instances =0, int addFileId =0);\n");
  345.  
  346.     /*  read StrToVal_content   */
  347.     fprintf (f, "\n\tvirtual Severity StrToVal_content "
  348.          "(const char *, InstMgr * instances =0);\n");
  349.  
  350.     /*    constructor(s)    */
  351.     fprintf (f, "\n// STEP Part 22:  SDAI\n");
  352.     fprintf( f, "\n// structors\n\t%s();\n", classnm );
  353.  
  354.     fprintf( f, "\t//  part 1\n" );
  355.  
  356.     LISTdo( SEL_TYPEget_items(type), t, Type )
  357.       if ( (TYPEis_entity (t)) ||
  358.            ( !utype_member(dups, t) ))
  359.         /**  if an entity or not in the dup list  **/
  360.         fprintf (f, "\t%s( const %s& );\n", SelectName (TYPEget_name (type)), AccessType (t) );
  361.     LISTod;
  362.     LISTdo( dups, t, Type )
  363.       if (! TYPEis_entity (t))  /*  entity\'s were done already */
  364.         fprintf (f, "\t%s( const %s& );\n", SelectName (TYPEget_name (type)), TYPEget_utype(t) );
  365.     LISTod;
  366.  
  367.              /*    destructor    */
  368.    fprintf( f, "\tvirtual ~%s();\n", classnm );
  369.  
  370. }
  371.  
  372. /*******************
  373. TYPEselect_inc_print prints the class member function declarations of a select class.
  374. *******************/
  375. void
  376. TYPEselect_inc_print (const Type type, FILE* f)
  377. {
  378.   char n[BUFSIZ];    /*  class name  */
  379.   char tdnm [BUFSIZ];  /*  TypeDescriptor name  */
  380.   String attrnm;
  381.   Linked_List dups;
  382.   int dup_result;
  383.   Linked_List attrs; 
  384.  
  385.    dup_result = find_duplicate_list( type, &dups );
  386.    strncpy( n, SelectName(TYPEget_name (type)), BUFSIZ );
  387.    TYPEselect_inc_print_vars( type, f, dups );
  388.  
  389.   fprintf( f, "\n\t//  part 2\n" );
  390.  
  391.     LISTdo( SEL_TYPEget_items(type), t, Type )
  392.       if ( (TYPEis_entity (t)) ||
  393.            ( !utype_member(dups, t) ))
  394.         /**  if an entity or not in the dup list  **/
  395.         fprintf (f, "\toperator %s();\n", AccessType (t) );
  396.     LISTod;
  397.     LISTdo( dups, t, Type )
  398.       if (! TYPEis_entity (t))  /*  entity\'s were done already */
  399.         fprintf (f, "\toperator %s ();\n", 
  400.              TYPEis_aggregate (t) ? 
  401.              AccessType (t) : TYPEget_utype(t) );
  402.     LISTod;
  403.  
  404.   fprintf( f, "\n\t//  part 3\n" );
  405.   attrs = SEL_TYPEgetnew_attribute_list (type);  
  406.   /* get the list of unique attributes from the entity items */
  407.   LISTdo( attrs, a, Variable )
  408.     if (VARget_initializer (a) == EXPRESSION_NULL)
  409.       ATTRsign_access_methods (a, f); 
  410.   LISTod;
  411.  
  412.   fprintf( f, "\n\t//  part 4\n" );
  413.   LISTdo( SEL_TYPEget_items(type), t, Type )
  414.     if ( (TYPEis_entity (t)) ||
  415.      ( !utype_member(dups, t) ))
  416.       /**  if an entity or not in the dup list  **/
  417.       fprintf (f, "\t%s& operator =( const %s& );\n", 
  418.            SelectName (TYPEget_name (type)), AccessType (t) );
  419.   LISTod;
  420.   LISTdo( dups, t, Type )
  421.     if (! TYPEis_entity (t))  /*  entity\'s were done already */
  422.       fprintf (f, "\t%s& operator =( const %s& );\n", 
  423.            SelectName (TYPEget_name (type)), TYPEget_utype(t) );
  424.   LISTod;
  425.  
  426.   fprintf( f, "\n#ifdef COMPILER_DEFINES_OPERATOR_EQ\n#else\n" 
  427.        "\t// not in SDAI\n" );
  428.   fprintf( f, "\t%s& operator =( const %sH& );\n", n, n );
  429.   fprintf( f, "\t%s& operator =( const %s& );\n", n, n );
  430.   fprintf( f, "#endif\n" );
  431.  
  432.   fprintf( f, "\n\t//  part 5\n" );
  433.    LISTdo( SEL_TYPEget_items(type), t, Type )
  434.       fprintf( f, "\t%sLogical Is%s() const;\n", ENTITYCLASS_PREFIX,
  435.     FirstToUpper(TYPEget_name(t)) );
  436.    LISTod;
  437.  
  438.   fprintf( f, "\n\t//  part 6 ... UnderlyingTypeName () implemented in SdaiSelect class ...\n" );
  439. /*   fprintf( f, "\tSdaiString UnderlyingTypeName() const;\n" );*/
  440. /*   fprintf( f, "\tconst EntityDescriptor * CurrentUnderlyingType();\n" );*/
  441.  
  442.    if( dup_result )
  443.    {  /**  if there are duplicate underlying types  **/
  444.       fprintf( f, "\n\t//  part 7\n" );
  445.       fprintf( f, "\tconst TypeDescriptor *" 
  446.            "SetUnderlyingType ( const TypeDescriptor * td );\n", n );
  447.    } 
  448.    else
  449.       fprintf( f, "\n\t//  part 7 ... NONE\tonly for complex selects...\n" );
  450.  
  451. #ifdef PART8
  452.   fprintf( f, "\n\t//  part 8\n" );
  453.   fprintf( f, "\t%s* operator->();\n", n );
  454. #endif
  455.  
  456.   fprintf( f, "};\n");
  457.  
  458.   /*  print things for aggregate class  */
  459.   fprintf (f, "\nclass %ss  :  public  SelectAggregate  {\n", n);
  460.   fprintf (f, "  public:\n\tvirtual SingleLinkNode * NewNode ()  {\n");
  461.   fprintf (f, "\t  return new SelectNode (new %s);\t}\n};\n", n);
  462.   fprintf (f, "\n/////  END SELECT TYPE %s \n\n", 
  463.        TYPEget_name (type) );
  464.  
  465.   LISTfree( dups );
  466. }
  467.  
  468.  
  469. /*******************
  470. TYPEselect_lib_print_part_one prints constructor(s)/destructor of a select class.
  471. *******************/
  472. void
  473. TYPEselect_lib_print_part_one( const Type type, FILE* f, Schema schema, Linked_List dups, char *n )
  474. {
  475. #define schema_name    SCHEMAget_name(schema)
  476.   char var,
  477.     attrnm[BUFSIZ],
  478.     tdnm [BUFSIZ];
  479.  
  480.   strncpy (tdnm, TYPEtd_name (type, schema), BUFSIZ);
  481.  
  482.     /*    constructor(s)    */
  483.     /*  null constructor  */
  484.   fprintf (f, "\n// STEP Part 22:  SDAI\n");
  485.   fprintf( f, "\n\t//  part 0\n" );
  486.   fprintf( f, "%s::%s()\n", n, n);
  487.   fprintf( f, "  : " BASE_SELECT " (%s)\n{\n", tdnm);
  488.  
  489. /*  fprintf( f, "#ifdef  WE_WANT_TO_HAVE_THIS_CONSTRUCTOR\n" );*/
  490.   fprintf( f, "   nullify();\n" );
  491. /*  fprintf( f, "#endif\n" );*/
  492.   fprintf( f, "}\n" );
  493.  
  494.     /*  constructors with underlying types  */
  495.   fprintf( f, "\n\t//  part 1\n" );
  496.   LISTdo( SEL_TYPEget_items(type), t, Type )
  497.     if ( (TYPEis_entity (t)) ||
  498.      ( !utype_member(dups, t) ))
  499.     /* if there is not more than one underlying type that map to
  500.      *  the same base type print out the constructor using the
  501.      *  type from the TYPE statement as the underlying type.
  502.             */
  503.  
  504.       {  /**  if not an entity or in the dups list  **/
  505.     fprintf( f, "%s::%s( const %s& o )\n", 
  506.          n, n, AccessType (t));
  507.  
  508.     fprintf( f, "  : " BASE_SELECT " (%s, %s )\n{\n", 
  509.          tdnm,  TYPEtd_name (t, schema));
  510.     fprintf( f, "   _%s = o;\n", SEL_ITEMget_dmname (t) );
  511.  
  512.          fprintf( f, "}\n\n" );
  513.       }
  514.    LISTod;
  515.    LISTdo( dups, t, Type )
  516.      /* if there is more than one underlying type that maps to the
  517.       *  same base type, print a constructor using the base type.
  518.       */
  519.      if (! TYPEis_entity (t))  /*  entity\'s were done already */
  520.      {
  521.     fprintf( f, "%s::%s( const %s& o )\n", n, n, TYPEget_utype (t) );
  522.     fprintf( f, "  : " BASE_SELECT " (%s, %s )\n{\n", 
  523.          tdnm, TYPEtd_name (t, schema));
  524.         fprintf( f, "   _%s = o;\n", SEL_ITEMget_dmname (t));
  525.         fprintf( f, 
  526.         "//  NOTE:  Underlying type defaults to %s instead of NULL\n", 
  527.          TYPEtd_name (t, schema));
  528.          fprintf( f, "}\n\n" );
  529.    }
  530.    LISTod;
  531.  
  532.    fprintf( f, "%s::~%s()\n{\n", n, n );
  533.    fprintf( f, "}\n\n" );
  534. #undef schema_name    
  535. }
  536.  
  537. Linked_List
  538. ENTITYget_expanded_entities  (Entity e, Linked_List l)
  539. {
  540.   Linked_List supers;
  541.   int super_cnt =0;
  542.   Entity super;
  543.  
  544.   if (! LISTmember (l, e)) 
  545.     LISTadd_first (l, e);
  546.  
  547.  
  548. #ifdef MULTIPLE_INHERITANCE 
  549.   supers = ENTITYget_supertypes (e);
  550.   LISTdo (supers, s, Entity)
  551.   /* ignore the more than one supertypes 
  552.      since multiple inheritance isn\'t implemented  */
  553.     if (super_cnt == 0) 
  554.       ENTITYget_expanded_entities (s, l);
  555.       ++ super_cnt;
  556.   LISTod;
  557. #else
  558.   /* ignore the more than one supertypes 
  559.      since multiple inheritance isn\'t implemented  */
  560.   super = ENTITYget_superclass (e);
  561.   ENTITYget_expanded_entities (super, l);
  562. #endif
  563.   return l;
  564.  
  565. }
  566.  
  567. Linked_List 
  568. SELget_entity_itemlist (const Type type) 
  569. {
  570.   Linked_List complete = SEL_TYPEget_items(type);
  571.   Linked_List newlist = LISTcreate ();
  572.   Entity cur;
  573.  
  574.   LISTdo (complete, t, Type)
  575.     if( TYPEis_entity(t) )
  576.       {  
  577.     cur = ENT_TYPEget_entity (t);
  578.     ENTITYget_expanded_entities (cur, newlist);
  579.       }
  580.   LISTod; 
  581.   return newlist;
  582.  
  583. }
  584.  
  585. /*******************
  586. TYPEselect_lib_print_part_three prints part 3) of the SDAI C++ binding for
  587. a select class -- access functions for the data members of underlying entity
  588. types.
  589. *******************/
  590. void
  591. TYPEselect_lib_print_part_three( const Type type, FILE* f, Schema schema, char *classnm )
  592. {
  593. #define ENTITYget_type(e)  ((e)->u.entity->type)
  594.  
  595.   char uent[BUFSIZ],  /*  name of underlying entity type  */
  596.     utype[BUFSIZ],    /*  underlying type name  */
  597.     attrnm [BUFSIZ],  /*  attribute name ->  data member = _attrnm  */
  598.     funcnm[BUFSIZ];   /*  access function name = Attrnm  */
  599.   Class_Of_Type class;
  600.   Linked_List items = SEL_TYPEget_items (type);
  601.                       /* all the items in the select type  */
  602.   Linked_List attrs = SEL_TYPEgetnew_attribute_list (type);
  603.                       /*  list of attributes with unique names */
  604.   Linked_List supers;
  605.   Entity super;  /*  super type used for super class with single inheritance  */
  606.  
  607.   Variable uattr;     /*  attribute in underlying type  */
  608.  
  609.   fprintf( f, "\n\t//  part 3\n" );
  610.  
  611.   LISTdo( attrs, a, Variable )
  612.     /*  go through all the unique attributes  */
  613.     if (VARget_initializer (a) == EXPRESSION_NULL)
  614.       { /*  only do for explicit attributes  */
  615.     generate_attribute_name( a, attrnm );
  616.     strncpy (funcnm, attrnm, BUFSIZ);
  617.     funcnm [0] = toupper (funcnm[0]);
  618.     strncpy( utype, TYPEget_ctype (VARget_type (a)), BUFSIZ );
  619.     /*  use the ctype since utype will be the same for all entities  */
  620.     class = TYPEget_type (VARget_type (a));
  621.  
  622.      /*   get method  */
  623.     ATTRprint_access_methods_get_head (classnm, a, f);
  624.     fprintf (f, "{\n");
  625.  
  626.     LISTdo (items, t, Type)
  627.       if (TYPEis_entity (t) && 
  628.           (uattr = ENTITYget_named_attribute (ENT_TYPEget_entity (t), (char *) StrToLower (attrnm))))
  629.  
  630.         {  /*  for the select items which have the current attribute  */
  631.  
  632.         /*  hack around multiple inheritance
  633.         only do for first supertype   */
  634. #ifdef MULTIPLE_INHERITANCE 
  635.         supers = ENTITYget_supertypes (ENT_TYPEget_entity (t));
  636.         if (!supers 
  637.         || (supers
  638.         && LISTmember (ENTITYget_all_attributes ((Entity) LISTget_first (supers)), uattr)) )
  639. #else
  640.         super = ENTITYget_superclass (ENT_TYPEget_entity (t));
  641.         if (LISTmember (ENTITYget_attributes (ENT_TYPEget_entity (t)), uattr)
  642.         /*  attribute is in this entity - not parent  */
  643.         || (super && LISTmember (ENTITYget_all_attributes (super), uattr)) )
  644.             /*  or the attribute is from the parent that\'s being used  */
  645. #endif
  646.           {
  647.  
  648.             if (! VARis_derived (uattr))  {
  649.  
  650.           if (!strcmp (utype, TYPEget_ctype (VARget_type (uattr)) ))  {
  651.         /*  check to make sure the underlying attribute\'s type is 
  652.             the same as the current attribute.  
  653.             */
  654.  
  655.         strncpy( uent, TYPEget_ctype (t), BUFSIZ );
  656.  
  657.                 /*  if the underlying type is that item\'s type
  658.             call the underlying_item\'s member function  */
  659.         fprintf( f, "  if( CurrentUnderlyingType () == %s ) \n\t//  %s\n", 
  660.              TYPEtd_name (t, schema), StrToUpper (TYPEget_name (t)));
  661.         fprintf( f, "\treturn ((%s) _%s) ->%s();\n", 
  662.              uent, SEL_ITEMget_dmname (t),  funcnm );
  663.  
  664.           } else {
  665.         /*  types are not the same issue a warning  */
  666.         fprintf (stderr, 
  667.             "WARNING: in SELECT TYPE %s: \n\t"
  668.             "ambiguous attribute \"%s\" from underlying type \"%s\".\n\n", 
  669.              TYPEget_name (type), attrnm, TYPEget_name (t));
  670.         fprintf (f, "  //  %s\n\t//  attribute access function"
  671.              " has a different return type\n", 
  672.              StrToUpper (TYPEget_name (t)));
  673.           }
  674.  
  675.         } else /*  derived attributes  */
  676.         fprintf (f, "  //  for %s  attribute is derived\n",
  677.              StrToUpper (TYPEget_name (t)));
  678.  
  679.         }
  680.       }
  681.     LISTod;
  682.     PRINT_BUG_REPORT (f);
  683.     fprintf( f, "   return NULL;\n}\n\n" );
  684.  
  685.     /*   put method  */
  686.     ATTRprint_access_methods_put_head  (classnm, a, f);
  687.     fprintf (f, "{\n");
  688.     LISTdo (items, t, Type)
  689.       if (TYPEis_entity (t) && 
  690.           (uattr = ENTITYget_named_attribute (ENT_TYPEget_entity (t), (char *) StrToLower (attrnm))) )
  691.  
  692.         {  /*  for the select items which have the current attribute  */
  693.  
  694.         /*  hack around multiple inheritance
  695.         only do for first supertype   */
  696.  
  697. #ifdef MULTIPLE_INHERITANCE 
  698.         supers = ENTITYget_supertypes (ENT_TYPEget_entity (t));
  699.         if (supers 
  700.         && LISTmember (ENTITYget_all_attributes ((Entity) LISTget_first (supers)), uattr))  
  701. #else
  702.         super = ENTITYget_superclass (ENT_TYPEget_entity (t));
  703.         if (LISTmember (ENTITYget_attributes (ENT_TYPEget_entity (t)), uattr)
  704.         /*  attribute is in this entity - not parent  */
  705.         || (super && LISTmember (ENTITYget_all_attributes (super), uattr)) )
  706.             /*  or the attribute is from the parent that\'s being used  */
  707. #endif
  708.           {
  709.  
  710.             if (! VARis_derived (uattr))  {
  711.  
  712.           if (!strcmp (utype, TYPEget_ctype (VARget_type (uattr)) ))  {
  713.         /*  check to make sure the underlying attribute\'s type is 
  714.             the same as the current attribute.  
  715.             */
  716.  
  717.         /*  if the underlying type is that item\'s type
  718.             call the underlying_item\'s member function  */
  719.         strncpy( uent, TYPEget_ctype (t), BUFSIZ );
  720.         fprintf( f, "  if( CurrentUnderlyingType () == %s ) \n\t//  %s\n",
  721.              TYPEtd_name (t, schema), StrToUpper (TYPEget_name (t)));
  722.         fprintf( f, "\t{  ((%s) _%s) ->%s( x );\n\t  return;\n\t}\n",
  723.              uent, SEL_ITEMget_dmname (t),  funcnm );
  724.           } else   /*  warning printed above  */
  725.         fprintf (f, "  //  for %s  attribute access function"
  726.              " has a different argument type\n", 
  727.              SEL_ITEMget_enumtype (t));
  728.         } else /*  derived attributes  */
  729.         fprintf (f, "  //  for %s  attribute is derived\n",
  730.              SEL_ITEMget_enumtype (t));
  731.       }
  732.       }
  733.     LISTod;
  734.     PRINT_SELECTBUG_WARNING (f);
  735.     fprintf( f, "\n}\n" );
  736.       } 
  737.   LISTod;
  738.  
  739. #ifdef NO_OVERLAPS
  740.   Linked_List l = SELget_entity_itemlist (type);
  741.   /*  this part only applies to entities  */
  742.   Type t;
  743.  
  744.   fprintf( f, "\n\t//  part 3\n" );
  745.  
  746.    LISTdo( l, e, Entity )
  747.      strncpy( uent, ClassName (ENTITYget_name(e)), BUFSIZ );
  748.      LISTdo (ENTITYget_attributes (e), a, Variable)
  749.        t = ENTITYget_type (e);
  750.        if (VARget_initializer (a) == EXPRESSION_NULL)
  751.      { 
  752.        generate_attribute_name( a, attrnm );
  753.        attrnm [0] = toupper (attrnm[0]);
  754.        strncpy( utype, TYPEget_ctype (VARget_type (a)), BUFSIZ );
  755.      } 
  756.        class = TYPEget_type (VARget_type (a));
  757.  
  758.      /*   get method  */
  759.  
  760.        ATTRprint_access_methods_get_head
  761.      (n, a, VARget_type (a), f, class, attrnm, utype );
  762.        fprintf( f, "{\n  //  %s\n"
  763.         "  if( CurrentUnderlyingType () == %s )\n", 
  764. p        StrToUpper (TYPEget_name (t)),
  765.         TYPEtd_name (t, schema));
  766.        fprintf( f, "\treturn ((%sH) _%s) ->%s();\n\n", 
  767.         uent, SEL_ITEMget_dmname (t),  attrnm );
  768.        PRINT_SELECTBUG_WARNING (f);
  769.        fprintf( f, "   return NULL;\n}\n\n" );
  770.  
  771.      /*   put method  */
  772.  
  773.        ATTRprint_access_methods_put_head  (n, a, t, f, class, attrnm, utype );
  774.        fprintf( f, "{\n   if( CurrentUnderlyingType () == %s )  //  %s\n",
  775.         TYPEtd_name (t, schema), SEL_ITEMget_enumtype (t));
  776.        fprintf( f, "\t((%sH) _%s) ->%s( x );\n   else  {\n", 
  777.         uent, SEL_ITEMget_dmname (t),  attrnm );
  778. /*       print_error_msg();*/
  779.        PRINT_SELECTBUG_WARNING (f);
  780.        fprintf( f, "  }\n}\n" );
  781.      LISTod;
  782.   LISTod;
  783.  
  784. #endif
  785. }
  786.  
  787. /*******************
  788. TYPEselect_lib_print_part_four prints part 4) of the SDAI document of a select class.
  789. *******************/
  790. void
  791. TYPEselect_lib_print_part_four( const Type type, FILE* f, Schema schema, Linked_List dups, char *n )
  792. {
  793.   char nvar = tolower( n[4] ),
  794.     x[BUFSIZ];
  795.  
  796.   fprintf( f, "\n\t//  part 4\n" );
  797.  
  798.   LISTdo( SEL_TYPEget_items(type), t, Type )
  799.     if ( (TYPEis_entity (t)) ||
  800.      ( !utype_member(dups, t) ))
  801.       {  /**  if an entity or not in dups list  **/
  802.      fprintf( f, "%s& %s::operator =( const %s& o )\n{\n"
  803.           "  nullify ();\n",
  804.           n, n, AccessType (t));
  805.  
  806.          fprintf( f, "   _%s = o;\n", SEL_ITEMget_dmname (t) );
  807.      fprintf( f, "   SetUnderlyingType (%s);\n", TYPEtd_name (t, schema));
  808.          fprintf( f, "   return *this;\n}\n\n" );
  809.       }  
  810.    LISTod;
  811.    LISTdo( dups, t, Type )
  812.      if (! TYPEis_entity (t))  /*  entity\'s were done already */
  813.        {
  814.       fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", n, n, TYPEget_utype (t));
  815.             /**** MUST CHANGE FOR multiple big types ****/
  816.       fprintf( f, "   _%s = o;\n", SEL_ITEMget_dmname (t));
  817.       fprintf (f, "  underlying_type = 0; // MUST BE SET BY USER \n");
  818.       fprintf( f, "//    discriminator = UNSET\n" );
  819.       fprintf( f, "   return *this;\n}\n\n" );
  820.     }
  821.    LISTod;
  822.  
  823.    fprintf( f, "%s& %s::operator =( const %sH& o )\n{\n", n,n,n );
  824.  
  825.  
  826.    LISTdo( SEL_TYPEget_items(type), t, Type )
  827.      strncpy ( x, TYPEget_name(t), BUFSIZ );
  828.     fprintf( f, "   if( o -> CurrentUnderlyingType () == %s )\n", TYPEtd_name (t, schema));
  829.          if( utype_member(dups,t) )
  830.          /**  if in the dup list  **/
  831.        fprintf( f, "      _%s = o -> _%s;\n", 
  832.             SEL_ITEMget_dmname (t), 
  833.             StrToLower(TYPEget_utype(t)) );
  834.          else
  835.        fprintf( f, "\t_%s =  o -> _%s;\n", 
  836.             SEL_ITEMget_dmname (t), 
  837.             SEL_ITEMget_dmname (t));
  838.    LISTod;
  839.    fprintf( f, "   underlying_type = o -> CurrentUnderlyingType ();\n" );
  840.    fprintf( f, "   return *this;\n}\n" );
  841.  
  842.    fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", n,n,n );
  843.  
  844.    LISTdo( SEL_TYPEget_items(type), t, Type )
  845.      strncpy ( x, TYPEget_name(t), BUFSIZ );
  846.     fprintf( f, "   if( o.CurrentUnderlyingType () == %s )\n", TYPEtd_name (t, schema));
  847.          if( utype_member(dups,t) )
  848.          /**  if in the dup list  **/
  849.        fprintf( f, "      _%s = o._%s;\n", 
  850.             SEL_ITEMget_dmname (t), 
  851.             StrToLower(TYPEget_utype(t)) );
  852.          else
  853.        fprintf( f, "\t_%s =  o._%s;\n", 
  854.             SEL_ITEMget_dmname (t), 
  855.             SEL_ITEMget_dmname (t));
  856.    LISTod;
  857.    fprintf( f, "   underlying_type = o.CurrentUnderlyingType ();\n" );
  858.    fprintf( f, "   return *this;\n}\n" );
  859.  
  860. }
  861.  
  862.  
  863. /*******************
  864. TYPEselect_init_print prints the types that belong to the select type
  865. *******************/
  866.  
  867. void
  868. TYPEselect_init_print (const Type type, FILE* f, Schema schema)
  869. {
  870. #define schema_name    SCHEMAget_name(schema)
  871.    LISTdo( SEL_TYPEget_items(type), t, Type )
  872.  
  873.     fprintf(f,"\t%s -> Elements ().AddNode",
  874.         TYPEtd_name (type, schema));
  875.     fprintf(f," (%s);\n", 
  876.         TYPEtd_name (t, schema));
  877.    LISTod;
  878. #undef schema_name    
  879.  
  880. }
  881.  
  882.  
  883. void
  884. TYPEselect_lib_part21 (const Type type, FILE* f, Schema schema)
  885. {
  886.   char n[BUFSIZ], *z;     /*  pointers to class name(s)  */
  887.   const char * dm;  /*  data member name */
  888.   Linked_List dups;
  889.   Linked_List data_members = SELgetnew_dmlist (type);
  890.   int dup_result;
  891.  
  892.   dup_result = find_duplicate_list( type, &dups );
  893.   strncpy( n, SelectName(TYPEget_name(type)), BUFSIZ );
  894.  
  895.   fprintf (f, "// STEP Part 21\n");
  896.   /*  write part 21   */
  897.   fprintf (f, "\nvoid\n%s::STEPwrite_content (ostream& out) const\n{\n", n);
  898.  
  899. /*  go through the items  */
  900.   LISTdo( SEL_TYPEget_items(type), t, Type )
  901.     dm = SEL_ITEMget_dmname (t);
  902.     
  903.     fprintf( f, "  if (CurrentUnderlyingType () == %s)\n", 
  904.          TYPEtd_name (t, schema));
  905.  
  906.     switch (TYPEget_body(t)->type) {
  907.  
  908.       /*  if it\'s a number, just print it  */
  909.     case integer_:
  910.     case real_:
  911.     case number_:
  912.       fprintf( f, "\tout <<  _%s;\n  else  ", dm);
  913.       break;
  914.  
  915.     case entity_:
  916.       fprintf( f, 
  917.            "\t_%s -> STEPwrite_reference (out);\n  else  ", dm);
  918.       break;
  919.     case string_:
  920.     case enumeration_:
  921.     case aggregate_:
  922.     case array_:
  923.     case bag_:
  924.     case set_:
  925.     case list_:
  926.     case select_:
  927.       /*  for string\'s, enum\'s, select\'s and aggregate\'s
  928.       it\'ll be embedded; 
  929.       */
  930.       fprintf( f, 
  931.            "\t_%s.STEPwrite (out);\n  else  ", dm);
  932.       break;
  933.  
  934.     default:
  935.       /*  otherwise it\'s a pointer  */
  936.       fprintf( f, 
  937.            "\t_%s -> STEPwrite (out);\n  else  ", dm);
  938.       break;
  939.     }
  940.   LISTod;
  941.  
  942.   fprintf (f, "  {\n");
  943.   PRINT_BUG_REPORT
  944.   fprintf (f, "  }\n");
  945.   fprintf (f, "  return;\n}\n");
  946.  
  947.   /*  read part 21   */
  948.   fprintf (f, "\nSeverity\n%s::STEPread_content "
  949.        "(istream& in, InstMgr * instances, int addFileId)"
  950.        "\n{\n", n);
  951.  
  952. /*  go through the items  */
  953.   LISTdo( SEL_TYPEget_items(type), t, Type )
  954.     
  955.     fprintf( f, "\n  if (CurrentUnderlyingType () == %s) ", 
  956.          TYPEtd_name (t, schema));
  957.  
  958.     dm = SEL_ITEMget_dmname (t);
  959.  
  960.     switch (TYPEget_body(t)->type) {
  961.       /*  if it\'s a number, just read it  */
  962.     case real_:
  963.     case number_:
  964.       /*  since REAL and NUMBER are handled the same they both need 
  965.       to be included in the case stmt  */
  966.       fprintf( f, "  {\n\tReadReal (_%s, in, &_error, \"),\");\n"
  967.            "\treturn severity ();\n  }\n",
  968.            dm);
  969.       break;
  970.  
  971.     case integer_:
  972.       fprintf( f, "  {\n\tReadInteger (_%s, in, &_error, \"),\");\n"
  973.            "\treturn severity ();\n  }\n",
  974.            dm);
  975.       break;
  976.  
  977.     case entity_:
  978.       /*  if it\'s an entity, use Assign - done in Select class  */
  979.       fprintf (f, 
  980.            "  {\n\t// set Underlying Type in Select class\n"
  981.            "\t_%s = ReadEntityRef "
  982.            "(in, &_error, \",)\", instances, addFileId);\n", dm);
  983.       fprintf (f, "\tif (_%s && (_%s != S_ENTITY_NULL)\n "
  984.            "\t  && (CurrentUnderlyingType () -> CanBe (_%s -> EntityDescriptor )) )\n"
  985.            "\t  return severity ();\n",
  986.            dm, dm, dm);
  987.       fprintf (f, "\telse {\n "
  988.            "\t  Error (\"Reference to instance that is not indicated type\\n\");\n"
  989.            "\t  _%s = 0;\n"
  990.            "\t  nullify ();\n"
  991.            "\t  return severity (SEVERITY_USERMSG);\n\t}\n  }\n",
  992.            dm
  993.            );
  994.       break;
  995.  
  996.     case string_:
  997.     case enumeration_:
  998.       fprintf( f, 
  999.            "  {\n\t_%s.STEPread (in, &_error);\n"
  1000.            "\treturn severity ();\n  }",
  1001.            dm);
  1002.       break;
  1003.     case select_:
  1004.       fprintf( f, 
  1005.            "  {\n\t_%s.STEPread (in, &_error, instances, addFileId);\n"
  1006.            "\treturn severity ();\n  }",
  1007.            dm);
  1008.       break;
  1009.     case aggregate_:
  1010.     case array_:
  1011.     case bag_:
  1012.     case set_:
  1013.     case list_:
  1014.       fprintf( f, 
  1015.            "  {\n\t_%s.STEPread (in, &_error, "
  1016.            "%s -> AggrElemTypeDescriptor (), "
  1017.            "instances, addFileId);\n"
  1018.            "\treturn severity ();\n  }",
  1019.            dm,
  1020.            TYPEtd_name (t, schema));
  1021.       break;
  1022.  
  1023.     default:      
  1024.       fprintf( f, 
  1025.            "  {\n\t_%s -> STEPread (in, &_error, instances, addFileId);\n"
  1026.            "\treturn severity ();\n  }",
  1027.            dm);
  1028.       break;
  1029.     }
  1030.  
  1031.   LISTod;
  1032.  
  1033.   PRINT_SELECTBUG_WARNING (f) ;
  1034.  
  1035.   LISTfree (data_members);
  1036.   fprintf (f, 
  1037. /*       "#ifdef __GNUG__\n"*/
  1038. /*       "\n  return SEVERITY_NULL;\n"*/
  1039. /*       "#endif"*/
  1040.        "\n  return severity ();"
  1041.        "\n}\n");
  1042. }
  1043.  
  1044.  
  1045. void
  1046. TYPEselect_lib_StrToVal (const Type type, FILE* f, Schema schema)
  1047. {
  1048.   char n[BUFSIZ], *z;     /*  pointers to class name  */
  1049.   Linked_List dups;
  1050.   Linked_List data_members = SELgetnew_dmlist (type);
  1051.   int dup_result;
  1052.  
  1053.   dup_result = find_duplicate_list( type, &dups );
  1054.   strncpy( n, SelectName(TYPEget_name(type)), BUFSIZ );
  1055.  
  1056.   /*  read StrToVal_content   */
  1057.   fprintf (f, "\nSeverity\n%s::StrToVal_content "
  1058.        "(const char * val, InstMgr * instances)"
  1059.        "\n{\n", n);
  1060.  
  1061.   /*fprintf (f, "  switch (base_type)  {\n");*/
  1062.   LISTdo( data_members, t, Type )
  1063. /*    fprintf (f, "  case %s :  \n",     FundamentalType (t, 0));*/
  1064.  
  1065.     switch (TYPEget_body(t)->type) {
  1066.  
  1067.     case real_:
  1068.     case integer_:
  1069.     case number_:
  1070.     case select_:
  1071.       /*  if it\'s a number, use STEPread_content - done in Select class  */
  1072.       /*  if it\'s a select, use STEPread_content - done in Select class  */
  1073. /*      fprintf (f, "\t// done in Select class\n\treturn SEVERITY_NULL;\n");*/
  1074.       break;
  1075.  
  1076.     case entity_:
  1077.       /*  if it\'s an entity, use AssignEntity - done in Select class  */
  1078. /*      fprintf (f, "\t// done in Select class\n\treturn SEVERITY_NULL;\n");*/
  1079.  
  1080.       break;
  1081.     case enumeration_:
  1082.       fprintf (f, "  if(base_type = %s )  \n",     FundamentalType (t, 0));
  1083.       fprintf( f, 
  1084.            "\treturn _%s.StrToVal (val, &_error);\n",
  1085.            SEL_ITEMget_dmname (t));
  1086.       break;
  1087.  
  1088.     case string_:
  1089.       fprintf (f, " if(base_type = %s )\n",     FundamentalType (t, 0));
  1090.       fprintf( f, 
  1091.            "\treturn _%s.StrToVal (val);\n",
  1092.            SEL_ITEMget_dmname (t));
  1093.       break;
  1094.  
  1095.     case aggregate_:
  1096.     case array_:
  1097.     case bag_:
  1098.     case set_:
  1099.     case list_:
  1100.       fprintf (f, "  if(base_type = %s )\n",     FundamentalType (t, 0));
  1101.       fprintf( f, 
  1102.            "\treturn _%s.StrToVal (val, &_error, "
  1103.            "%s -> AggrElemTypeDescriptor ()); ",
  1104. /*           "instances, addFileId);  "*/
  1105.            SEL_ITEMget_dmname (t),
  1106.            TYPEtd_name (t, schema));
  1107.       break;
  1108.  
  1109.     default:      
  1110.       /*  otherwise use StrToVal on the contents to check the format  */
  1111.       fprintf (f, "if(base_type = %s )\n",     FundamentalType (t, 0));
  1112.       fprintf( f, 
  1113.            "\treturn _%s -> StrToVal (val, instances);\n",
  1114.            SEL_ITEMget_dmname (t));
  1115.     }
  1116.   LISTod;
  1117.  
  1118.   
  1119.   LISTfree (data_members);
  1120.   fprintf (f,"\n  return SEVERITY_NULL;\n}\n");
  1121. }
  1122.  
  1123. void
  1124. TYPEselect_lib_virtual (const Type type, FILE* f, Schema schema)
  1125. {
  1126.   TYPEselect_lib_part21 ( type, f,  schema);
  1127.   TYPEselect_lib_StrToVal ( type, f,  schema);
  1128. }
  1129.  
  1130. void
  1131. SELlib_print_protected (const Type type,  FILE* f, const Schema schema)  
  1132. {
  1133.   const char * snm;
  1134.  
  1135.   /*  SELECT::AssignEntity  */
  1136.   fprintf (f, "\nconst TypeDescriptor * \n%s::AssignEntity (STEPentity * se)\n"
  1137.      "{\n", 
  1138.        SelectName (TYPEget_name (type))
  1139.        );
  1140.  
  1141.  
  1142. /* loop through the items in the SELECT */
  1143.   LISTdo( SEL_TYPEget_items(type), t, Type )
  1144.     if (TYPEis_entity (t))  {
  1145.       fprintf (f, 
  1146.        "  //  %s\n"  /*  item name  */
  1147.        "  if (se -> EntityDescriptor -> IsA (%s))\n" /*  td */
  1148.        "  {  \n"
  1149.        "\t_%s = (%sH) se;\n"  /* underlying data member */
  1150.            /*  underlying data member type */
  1151.        "\treturn SetUnderlyingType (%s);\n"  /* td */
  1152.        "  }\n",
  1153.            StrToUpper (TYPEget_name (t)),
  1154.            TYPEtd_name (t, schema), 
  1155.            SEL_ITEMget_dmname (t),
  1156.            ClassName (TYPEget_name (t)),
  1157.            TYPEtd_name (t, schema)
  1158.     );
  1159.     }
  1160.   if  (TYPEis_select (t)) {
  1161.       fprintf (f, 
  1162.        "  //  %s\n"  /*  item name  */
  1163.        "  if (%s -> CanBe (se -> EntityDescriptor))\n" 
  1164.        "  {  \n"
  1165.        "\t_%s.AssignEntity (se);\n"  /* underlying data member */
  1166.        "\treturn SetUnderlyingType (%s);\n"  /* td */
  1167.        "  }\n",
  1168.            StrToUpper (TYPEget_name (t)),
  1169.            TYPEtd_name (t, schema), 
  1170.            SEL_ITEMget_dmname (t),
  1171.            TYPEtd_name (t, schema)
  1172.     );
  1173.     }
  1174.  
  1175.   LISTod;
  1176.   fprintf (f, "  return 0;\n}\n");
  1177.  
  1178.   /*  SELECT::NewSelect  */
  1179.   snm  = SelectName (TYPEget_name (type));
  1180.   fprintf (f, "\nSdaiSelect * \n%s::NewSelect ()\n"
  1181.        "{\n"
  1182.        "  %s * tmp = new %s ();\n"
  1183.        "  return tmp;\n}\n",
  1184.        snm, snm, snm
  1185.        );
  1186.  
  1187.  
  1188. }
  1189.  
  1190.  
  1191. /*******************
  1192. TYPEselect_lib_print prints the member functions (definitions) of a select class.
  1193. *******************/
  1194. void
  1195. TYPEselect_lib_print (const Type type, FILE* f, Schema schema)
  1196. {
  1197.     char n[BUFSIZ]; const char *z;    /*  pointers to class name(s)  */
  1198.     Linked_List dups;
  1199.     int dup_result;
  1200.  
  1201.     dup_result = find_duplicate_list( type, &dups );
  1202.     strncpy( n, SelectName(TYPEget_name(type)), BUFSIZ );
  1203.     fprintf (f, "\n//////////  SELECT TYPE %s\n", TYPEget_name (type));
  1204.  
  1205.     SELlib_print_protected (type,  f,  schema)  ;
  1206.     TYPEselect_lib_virtual (type, f, schema);
  1207.     TYPEselect_lib_print_part_one( type, f, schema, dups, n );
  1208.  
  1209.     fprintf( f, "\n\t//  part 2\n" );
  1210.  
  1211.     LISTdo( SEL_TYPEget_items(type), t, Type )
  1212.       if  (TYPEis_entity (t)) 
  1213.         {  /*  if an entity  */
  1214.           fprintf( f, "%s::operator %sH()\n{\n", n, ClassName(TYPEget_name(t)) );
  1215.           fprintf( f, "   if( CurrentUnderlyingType () == %s )\n", TYPEtd_name (t, schema));
  1216.           fprintf( f, "      return ((%sH) _%s);\n", 
  1217.                ClassName(TYPEget_name(t)),
  1218.                SEL_ITEMget_dmname (t));
  1219.           PRINT_SELECTBUG_WARNING (f);
  1220.           fprintf( f, "   return NULL;\n}\n\n" );
  1221.         }
  1222.       else if  ( !utype_member(dups, t) )
  1223.         {  /**  if not in the dup list  **/
  1224.           fprintf( f, "%s::operator %s()\n{\n", n, AccessType (t));
  1225.           fprintf( f, "   if( CurrentUnderlyingType () == %s )\n", TYPEtd_name (t, schema));
  1226.           fprintf( f, "      return %s _%s;\n", 
  1227.                ((TYPEis_aggregate (t) || TYPEis_select (t))  ? "&" : ""),
  1228.                SEL_ITEMget_dmname (t)
  1229.                );
  1230.           fprintf( f, "\n  severity( SEVERITY_WARNING );\n" ); 
  1231.           fprintf( f, "  Error( \"Underlying type is not %s\" );\n", AccessType (t) );
  1232.           PRINT_SELECTBUG_WARNING (f) ;
  1233.           fprintf( f, "   return NULL;\n}\n\n" );
  1234.         }
  1235.     LISTod;
  1236.     LISTdo( dups, t, Type )
  1237.       if (! TYPEis_entity (t))  /*  entity\'s were done already */
  1238.         {
  1239.           fprintf( f, "%s::operator %s()\n{\n", n, 
  1240.              TYPEis_aggregate (t) ? 
  1241.              AccessType (t) : TYPEget_utype(t) );
  1242.           
  1243.                 /**** MUST CHANGE FOR multiple big types ****/
  1244.           LISTdo( SEL_TYPEget_items(type), x, Type )
  1245.         if( strcmp(TYPEget_utype(t), TYPEget_utype(x)) == 0 )
  1246.           {  /** if this is one of the dups  **/
  1247.             fprintf( f, "   if( CurrentUnderlyingType () == %s )\n", TYPEtd_name (x, schema));
  1248.             fprintf( f, "      return %s _%s;\n", 
  1249.                ((TYPEis_aggregate (t))  ? "&" : ""),
  1250.                SEL_ITEMget_dmname (t)
  1251.                );
  1252.           }
  1253.           LISTod;
  1254.           fprintf( f, "\n  severity( SEVERITY_WARNING );\n" ); 
  1255.           fprintf( f, "  Error( \"Underlying type is not %s\" );\n", 
  1256.              TYPEis_aggregate (t) ? 
  1257.              AccessType (t) : TYPEget_utype(t) );
  1258.           PRINT_SELECTBUG_WARNING (f) ;
  1259.           fprintf( f, "   return NULL;\n}\n\n" );
  1260.         }
  1261.     LISTod;
  1262.  
  1263.    TYPEselect_lib_print_part_three( type, f, schema, n );
  1264.    TYPEselect_lib_print_part_four( type, f, schema, dups, n );
  1265.  
  1266. fprintf( f, "\n\t//  part 5\n" );
  1267.    LISTdo( SEL_TYPEget_items(type), t, Type )
  1268.       z = FirstToUpper( TYPEget_name(t) );
  1269.       fprintf( f, "%sLogical %s::Is%s() const\n{\n", ENTITYCLASS_PREFIX, n, z );
  1270.       fprintf( f, "   if( !exists() )\n", n );
  1271.       fprintf( f, "      return sdaiUNKNOWN;\n" );
  1272.       fprintf( f, "   if( CurrentUnderlyingType () == %s )\n", TYPEtd_name (t, schema));
  1273.       fprintf( f, "      return sdaiTRUE;\n" );
  1274.       fprintf( f, "   return sdaiFALSE;\n}\n\n" );
  1275.    LISTod;
  1276.  
  1277. #ifdef UNDERLYINGTYPE
  1278. fprintf( f, "\n\t//  part 6\n" );
  1279.    fprintf( f, "SdaiString %s::UnderlyingTypeName() const\n{\n", n );
  1280.    fprintf( f, "   if( exists() )\n" );
  1281.    fprintf( f, "   {\n" );
  1282.    LISTdo( SEL_TYPEget_items(type), t, Type )
  1283.       fprintf( f, "   if( CurrentUnderlyingType () == %s )\n", TYPEtd_name (t, schema));
  1284.       if( TYPEis_entity(t) )
  1285.          fprintf( f, "         return( _%s->Name() );\n", StrToLower(TYPEget_name(t)) );
  1286.       else
  1287.          fprintf( f, "         return( \"%s\" );\n", TYPEget_utype(t) );
  1288.    LISTod;
  1289.    fprintf( f, "   }\n   return NULL;\n}\n\n" );
  1290.  
  1291.    fprintf( f, "const EntityDescriptor * %s::CurrentUnderlyingType()\n{\n", n );
  1292.    fprintf( f, "   if( exists() )\n" );
  1293.    fprintf( f, "   {\n" );
  1294.    LISTdo( SEL_TYPEget_items(type), t, Type )
  1295.       if( TYPEis_entity(t) )
  1296.       { 
  1297.     fprintf( f, "   if( discriminator == %s )\n", SEL_ITEMget_enumtype (t));
  1298.          fprintf( f, "         return( _%s->EntityDescriptor );\n", 
  1299.           SEL_ITEMget_dmname (t) );
  1300.       } 
  1301.    LISTod;
  1302.    fprintf( f, "   }\n   return NULL;\n}\n\n" );
  1303.  
  1304. #endif
  1305.     if( dup_result )  {
  1306.     fprintf( f, "\n\t//  part 7\n" );
  1307.     fprintf( f, 
  1308.          "const TypeDescriptor * \n"
  1309.          "%s::SetUnderlyingType (const TypeDescriptor * td)\n{\n"
  1310.          "  return " BASE_SELECT "::SetUnderlyingType (td);\n}\n", 
  1311.          n);
  1312.       }
  1313.  
  1314. #ifdef PART8
  1315.     fprintf( f, "\n\t//  part 8\n" );
  1316.     fprintf( f, "%s* %s::operator->()\n", n, n );
  1317.     fprintf( f, "{\n   return this;\n}\n" );
  1318. #endif
  1319.    LISTfree( dups );
  1320.  
  1321.     fprintf (f, "//////////  END SELECT TYPE %s\n\n", n);
  1322.  
  1323. }
  1324.  
  1325. void
  1326. TYPEselect_print (Type t, FILES* files, Schema schema)  
  1327. {
  1328.  
  1329.   SelectTag tag, tmp;
  1330.  
  1331.   /*  if type is already marked, return  */
  1332.   if ((SelectTag) (tmp = TYPEget_clientData (t)))  {
  1333.     if ((tmp ->started) && (! tmp ->complete))
  1334.       fprintf (stderr, "WARNING:  SELECT type %s causes circular references\n",
  1335.            TYPEget_name (t));
  1336.     return;
  1337.   }
  1338.   /*  mark the type as being processed  */
  1339.   tag = (SelectTag ) malloc (sizeof (struct SelectTag));
  1340.   tag -> started =1;
  1341.   tag -> complete =0;
  1342.   TYPEput_clientData (t, tag);
  1343.  
  1344.   LISTdo ( SEL_TYPEget_items(t), i, Type )
  1345.  
  1346.   /*  check the items for select types  */
  1347.   /*  and do the referenced select types first  */
  1348.     if (TYPEis_select (i) && !TYPEget_clientData (i))  
  1349.       TYPEselect_print (i, files, schema);
  1350.  
  1351.   /*  check the attributes to see if a select is referenced  */
  1352.     if (TYPEis_entity (i)) {
  1353.       LISTdo (ENTITYget_all_attributes (ENT_TYPEget_entity (i)), a, Variable)
  1354.     if (TYPEis_select (VARget_type (a)))
  1355.       TYPEselect_print (VARget_type (a), files, schema);
  1356.       LISTod
  1357.       }
  1358.  
  1359.   LISTod
  1360.  
  1361.   TYPEselect_inc_print (t, files -> inc);
  1362.   TYPEselect_lib_print (t, files -> lib, schema);
  1363.   TYPEselect_init_print (t, files -> init, schema);
  1364.   tag -> complete =1;
  1365. }  
  1366. #undef BASE_SELECT
  1367.  
  1368.  
  1369. /**************************************************************************
  1370. ********        END  of SELECT TYPE
  1371. **************************************************************************/
  1372.