Topic
  • 2 replies
  • Latest Post - ‏2013-04-05T12:37:16Z by kabr
kabr
kabr
115 Posts

Pinned topic comparing attribute definitions

‏2013-04-04T09:21:54Z |
Hi all,

does anybody know of a simple/easy way to compare attribute definitions between modules?
I want to be able to tell if the attribute definitions (type, scope, enum values, etc.) in a given module are identical with the attribute definitions in a reference module.

Karl
Updated on 2013-04-05T12:37:16Z at 2013-04-05T12:37:16Z by kabr
  • llandale
    llandale
    3035 Posts

    Re: comparing attribute definitions

    ‏2013-04-04T17:27:12Z  

    Something like this, but you need to add your own error reporting.

    bool IsAttrSame(string in_NameAttr, Module in_mReference, in_mLive)
    {   // Is this attribute defined the same in both the Reference and Live modules?
     
      AttrDef adR = find(in_mReference, in_NameAttr)
      AttrDef adL = find(in_mLive, in_NameAttr)
      
      bool Same = true
      if ( null adR and  null adL) then { Neither exists; return(false)}
      if ( null adR and !null adL) then { adL only exists; return(false)}
      if (!null adR and  null adL) then { adR only exists; return(false)}
           // both exist:
      if (adR.typeName != adL.typeName) {type mismatch; Same = false}
      if (adR.multi != adL.multi) {multi mismatch; Same = false}
      if (adR.(bool defval) != adL.(bool defval) ) {HasDefault  mismatch; Same = false}
      if (adR.(string defval) != adL.(string defval) ) {Default Value  mismatch; Same = false}
           // I have doubts about the above line.
    ... ditto for nobars, nochanges, nohistory, inherit, bool dxl, string dxl, module, object,
               description, and I suppose: canWrite, useraccess, system, hidden.
     
       phew.
     
       return(Same)
    } // end IsAttrSame()
     
    Skip skpNames = createString() // KEY and DATA both 'string' NameAttr
    for Name in mReference do {put(skpNames, Name, Name)}
    for Name in mLive do {put(skpNames, Name, Name)
    for Name in skpNames do
    {  IsSameAttr(mReference, mLive, Name)
    }
    delete(skpNames)
    


    -Louie

    Updated on 2014-01-08T00:27:02Z at 2014-01-08T00:27:02Z by iron-man
  • kabr
    kabr
    115 Posts

    Re: comparing attribute definitions

    ‏2013-04-05T12:37:16Z  
    • llandale
    • ‏2013-04-04T17:27:12Z

    Something like this, but you need to add your own error reporting.

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">bool IsAttrSame(string in_NameAttr, Module in_mReference, in_mLive) { // Is this attribute defined the same in both the Reference and Live modules? AttrDef adR = find(in_mReference, in_NameAttr) AttrDef adL = find(in_mLive, in_NameAttr) bool Same = true if ( null adR and null adL) then { Neither exists; return(false)} if ( null adR and !null adL) then { adL only exists; return(false)} if (!null adR and null adL) then { adR only exists; return(false)} // both exist: if (adR.typeName != adL.typeName) {type mismatch; Same = false} if (adR.multi != adL.multi) {multi mismatch; Same = false} if (adR.(bool defval) != adL.(bool defval) ) {HasDefault mismatch; Same = false} if (adR.(string defval) != adL.(string defval) ) {Default Value mismatch; Same = false} // I have doubts about the above line. ... ditto for nobars, nochanges, nohistory, inherit, bool dxl, string dxl, module, object, description, and I suppose: canWrite, useraccess, system, hidden. phew. return(Same) } // end IsAttrSame() Skip skpNames = createString() // KEY and DATA both 'string' NameAttr for Name in mReference do {put(skpNames, Name, Name)} for Name in mLive do {put(skpNames, Name, Name) for Name in skpNames do { IsSameAttr(mReference, mLive, Name) } delete(skpNames) </pre>


    -Louie

    Many thanks, Louie,

    that's what I feared.
    I was sort of hoping there was a simpler way than to write my own compare function, because I assume that there's something similar going on when you import attributes from another module.

    Thanks again.
    Karl