Changeset 3977


Ignore:
Timestamp:
04/24/08 14:19:36 (12 years ago)
Author:
curtis
Message:

New autogenerator is done and produces compilable code! Time for testing.

Location:
trunk/loci/formats/auto
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/auto/AggregateMetadata.vm

    r3917 r3977  
    9898#if ($q.countable()) 
    9999 
    100   /* @see MetadataRetrieve#get${entity}Count($q.indicesList(true, false, false)) */ 
    101   public int get${entity}Count($q.indicesList(true, true, false)) { 
     100  /* @see MetadataRetrieve#get${entity}Count($q.typesList($q.chop())) */ 
     101  public int get${entity}Count($q.argsList($q.chop())) { 
    102102    for (Iterator iter = delegates.iterator(); iter.hasNext();) { 
    103103      Object o = iter.next(); 
    104104      if (o instanceof MetadataRetrieve) { 
    105105        MetadataRetrieve retrieve = (MetadataRetrieve) o; 
    106         int result = retrieve.get${entity}Count($q.indicesList(false, true, false)); 
     106        int result = retrieve.get${entity}Count($q.varsList($q.chop())); 
    107107        if (result >= 0) return result; 
    108108      } 
     
    121121#set ($dummy = $q.setProperty($prop)) 
    122122 
    123   /* @see MetadataRetrieve#get$entity$prop($q.indicesList(true, false)) */ 
    124   public $q.type() get$entity$prop($q.indicesList(true, true)) { 
     123  /* @see MetadataRetrieve#get$entity$prop($q.typesList()) */ 
     124  public $q.type() get$entity$prop($q.argsList()) { 
    125125    for (Iterator iter = delegates.iterator(); iter.hasNext();) { 
    126126      Object o = iter.next(); 
    127127      if (o instanceof MetadataRetrieve) { 
    128128        MetadataRetrieve retrieve = (MetadataRetrieve) o; 
    129         $q.type() result = retrieve.get$entity$prop($q.indicesList(false, true)); 
     129        $q.type() result = retrieve.get$entity$prop($q.varsList()); 
    130130        if (result != null) return result; 
    131131      } 
     
    172172#set ($dummy = $q.setProperty($prop)) 
    173173 
    174   /* @see MetadataStore#set$entity$prop($q.type(), $q.indicesList(true, false)) */ 
    175   public void set$entity$prop($q.type() $q.var($prop), $q.indicesList(true, true)) { 
     174  /* @see MetadataStore#set$entity$prop($q.type(), $q.typesList()) */ 
     175  public void set$entity$prop($q.type() $q.var($prop), $q.argsList()) { 
    176176    for (Iterator iter = delegates.iterator(); iter.hasNext();) { 
    177177      Object o = iter.next(); 
    178178      if (o instanceof MetadataStore) { 
    179179        MetadataStore store = (MetadataStore) o; 
    180         store.set$entity$prop($q.var($prop), $q.indicesList(false, true)); 
     180        store.set$entity$prop($q.var($prop), $q.varsList()); 
    181181      } 
    182182    } 
  • trunk/loci/formats/auto/DummyMetadata.vm

    r3917 r3977  
    5454#if ($q.countable()) 
    5555 
    56   /* @see MetadataRetrieve#get${entity}Count($q.indicesList(true, false, false)) */ 
    57   public int get${entity}Count($q.indicesList(true, true, false)) { 
     56  /* @see MetadataRetrieve#get${entity}Count($q.typesList($q.chop())) */ 
     57  public int get${entity}Count($q.argsList($q.chop())) { 
    5858    return -1; 
    5959  } 
     
    6969#foreach ($prop in $q.props()) 
    7070#set ($dummy = $q.setProperty($prop)) 
    71   /* @see MetadataRetrieve#get$entity$prop($q.indicesList(true, false)) */ 
    72   public $q.type() get$entity$prop($q.indicesList(true, true)) { 
     71  /* @see MetadataRetrieve#get$entity$prop($q.typesList()) */ 
     72  public $q.type() get$entity$prop($q.argsList()) { 
    7373    return null; 
    7474  } 
     
    9595#set ($dummy = $q.setProperty($prop)) 
    9696 
    97   /* @see MetadataStore#set$entity$prop($q.type(), $q.indicesList(true, false)) */ 
    98   public void set$entity$prop($q.type() $q.var($prop), $q.indicesList(true, true)) { 
     97  /* @see MetadataStore#set$entity$prop($q.type(), $q.typesList()) */ 
     98  public void set$entity$prop($q.type() $q.var($prop), $q.argsList()) { 
    9999  } 
    100100#end##foreach $prop 
  • trunk/loci/formats/auto/EntityList.java

    r3959 r3977  
    221221  } 
    222222 
     223  /** Gets the active version. */ 
     224  public String getVersion() { 
     225    return ver; 
     226  } 
     227 
    223228  /** Sets the active entity. */ 
    224229  public void setEntity(String entity) { 
     
    227232  } 
    228233 
     234  /** Gets the active entity. */ 
     235  public String getEntity() { 
     236    return ent; 
     237  } 
     238 
    229239  /** Sets the active property. */ 
    230240  public void setProperty(String property) { 
    231241    prop = property; 
     242  } 
     243 
     244  /** Gets the active property. */ 
     245  public String getProperty() { 
     246    return prop; 
    232247  } 
    233248 
  • trunk/loci/formats/auto/FilterMetadata.vm

    r3917 r3977  
    8282#set ($dummy = $q.setProperty($prop)) 
    8383 
    84   /* @see MetadataStore#set$entity$prop($q.type(), $q.indicesList(true, false)) */ 
    85   public void set$entity$prop($q.type() $q.var($prop), $q.indicesList(true, true)) { 
     84  /* @see MetadataStore#set$entity$prop($q.type(), $q.typesList()) */ 
     85  public void set$entity$prop($q.type() $q.var($prop), $q.argsList()) { 
    8686#if ($q.type() == "String") 
    8787    String value = filter ? DataTools.sanitize($q.var($prop)) : $q.var($prop); 
    88     store.set$entity$prop(value, $q.indicesList(false, true)); 
     88    store.set$entity$prop(value, $q.varsList()); 
    8989#else 
    90     store.set$entity$prop($q.var($prop), $q.indicesList(false, true)); 
     90    store.set$entity$prop($q.var($prop), $q.varsList()); 
    9191#end 
    9292  } 
  • trunk/loci/formats/auto/MetaEntityList.java

    r3959 r3977  
    8181  public String last() { return last(path()); } 
    8282 
     83  /** Path without its last <em>countable</em> node. Derived from path. */ 
     84  public String chop() { return chop(path()); } 
     85 
    8386  /** List of indices in the path. Derived from path. */ 
    8487  public Vector<String> indices() { return indices(path()); } 
    8588 
    86   public String indicesList(boolean doTypes, boolean doVars) { 
    87     return indicesList(doTypes, doVars, true); 
    88   } 
    89  
    90   public String indicesList(boolean doTypes, boolean doVars, boolean doLast) { 
    91     return indicesList(path(), doTypes, doVars, doLast); 
    92   } 
    93  
    94   public String defaultIndicesList(boolean doTypes, boolean doVars, boolean doLast) { 
    95     return indicesList(defaultPath(), doTypes, doVars, doLast); 
    96   } 
     89  /** List of method arguments for the path indices. Derived from path. */ 
     90  public String argsList() { return argsList(defaultPath()); } 
     91 
     92  /** List of types for the path indices. Derived from path. */ 
     93  public String typesList() { return typesList(defaultPath()); } 
     94 
     95  /** List of variables for the path indices. Derived from path. */ 
     96  public String varsList() { return varsList(path(), defaultPath()); } 
    9797 
    9898  /** 
     
    128128  public String defaultType() { return value("type", null, ent, prop); } 
    129129 
    130   public String getter() { 
     130  public String getter(String nodeVar) { 
    131131    String getter = value("getter"); 
    132132    String s = getter == null ? "get" + name() : getter; 
     133    s = nodeVar + "." + s; 
    133134 
    134135    // inject conversion method if needed 
     
    140141  } 
    141142 
    142   public String setter(String value) { 
     143  public String setter(String nodeVar, String value) { 
    143144    String setter = value("setter"); 
    144145    String s = setter == null ? "set" + name() : setter; 
     
    149150    if (type.equals(defaultType)) s = s + "(" + value + ")"; 
    150151    else s = s + "(" + var(defaultType) + "To" + type + "(" + value + "))"; 
    151     return s; 
     152    return nodeVar + "." + s; 
    152153  } 
    153154 
     
    186187      } 
    187188    } 
    188     return new String(c).replaceAll("[@!+]", ""); 
     189    return new String(c).replaceAll("\\+", ""); 
    189190  } 
    190191 
     
    192193  public String last(String path) { 
    193194    int first = path.lastIndexOf("/") + 1; 
    194     return path.substring(first).replaceAll("[@\\!\\+]", ""); 
     195    return path.substring(first).replaceAll("\\+", ""); 
     196  } 
     197 
     198  /** Gets a path without its last <em>countable</em> node. */ 
     199  public String chop(String path) { 
     200    int plus = path.lastIndexOf("+"); 
     201    if (plus < 0) return null; 
     202    int slash = path.lastIndexOf("/", plus); 
     203    return slash < 0 ? "" : path.substring(0, slash); 
    195204  } 
    196205 
     
    202211    for (int i=0; i<tokens; i++) { 
    203212      String t = st.nextToken(); 
    204       if (t.endsWith("+")) list.add(t.replaceAll("[@\\!\\+]", "")); 
     213      if (t.endsWith("+")) list.add(t.replaceAll("\\+", "")); 
    205214    } 
    206215    return list; 
    207216  } 
    208217 
    209   public String indicesList(String path, 
    210     boolean doTypes, boolean doVars, boolean doLast) 
     218  /** 
     219   * Gets a list of method arguments for the indices in the given path. 
     220   * E.g., "int imageIndex, int pixelsIndex, int planeIndex". 
     221   */ 
     222  public String argsList(String path) { 
     223    return indicesList(path, path, true, true); 
     224  } 
     225 
     226  /** 
     227   * Gets a list of types for the indices in the given path. 
     228   * E.g., "int, int, int". 
     229   */ 
     230  public String typesList(String path) { 
     231    return indicesList(path, path, true, false); 
     232  } 
     233 
     234  /** 
     235   * Gets a list of variables for the indices in the given path. 
     236   * E.g., "imageIndex, pixelsIndex, planeIndex". 
     237   */ 
     238  public String varsList(String path) { 
     239    return varsList(path, path); 
     240  } 
     241 
     242  /** 
     243   * Gets a list of variables for the indices in the given path. 
     244   * E.g., "imageIndex, pixelsIndex, planeIndex". 
     245   */ 
     246  public String varsList(String path, String defaultPath) { 
     247    return indicesList(path, defaultPath, false, true); 
     248  } 
     249 
     250  private String indicesList(String path, String defaultPath, 
     251    boolean doTypes, boolean doVars) 
    211252  { 
    212253    StringBuffer sb = new StringBuffer(); 
    213254    Vector<String> indices = indices(path); 
    214     if (!doLast && indices.size() > 0) { 
    215       indices.remove(indices.size() - 1); // ignore last element 
     255    Vector<String> defaultIndices = indices(defaultPath); 
     256    while (defaultIndices.size() > indices.size()) { 
     257      defaultIndices.remove(defaultIndices.size() - 1); 
    216258    } 
    217259    boolean first = true; 
    218     for (String index : indices) { 
     260    for (String index : defaultIndices) { 
    219261      if (first) first = false; 
    220262      else sb.append(", "); 
     
    225267    return sb.toString(); 
    226268  } 
     269 
    227270} 
  • trunk/loci/formats/auto/MetadataAutogen.java

    r3917 r3977  
    113113  } 
    114114 
    115   private static String generateConvertMetadata(MetaEntityList q) { 
     115  private static String generateConvertMetadata(final MetaEntityList q) { 
     116    System.out.println("Generating convertMetadata body"); 
    116117    StringWriter sw = new StringWriter(); 
    117118    PrintWriter out = new PrintWriter(sw); 
     
    120121    Vector<String> entities = q.entities(); 
    121122 
     123    // sort entities by path 
     124    Collections.sort(entities, new Comparator<String>() { 
     125      public int compare(String e1, String e2) { 
     126        q.setEntity(e1); 
     127        String path1 = q.path(); 
     128        q.setEntity(e2); 
     129        String path2 = q.path(); 
     130        return path1.compareTo(path2); 
     131      } 
     132    }); 
     133 
    122134    StringBuffer spaces = new StringBuffer(); 
    123135    Vector<String> lastIndices = new Vector<String>(); 
     
    125137    for (String entity : entities) { 
    126138      q.setEntity(entity); 
     139      System.out.println("\t" + q.path()); 
    127140 
    128141      Vector<String> indices = q.indices(); 
     
    156169        out.println(spaces + "int " + countVar + " = " + 
    157170          "src.get" + index + "Count" + "(" + 
    158           q.indicesList(false, true, false) + ");"); 
     171          q.varsList(q.chop(), q.chop(q.defaultPath())) + ");"); 
    159172        out.println(spaces + "for (int " + iVar + "=0; " + 
    160173          iVar + "<" + countVar + "; " + iVar + "++) {"); 
     
    166179      for (String prop : props) { 
    167180        String methodName = entity + prop; 
    168         String iList = q.indicesList(false, true); 
     181        String iList = q.varsList(); 
    169182        out.println(spaces + "  dest.set" + methodName + 
    170183          "(src.get" + methodName + "(" + iList + "), " + iList + ");"); 
  • trunk/loci/formats/auto/MetadataRetrieve.vm

    r3917 r3977  
    5050#if ($q.countable()) 
    5151 
    52   int get${entity}Count($q.indicesList(true, true, false)); 
     52  int get${entity}Count($q.argsList($q.chop())); 
    5353#end###if countable 
    5454#end##foreach $entity 
     
    6868#end##foreach $index 
    6969   */ 
    70   $q.type() get$entity$prop($q.indicesList(true, true)); 
     70  $q.type() get$entity$prop($q.argsList()); 
    7171#end 
    7272#end 
  • trunk/loci/formats/auto/MetadataStore.vm

    r3917 r3977  
    6969#end##foreach $index 
    7070   */ 
    71   void set$entity$prop($q.type() $q.var($prop), $q.indicesList(true, true)); 
     71  void set$entity$prop($q.type() $q.var($prop), $q.argsList()); 
    7272#end##foreach $prop 
    7373#end##foreach $entity 
  • trunk/loci/formats/auto/OMEXMLMetadata.vm

    r3961 r3977  
    7575#set ($last = $q.last()) 
    7676 
    77   /* @see loci.formats.meta.MetadataRetrieve#get${entity}Count($q.indicesList(true, false, false)) */ 
    78   public int get${entity}Count($q.indicesList(true, true, false)) { 
    79     return 0;//TEMP 
    80 /* 
     77  /* @see loci.formats.meta.MetadataRetrieve#get${entity}Count($q.typesList($q.chop($q.defaultPath()))) */ 
     78  public int get${entity}Count($q.argsList($q.chop($q.defaultPath()))) { 
    8179#if ($q.path() == "-") 
    8280    // NB: $entity unsupported for schema version $q.version() 
     
    8482#else 
    8583    for (int i=0; i<Integer.MAX_VALUE; i++) { 
    86       if (get$entity($q.indicesList(false, true).replaceFirst("[a-zA-Z_0-9]+$", "i")) == null) return i; 
     84      if (get${last}Node($q.varsList().replaceFirst("[a-zA-Z_0-9]+$", "i"), false) == null) return i; 
    8785    } 
    8886    return -1; 
    8987#end##if "-" 
    90 */ 
    9188  } 
    9289#end##if countable 
     
    103100#set ($dummy = $q.setProperty($prop)) 
    104101 
    105   /* @see loci.formats.meta.MetadataRetrieve#get$entity$prop($q.defaultIndicesList(true, false, true)) */ 
    106   public $q.defaultType() get$entity$prop($q.defaultIndicesList(true, true, true)) { 
     102  /* @see loci.formats.meta.MetadataRetrieve#get$entity$prop($q.typesList()) */ 
     103  public $q.defaultType() get$entity$prop($q.argsList()) { 
    107104#if ($q.path() == "-") 
    108105    // NB: $prop unsupported for schema version $q.version() 
    109106    return null; 
    110107#else 
    111     ${last}Node $lastVar = get${last}Node($q.indicesList(false, true), false); 
    112     return $lastVar == null ? null : ${lastVar}.$q.getter(); 
     108    ${last}Node $lastVar = get${last}Node($q.varsList(), false); 
     109    return $lastVar == null ? null : $q.getter($lastVar); 
    113110#end##if "-" 
    114111  } 
     
    150147#set ($varName = $q.var($prop)) 
    151148 
    152   /* @see loci.formats.meta.MetadataStore#set$entity$prop($q.defaultType(), $q.defaultIndicesList(true, false, true)) */ 
    153   public void set$entity$prop($q.defaultType() $varName, $q.defaultIndicesList(true, true, true)) { 
     149  /* @see loci.formats.meta.MetadataStore#set$entity$prop($q.defaultType(), $q.typesList()) */ 
     150  public void set$entity$prop($q.defaultType() $varName, $q.argsList()) { 
    154151#if ($q.path() == "-") 
    155152    // NB: $prop unsupported for schema version $q.version() 
    156153#else 
    157154    if ($varName == null) return; 
    158     ${last}Node $lastVar = get${last}Node($q.indicesList(false, true), true); 
    159     ${lastVar}.$q.setter($varName); 
     155    ${last}Node $lastVar = get${last}Node($q.varsList(), true); 
     156    $q.setter($lastVar, $varName); 
    160157#end##if "-" 
    161158  } 
     
    169166 
    170167  // $path 
    171   private ${last}Node get${last}Node($q.indicesList($path, true, true, true), boolean create) { 
     168  private ${last}Node get${last}Node($q.argsList($path), boolean create) { 
    172169#set ($slash = $path.lastIndexOf("/")) 
    173170#if ($slash < 0) 
     
    181178#set ($nodeVar = $q.var($node)) 
    182179#set ($multi = $path.endsWith("+")) 
    183 #set ($indices = $q.indicesList($pre, false, true, true)) 
    184 #if ($indices == "") 
     180#set ($vars = $q.varsList($pre)) 
     181#if ($vars == "") 
    185182    ${node}Node $nodeVar = (${node}Node) root; 
    186183#else 
    187184    // get $pre node 
    188     ${node}Node $nodeVar = get${node}Node($indices, create); 
     185    ${node}Node $nodeVar = get${node}Node($vars, create); 
    189186    if ($nodeVar == null) return null; 
    190 #end##if $indices == "" 
     187#end##if $vars == "" 
    191188    // get $last node 
    192189#if ($multi) 
Note: See TracChangeset for help on using the changeset viewer.