root/trunk/idldoc/src/tree/doctreeclass__define.pro @ 214

Revision 214, 4.7 KB (checked in by mgalloy, 6 years ago)

Displaying get/set/init for properties.

Line 
1; docformat = 'rst'
2
3;+
4; Get variables for use with templates.
5;
6; :Returns: variable
7; :Params:
8;    `name` : in, required, type=string
9;       name of variable
10;
11; :Keywords:
12;    `found` : out, optional, type=boolean
13;       set to a named variable, returns if variable name was found
14;-
15function doctreeclass::getVariable, name, found=found
16  compile_opt strictarr
17 
18  found = 1B
19  case strlowcase(name) of
20    'classname': return, self.classname
21    'url': begin
22        if (~obj_valid(self.proFile)) then return, ''
23       
24        self.proFile->getProperty, directory=directory
25        dirUrl = directory->getVariable('url')
26        proUrl = self.proFile->getVariable('local_url')
27        return, dirUrl + proUrl
28      end
29     
30    'n_parents': return, self.parents->count()
31    'parents': return, self.parents->get(/all)
32         
33    'n_ancestors': return, self.ancestors->count()
34    'ancestors': return, self.ancestors->get(/all)
35
36    'n_fields': return, self.fields->count()
37    'fields': return, self.fields->get(/all)
38
39    'n_properties': return, self.properties->count()
40    'properties': return, self.properties->values()
41           
42    else: begin
43        ; search in the system object if the variable is not found here
44        var = self.proFile->getVariable(name, found=found)
45        if (found) then return, var
46       
47        found = 0B
48        return, -1L
49      end   
50  endcase
51end
52
53function doctreeclass::getClassname
54  compile_opt strictarr
55 
56  return, self.classname
57end
58
59
60function doctreeclass::hasUrl
61  compile_opt strictarr
62 
63  return, obj_valid(self.proFile)
64end
65
66
67function doctreeclass::getUrl
68  compile_opt strictarr
69 
70  if (~obj_valid(self.proFile)) then return, ''
71 
72  self.proFile->getProperty, directory=directory
73  dirUrl = directory->getVariable('url')
74  proUrl = self.proFile->getVariable('local_url')
75  return, dirUrl + proUrl 
76end
77
78
79pro doctreeclass::setProperty, pro_file=proFile, classname=classname
80  compile_opt strictarr
81 
82  if (n_elements(proFile) gt 0) then self.proFile = proFile
83  if (n_elements(classname) gt 0) then self.classname = classname
84end
85
86
87pro doctreeclass::getProperty, ancestors=ancestors, classname=classname
88  compile_opt strictarr
89
90  if (arg_present(ancestors)) then ancestors = self.ancestors
91  if (arg_present(classname)) then classname = self.classname
92end
93
94
95pro doctreeclass::cleanup
96  compile_opt strictarr
97
98  obj_destroy, self.fields
99end
100
101
102pro doctreeclass::findParents
103  compile_opt strictarr
104 
105  s = create_struct(name=self.classname)
106  parents = obj_class(self.classname, /superclass)
107  if (n_elements(parents) eq 1 && parents eq '') then return
108 
109  for i = 0L, n_elements(parents) - 1L do begin
110    p = self.classes->get(strlowcase(parents[i]), found=found)
111    if (~found) then begin
112      p = obj_new('DOCtreeClass', parents[i], system=self.system)
113      self.classes->put, strlowcase(parents[i]), p
114    endif
115   
116    self.parents->add, p
117    self.ancestors->add, p
118   
119    p->getProperty, ancestors=ancestors
120    if (ancestors->count() gt 0) then begin
121      self.ancestors->add, ancestors->get(/all)
122    endif
123  endfor
124end
125
126
127function doctreeclass::addProperty, propertyName
128  compile_opt strictarr
129 
130  property = self.properties->get(strlowcase(propertyName), found=found)
131  if (~found) then begin
132    property = obj_new('DOCtreeProperty', propertyName, $
133                       class=self, system=self.system)
134    self.properties->put, strlowcase(propertyName), property
135  endif
136  return, property
137end
138
139
140pro doctreeclass::findFields
141  compile_opt strictarr
142 
143  ; TODO: create structure to find fields (and then run them past ancestors)
144end
145
146
147pro doctreeclass::cleanup
148  compile_opt strictarr
149 
150  obj_destroy, self.fields
151  if (self.properties->count() gt 0) then obj_destroy, self.properties->values()
152  obj_destroy, self.properties
153end
154
155
156function doctreeclass::init, classname, pro_file=proFile, system=system
157  compile_opt strictarr
158 
159  self.classname = classname
160  if (n_elements(proFile) gt 0) then self.proFile = proFile
161  self.system = system
162 
163  self.system->getProperty, classes=classes
164  self.classes = classes
165  self.classes->put, strlowcase(self.classname), self
166
167  self.parents = obj_new('MGcoArrayList', type=11)
168  self.ancestors = obj_new('MGcoArrayList', type=11)
169  self.properties = obj_new('MGcoHashtable', key_type=7, value_type=11)
170 
171  self->findParents
172  self->findFields
173 
174  return, 1
175end
176
177
178pro doctreeclass__define
179  compile_opt strictarr
180 
181  define = { DOCtreeClass, $
182             system: obj_new(), $
183             classes: obj_new(), $
184             proFile: obj_new(), $
185             
186             classname: '', $
187             
188             parents: obj_new(), $
189             ancestors: obj_new(), $
190             fields: obj_new(), $
191             properties: obj_new() $
192           }
193end
Note: See TracBrowser for help on using the browser.