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 / SCL.EXE / EXPDICT.CPP < prev    next >
C/C++ Source or Header  |  1994-08-06  |  16KB  |  615 lines

  1.  
  2. /*
  3. * NIST STEP Core Class Library
  4. * clstepcore/ExpDict.cc
  5. * February, 1994
  6. * K. C. Morris
  7. * David Sauder
  8.  
  9. * Development of this software was funded by the United States Government,
  10. * and is not subject to copyright.
  11. */
  12.  
  13. /* $Id: ExpDict.cc,v 2.0.1.4 1994/04/05 16:39:11 sauderd Exp $  */ 
  14.  
  15. #include <ExpDict.h> 
  16. #include <aggregat.h> 
  17.  
  18. /*
  19. const TypeDescriptor * const t_INTEGER_TYPE = & TypeDescriptor
  20.                        ("INTEGER",     // Name
  21.                INTEGER_TYPE, // FundamentalType
  22.                "INTEGER");   // Description
  23. extern const TypeDescriptor _t_INTEGER_TYPE
  24.                        ("INTEGER",     // Name
  25.                INTEGER_TYPE, // FundamentalType
  26.                "INTEGER");   // Description
  27.                */
  28. /*const TypeDescriptor * const t_INTEGER_TYPE = &_t_INTEGER_TYPE;*/
  29.  
  30. /*extern const TypeDescriptor _t_REAL_TYPE ("REAL", REAL_TYPE, "Real");*/
  31. /*const TypeDescriptor * const t_REAL_TYPE = &_t_REAL_TYPE;*/
  32.  
  33. /*extern const TypeDescriptor _t_STRING_TYPE ("STRING", STRING_TYPE, "String");*/
  34. /*const TypeDescriptor * const t_STRING_TYPE = &_t_STRING_TYPE;*/
  35.  
  36. /*extern const TypeDescriptor _t_BINARY_TYPE ("BINARY", BINARY_TYPE, "Binary") ;*/
  37. /*const TypeDescriptor * const t_BINARY_TYPE = &_t_BINARY_TYPE;*/
  38.  
  39. /*extern const TypeDescriptor _t_BOOLEAN_TYPE ("BOOLEAN", BOOLEAN_TYPE, "Boolean") ;*/
  40. /*const TypeDescriptor * const t_BOOLEAN_TYPE = &_t_BOOLEAN_TYPE;*/
  41.  
  42. /*extern const TypeDescriptor _t_LOGICAL_TYPE ("LOGICAL", LOGICAL_TYPE, "Logical") ;*/
  43. /*const TypeDescriptor * const t_LOGICAL_TYPE = &_t_LOGICAL_TYPE;*/
  44.  
  45. /*extern const TypeDescriptor _t_NUMBER_TYPE ("NUMBER", NUMBER_TYPE, "Number") ;*/
  46. /*const TypeDescriptor * const t_NUMBER_TYPE = &_t_NUMBER_TYPE;*/
  47.  
  48. /*extern const TypeDescriptor _t_GENERIC_TYPE ("GENERIC", GENERIC_TYPE, "Generic") ;*/
  49. /*const TypeDescriptor * const t_GENERIC_TYPE = &_t_GENERIC_TYPE;*/
  50.  
  51.  
  52. const EntityDescriptor * 
  53. EntityDescItr::NextEntityDesc()
  54. {
  55.     if(cur)
  56.     {
  57.     const EntityDescriptor *ed = cur->EntityDesc();
  58.     cur = (EntityDescLinkNode *)( cur->NextNode() );
  59.     return ed;
  60.     }
  61.     return 0;
  62.  
  63. const AttrDescriptor * 
  64. AttrDescItr::NextAttrDesc()
  65. {
  66.     if(cur)
  67.     {
  68.     const AttrDescriptor *ad = cur->AttrDesc();
  69.     cur = (AttrDescLinkNode *)( cur->NextNode() );
  70.     return ad;
  71.     }
  72.     return 0;
  73.  
  74. const InverseAttrDescriptor * 
  75. InverseADItr::NextInverseAttrDesc()
  76. {
  77.     if(cur)
  78.     {
  79.     const InverseAttrDescriptor *iad = cur->InverseAttrDesc();
  80.     cur = (InverseAttrDescLinkNode *)( cur->NextNode() );
  81.     return iad;
  82.     }
  83.     return 0;
  84.  
  85. const TypeDescriptor * 
  86. TypeDescItr::NextTypeDesc()
  87. {
  88.     if(cur)
  89.     {
  90.     const TypeDescriptor *td = cur->TypeDesc();
  91.     cur = (TypeDescLinkNode *)( cur->NextNode() );
  92.     return td;
  93.     }
  94.     return 0;
  95.  
  96. ///////////////////////////////////////////////////////////////////////////////
  97. // AttrDescriptor functions
  98. ///////////////////////////////////////////////////////////////////////////////
  99.  
  100. const char *
  101. AttrDescriptor::AttrExprDefStr(SCLstring & s) const
  102. {
  103.   s = Name ();
  104.   s.Append (" : ");
  105.   if(_optional.asInt() == T)
  106.     s.Append( "OPTIONAL ");
  107.   if(DomainType())
  108.     s.Append (DomainType()->AttrTypeName());
  109.   return s.chars();
  110. }    
  111.  
  112. const BASE_TYPE 
  113. AttrDescriptor::BaseType() const
  114. {
  115.     if(_domainType)
  116.     return _domainType->BaseType();
  117.     return UNKNOWN_TYPE;
  118. }
  119.  
  120. const BASE_TYPE 
  121. AttrDescriptor::AggrElemType() const
  122. {
  123.     if(NonRefType() == AGGREGATE_TYPE)
  124.     {
  125.     return ReferentType()->AggrElemType();
  126.     }
  127.     return UNKNOWN_TYPE;
  128. }
  129.  
  130. const TypeDescriptor *
  131. AttrDescriptor::AggrElemTypeDescriptor() const
  132. {
  133.     if(NonRefType() == AGGREGATE_TYPE)
  134.     {
  135.     return ReferentType()->AggrElemTypeDescriptor();
  136.     }
  137.     return 0;
  138. }
  139.  
  140. const TypeDescriptor * 
  141. AttrDescriptor::NonRefTypeDescriptor() const
  142. {
  143.     if(_domainType)
  144.     return _domainType->NonRefTypeDescriptor();
  145.     return 0;
  146. }
  147.  
  148. const BASE_TYPE 
  149. AttrDescriptor::NonRefType() const
  150. {
  151.     if(_domainType)
  152.     return _domainType->NonRefType();
  153.     return UNKNOWN_TYPE;
  154. }
  155.  
  156. const BASE_TYPE 
  157. AttrDescriptor::Type() const
  158. {
  159.     if(_domainType)
  160.     return _domainType->Type();
  161.     return UNKNOWN_TYPE;
  162. }
  163.  
  164.     // right side of attr def
  165. // NOTE this returns a \'const char * \' instead of an SCLstring
  166. const char *
  167. AttrDescriptor::TypeName() const
  168. {
  169.     if(_domainType)
  170.     return _domainType->AttrTypeName();
  171.     else
  172.     return "";
  173. }
  174.  
  175.     // an expanded right side of attr def
  176. const char *
  177. AttrDescriptor::ExpandedTypeName(SCLstring & s) const
  178. {
  179.     s.set_null();
  180.     if ((LOGICAL) Derived () == sdaiTRUE) s = "DERIVE  ";
  181.     if(_domainType)
  182.     {
  183.     SCLstring tmp;
  184.     return s.Append (_domainType->TypeString(tmp));
  185.     }
  186.     else
  187.     return 0;
  188. }
  189.  
  190. ///////////////////////////////////////////////////////////////////////////////
  191. // InverseAttrDescriptor functions
  192. ///////////////////////////////////////////////////////////////////////////////
  193.  
  194.  
  195. ///////////////////////////////////////////////////////////////////////////////
  196. // EntityDescriptor functions
  197. ///////////////////////////////////////////////////////////////////////////////
  198.  
  199. EntityDescriptor::EntityDescriptor ( ) : _abstractEntity("U")
  200. {
  201.     _originatingSchema = 0;
  202. //    _derivedAttr = new StringAggregate;
  203. /*
  204.     _subtypes = 0;
  205.     _supertypes = 0;
  206.     _explicitAttr = 0;
  207.     _inverseAttr = 0;
  208. */
  209. }
  210.  
  211. EntityDescriptor::EntityDescriptor (const char * name, // i.e. char *
  212.                     SchemaDescriptor *origSchema, 
  213.                     LOGICAL abstractEntity, // F U or T
  214.                     Creator f
  215. /*
  216.                     EntityDescriptorList *subtypes,
  217.                     EntityDescriptorList *supertypes,
  218.                     AttrDescriptorList *explicitAttr,
  219.                     StringAggregate *derivedAttr,
  220.                     InverseAttrDescriptorList *inverseAttr
  221. */
  222.                     ) 
  223. : TypeDescriptor (name, ENTITY_TYPE, name), _originatingSchema (origSchema),  
  224.   _abstractEntity(abstractEntity), NewSTEPentity(f)
  225. {
  226. /*
  227.     _subtypes = subtypes;
  228.     _supertypes = supertypes;
  229.     _explicitAttr = explicitAttr;
  230.     _derivedAttr = derivedAttr;
  231.     _inverseAttr = inverseAttr;
  232. */
  233. }
  234.  
  235. EntityDescriptor::~EntityDescriptor ()  
  236. {
  237. }
  238.  
  239. const TypeDescriptor * 
  240. EntityDescriptor::IsA (const TypeDescriptor * td) const 
  241. { if (td -> NonRefType () == ENTITY_TYPE)
  242.     return IsA ((EntityDescriptor *) td);
  243.   else return 0;
  244. }
  245.  
  246. const EntityDescriptor * 
  247. EntityDescriptor::IsA (const EntityDescriptor * other)  const {
  248.   const EntityDescriptor * found =0;
  249.   const EntityDescLinkNode * link = (const EntityDescLinkNode *) (GetSupertypes ().GetHead());
  250.  
  251.   if (this == other) return other;
  252.   else {
  253.     while (link && ! found)  {
  254.       found = link -> EntityDesc() -> IsA (other);
  255.       link = (EntityDescLinkNode *) link -> NextNode ();
  256.     }
  257.   }
  258.   return found;
  259. }
  260. /*
  261. EntityDescriptor::FindLongestAttribute()
  262. {
  263.     AttrDescLinkNode *attrPtr = 
  264.           (AttrDescLinkNode *)(ed->ExplicitAttr().GetHead());
  265.     while( attrPtr != 0)
  266.     {
  267.     if(attrPtr->AttrDesc()->IsEntityType())
  268.         maxAttrLen = max(maxAttrLen, 
  269.             (strlen(attrPtr->AttrDesc()->EntityType()->Name()) +
  270.               strlen(attrPtr->AttrDesc()->Name()) + 3
  271.              )
  272.             );
  273.     else
  274.         maxAttrLen = max(maxAttrLen, 
  275.           (strlen(attrPtr->AttrDesc()->DomainType()->NameOrDescription()) +
  276.            strlen(attrPtr->AttrDesc()->Name()) + 3
  277.           )
  278.             );
  279.     attrPtr = (AttrDescLinkNode *)attrPtr->NextNode();
  280.     }
  281. }
  282. */
  283. ///////////////////////////////////////////////////////////////////////////////
  284. // TypeDescriptor functions
  285. ///////////////////////////////////////////////////////////////////////////////
  286.  
  287.     ///////////////////////////////////////////////////////////////////////
  288.     // This is a fully expanded description of the type.
  289.     // This returns a string like the _description member variable
  290.     // except it is more thorough of a description where possible
  291.     // e.g. if the description contains a TYPE name it will also
  292.     // be explained.
  293.     ///////////////////////////////////////////////////////////////////////
  294. const char *
  295. TypeDescriptor::TypeString(SCLstring & s) const
  296. {
  297.     switch(Type())
  298.     {
  299.       case REFERENCE_TYPE:
  300.         if(Name())
  301.         {
  302.           s.Append ( "TYPE ");
  303.           s.Append (Name());
  304.           s.Append ( " = ");
  305.         }
  306.         if(Description())
  307.           s.Append ( Description ());
  308.         if(ReferentType())
  309.         {
  310.           s.Append ( " -- ");
  311.           SCLstring tmp;
  312.           s.Append ( ReferentType()->TypeString(tmp));
  313.         }
  314.         return s;
  315.  
  316.       case INTEGER_TYPE:
  317.         s.set_null();
  318.         if(_referentType != 0)
  319.         {
  320.             s = "TYPE ";
  321.             s.Append (Name());
  322.             s.Append ( " = ");
  323.         }
  324.         s.Append("Integer");
  325.         break;
  326.  
  327.       case STRING_TYPE:
  328.         s.set_null();
  329.         if(_referentType != 0)
  330.         {
  331.             s = "TYPE ";
  332.             s.Append (Name());
  333.             s.Append ( " = ");
  334.         }
  335.         s.Append("String");
  336.         break;
  337.  
  338.       case REAL_TYPE:
  339.         s.set_null();
  340.         if(_referentType != 0)
  341.         {
  342.             s = "TYPE ";
  343.             s.Append (Name());
  344.             s.Append ( " = ");
  345.         }
  346.         s.Append("Real");
  347.         break;
  348.  
  349.       case ENUM_TYPE:
  350.         s = "Enumeration: ";
  351.         if(Name())
  352.         {
  353.           s.Append ( "TYPE ");
  354.           s.Append (Name());
  355.           s.Append ( " = ");
  356.         }
  357.         if(Description())
  358.           s.Append ( Description ());
  359.         break;
  360.  
  361.       case BOOLEAN_TYPE:
  362.         s.set_null();
  363.         if(_referentType != 0)
  364.         {
  365.             s = "TYPE ";
  366.             s.Append (Name());
  367.             s.Append ( " = ");
  368.         }
  369.         s.Append("Boolean: F, T");
  370.         break;
  371.       case LOGICAL_TYPE:
  372.         s.set_null();
  373.         if(_referentType != 0)
  374.         {
  375.             s = "TYPE ";
  376.             s.Append (Name());
  377.             s.Append ( " = ");
  378.         }
  379.         s.Append("Logical: F, T, U");
  380.         break;
  381.       case NUMBER_TYPE:
  382.         s.set_null();
  383.         if(_referentType != 0)
  384.         {
  385.             s = "TYPE ";
  386.             s.Append (Name());
  387.             s.Append ( " = ");
  388.         }
  389.         s.Append("Number");
  390.         break;
  391.       case BINARY_TYPE:
  392.         s.set_null();
  393.         if(_referentType != 0)
  394.         {
  395.             s = "TYPE ";
  396.             s.Append (Name());
  397.             s.Append ( " = ");
  398.         }
  399.         s.Append("Binary");
  400.         break;
  401.       case ENTITY_TYPE:
  402.         s = "Entity: ";
  403.         if(Name())
  404.           s.Append (Name());
  405.         break;
  406.       case AGGREGATE_TYPE:
  407.         s = Description();
  408.         if(ReferentType())
  409.         {
  410.           s.Append ( " -- ");
  411.           SCLstring tmp;
  412.           s.Append ( ReferentType()->TypeString(tmp));
  413.         }
  414.         break;
  415.       case SELECT_TYPE:
  416.           s.Append ( Description ());
  417.         break;
  418.       case GENERIC_TYPE:
  419.       case UNKNOWN_TYPE:
  420.         s = "Unknown";
  421.         break;
  422.     } // end switch
  423.   return s;
  424.  
  425. }
  426. /* this works
  427.     if( ( (ReferentType() != 0) || (ReferentEntity() != 0) ) && Name())
  428.     {
  429.     strcat(tStr, "TYPE ");
  430.     strcat(tStr, Name());
  431.     strcat(tStr, " = ");
  432.     }
  433.     if(Description())
  434.     strcat(tStr, Description());
  435.     if(ReferentType())
  436.     {
  437.     strcat(tStr, " -- ");
  438.     SCLstring tmp;
  439.     strcat(tStr, ReferentType()->TypeString(tmp));
  440.     }
  441.     else if(ReferentEntity())
  442.     {
  443.     strcat(tStr, " -- ");
  444.     strcat(tStr, "Entity: ");
  445.     strcat(tStr, ReferentEntity()->Name());
  446.     }
  447.     return tStr;
  448. }
  449. */
  450.  
  451.  
  452. const TypeDescriptor * 
  453. TypeDescriptor::IsA (const TypeDescriptor * other)  const {
  454.   if (this == other)  return other;
  455.   return 0;
  456. }
  457.  
  458. const TypeDescriptor * 
  459. TypeDescriptor::IsA (const char * other) const  {
  460.   if (!Name())  return 0;
  461.   if (!strcmp (Name (), PrettyTmpName (other)))  // this is the type
  462.     return this;
  463.   return (ReferentType () ? ReferentType () -> IsA (other) : 0);
  464. }
  465.  
  466.     ///////////////////////////////////////////////////////////////////////
  467.     // the first BASE_TYPE that is not REFERENCE_TYPE (the first 
  468.     // TypeDescriptor *_referentType that does not have REFERENCE_TYPE 
  469.     // for it's fundamentalType variable).  This would return the same 
  470.     // as BaseType() for fundamental types.  An aggregate type
  471.     // would return AGGREGATE_TYPE then you could find out the type of
  472.     // an element by calling AggrElemType().  Select types
  473.     // would work the same?
  474.     ///////////////////////////////////////////////////////////////////////
  475.  
  476. const BASE_TYPE 
  477. TypeDescriptor::NonRefType() const
  478. {
  479.     const TypeDescriptor *td = NonRefTypeDescriptor();
  480.     if(td)
  481.     return td->FundamentalType();
  482.     return UNKNOWN_TYPE;
  483. }
  484.  
  485.  
  486. const TypeDescriptor *
  487. TypeDescriptor::NonRefTypeDescriptor() const
  488. {  
  489.     const TypeDescriptor *td = this;
  490.  
  491.     while ( td->ReferentType() ) {
  492.       if (td->Type() != REFERENCE_TYPE) 
  493.       return td;
  494.       td = td->ReferentType();
  495.     }
  496.  
  497.     return td;
  498. }
  499.  
  500.     ///////////////////////////////////////////////////////////////////////
  501.     // This returns the BASE_TYPE of the first non-aggregate element of 
  502.     // an aggregate
  503.     ///////////////////////////////////////////////////////////////////////
  504.  
  505. const BASE_TYPE 
  506. TypeDescriptor::AggrElemType() const
  507. {
  508.     const TypeDescriptor *aggrElemTD = AggrElemTypeDescriptor();
  509.     if(aggrElemTD)
  510.     {
  511.     return aggrElemTD->Type();
  512.     }
  513.     return UNKNOWN_TYPE;
  514. }
  515.  
  516. const TypeDescriptor *
  517. TypeDescriptor::AggrElemTypeDescriptor() const
  518. {
  519.     const TypeDescriptor *aggrTD = NonRefTypeDescriptor();
  520.     const TypeDescriptor *aggrElemTD = aggrTD->ReferentType();
  521.     if(aggrElemTD)
  522.     {
  523.     aggrElemTD = aggrElemTD->NonRefTypeDescriptor();
  524.     }
  525.     return aggrElemTD;
  526. }
  527.  
  528.     ////////////////////////////////////////////////////////////
  529.     // This is the underlying type of this type. For instance:
  530.     // TYPE count = INTEGER;
  531.     // TYPE ref_count = count;
  532.     // TYPE count_set = SET OF ref_count;
  533.     //  each of the above will generate a TypeDescriptor and for 
  534.     //  each one, BASE_TYPE BaseType() will return INTEGER_TYPE
  535.     //  TypeDescriptor *BaseTypeDescriptor() returns the TypeDescriptor 
  536.     //  for Integer
  537.     ////////////////////////////////////////////////////////////
  538.  
  539. const BASE_TYPE
  540. TypeDescriptor::BaseType() const
  541. {
  542.     const TypeDescriptor *td = BaseTypeDescriptor();
  543.     if(td)
  544.     return td->FundamentalType();
  545.     else
  546.     return ENTITY_TYPE;
  547. }
  548.  
  549. const TypeDescriptor *
  550. TypeDescriptor::BaseTypeDescriptor() const
  551. {
  552.     const TypeDescriptor *td = this;
  553.  
  554.     while (td -> ReferentType ()) td = td->ReferentType ();
  555.     return td;
  556. }
  557. #ifdef NOT_YET
  558. ///////////////////////////////////////////////////////////////////////////////
  559. // EnumerationTypeDescriptor functions
  560. ///////////////////////////////////////////////////////////////////////////////
  561. EnumerationTypeDescriptor::EnumerationTypeDescriptor( ) 
  562. {
  563.     _elements = new StringAggregate; 
  564. }
  565. #endif
  566. ///////////////////////////////////////////////////////////////////////////////
  567. // SelectTypeDescriptor functions
  568. ///////////////////////////////////////////////////////////////////////////////
  569. const TypeDescriptor *
  570. SelectTypeDescriptor::IsA (const TypeDescriptor * other) const
  571. {  return TypeDescriptor::IsA (other);  }
  572.  
  573. const TypeDescriptor *
  574. SelectTypeDescriptor::CanBe (const TypeDescriptor * other) const
  575. {
  576.   const TypeDescriptor * found =0;
  577.   TypeDescItr elements (GetElements()) ;
  578.   const TypeDescriptor * td =0;
  579.  
  580.   if (this == other) return other;
  581.   while (td = elements.NextTypeDesc ())  {
  582.     if (found = (td -> CanBe (other))) return found;
  583.   }
  584.   return 0;
  585. }
  586.  
  587. ///////////////////////////////////////////////////////////////////////////////
  588. // AggregateTypeDescriptor functions
  589. ///////////////////////////////////////////////////////////////////////////////
  590.  
  591. AggregateTypeDescriptor::AggregateTypeDescriptor( ) : 
  592.         _uniqueElements("UNKNOWN_TYPE")
  593. {
  594.     _bound1 = -1;
  595.     _bound2 = -1;
  596.     _aggrDomainType = 0;
  597. }
  598.  
  599. AggregateTypeDescriptor::AggregateTypeDescriptor(SdaiInteger b1, 
  600.                          SdaiInteger b2, 
  601.                          LOGICAL uniqElem, 
  602.                          TypeDescriptor *aggrDomType)
  603.           : _bound1(b1), _bound2(b2), _uniqueElements(uniqElem)
  604. {
  605.     _aggrDomainType = aggrDomType;
  606. }
  607.  
  608. AggregateTypeDescriptor::~AggregateTypeDescriptor()
  609. {
  610. }
  611.