// ** This class was generated with DemFGen (vers:09/27/2009) import edu.neu.ccs.demeterf.control.Fields; public class InlineParToSVG{ final int THRESHHOLD; final private ToSVG func; public InlineParToSVG(ToSVG f, int T){ func = f; THRESHHOLD = T; } public InlineParToSVG(ToSVG f){ this(f,10); } // New One... public String traverse(Pict _h, Ctx _targ_){ //_ParTrav.count = 0; String ret = traversePict(_h, 0, _targ_); //System.err.println("THREADS: "+_ParTrav.count); return ret; } public String traverseSquare(final Square _h, final int weight, Ctx _targ_){ int _size = func.combine(_h.size); return func.combine((Square)_h,(int)_size, (Ctx)_targ_); } public String traversePict(final Pict _h, final int weight, Ctx _targ_){ if(_h instanceof Overlay) return this.traverseOverlay((Overlay)_h,weight, _targ_); if(_h instanceof Offset) return this.traverseOffset((Offset)_h,weight, _targ_); if(_h instanceof Circle) return this.traverseCircle((Circle)_h,weight, _targ_); if(_h instanceof Square) return this.traverseSquare((Square)_h,weight, _targ_); else throw new RuntimeException("Unknown Pict Variant"); } public String traverseOverlay(final Overlay _h, final int weight, Ctx _targ_){ _Result _top = (weight!=THRESHHOLD)? new _Trav(traversePict(_h.top,weight+1, _targ_)): new _ParTrav(_h.top,this, _targ_){ public String traverse(){ return trav.traversePict(tobj, weight+1, targ); } }; _Result _bot = (weight!=THRESHHOLD)? new _Trav(traversePict(_h.bot,weight+1, _targ_)): new _ParTrav(_h.bot,this, _targ_){ public String traverse(){ return trav.traversePict(tobj, weight+1, targ); } }; return func.combine((Overlay)_h,(String)(_top.result()), (String)(_bot.result())); } public String traverseOffset(final Offset _h, final int weight, Ctx _targ_){ int _dx = func.combine(_h.dx); int _dy = func.combine(_h.dy); _Result _inner = (weight!=THRESHHOLD)? new _Trav(traversePict(_h.inner,weight+1, func.update(_h, new Fields.any(), _targ_))): new _ParTrav(_h.inner,this, _targ_){ public String traverse(){ return trav.traversePict(tobj, weight+1, func.update(_h, new Fields.any(), targ)); } }; return func.combine((Offset)_h,(int)_dx, (int)_dy, (String)(_inner.result())); } public String traverseCircle(final Circle _h, final int weight, Ctx _targ_){ int _rad = func.combine(_h.rad); return func.combine((Circle)_h,(int)_rad, (Ctx)_targ_); } static interface _Result<_R>{ _R result(); } static class _Trav<_R> implements _Result<_R>{ final _R res; _Trav(_R r){ res = r; } public _R result(){ return res; } } static abstract class _ParTrav<_T,_R> extends Thread implements _Result<_R>{ static int count = 0; final _T tobj; final InlineParToSVG trav; _R res = null; boolean done = false; final Ctx targ; _ParTrav(_T to, InlineParToSVG t, Ctx ta){ tobj = to; trav = t; targ = ta; this.start(); //count++; System.err.println(" ----- "+count+" ----- "+tobj.getClass().getSimpleName()); } public void run(){ setDone(traverse()); } synchronized void setDone(_R r){ res = r; done = true; this.notify(); } public synchronized _R result(){ if(!done) try{ this.wait(); }catch(InterruptedException e){ System.err.println(" ** Error Waiting on Thread!!"); } return res; } /** Do the Actual Traversal */ public abstract _R traverse(); } }