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: wwlytton, tom_morse

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

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

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()

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 ... ml#argtype
Post Reply