Page 1 of 1

How to determine the type of an objref

Posted: Thu Jul 13, 2006 1:49 pm
by ted
A NEURON user asked:
I am trying to write a function that needs to either work on a sectionList or a list of SectionLists. Is there a way to ask an object its type?
Michael Hines proposed a solution based on the idea of printing the name of the objref's
class to a string, and then using a conditional based on a string comparison. The details
of this solution make use of classname(), a proc that is defined in stdlib.hoc

Code: Select all

{load_file("stdlib.hoc")}
func is_list() { localobj s
       s = new String()
       classname($o1, s.s)
       return strcmp(s.s, "List") == 0
}

objref a, b
a = new List()
b = new Vector()

is_list(a)
is_list(b)
His further comments:
If the incessant creation/destruction of strings offends your sense of fastidiousness
then remove the
localobj s ...
and use a global strdef tstr

Apart from distinguishing object arguments see
http://www.neuron.yale.edu/neuron/stati ... ml#argtype