| 1 | ; docformat = 'rst' |
|---|
| 2 | |
|---|
| 3 | ;+ |
|---|
| 4 | ; Properties represent keywords to the setProperty/getProperty/init set of |
|---|
| 5 | ; methods. |
|---|
| 6 | ; |
|---|
| 7 | ; :Properties: |
|---|
| 8 | ; is_get |
|---|
| 9 | ; boolean indicating whether the property can be retrieved with the |
|---|
| 10 | ; getProprty method |
|---|
| 11 | ; is_set |
|---|
| 12 | ; boolean indicating whether the property can be set with the setProperty |
|---|
| 13 | ; method |
|---|
| 14 | ; is_init |
|---|
| 15 | ; boolean indicating whether the property can be set in the init method |
|---|
| 16 | ; type |
|---|
| 17 | ; IDL data type of the property |
|---|
| 18 | ; comments |
|---|
| 19 | ; parse tree object; comments about the property |
|---|
| 20 | ; class |
|---|
| 21 | ; class object |
|---|
| 22 | ; system |
|---|
| 23 | ; system object |
|---|
| 24 | ;- |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | ;+ |
|---|
| 28 | ; Retrieve properties. |
|---|
| 29 | ;- |
|---|
| 30 | pro doctreeproperty::getProperty, is_get=isGet, is_set=isSet, is_init=isInit, $ |
|---|
| 31 | comments=comments, name=name, type=type, $ |
|---|
| 32 | is_private=isPrivate, is_hidden=isHidden |
|---|
| 33 | compile_opt strictarr, hidden |
|---|
| 34 | |
|---|
| 35 | if (arg_present(isGet)) then isGet = self.isGet |
|---|
| 36 | if (arg_present(isSet)) then isSet = self.isSet |
|---|
| 37 | if (arg_present(isInit)) then isInit = self.isInit |
|---|
| 38 | if (arg_present(type)) then type = self.type |
|---|
| 39 | if (arg_present(isPrivate)) then isPrivate = self.isPrivate |
|---|
| 40 | if (arg_present(isHidden)) then isHidden = self.isHidden |
|---|
| 41 | if (arg_present(comments)) then comments = self.comments |
|---|
| 42 | if (arg_present(name)) then name = self.name |
|---|
| 43 | end |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | ;+ |
|---|
| 47 | ; Set properties. |
|---|
| 48 | ;- |
|---|
| 49 | pro doctreeproperty::setProperty, is_get=isGet, is_set=isSet, is_init=isInit, $ |
|---|
| 50 | comments=comments, class=class, type=type, $ |
|---|
| 51 | is_private=isPrivate, is_hidden=isHidden |
|---|
| 52 | compile_opt strictarr, hidden |
|---|
| 53 | |
|---|
| 54 | if (n_elements(isGet) gt 0) then self.isGet = isGet |
|---|
| 55 | if (n_elements(isSet) gt 0) then self.isSet = isSet |
|---|
| 56 | if (n_elements(IsInit) gt 0) then self.IsInit = IsInit |
|---|
| 57 | |
|---|
| 58 | if (n_elements(type) gt 0) then self.type = type |
|---|
| 59 | if (n_elements(isPrivate) gt 0) then self.isPrivate = isPrivate |
|---|
| 60 | if (n_elements(isHidden) gt 0) then self.isHidden = isHidden |
|---|
| 61 | |
|---|
| 62 | if (n_elements(comments) gt 0) then begin |
|---|
| 63 | if (obj_valid(self.comments)) then begin |
|---|
| 64 | parent = obj_new('MGtmTag') |
|---|
| 65 | parent->addChild, self.comments |
|---|
| 66 | parent->addChild, comments |
|---|
| 67 | self.comments = parent |
|---|
| 68 | endif else self.comments = comments |
|---|
| 69 | endif |
|---|
| 70 | |
|---|
| 71 | if (n_elements(class) gt 0) then self.class = class |
|---|
| 72 | end |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | ;+ |
|---|
| 76 | ; Get variables for use with templates. |
|---|
| 77 | ; |
|---|
| 78 | ; :Returns: |
|---|
| 79 | ; variable |
|---|
| 80 | ; |
|---|
| 81 | ; :Params: |
|---|
| 82 | ; name : in, required, type=string |
|---|
| 83 | ; name of variable |
|---|
| 84 | ; |
|---|
| 85 | ; :Keywords: |
|---|
| 86 | ; found : out, optional, type=boolean |
|---|
| 87 | ; set to a named variable, returns if variable name was found |
|---|
| 88 | ;- |
|---|
| 89 | function doctreeproperty::getVariable, name, found=found |
|---|
| 90 | compile_opt strictarr, hidden |
|---|
| 91 | |
|---|
| 92 | found = 1B |
|---|
| 93 | case strlowcase(name) of |
|---|
| 94 | 'name': return, self.name |
|---|
| 95 | |
|---|
| 96 | 'is_get': return, self.isGet |
|---|
| 97 | 'is_set': return, self.isSet |
|---|
| 98 | 'is_init': return, self.isInit |
|---|
| 99 | |
|---|
| 100 | 'has_type': return, self.type ne '' |
|---|
| 101 | 'type': return, self.type |
|---|
| 102 | |
|---|
| 103 | 'has_comments': return, obj_valid(self.comments) |
|---|
| 104 | 'comments': return, self.system->processComments(self.comments) |
|---|
| 105 | 'comments_first_line': begin |
|---|
| 106 | if (~obj_valid(self.comments)) then return, '' |
|---|
| 107 | firstline = mg_tm_firstline(self.comments) |
|---|
| 108 | return, self.system->processComments(firstline) |
|---|
| 109 | end |
|---|
| 110 | |
|---|
| 111 | 'index_name': return, self.name |
|---|
| 112 | 'index_type': begin |
|---|
| 113 | self.class->getProperty, classname=classname |
|---|
| 114 | return, 'property in class ' + classname |
|---|
| 115 | end |
|---|
| 116 | |
|---|
| 117 | else: begin |
|---|
| 118 | var = self.class->getVariable(name, found=found) |
|---|
| 119 | if (found) then return, var |
|---|
| 120 | |
|---|
| 121 | found = 0B |
|---|
| 122 | return, -1L |
|---|
| 123 | end |
|---|
| 124 | endcase |
|---|
| 125 | end |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | ;+ |
|---|
| 129 | ; Properties are visible if their class is visible. |
|---|
| 130 | ; |
|---|
| 131 | ; :Returns: |
|---|
| 132 | ; 1 if visible, 0 if not visible |
|---|
| 133 | ;- |
|---|
| 134 | function doctreeproperty::isVisible |
|---|
| 135 | compile_opt strictarr, hidden |
|---|
| 136 | |
|---|
| 137 | if (self.isHidden) then return, 0B |
|---|
| 138 | |
|---|
| 139 | self.system->getProperty, user=user |
|---|
| 140 | if (self.isPrivate && user) then return, 0B |
|---|
| 141 | |
|---|
| 142 | return, obj_valid(self.class) ? self.class->isVisible() : 0B |
|---|
| 143 | end |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | ;+ |
|---|
| 147 | ; Free up resources. |
|---|
| 148 | ;- |
|---|
| 149 | pro doctreeproperty::cleanup |
|---|
| 150 | compile_opt strictarr, hidden |
|---|
| 151 | |
|---|
| 152 | obj_destroy, self.comments |
|---|
| 153 | end |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | ;+ |
|---|
| 157 | ; Create a DOCtreeProperty class. |
|---|
| 158 | ; |
|---|
| 159 | ; :Returns: |
|---|
| 160 | ; 1 if successful, 0 for failure |
|---|
| 161 | ; |
|---|
| 162 | ; :Params: |
|---|
| 163 | ; name : in, required, type=string |
|---|
| 164 | ; name of the property |
|---|
| 165 | ; |
|---|
| 166 | ; :Keywords: |
|---|
| 167 | ; system : in, required, type=object |
|---|
| 168 | ; system object |
|---|
| 169 | ;- |
|---|
| 170 | function doctreeproperty::init, name, system=system |
|---|
| 171 | compile_opt strictarr, hidden |
|---|
| 172 | |
|---|
| 173 | self.name = name |
|---|
| 174 | self.system = system |
|---|
| 175 | |
|---|
| 176 | self.system->getProperty, index_level=indexLevel |
|---|
| 177 | if (indexLevel ge 2L) then self.system->createIndexEntry, self.name, self |
|---|
| 178 | |
|---|
| 179 | return, 1 |
|---|
| 180 | end |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | ;+ |
|---|
| 184 | ; Define instance variables. |
|---|
| 185 | ; |
|---|
| 186 | ; :Fields: |
|---|
| 187 | ; system |
|---|
| 188 | ; system object |
|---|
| 189 | ; class |
|---|
| 190 | ; class object that the property is part of |
|---|
| 191 | ; name |
|---|
| 192 | ; name of the property |
|---|
| 193 | ; isGet |
|---|
| 194 | ; boolean that indicates whether the property can be retrieved with the |
|---|
| 195 | ; getProperty method |
|---|
| 196 | ; isSet |
|---|
| 197 | ; boolean that indicates whether the property can be set with the |
|---|
| 198 | ; setProperty method |
|---|
| 199 | ; isInit |
|---|
| 200 | ; boolean that indicates whether the property can be set on initialization |
|---|
| 201 | ; comments |
|---|
| 202 | ; parse tree object |
|---|
| 203 | ;- |
|---|
| 204 | pro doctreeproperty__define |
|---|
| 205 | compile_opt strictarr, hidden |
|---|
| 206 | |
|---|
| 207 | define = { DOCtreeProperty, $ |
|---|
| 208 | system: obj_new(), $ |
|---|
| 209 | class: obj_new(), $ |
|---|
| 210 | |
|---|
| 211 | name: '', $ |
|---|
| 212 | isGet: 0B, $ |
|---|
| 213 | isSet: 0B, $ |
|---|
| 214 | isInit: 0B, $ |
|---|
| 215 | |
|---|
| 216 | type: '', $ |
|---|
| 217 | isPrivate: 0B, $ |
|---|
| 218 | isHidden: 0B, $ |
|---|
| 219 | comments: obj_new() $ |
|---|
| 220 | } |
|---|
| 221 | end |
|---|