How to determine the type of an objref

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: ted, wwlytton, tom_morse

Post Reply
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

How to determine the type of an objref

Post 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
Post Reply