MISR Toolkit  1.5.1
ao_nodesao.c
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Description: This file contains C routines that navigate among the object
4  nodes of an ODL tree. These routines augment the general
5  purpose routines for manipulating aggregate nodes. The main
6  differences between these routines and the general routines
7  for handling aggregates are the following:
8 
9  - These routines ignore group nodes when navigating through
10  an ODL tree;
11 
12  - The search routines FindObject and FindNextObject are
13  able to search for a specific class of object as well
14  as for an object node with a specific name.
15 
16  Author: Randy Davis, University of Colorado LASP
17 
18  Creation Date: 13 March 1991
19  Last Modified: 18 May 1991
20 
21  History:
22 
23  Creation - This set of routines was introduced in the Version 2.1
24  release of the ODLC library.
25 
26  Version 2.2 - 18 May 1991 - M. DeMore, Jet Propulsion Laboratory
27  Removed include statements that were Unix specific and placed them
28  in odldef.h.
29 
30 *****************************************************************************/
31 
32 #include "odldef.h"
33 #include "odlinter.h"
34 
35 
36 
37 
38 
39 /*****************************************************************************
40 
41  Routine: ParentObject
42 
43  Description: Returns a pointer to an aggregate's parent object.
44 
45  Input:
46  base_node - A pointer to an aggregate node.
47 
48  Output: A pointer to the parent object node. If there is no parent object
49  (if, for example, the input base node is the root node of an ODL
50  tree) then the NULL value is returned. The NULL value is also
51  returned if the input argument is NULL.
52 
53 *****************************************************************************/
54 
55 
57 {
58  AGGREGATE node; /* Pointer to current aggregate node */
59 
60 
61  node = base_node;
62 
63  do
64  {
65  node = ParentAggregate (node);
66  } while (node != NULL && node->kind != KA_OBJECT);
67 
68  return (node);
69 }
70 
71 
72 
73 
74 /*****************************************************************************
75 
76  Routine: NextObject
77 
78  Description: Returns the next object node after the one pointed to by the
79  input aggregate node, according to a pre-order traversal of
80  the ODL tree.
81 
82  Input:
83  base_node - A pointer to the starting aggregate node.
84 
85  Output: A pointer to the next object node is returned as the function
86  value. A NULL value indicates that there is no next object
87  node. The NULL value is also returned if the input argument
88  is NULL.
89 
90 *****************************************************************************/
91 
92 
94 {
95  AGGREGATE node; /* Pointer to the next node */
96 
97 
98  node = base_node;
99 
100  do
101  {
102  node = NextAggregate (node);
103  } while (node != NULL && node->kind != KA_OBJECT);
104 
105  return node;
106 }
107 
108 
109 
110 
111 /*****************************************************************************
112 
113  Routine: NextSubObject
114 
115  Description: Returns the next sub-object of the base node after the one
116  pointed to by the start node.
117 
118  Input:
119  base_node - A pointer to the base aggregate node.
120  start_node - A pointer to the starting node.
121 
122  Output: A pointer to the next object sub-node of the base node is
123  returned as the function value. A NULL value indicates that
124  there is no next object sub-node. The NULL value is also
125  returned if the input argument is NULL.
126 
127 *****************************************************************************/
128 
129 
130 OBJECT NextSubObject (AGGREGATE base_node, AGGREGATE start_node)
131 {
132  AGGREGATE node; /* Pointer to the next node */
133 
134 
135  node = start_node;
136 
137  do
138  {
139  node = NextSubAggregate (base_node, node);
140  } while (node != NULL && node->kind != KA_OBJECT);
141 
142  return node;
143 }
144 
145 
146 
147 
148 /*****************************************************************************
149 
150  Routine: FindObject
151 
152  Description: Finds an object node with a specified name and/or class.
153  The search starts with the base node and continues as
154  necessary with all of the base nodes's children, all their
155  children, and so on using a preorder search.
156 
157  Input:
158  base_node - A pointer to the starting aggregate node.
159  name - Pointer to a character string containing the object
160  name to be located. This may be NULL; if it is, the
161  search will be for the first object node of the
162  specified class.
163  thisClass - Pointer to a character string with the object class
164  to be located. This may be NULL; if it is, the search
165  will be for the first object node with the specified
166  name, regardless of its class.
167 
168  Output: A pointer to the first object node that has the specified name
169  and/or class is returned as the function value. If no match is
170  found, then the NULL value is returned. The NULL value is also
171  returned if the input pointer to the base node is NULL or if
172  both the input name and class are NULL.
173 
174 *****************************************************************************/
175 
176 
177 OBJECT FindObject (AGGREGATE base_node, char *name, char *thisClass)
178 {
179  AGGREGATE node; /* Pointer to current node */
180 
181 
182  if (base_node == NULL || (name == NULL && thisClass == NULL))
183  {
184  return (NULL);
185  }
186 
187  /* Start searching with the base node and stop searching when we
188  find a node with the specified name and/or class or when we
189  have visited all of the progeny of the base node */
190 
191  node = base_node;
192 
193  while (node != NULL)
194  {
195  if (node->kind == KA_OBJECT &&
196  (name == NULL || strcmp (node->name, name) == 0) &&
197  (thisClass == NULL || strcmp (node->objClass, thisClass) == 0))
198  {
199  break;
200  }
201 
202  node = NextSubObject (base_node, node);
203  }
204 
205  return (node);
206 }
207 
208 
209 
210 /*****************************************************************************
211 
212  Routine: FindNextObject
213 
214  Description: This routine is similar to routine FindObject in that it
215  searches the progeny of the specified base node, except that
216  the search begins with the node specified by the second
217  argument. This is useful when there is more than one object
218  node with the same name or class in the search path.
219 
220  Input:
221  base_node - A pointer to the base node for the search.
222  start_node - A pointer to the starting node for the search. The
223  search does not include the start node.
224  name - Pointer to a character string containing the name of
225  the object to be located. This pointer can be NULL:
226  if it is, the first object node of the specified
227  class is returned, regardless of its name.
228  class - Pointer to a character string containing the class of
229  object to be located. If this pointer is NULL, the
230  first object node located with the specified name
231  is returned, regardless of its class.
232 
233  Output: A pointer to the next object node that has the specified name
234  and/or class is returned as function value. If no match is
235  found, then the NULL value is returned. The NULL value is
236  also returned if either the input base node or start node
237  pointers are NULL, or if both the name and class arguments
238  are NULL.
239 
240 *****************************************************************************/
241 
242 
243 OBJECT FindNextObject (AGGREGATE base_node, AGGREGATE start_node, char *name, char *thisClass)
244 {
245  AGGREGATE node; /* Pointer to current node */
246 
247 
248  if (base_node == NULL || start_node == NULL ||
249  (name == NULL && thisClass == NULL))
250  {
251  return (NULL);
252  }
253 
254  /* Start searching from the start node and stop searching when we
255  find an object node with the specified name and/or class, or
256  when we have visited all of the progeny of the base node */
257 
258  node = NextSubObject (base_node, start_node);
259 
260  while (node != NULL)
261  {
262  if ((name == NULL || strcmp (node->name, name) == 0) &&
263  (thisClass == NULL || strcmp (node->objClass, thisClass) == 0))
264  {
265  break;
266  }
267 
268  node = NextSubObject (base_node, node);
269  }
270 
271  return (node);
272 }
AGGREGATE ParentAggregate(AGGREGATE base_node)
Definition: a_nodesa.c:295
OBJECT NextObject(AGGREGATE base_node)
Definition: ao_nodesao.c:93
OBJECT ParentObject(AGGREGATE base_node)
Definition: ao_nodesao.c:56
AGGREGATE NextAggregate(AGGREGATE base_node)
Definition: a_nodesa.c:342
OBJECT FindObject(AGGREGATE base_node, char *name, char *thisClass)
Definition: ao_nodesao.c:177
AGGREGATE_KIND kind
Definition: odldef.h:115
HDFFCLIBAPI _fcd name
OBJECT NextSubObject(AGGREGATE base_node, AGGREGATE start_node)
Definition: ao_nodesao.c:130
OBJECT FindNextObject(AGGREGATE base_node, AGGREGATE start_node, char *name, char *thisClass)
Definition: ao_nodesao.c:243
char * objClass
Definition: odldef.h:113
AGGREGATE NextSubAggregate(AGGREGATE base_node, AGGREGATE start_node)
Definition: a_nodesa.c:410
char * name
Definition: odldef.h:112

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51