Debian Codegraph @

doc/man/ivman/ClassDef.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 #include <Inventor/SoLists.h>
38 #include <Inventor/SoPath.h>
39 #include <Inventor/engines/SoConcatenate.h>
40 #include <Inventor/engines/SoEngine.h>
41 #include <Inventor/engines/SoGate.h>
42 #include <Inventor/engines/SoSelectOne.h>
43 #include <Inventor/fields/SoField.h>
44 #include <Inventor/fields/SoMFTime.h>
45 #include <Inventor/fields/SoMFInt32.h>
46 #include <Inventor/fields/SoMFUInt32.h>
47 #include <Inventor/fields/SoSFTime.h>
48 #include <Inventor/fields/SoSFInt32.h>
49 #include <Inventor/fields/SoSFUInt32.h>
50 #include <Inventor/nodekits/SoBaseKit.h>
51 #include <Inventor/nodekits/SoNodekitCatalog.h>
52 #include "Man.h"
53
54 /////////////////////////////////////////////////////////////////////////////
55 //
56 // Class: ClassDef
57 //
58 /////////////////////////////////////////////////////////////////////////////
59
60 const ClassDef * ClassDef::curClass = NULL;
61
62 ClassDef::ClassDef()
63 {
64 parentClass = NULL;
65 }
66
67 ClassDef::~ClassDef()
68 {
69 if (type.isDerivedFrom(SoBase::getClassTypeId()) && instance != NULL)
70 ((SoBase *) instance)->unref();
71 }
72
73 void
74 ClassDef::addInherit(ClassDef *def)
75 {
76 // FALSE = add to start of list
77 inherits.add(new Inherit(def->name), FALSE);
78 }
79
80 SbBool
81 ClassDef::read()
82 {
83 SbName nm;
84 SbBool ok = TRUE;
85
86 curClass = this;
87
88 // Read statements while they exist
89 while (ok && Reader::readName(nm)) {
90
91 // See what kind of statement we have
92 switch (getStatementType(nm)) {
93
94 case NAME:
95 ok = (Reader::readName(name) &&
96 Reader::readName(cPrefix) &&
97 Reader::readName(cEnumPrefix) &&
98 Reader::readBracketed(shortDescription));
99 if (! ok)
100 Reader::error("NAME spec");
101 break;
102
103 case DESCRIPTION:
104 ok = Reader::readBracketed(longDescription);
105 if (! ok)
106 Reader::error("DESC");
107 break;
108
109 case INCLUDE:
110 ok = readItem(new Include, &includes);
111 break;
112
113 case TYPEDEF:
114 ok = readItem(new Typedef, &typedefs);
115 break;
116
117 case DEFINE:
118 ok = readItem(new Define, &defines);
119 break;
120
121 case ENUM:
122 ok = readItem(new Enum, &enums);
123 break;
124
125 case FIELD:
126 ok = readItem(new Field, &fields);
127 break;
128
129 case INPUT:
130 ok = readItem(new Input, &inputs);
131 break;
132
133 case OUTPUT:
134 ok = readItem(new Output, &outputs);
135 break;
136
137 case PART:
138 ok = readItem(new Part, &parts);
139 break;
140
141 case METHOD:
142 ok = readItem(new Method, &methods);
143 break;
144
145 case DRAGGER_RESOURCE:
146 ok = readItem(new DraggerResource, &draggerResources);
147 break;
148
149 case MACRO:
150 ok = readItem(new Macro, &macros);
151 break;
152
153 case ACTION:
154 ok = readItem(new Action, &actions);
155 break;
156
157 case MISC:
158 ok = readItem(new Misc, &miscs);
159 break;
160
161 case ALSO:
162 ok = readItem(new Also, &alsos);
163 break;
164
165 case BEGIN:
166 {
167 SbName langName;
168
169 ok = Reader::readName(langName);
170
171 if (ok) {
172 if (langName == "C")
173 Item::setCurLanguage(C);
174 else if (langName == "C++")
175 Item::setCurLanguage(C_PLUS_PLUS);
176 else
177 ok = FALSE;
178 }
179
180 if (! ok)
181 Reader::error("BEGIN language name");
182 }
183 break;
184
185 case END:
186 Item::setCurLanguage(ALL);
187 break;
188
189 default:
190 Reader::error("statement keyword");
191 ok = FALSE;
192 }
193 }
194
195 // If there's stuff left in the file, error
196 if (Reader::get() != EOF)
197 ok = FALSE;
198
199 return ok;
200 }
201
202 SbBool
203 ClassDef::readItem(Item *item, ItemList *list)
204 {
205 if (! item->read())
206 return FALSE;
207
208 list->add(item);
209
210 return TRUE;
211 }
212
213 ClassDef::StatementType
214 ClassDef::getStatementType(const SbName &keyword)
215 {
216 static SbName *names = NULL;
217 static const char *keywords[] = {
218 "NAME",
219 "DESC",
220 "INCLUDE",
221 "TYPEDEF",
222 "DEFINE",
223 "ENUM",
224 "FIELD",
225 "INPUT",
226 "OUTPUT",
227 "PART",
228 "METHOD",
229 "MACRO",
230 "ACTION",
231 "MISC",
232 "ALSO",
233 "BEGIN",
234 "END",
235 "DRAGGER_RESOURCE",
236 };
237
238 #define NUM_KEY_WORDS (sizeof(keywords) / sizeof(keywords[0]))
239
240 size_t i;
241
242 if (names == NULL) {
243 names = new SbName[NUM_KEY_WORDS];
244 for (i = 0; i < NUM_KEY_WORDS; i++)
245 names[i] = keywords[i];
246 }
247
248 for (i = 0; i < NUM_KEY_WORDS; i++)
249 if (keyword == keywords[i])
250 return (StatementType) i;
251
252 return UNKNOWN;
253 }
254
255 SbBool
256 ClassDef::setUp(const ClassDef *mainDef)
257 {
258 curClass = this;
259
260 // Find out the type of the class, if any. Remove the "So" from
261 // the name, since the names don't contain the prefix.
262 // But first check to see if the prefix is Sb. If so, don't setup
263 // up the file format section.
264 SbBool isSb = strncmp(name.getString(), "Sb", 2) ? FALSE : TRUE;
265 type = SoType::fromName(name.getString() + 2);
266
267 // Get an instance of the class, if possible. If this is not the
268 // main ClassDef (mainDef is NULL), we will use an instance of the
269 // main ClassDef for this class as well, rather than choosing one
270 // randomly in getInstance().
271 if (mainDef != NULL)
272 instance = mainDef->instance;
273
274 else if (type.isBad() || isSb)
275 instance = NULL;
276
277 else {
278 instance = getInstance();
279
280 // Ref instance if necessary to keep it around
281 if (type.isDerivedFrom(SoBase::getClassTypeId()) && instance != NULL)
282 ((SoBase *) instance)->ref();
283 }
284
285 // Set the C prefix to the class name, unless it was specified
286 if (Writer::getLanguage() == C && ! cPrefix)
287 cPrefix = name;
288
289 if (Writer::getLanguage() == C)
290 setUpTypedefs();
291
292 if (! fields.isEmpty() && ! setUpFields())
293 return FALSE;
294
295 if (! inputs.isEmpty() && ! setUpInputs())
296 return FALSE;
297
298 if (! outputs.isEmpty() && ! setUpOutputs())
299 return FALSE;
300
301 // Look up part types (if any)
302 if (! parts.isEmpty() && ! setUpParts())
303 return FALSE;
304
305 // Produce nodekit catalog and file format if necessary
306 if (! isSb) {
307 setUpCatalog();
308 setUpFileFormat();
309 }
310
311 return TRUE;
312 }
313
314 SbBool
315 ClassDef::setUpTypedefs()
316 {
317 // The C language version has a typedef for the class if the
318 // prefix is not the same as the class name
319 if (cPrefix != name) {
320 Typedef *def = new Typedef;
321 def->language = C;
322 def->type = name.getString();
323 def->name = cPrefix;
324
325 typedefs.add(def);
326 }
327
328 return TRUE;
329 }
330
331 SbBool
332 ClassDef::setUpFields()
333 {
334 if (instance == NULL ||
335 ! type.isDerivedFrom(SoFieldContainer::getClassTypeId())) {
336 fprintf(stderr, "Can't create a (non-abstract) field container from "
337 "class \"%s\"\n", name.getString());
338 return FALSE;
339 }
340
341 SoFieldContainer *fc = (SoFieldContainer *) instance;
342
343 for (Item *item = fields.first; item != NULL; item = item->next) {
344 Field *f = (Field *) item;
345
346 SoField *field = fc->getField(f->name);
347
348 if (field == NULL) {
349 fprintf(stderr, "No field \"%s\" in class \"%s\"\n",
350 f->name.getString(), name.getString());
351 return FALSE;
352 }
353
354 SbString typeName = "So";
355 SoType fieldType = field->getTypeId();
356 if (fieldType == SoSFInt32::getClassTypeId()) {
357 typeName += "SFInt32";
358 } else if (fieldType == SoMFInt32::getClassTypeId()) {
359 typeName += "MFInt32";
360 } else if (fieldType == SoSFUInt32::getClassTypeId()) {
361 typeName += "SFUInt32";
362 } else if (fieldType == SoMFUInt32::getClassTypeId()) {
363 typeName += "MFUInt32";
364 } else
365 typeName += fieldType.getName().getString();
366
367 f->type = typeName;
368 }
369
370 return TRUE;
371 }
372
373 SbBool
374 ClassDef::setUpInputs()
375 {
376 if (instance == NULL ||
377 ! type.isDerivedFrom(SoEngine::getClassTypeId())) {
378 fprintf(stderr, "Can't create a (non-abstract) engine from "
379 "class \"%s\"\n", name.getString());
380 return FALSE;
381 }
382
383 SoEngine *eng = (SoEngine *) instance;
384
385 for (Item *item = inputs.first; item != NULL; item = item->next) {
386 Input *in = (Input *) item;
387
388 SoField *input = eng->getField(in->name);
389
390 if (input == NULL) {
391 fprintf(stderr,
392 "No input \"%s\" in class \"%s\"\n"
393 "Assuming <inputType>\n",
394 in->name.getString(), name.getString());
395 SbString typeName = "<inputType>";
396 in->type = typeName;
397 }
398 else {
399 SbString typeName = "So";
400 SoType inputType = input->getTypeId();
401
402 if (inputType == SoSFInt32::getClassTypeId()) {
403 typeName += "SFInt32";
404 } else if (inputType == SoMFInt32::getClassTypeId()) {
405 typeName += "MFInt32";
406 } else if (inputType == SoSFUInt32::getClassTypeId()) {
407 typeName += "SFUInt32";
408 } else if (inputType == SoMFUInt32::getClassTypeId()) {
409 typeName += "MFUInt32";
410 } else
411 typeName += inputType.getName().getString();
412
413 in->type = typeName;
414 }
415 }
416
417 return TRUE;
418 }
419
420 SbBool
421 ClassDef::setUpOutputs()
422 {
423 if (instance == NULL ||
424 ! type.isDerivedFrom(SoEngine::getClassTypeId())) {
425 fprintf(stderr, "Can't create a (non-abstract) engine from "
426 "class \"%s\"\n", name.getString());
427 return FALSE;
428 }
429
430 SoEngine *eng = (SoEngine *) instance;
431
432 for (Item *item = outputs.first; item != NULL; item = item->next) {
433 Output *out = (Output *) item;
434
435 SoEngineOutput *output = eng->getOutput(out->name);
436
437 if (output == NULL) {
438 fprintf(stderr, "No output \"%s\" in class \"%s\"\n"
439 "Assuming <outputType>\n",
440 out->name.getString(), name.getString());
441 SbString typeName = "<outputType>";
442 out->type = typeName;
443 }
444 else {
445 SbString typeName = "So";
446
447 SoType outputType = output->getConnectionType();
448 if (outputType == SoSFInt32::getClassTypeId()) {
449 typeName += "SFInt32";
450 } else if (outputType == SoMFInt32::getClassTypeId()) {
451 typeName += "MFInt32";
452 } else if (outputType == SoSFUInt32::getClassTypeId()) {
453 typeName += "SFUInt32";
454 } else if (outputType == SoMFUInt32::getClassTypeId()) {
455 typeName += "MFUInt32";
456 } else
457 typeName += outputType.getName().getString();
458
459 out->type = typeName;
460 }
461 }
462
463 return TRUE;
464 }
465
466 SbBool
467 ClassDef::setUpParts()
468 {
469 if (instance == NULL ||
470 ! type.isDerivedFrom(SoBaseKit::getClassTypeId())) {
471 fprintf(stderr, "Can't create a (non-abstract) node kit from "
472 "class \"%s\"\n", name.getString());
473 return FALSE;
474 }
475
476 SoBaseKit *kit = (SoBaseKit *) instance;
477
478 for (Item *item = parts.first; item != NULL; item = item->next) {
479 Part *part = (Part *) item;
480
481 const SoNodekitCatalog *cat = kit->getNodekitCatalog();
482 SoType type = cat->getType(part->name);
483
484 if (type.isBad()) {
485 fprintf(stderr,"No part \"%s\" in class \"%s\"\n",
486 part->name.getString(), name.getString());
487 return FALSE;
488 }
489
490 SbString typeName = "So";
491 typeName += type.getName().getString();
492
493 part->type = typeName;
494 }
495
496 return TRUE;
497 }
498
499 SbBool
500 ClassDef::setUpCatalog()
501 {
502 int i;
503
504 if (instance == NULL ||
505 ! type.isDerivedFrom(SoBaseKit::getClassTypeId())) {
506 return TRUE;
507 }
508
509 SoBaseKit *kit = (SoBaseKit *) instance;
510
511 const SoNodekitCatalog *cat = kit->getNodekitCatalog();
512
513 //
514 // Main catalog part table
515 //
516
517 // The .ne (need) request makes sure the smallest table fits on
518 // the page. For some reason, tbl gets the wrong value for its own
519 // .ne, so this hack fixes up some simple cases.
520 // First, figure out how many entries are gonna be in the table:
521 int numInPublicTable = 0;
522 for (i = 0; i < cat->getNumEntries(); i++ )
523 if (cat->isPublic(i))
524 numInPublicTable++;
525
526 // Next, print a .ne command to a string, adding our fudge number:
527 #define PUBLIC_TBL_FUDGE_NUM 9
528 char nePublicString[20];
529 sprintf(nePublicString, ".ne %d\n", PUBLIC_TBL_FUDGE_NUM+numInPublicTable);
530
531 catalog = nePublicString;
532 catalog += ".TS\n"
533 "box, tab(!);\n"
534 "cb s s s\n"
535 "lb lb lb lb\n"
536 "lb lb lb lb\n"
537 "l l l c.\n"
538 "All parts\n"
539 "!!!NULL by\n"
540 "Part Name!Part Type!Default Type!Default\n"
541 "\n";
542
543 for (i = 0; i < cat->getNumEntries(); i++ ) {
544
545 if (cat->isPublic(i)) {
546
547 // Part name
548 catalog += cat->getName(i).getString();
549
550 // Part type
551 catalog += "!";
552 catalog += cat->getType(i).getName().getString();
553
554 // Default type
555 catalog += "!";
556 if (cat->getDefaultType(i) != cat->getType(i))
557 catalog += cat->getDefaultType(i).getName().getString();
558 else
559 catalog += "--";
560
561 // NULL by default
562 catalog += "!";
563 catalog += (cat->isNullByDefault(i) ? "yes" : "no");
564
565 catalog += "\n";
566 }
567 }
568
569 catalog += "\n.TE\n";
570
571 //
572 // Catalog list part table
573 //
574
575 // Make sure there is at least one list first
576 SbBool anyLists = FALSE;
577 for (i = 0; i < cat->getNumEntries(); i++ ) {
578 if (cat->isList(i) && cat->isPublic(i)) {
579 anyLists = TRUE;
580 break;
581 }
582 }
583
584 if (anyLists) {
585
586 // The .ne (need) request makes sure the smallest table fits on
587 // the page. For some reason, tbl gets the wrong value for its own
588 // .ne, so this hack fixes up some simple cases.
589
590 // First, figure out how many entries are gonna be in the table:
591 int numInListTable = 0;
592 for (i = 0; i < cat->getNumEntries(); i++ )
593 if (cat->isList(i) && cat->isPublic(i))
594 numInListTable++;
595
596 // Next, print a .ne command to a string, adding our fudge number:
597 #define LIST_TBL_FUDGE_NUM 9
598 char neListSTring[20];
599 sprintf(neListSTring, ".ne %d\n", LIST_TBL_FUDGE_NUM+numInListTable);
600
601 catalog += neListSTring;
602 catalog += ".TS\n"
603 "box, tab(!);\n"
604 "cb s s\n"
605 "lb lb lbw(30n)\n"
606 "l l l.\n"
607 "Extra information for list parts from above table\n"
608 ".sp\n"
609 "Part Name!Container Type!Permissible Types\n"
610 "\n";
611
612 for (i = 0; i < cat->getNumEntries(); i++ ) {
613
614 if (cat->isList(i) && cat->isPublic(i)) {
615
616 // Part name
617 catalog += cat->getName(i).getString();
618
619 // Container type
620 catalog += "!";
621 catalog += cat->getListContainerType(i).getName().getString();
622
623 // Permissible types
624 // Note: type names are entered within T{ and T}
625 // blocks so that they can be formatted when necessary.
626 catalog += "!T{\n";
627 const SoTypeList &permTypes = cat->getListItemTypes(i);
628 for (int j = 0; j < permTypes.getLength(); j++) {
629 catalog += permTypes[j].getName().getString();
630 if (j < permTypes.getLength() - 1)
631 catalog += ", ";
632 }
633 catalog += "\nT}";
634
635 catalog += "\n";
636 }
637 }
638
639 catalog += "\n.TE\n";
640 }
641
642 return TRUE;
643 }
644
645 SbBool
646 ClassDef::setUpFileFormat()
647 {
648 hasFileFormat = FALSE;
649 fileFormat.makeEmpty();
650 fileFormatTabLength = -1;
651
652 // We need file format if the class is derived from SoNode or SoEngine
653 if (type.isDerivedFrom(SoNode::getClassTypeId()) ||
654 type.isDerivedFrom(SoEngine::getClassTypeId())) {
655
656 // Abstract class?
657 if (isAbstract) {
658 fileFormat = "This is an abstract class. See the reference page "
659 "of a derived class for the format and default values.\n";
660 hasFileFormat = TRUE;
661 }
662
663 else if (type.isDerivedFrom(SoBaseKit::getClassTypeId())) {
664 ////////////////////////////////////////////////////////
665 //
666 // Special case for nodekits. They print their fields in
667 // a different order than they are defined.
668 //
669 if (instance == NULL)
670 return TRUE;
671
672 SoBaseKit *kit = (SoBaseKit *) instance;
673 const SoNodekitCatalog *cat = kit->getNodekitCatalog();
674
675 SoFieldList list;
676 kit->getFields(list);
677
678 SoField *field;
679 int partNum, i;
680 SbString fieldVal;
681 SbName fieldName;
682 int len;
683
684 // First, write out fields that are NOT parts...
685 // Whatever they are, just write out the field value.
686 for (i = 0; i < list.getLength(); i++) {
687
688 field = list[i];
689 kit->getFieldName(field, fieldName);
690 partNum = cat->getPartNumber(fieldName);
691
692 if (partNum == SO_CATALOG_NAME_NOT_FOUND) {
693 field->get(fieldVal);
694 fileFormat += fieldName.getString();
695 fileFormat += "\t";
696 fileFormat += fieldVal;
697 fileFormat += "\n";
698 len = fieldName.getLength();
699 if (len > fileFormatTabLength)
700 fileFormatTabLength = len;
701 }
702 }
703
704 // Note: we skip all of this for the BOOK version...
705 if (! Writer::isForBook()) {
706
707 // Second, write out fields that are PUBLIC PARTS.
708 // Private parts do not get written in the man page.
709 // When writing parts, we write <"resourcename"
710 // resource> if the node is named in the global
711 // database. Otherwise, we write out the scene graph.
712 SoNode *partNode;
713 for (i = 0; i < list.getLength(); i++) {
714
715 field = list[i];
716 kit->getFieldName(field, fieldName);
717 partNum = cat->getPartNumber(fieldName);
718
719 if (partNum != SO_CATALOG_NAME_NOT_FOUND &&
720 cat->isPublic(partNum)) {
721
722 partNode = ((SoSFNode *)field)->getValue();
723 if (partNode == NULL || !partNode->getName()) {
724 // If the node has no name in the global dictionary
725 // or is NULL, print out the value of the node.
726 // This might turn out to be an entire scene graph!
727 field->get(fieldVal);
728 }
729 else {
730 // Just print out the name of the node.
731 fieldVal = "<";
732 fieldVal += partNode->getName().getString();
733 fieldVal += " resource>";
734 }
735 fileFormat += fieldName.getString();
736 fileFormat += "\t";
737 fileFormat += fieldVal;
738 fileFormat += "\n";
739 len = fieldName.getLength();
740 if (len > fileFormatTabLength)
741 fileFormatTabLength = len;
742 }
743 }
744
745 // Finally, dragger resources may exist for parts that are in
746 // nested draggers. Write out these nested partNames
747 // and <"resourcename" resource>
748 if (! draggerResources.isEmpty()) {
749 Item *item;
750 for (item = draggerResources.first;
751 item != NULL; item = item->next ) {
752
753 DraggerResource *res = (DraggerResource *) item;
754
755 // Check if any of the parts that use this resource
756 // do not simply match the partNames in the catalog.
757 // If not, we write out the partName and resource.
758 for (int j = 0; j < res->getNumPartDefs(); j++ ) {
759 const SbName pDefName = res->getPartDefName(j);
760 if ( cat->getPartNumber(pDefName)
761 == SO_CATALOG_NAME_NOT_FOUND ) {
762 // Write it all out...
763 fieldVal = "<";
764 fieldVal += res->getResourceName().getString();
765 fieldVal += " resource>";
766
767 fileFormat += pDefName.getString();
768 fileFormat += "\t";
769 fileFormat += fieldVal;
770 fileFormat += "\n";
771 len = pDefName.getLength();
772 if (len > fileFormatTabLength)
773 fileFormatTabLength = len;
774 }
775 }
776 }
777 }
778 }
779
780 hasFileFormat = TRUE;
781
782 //
783 ////////////////////////////////////////////////////////
784 }
785 else {
786 SoFieldContainer *fc = (SoFieldContainer *) instance;
787
788 ////////////////////////////////////////////////////////
789 //
790 // Special case for engines whose constructor takes the
791 // type of field to operate on
792 //
793 if (fc->isOfType(SoConcatenate::getClassTypeId()))
794 fileFormat += "type\t<inputType>\n"
795 "input0\t[]\n"
796 "input1\t[]\n"
797 "input2\t[]\n"
798 "input3\t[]\n"
799 "input4\t[]\n"
800 "input5\t[]\n"
801 "input6\t[]\n"
802 "input7\t[]\n"
803 "input8\t[]\n"
804 "input9\t[]\n";
805
806 else if (fc->isOfType(SoGate::getClassTypeId()) ||
807 fc->isOfType(SoSelectOne::getClassTypeId()))
808 fileFormat += "type\t<inputType>\ninput\t[]\n";
809 //
810 ////////////////////////////////////////////////////////
811
812 // Make sure each field does not have a default value
813 SoFieldList list;
814
815 fc->getFields(list);
816
817 for (int i = 0; i < list.getLength(); i++) {
818 SoField *field = list[i];
819 SbString fieldVal;
820 SbName fieldName;
821 int len;
822
823 fc->getFieldName(field, fieldName);
824
825 // Special case for time fields connected to the clock
826 if (field->isConnected() &&
827 (field->isOfType(SoSFTime::getClassTypeId()) ||
828 field->isOfType(SoMFTime::getClassTypeId())))
829 fieldVal = "<current time>";
830 else
831 field->get(fieldVal);
832
833 fileFormat += fieldName.getString();
834 fileFormat += "\t";
835 fileFormat += fieldVal;
836 fileFormat += "\n";
837
838 len = fieldName.getLength();
839 if (len > fileFormatTabLength)
840 fileFormatTabLength = len;
841 }
842 hasFileFormat = TRUE;
843 }
844 }
845
846 return TRUE;
847 }
848
849 void *
850 ClassDef::getInstance()
851 {
852 void *inst;
853
854 isAbstract = ! type.canCreateInstance();
855
856 // If the given class is not abstract, return an instance of it
857 if (! isAbstract)
858 inst = type.createInstance();
859
860 else {
861 // Otherwise, find all classes derived from the class and
862 // return the first one that is not abstract
863 SoTypeList list;
864 SoType::getAllDerivedFrom(type, list);
865
866 inst = NULL;
867
868 for (int i = 0; i < list.getLength(); i++) {
869 if (list[i].canCreateInstance()) {
870 inst = list[i].createInstance();
871 break;
872 }
873 }
874 }
875
876 // No non-abstract classes
877 return inst;
878 }
879
880 void
881 ClassDef::cullMethods()
882 {
883 ////////////////////////////////////////////
884 //
885 // This method is called on the main ClassDef - the one the man
886 // page is for. It removes any method from an inherited class that:
887 // (1) is a constructor,
888 // or (2) has the same name as a method on a more derived class,
889 // or (3) is a destructor and the language is C++.
890 //
891 // It also removes hidden methods from the main ClassDef and all
892 // inherited ClassDefs.
893 //
894 ////////////////////////////////////////////
895
896 ClassDef *cd, *inheritedCd;
897 Method *meth, *inhMeth, *prevMeth;
898
899 //
900 // Pass 1: Mark all constructors and destructors
901 //
902 for (cd = parentClass; cd != NULL; cd = cd->parentClass) {
903 for (meth = (Method *) cd->methods.first;
904 meth != NULL;
905 meth = (Method *) meth->next) {
906
907 // Remove constructors
908 if (meth->type == Method::CONSTRUCTOR)
909 meth->skipThis = TRUE;
910
911 // Remove destructors from C++
912 else if (meth->type == Method::DESTRUCTOR &&
913 Writer::getLanguage() == C_PLUS_PLUS)
914 meth->skipThis = TRUE;
915 }
916 }
917
918 //
919 // Pass 2: Mark any method with the same name as in a more
920 // derived class. This is a slow way to do this, but it shouldn't
921 // be too bad in most cases.
922 //
923 for (cd = this; cd != NULL; cd = cd->parentClass) {
924 for (meth = (Method *) cd->methods.first;
925 meth != NULL;
926 meth = (Method *) meth->next) {
927
928 if (! meth->skipThis) {
929
930 // Look through inherited classes for a method with
931 // the same name
932
933 for (inheritedCd = cd->parentClass; inheritedCd != NULL;
934 inheritedCd = inheritedCd->parentClass) {
935
936 if (Writer::getLanguage() == C) {
937 for (inhMeth = (Method *) inheritedCd->methods.first;
938 inhMeth != NULL;
939 inhMeth = (Method *) inhMeth->next) {
940
941 if (inhMeth->cName == meth->cName)
942 inhMeth->skipThis = TRUE;
943 }
944 }
945 else {
946 for (inhMeth = (Method *) inheritedCd->methods.first;
947 inhMeth != NULL;
948 inhMeth = (Method *) inhMeth->next) {
949
950 if (inhMeth->name == meth->name)
951 inhMeth->skipThis = TRUE;
952 }
953 }
954 }
955 }
956 }
957 }
958
959 //
960 // Pass 3: Mark hidden methods
961 //
962 for (cd = this; cd != NULL; cd = cd->parentClass) {
963 for (meth = (Method *) cd->methods.first;
964 meth != NULL;
965 meth = (Method *) meth->next) {
966
967 if (meth->isHidden)
968 meth->skipThis = TRUE;
969 }
970 }
971
972 //
973 // Pass 4: Actually remove marked methods from lists
974 //
975 for (cd = this; cd != NULL; cd = cd->parentClass) {
976
977 prevMeth = NULL;
978
979 for (meth = (Method *) cd->methods.first;
980 meth != NULL;
981 meth = (Method *) meth->next) {
982
983 if (meth->skipThis) {
984 if (prevMeth == NULL)
985 cd->methods.first = meth->next;
986 else
987 prevMeth->next = meth->next;
988 }
989 else
990 prevMeth = meth;
991 }
992 }
993 }
994
995 void
996 ClassDef::write(SbBool)
997 {
998 curClass = this;
999
1000 Writer::writePreface(name);
1001
1002 if (Writer::isForBook())
1003 writeForBook();
1004 else
1005 writeForNonBook();
1006 }
1007
1008 void
1009 ClassDef::writeForBook()
1010 {
1011 ClassDef *cd;
1012 SbBool anyItem;
1013
1014 ////////////////////////////////////////////////////////
1015 //
1016 // NAME section
1017 //
1018
1019 writeName();
1020
1021 ////////////////////////////////////////////////////////
1022 //
1023 // INHERITS FROM section
1024 //
1025
1026 Writer::startSection("INHERITS FROM");
1027 inherits.write();
1028
1029 ////////////////////////////////////////////////////////
1030 //
1031 // DESCRIPTION section
1032 //
1033
1034 Writer::startSection("DESCRIPTION");
1035 Writer::writeBracketed(longDescription);
1036
1037 ////////////////////////////////////////////////////////
1038 //
1039 // FIELDS section
1040 //
1041
1042 anyItem = FALSE;
1043 for (cd = this; cd != NULL; cd = cd->parentClass) {
1044 if (! cd->fields.isEmpty()) {
1045 anyItem = TRUE;
1046 break;
1047 }
1048 }
1049 if (anyItem) {
1050 Writer::startSection("FIELDS");
1051 if (! fields.isEmpty())
1052 fields.write();
1053 for (cd = parentClass; cd != NULL; cd = cd->parentClass)
1054 if (! cd->fields.isEmpty())
1055 cd->writeFromClass(&cd->fields, "Fields", TRUE);
1056 }
1057
1058 ////////////////////////////////////////////////////////
1059 //
1060 // INPUTS section
1061 //
1062
1063 anyItem = FALSE;
1064 for (cd = this; cd != NULL; cd = cd->parentClass) {
1065 if (! cd->inputs.isEmpty()) {
1066 anyItem = TRUE;
1067 break;
1068 }
1069 }
1070 if (anyItem) {
1071 Writer::startSection("INPUTS");
1072 if (! inputs.isEmpty())
1073 inputs.write();
1074 for (cd = parentClass; cd != NULL; cd = cd->parentClass)
1075 if (! cd->inputs.isEmpty())
1076 cd->writeFromClass(&cd->inputs, "Inputs", TRUE);
1077 }
1078
1079 ////////////////////////////////////////////////////////
1080 //
1081 // OUTPUTS section
1082 //
1083
1084 anyItem = FALSE;
1085 for (cd = this; cd != NULL; cd = cd->parentClass) {
1086 if (! cd->outputs.isEmpty()) {
1087 anyItem = TRUE;
1088 break;
1089 }
1090 }
1091 if (anyItem) {
1092 Writer::startSection("OUTPUTS");
1093 if (! outputs.isEmpty())
1094 outputs.write();
1095 for (cd = parentClass; cd != NULL; cd = cd->parentClass)
1096 if (! cd->outputs.isEmpty())
1097 cd->writeFromClass(&cd->outputs, "Outputs", TRUE);
1098 }
1099
1100 ////////////////////////////////////////////////////////
1101 //
1102 // PARTS section
1103 //
1104
1105 anyItem = FALSE;
1106 for (cd = this; cd != NULL; cd = cd->parentClass) {
1107 if (! cd->parts.isEmpty()) {
1108 anyItem = TRUE;
1109 break;
1110 }
1111 }
1112 if (anyItem) {
1113 Writer::startSection("PARTS");
1114 if (! parts.isEmpty())
1115 parts.write();
1116 for (cd = parentClass; cd != NULL; cd = cd->parentClass)
1117 if (! cd->parts.isEmpty())
1118 cd->writeFromClass(&cd->parts, "Parts", TRUE);
1119 }
1120
1121 ////////////////////////////////////////////////////////
1122 //
1123 // METHODS section
1124 //
1125
1126 anyItem = FALSE;
1127 for (cd = this; cd != NULL; cd = cd->parentClass) {
1128 if (! cd->methods.isEmpty()) {
1129 anyItem = TRUE;
1130 break;
1131 }
1132 }
1133 if (anyItem) {
1134 Writer::startSection(Writer::getLanguage() == C ?
1135 "FUNCTIONS" : "METHODS");
1136 if (! methods.isEmpty())
1137 methods.write();
1138 for (cd = parentClass; cd != NULL; cd = cd->parentClass)
1139 if (! cd->methods.isEmpty())
1140 cd->writeFromClass(&cd->methods,
1141 (Writer::getLanguage() == C ?
1142 "Functions" : "Methods"),
1143 TRUE);
1144 }
1145
1146 ////////////////////////////////////////////////////////
1147 //
1148 // MACROS section
1149 //
1150
1151 anyItem = FALSE;
1152 for (cd = this; cd != NULL; cd = cd->parentClass) {
1153 if (! cd->macros.isEmpty()) {
1154 anyItem = TRUE;
1155 break;
1156 }
1157 }
1158 if (anyItem) {
1159 Writer::startSection("MACROS");
1160 if (! macros.isEmpty())
1161 macros.write();
1162 for (cd = parentClass; cd != NULL; cd = cd->parentClass)
1163 if (! cd->macros.isEmpty())
1164 cd->writeFromClass(&cd->macros, "Macros", TRUE);
1165 }
1166
1167 ////////////////////////////////////////////////////////
1168 //
1169 // ACTION BEHAVIOR section
1170 //
1171
1172 if (! actions.isEmpty()) {
1173 Writer::startSection("ACTION BEHAVIOR");
1174 actions.write();
1175 }
1176
1177 ////////////////////////////////////////////////////////
1178 //
1179 // CATALOG PARTS section
1180 //
1181
1182 if (! ! catalog) {
1183 Writer::startSection("CATALOG PARTS");
1184 Writer::write(catalog);
1185 }
1186
1187 ////////////////////////////////////////////////////////
1188 //
1189 // FILE FORMAT section
1190 //
1191
1192 writeFileFormat();
1193
1194 ////////////////////////////////////////////////////////
1195 //
1196 // Include files
1197 //
1198
1199 if (! includes.isEmpty()) {
1200 Writer::startSection("INCLUDE FILE");
1201
1202 Writer::changeSize(-1);
1203
1204 // Include files for this class
1205 includes.write();
1206
1207 // XXX we needed to list these things somewhere,
1208 // so here they are --AE
1209 // Typedefs for this class
1210 typedefs.write();
1211
1212 // Definitions for this class
1213 defines.write();
1214
1215 // Enums for this class
1216 enums.write();
1217 }
1218
1219 ////////////////////////////////////////////////////////
1220 //
1221 // Miscellaneous sections
1222 //
1223
1224 if (! miscs.isEmpty())
1225 miscs.write();
1226
1227 ////////////////////////////////////////////////////////
1228 //
1229 // SEE ALSO section
1230 //
1231
1232 if (! alsos.isEmpty()) {
1233 Writer::startSection("SEE ALSO");
1234 alsos.write();
1235 }
1236
1237 ////////////////////////////////////////////////////////
1238
1239 Writer::finish();
1240 }
1241
1242 void
1243 ClassDef::writeForNonBook()
1244 {
1245 ////////////////////////////////////////////////////////
1246 //
1247 // NAME section
1248 //
1249
1250 writeName();
1251
1252 ////////////////////////////////////////////////////////
1253 //
1254 // INHERITS FROM section
1255 //
1256
1257 Writer::startSection("INHERITS FROM");
1258 inherits.write();
1259
1260 ////////////////////////////////////////////////////////
1261 //
1262 // SYNOPSIS section
1263 //
1264
1265 writeSynopsis();
1266
1267 ////////////////////////////////////////////////////////
1268 //
1269 // DESCRIPTION section
1270 //
1271
1272 Writer::startSection("DESCRIPTION");
1273 Writer::writeBracketed(longDescription);
1274
1275 ////////////////////////////////////////////////////////
1276 //
1277 // FIELDS section
1278 //
1279
1280 if (! fields.isEmpty()) {
1281 Writer::startSection("FIELDS");
1282 fields.write();
1283 }
1284
1285 ////////////////////////////////////////////////////////
1286 //
1287 // INPUTS section
1288 //
1289
1290 if (! inputs.isEmpty()) {
1291 Writer::startSection("INPUTS");
1292 inputs.write();
1293 }
1294
1295 ////////////////////////////////////////////////////////
1296 //
1297 // OUTPUTS section
1298 //
1299
1300 if (! outputs.isEmpty()) {
1301 Writer::startSection("OUTPUTS");
1302 outputs.write();
1303 }
1304
1305 ////////////////////////////////////////////////////////
1306 //
1307 // PARTS section
1308 //
1309
1310 if (! parts.isEmpty()) {
1311 Writer::startSection("PARTS");
1312 parts.write();
1313 }
1314
1315 ////////////////////////////////////////////////////////
1316 //
1317 // METHODS section
1318 //
1319
1320 if (! methods.isEmpty()) {
1321 Writer::startSection(Writer::getLanguage() == C ?
1322 "FUNCTIONS" : "METHODS");
1323 methods.write();
1324 }
1325
1326 ////////////////////////////////////////////////////////
1327 //
1328 // MACROS section
1329 //
1330
1331 if (! macros.isEmpty()) {
1332 Writer::startSection("MACROS");
1333 macros.write();
1334 }
1335
1336 ////////////////////////////////////////////////////////
1337 //
1338 // ACTION BEHAVIOR section
1339 //
1340
1341 if (! actions.isEmpty()) {
1342 Writer::startSection("ACTION BEHAVIOR");
1343 actions.write();
1344 }
1345
1346 ////////////////////////////////////////////////////////
1347 //
1348 // CATALOG PARTS section
1349 //
1350
1351 if (! ! catalog) {
1352 Writer::startSection("CATALOG PARTS");
1353 Writer::write(catalog);
1354 }
1355
1356 ////////////////////////////////////////////////////////
1357 //
1358 // DRAGGER RESOURCES section (for draggers)
1359 //
1360
1361 if (! draggerResources.isEmpty()) {
1362 Writer::startSection("DRAGGER RESOURCES");
1363 draggerResources.write();
1364 }
1365
1366 ////////////////////////////////////////////////////////
1367 //
1368 // FILE FORMAT section
1369 //
1370
1371 writeFileFormat();
1372
1373 ////////////////////////////////////////////////////////
1374 //
1375 // Miscellaneous sections
1376 //
1377
1378 if (! miscs.isEmpty())
1379 miscs.write();
1380
1381 ////////////////////////////////////////////////////////
1382 //
1383 // SEE ALSO section
1384 //
1385
1386 if (! alsos.isEmpty()) {
1387 Writer::startSection("SEE ALSO");
1388 alsos.write();
1389 }
1390
1391 ////////////////////////////////////////////////////////
1392
1393 Writer::finish();
1394 }
1395
1396 void
1397 ClassDef::writeName()
1398 {
1399 Writer::startSection("NAME");
1400 Writer::write(name);
1401 if (Writer::getLanguage() == C) {
1402 Writer::write(" (");
1403 Writer::write(cPrefix);
1404 Writer::write(") \\(em ");
1405 }
1406 else
1407 Writer::write(" \\(em ");
1408
1409 Writer::writeBracketed(shortDescription);
1410 }
1411
1412 void
1413 ClassDef::writeSynopsis()
1414 {
1415 ClassDef *cd;
1416
1417 Writer::setInSynopsis(TRUE);
1418
1419 Writer::startSection("SYNOPSIS");
1420 Writer::changeSize(-1);
1421
1422 // Include files for this class
1423 includes.write();
1424
1425 // Typedefs for this class
1426 typedefs.write();
1427
1428 // Definitions for this class
1429 defines.write();
1430
1431 // Enums for this class
1432 enums.write();
1433
1434 // Fields for this class, then all parent classes
1435 for (cd = this; cd != NULL; cd = cd->parentClass)
1436 if (! cd->fields.isEmpty())
1437 cd->writeFromClass(&cd->fields, "Fields");
1438
1439 // Inputs for this class, then all parent classes
1440 for (cd = this; cd != NULL; cd = cd->parentClass)
1441 if (! cd->inputs.isEmpty())
1442 cd->writeFromClass(&cd->inputs, "Inputs");
1443
1444 // Outputs for this class, then all parent classes
1445 for (cd = this; cd != NULL; cd = cd->parentClass)
1446 if (! cd->outputs.isEmpty())
1447 cd->writeFromClass(&cd->outputs, "Outputs");
1448
1449 // Parts for this class, then all parent classes
1450 for (cd = this; cd != NULL; cd = cd->parentClass)
1451 if (! cd->parts.isEmpty())
1452 cd->writeFromClass(&cd->parts, "Parts");
1453
1454 // Methods for this class, then all parent classes
1455 for (cd = this; cd != NULL; cd = cd->parentClass)
1456 if (! cd->methods.isEmpty())
1457 cd->writeFromClass(&cd->methods,
1458 (Writer::getLanguage() == C ?
1459 "Functions" : "Methods"));
1460
1461 // Macros for this class, then all parent classes
1462 for (cd = this; cd != NULL; cd = cd->parentClass)
1463 if (! cd->macros.isEmpty())
1464 cd->writeFromClass(&cd->macros, "Macros");
1465
1466 Writer::setInSynopsis(FALSE);
1467 }
1468
1469 void
1470 ClassDef::writeFileFormat()
1471 {
1472 // Paths have a special file format:
1473 if (type == SoPath::getClassTypeId()) {
1474 Writer::startSection("FILE FORMAT/DEFAULTS");
1475
1476 Writer::setFill(FALSE);
1477 Writer::setFont(Writer::FIXED_ROMAN);
1478 Writer::write("SoPath {\n");
1479 Writer::setBaseIndent(0.5);
1480 Writer::write("[head node]\n"
1481 "[number of remaining indices]\n"
1482 "[index]\n"
1483 "\\&...\n"
1484 "[index]\n");
1485 Writer::setBaseIndent(0.0);
1486 Writer::write("}\n\n");
1487
1488 Writer::setFill(TRUE);
1489 Writer::setFont(Writer::TEXT_ROMAN);
1490 Writer::write("Note that the indices in a written path are "
1491 "adjusted based on the nodes that are actually "
1492 "written to a file. Since nodes in the graph "
1493 "that have no effect on the path (such as some "
1494 "separator nodes) are not written, the siblings "
1495 "of such nodes must undergo index adjustment "
1496 "when written. The actual nodes in the graph "
1497 "remain unchanged.\n");
1498 }
1499
1500 else if (hasFileFormat) {
1501 Writer::startSection("FILE FORMAT/DEFAULTS");
1502
1503 if (isAbstract)
1504 Writer::write(fileFormat);
1505
1506 else {
1507 Writer::setFill(FALSE);
1508 Writer::setFont(Writer::FIXED_ROMAN);
1509 // Remove "So" prefix from name
1510 Writer::write(name.getString() + 2);
1511 Writer::write(" {\n");
1512
1513 // Classes with no fields have an empty fileFormat string
1514 if (! ! fileFormat) {
1515 Writer::setBaseIndent(0.5);
1516 Writer::setTab(fileFormatTabLength +
1517 (fileFormatTabLength < 0 ? 0 : 2));
1518 Writer::write(fileFormat);
1519 Writer::setBaseIndent(0.0);
1520 }
1521
1522 Writer::write("}\n");
1523 }
1524 }
1525 }
1526
1527 void
1528 ClassDef::writeFromClass(ItemList *list, const char *whats, SbBool runIn)
1529 {
1530 if (Writer::isForBook()) {
1531 Writer::setBaseIndent(0.0);
1532 Writer::setFont(Writer::TEXT_BOLD);
1533 }
1534 else {
1535 Writer::setBaseIndent(0.5);
1536 Writer::setFont(Writer::TEXT_ROMAN);
1537 }
1538 Writer::write(whats);
1539 Writer::write(" from class ");
1540 Writer::write(name);
1541 Writer::write(":\n");
1542 if (Writer::isForBook()) {
1543 Writer::setBaseIndent(0.5);
1544 Writer::space(.25);
1545 }
1546 else {
1547 Writer::setBaseIndent(0.0);
1548 Writer::space();
1549 }
1550
1551 list->write(runIn);
1552 }