union

Accession:49838
Union allows storage of a double, string or object <br/> It is useful as a localobj in an obfunc since it will permit returning anything <br/> It also makes it easy to pick up any kind of value out of a list, vector or array <br/> USAGE: XO=new Union(val) where val can be a number string or object <ul> <li> XO=new Union(list,index) will pick up a string or object from list <li> XO=new Union(vec,index) will pick up a number from vector <li> XO=new Union(&dbl,index) will pick up a number from double array </ul>
Tool Information (Click on a link to find other Tools with that property)
Tool Type: Utility;
Simulation Environment: NEURON;
\
union
readme.txt
mosinit.hoc
union.hoc
                            
// readme.txt for Union class (NEURON template) by Bill Lytton

// here's an example for Union -- overloading plus so it can handle
// numbers, strings or lists

//* usage example -- overloading of addition
obfunc plus() { local i localobj lo
  lo=new Union()
  if (argtype(1)==0) { lo.x=$1+$2
  } else if (argtype(2)==2) { sprint(lo.s,"%s%s",$s1,$s2)
  } else if (argtype(2)==1) { lo.o=new List()
    for i=0,$o1.count-1 lo.o.append($o1.object(i))
    for i=0,$o2.count-1 lo.o.append($o2.object(i))
  }
  return lo
}

XO=plus(5,3)
print XO.x
XO=plus("hello ","there")
print XO.s
XO=plus(tmplist,tmplist)
print tmplist.count,XO.o.count