Panda3D
 All Classes Functions Variables Enumerations
dcFile.cxx
1 // Filename: dcFile.cxx
2 // Created by: drose (05Oct00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "dcFile.h"
16 #include "dcClass.h"
17 #include "dcSwitch.h"
18 #include "dcParserDefs.h"
19 #include "dcLexerDefs.h"
20 #include "dcTypedef.h"
21 #include "dcKeyword.h"
22 #include "hashGenerator.h"
23 
24 #ifdef WITHIN_PANDA
25 #include "filename.h"
26 #include "config_express.h"
27 #include "virtualFileSystem.h"
28 #include "executionEnvironment.h"
29 #include "configVariableList.h"
30 #endif
31 
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: DCFile::Constructor
35 // Access: Published
36 // Description:
37 ////////////////////////////////////////////////////////////////////
38 DCFile::
39 DCFile() {
40  _all_objects_valid = true;
41  _inherited_fields_stale = false;
42 
43  setup_default_keywords();
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: DCFile::Destructor
48 // Access: Published
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 DCFile::
52 ~DCFile() {
53  clear();
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: DCFile::clear
58 // Access: Published
59 // Description: Removes all of the classes defined within the DCFile
60 // and prepares it for reading a new file.
61 ////////////////////////////////////////////////////////////////////
62 void DCFile::
63 clear() {
64  Declarations::iterator di;
65  for (di = _declarations.begin(); di != _declarations.end(); ++di) {
66  delete (*di);
67  }
68  for (di = _things_to_delete.begin(); di != _things_to_delete.end(); ++di) {
69  delete (*di);
70  }
71 
72  _classes.clear();
73  _imports.clear();
74  _things_by_name.clear();
75  _typedefs.clear();
76  _typedefs_by_name.clear();
77  _keywords.clear_keywords();
78  _declarations.clear();
79  _things_to_delete.clear();
80  setup_default_keywords();
81 
82  _all_objects_valid = true;
83  _inherited_fields_stale = false;
84 }
85 
86 #ifdef WITHIN_PANDA
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: DCFile::read_all
90 // Access: Published
91 // Description: This special method reads all of the .dc files named
92 // by the "dc-file" config.prc variable, and loads them
93 // into the DCFile namespace.
94 ////////////////////////////////////////////////////////////////////
95 bool DCFile::
96 read_all() {
97  static ConfigVariableList dc_files
98  ("dc-file", PRC_DESC("The list of dc files to load."));
99 
100  if (dc_files.size() == 0) {
101  cerr << "No files specified via dc-file Config.prc variable!\n";
102  return false;
103  }
104 
105  int size = dc_files.size();
106 
107  // Load the DC files in opposite order, because we want to load the
108  // least-important (most fundamental) files first.
109  for (int i = size - 1; i >= 0; --i) {
110  string dc_file = ExecutionEnvironment::expand_string(dc_files[i]);
111  Filename filename = Filename::from_os_specific(dc_file);
112  if (!read(filename)) {
113  return false;
114  }
115  }
116 
117  return true;
118 }
119 
120 #endif // WITHIN_PANDA
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: DCFile::read
124 // Access: Published
125 // Description: Opens and reads the indicated .dc file by name. The
126 // distributed classes defined in the file will be
127 // appended to the set of distributed classes already
128 // recorded, if any.
129 //
130 // Returns true if the file is successfully read, false
131 // if there was an error (in which case the file might
132 // have been partially read).
133 ////////////////////////////////////////////////////////////////////
134 bool DCFile::
135 read(Filename filename) {
136 #ifdef WITHIN_PANDA
137  filename.set_text();
139  istream *in = vfs->open_read_file(filename, true);
140  if (in == (istream *)NULL) {
141  cerr << "Cannot open " << filename << " for reading.\n";
142  return false;
143  }
144  bool okflag = read(*in, filename);
145 
146  // For some reason--compiler bug in gcc 3.2?--explicitly deleting
147  // the in pointer does not call the appropriate global delete
148  // function; instead apparently calling the system delete
149  // function. So we call the delete function by hand instead.
150  vfs->close_read_file(in);
151 
152  return okflag;
153 
154 #else // WITHIN_PANDA
155 
156  pifstream in;
157  in.open(filename.c_str());
158 
159  if (!in) {
160  cerr << "Cannot open " << filename << " for reading.\n";
161  return false;
162  }
163 
164  return read(in, filename);
165 
166 #endif // WITHIN_PANDA
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: DCFile::read
171 // Access: Published
172 // Description: Parses the already-opened input stream for
173 // distributed class descriptions. The filename
174 // parameter is optional and is only used when reporting
175 // errors.
176 //
177 // The distributed classes defined in the file will be
178 // appended to the set of distributed classes already
179 // recorded, if any.
180 //
181 // Returns true if the file is successfully read, false
182 // if there was an error (in which case the file might
183 // have been partially read).
184 ////////////////////////////////////////////////////////////////////
185 bool DCFile::
186 read(istream &in, const string &filename) {
187  cerr << "DCFile::read of " << filename << "\n";
188  dc_init_parser(in, filename, *this);
189  dcyyparse();
190  dc_cleanup_parser();
191 
192  return (dc_error_count() == 0);
193 }
194 
195 ////////////////////////////////////////////////////////////////////
196 // Function: DCFile::write
197 // Access: Published
198 // Description: Opens the indicated filename for output and writes a
199 // parseable description of all the known distributed
200 // classes to the file.
201 //
202 // Returns true if the description is successfully
203 // written, false otherwise.
204 ////////////////////////////////////////////////////////////////////
205 bool DCFile::
206 write(Filename filename, bool brief) const {
207  pofstream out;
208 
209 #ifdef WITHIN_PANDA
210  filename.set_text();
211  filename.open_write(out);
212 #else
213  out.open(filename.c_str());
214 #endif
215 
216  if (!out) {
217  cerr << "Can't open " << filename << " for output.\n";
218  return false;
219  }
220  return write(out, brief);
221 }
222 
223 ////////////////////////////////////////////////////////////////////
224 // Function: DCFile::write
225 // Access: Published
226 // Description: Writes a parseable description of all the known
227 // distributed classes to the stream.
228 //
229 // Returns true if the description is successfully
230 // written, false otherwise.
231 ////////////////////////////////////////////////////////////////////
232 bool DCFile::
233 write(ostream &out, bool brief) const {
234  if (!_imports.empty()) {
235  Imports::const_iterator ii;
236  for (ii = _imports.begin(); ii != _imports.end(); ++ii) {
237  const Import &import = (*ii);
238  if (import._symbols.empty()) {
239  out << "import " << import._module << "\n";
240  } else {
241  out << "from " << import._module << " import ";
242  ImportSymbols::const_iterator si = import._symbols.begin();
243  out << *si;
244  ++si;
245  while (si != import._symbols.end()) {
246  out << ", " << *si;
247  ++si;
248  }
249  out << "\n";
250  }
251  }
252  out << "\n";
253  }
254 
255  Declarations::const_iterator di;
256  for (di = _declarations.begin(); di != _declarations.end(); ++di) {
257  (*di)->write(out, brief, 0);
258  out << "\n";
259  }
260 
261  return !out.fail();
262 }
263 
264 ////////////////////////////////////////////////////////////////////
265 // Function: DCFile::get_num_classes
266 // Access: Published
267 // Description: Returns the number of classes read from the .dc
268 // file(s).
269 ////////////////////////////////////////////////////////////////////
270 int DCFile::
272  return _classes.size();
273 }
274 
275 ////////////////////////////////////////////////////////////////////
276 // Function: DCFile::get_class
277 // Access: Published
278 // Description: Returns the nth class read from the .dc file(s).
279 ////////////////////////////////////////////////////////////////////
281 get_class(int n) const {
282  nassertr(n >= 0 && n < (int)_classes.size(), NULL);
283  return _classes[n];
284 }
285 
286 ////////////////////////////////////////////////////////////////////
287 // Function: DCFile::get_class_by_name
288 // Access: Published
289 // Description: Returns the class that has the indicated name, or
290 // NULL if there is no such class.
291 ////////////////////////////////////////////////////////////////////
293 get_class_by_name(const string &name) const {
294  ThingsByName::const_iterator ni;
295  ni = _things_by_name.find(name);
296  if (ni != _things_by_name.end()) {
297  return (*ni).second->as_class();
298  }
299 
300  return (DCClass *)NULL;
301 }
302 
303 ////////////////////////////////////////////////////////////////////
304 // Function: DCFile::get_switch_by_name
305 // Access: Published
306 // Description: Returns the switch that has the indicated name, or
307 // NULL if there is no such switch.
308 ////////////////////////////////////////////////////////////////////
310 get_switch_by_name(const string &name) const {
311  ThingsByName::const_iterator ni;
312  ni = _things_by_name.find(name);
313  if (ni != _things_by_name.end()) {
314  return (*ni).second->as_switch();
315  }
316 
317  return (DCSwitch *)NULL;
318 }
319 
320 ////////////////////////////////////////////////////////////////////
321 // Function: DCFile::get_field_by_index
322 // Access: Published, Static
323 // Description: Returns a pointer to the one DCField that has the
324 // indicated index number, of all the DCFields across
325 // all classes in the file.
326 //
327 // This method is only valid if dc-multiple-inheritance
328 // is set true in the Config.prc file. Without this
329 // setting, different DCFields may share the same index
330 // number, so this global lookup is not possible.
331 ////////////////////////////////////////////////////////////////////
333 get_field_by_index(int index_number) const {
334  nassertr(dc_multiple_inheritance, NULL);
335 
336  if (index_number >= 0 && index_number < (int)_fields_by_index.size()) {
337  return _fields_by_index[index_number];
338  }
339 
340  return NULL;
341 }
342 
343 ////////////////////////////////////////////////////////////////////
344 // Function: DCFile::get_num_import_modules
345 // Access: Published
346 // Description: Returns the number of import lines read from the .dc
347 // file(s).
348 ////////////////////////////////////////////////////////////////////
349 int DCFile::
351  return _imports.size();
352 }
353 
354 ////////////////////////////////////////////////////////////////////
355 // Function: DCFile::get_import_module
356 // Access: Published
357 // Description: Returns the module named by the nth import line read
358 // from the .dc file(s).
359 ////////////////////////////////////////////////////////////////////
360 string DCFile::
361 get_import_module(int n) const {
362  nassertr(n >= 0 && n < (int)_imports.size(), string());
363  return _imports[n]._module;
364 }
365 
366 ////////////////////////////////////////////////////////////////////
367 // Function: DCFile::get_num_import_symbols
368 // Access: Published
369 // Description: Returns the number of symbols explicitly imported by
370 // the nth import line. If this is 0, the line is
371 // "import modulename"; if it is more than 0, the line
372 // is "from modulename import symbol, symbol ... ".
373 ////////////////////////////////////////////////////////////////////
374 int DCFile::
376  nassertr(n >= 0 && n < (int)_imports.size(), 0);
377  return _imports[n]._symbols.size();
378 }
379 
380 ////////////////////////////////////////////////////////////////////
381 // Function: DCFile::get_import_symbol
382 // Access: Published
383 // Description: Returns the ith symbol named by the nth import line
384 // read from the .dc file(s).
385 ////////////////////////////////////////////////////////////////////
386 string DCFile::
387 get_import_symbol(int n, int i) const {
388  nassertr(n >= 0 && n < (int)_imports.size(), string());
389  nassertr(i >= 0 && i < (int)_imports[n]._symbols.size(), string());
390  return _imports[n]._symbols[i];
391 }
392 
393 ////////////////////////////////////////////////////////////////////
394 // Function: DCFile::get_num_typedefs
395 // Access: Published
396 // Description: Returns the number of typedefs read from the .dc
397 // file(s).
398 ////////////////////////////////////////////////////////////////////
399 int DCFile::
401  return _typedefs.size();
402 }
403 
404 ////////////////////////////////////////////////////////////////////
405 // Function: DCFile::get_typedef
406 // Access: Published
407 // Description: Returns the nth typedef read from the .dc file(s).
408 ////////////////////////////////////////////////////////////////////
410 get_typedef(int n) const {
411  nassertr(n >= 0 && n < (int)_typedefs.size(), NULL);
412  return _typedefs[n];
413 }
414 
415 ////////////////////////////////////////////////////////////////////
416 // Function: DCFile::get_typedef_by_name
417 // Access: Published
418 // Description: Returns the typedef that has the indicated name, or
419 // NULL if there is no such typedef name.
420 ////////////////////////////////////////////////////////////////////
422 get_typedef_by_name(const string &name) const {
423  TypedefsByName::const_iterator ni;
424  ni = _typedefs_by_name.find(name);
425  if (ni != _typedefs_by_name.end()) {
426  return (*ni).second;
427  }
428 
429  return NULL;
430 }
431 
432 ////////////////////////////////////////////////////////////////////
433 // Function: DCFile::get_num_keywords
434 // Access: Published
435 // Description: Returns the number of keywords read from the .dc
436 // file(s).
437 ////////////////////////////////////////////////////////////////////
438 int DCFile::
440  return _keywords.get_num_keywords();
441 }
442 
443 ////////////////////////////////////////////////////////////////////
444 // Function: DCFile::get_keyword
445 // Access: Published
446 // Description: Returns the nth keyword read from the .dc file(s).
447 ////////////////////////////////////////////////////////////////////
448 const DCKeyword *DCFile::
449 get_keyword(int n) const {
450  return _keywords.get_keyword(n);
451 }
452 
453 ////////////////////////////////////////////////////////////////////
454 // Function: DCFile::get_keyword_by_name
455 // Access: Published
456 // Description: Returns the keyword that has the indicated name, or
457 // NULL if there is no such keyword name.
458 ////////////////////////////////////////////////////////////////////
459 const DCKeyword *DCFile::
460 get_keyword_by_name(const string &name) const {
461  const DCKeyword *keyword = _keywords.get_keyword_by_name(name);
462  if (keyword == (const DCKeyword *)NULL) {
463  keyword = _default_keywords.get_keyword_by_name(name);
464  if (keyword != (const DCKeyword *)NULL) {
465  // One of the historical default keywords was used, but wasn't
466  // defined. Define it implicitly right now.
467  ((DCFile *)this)->_keywords.add_keyword(keyword);
468  }
469  }
470 
471  return keyword;
472 }
473 
474 ////////////////////////////////////////////////////////////////////
475 // Function: DCFile::get_hash
476 // Access: Published
477 // Description: Returns a 32-bit hash index associated with this
478 // file. This number is guaranteed to be consistent if
479 // the contents of the file have not changed, and it is
480 // very likely to be different if the contents of the
481 // file do change.
482 ////////////////////////////////////////////////////////////////////
483 unsigned long DCFile::
484 get_hash() const {
485  HashGenerator hashgen;
486  generate_hash(hashgen);
487  return hashgen.get_hash();
488 }
489 
490 ////////////////////////////////////////////////////////////////////
491 // Function: DCFile::generate_hash
492 // Access: Public, Virtual
493 // Description: Accumulates the properties of this file into the
494 // hash.
495 ////////////////////////////////////////////////////////////////////
496 void DCFile::
497 generate_hash(HashGenerator &hashgen) const {
498  if (dc_virtual_inheritance) {
499  // Just to make the hash number change in this case.
500  if (dc_sort_inheritance_by_file) {
501  hashgen.add_int(1);
502  } else {
503  hashgen.add_int(2);
504  }
505  }
506 
507  hashgen.add_int(_classes.size());
508  Classes::const_iterator ci;
509  for (ci = _classes.begin(); ci != _classes.end(); ++ci) {
510  (*ci)->generate_hash(hashgen);
511  }
512 }
513 
514 ////////////////////////////////////////////////////////////////////
515 // Function: DCFile::add_class
516 // Access: Public
517 // Description: Adds the newly-allocated distributed class definition
518 // to the file. The DCFile becomes the owner of the
519 // pointer and will delete it when it destructs.
520 // Returns true if the class is successfully added, or
521 // false if there was a name conflict.
522 ////////////////////////////////////////////////////////////////////
523 bool DCFile::
524 add_class(DCClass *dclass) {
525  if (!dclass->get_name().empty()) {
526  bool inserted = _things_by_name.insert
527  (ThingsByName::value_type(dclass->get_name(), dclass)).second;
528 
529  if (!inserted) {
530  return false;
531  }
532  }
533 
534  if (!dclass->is_struct()) {
535  dclass->set_number(get_num_classes());
536  }
537  _classes.push_back(dclass);
538 
539  if (dclass->is_bogus_class()) {
540  _all_objects_valid = false;
541  }
542 
543  if (!dclass->is_bogus_class()) {
544  _declarations.push_back(dclass);
545  } else {
546  _things_to_delete.push_back(dclass);
547  }
548 
549  return true;
550 }
551 
552 ////////////////////////////////////////////////////////////////////
553 // Function: DCFile::add_switch
554 // Access: Public
555 // Description: Adds the newly-allocated switch definition
556 // to the file. The DCFile becomes the owner of the
557 // pointer and will delete it when it destructs.
558 // Returns true if the switch is successfully added, or
559 // false if there was a name conflict.
560 ////////////////////////////////////////////////////////////////////
561 bool DCFile::
562 add_switch(DCSwitch *dswitch) {
563  if (!dswitch->get_name().empty()) {
564  bool inserted = _things_by_name.insert
565  (ThingsByName::value_type(dswitch->get_name(), dswitch)).second;
566 
567  if (!inserted) {
568  return false;
569  }
570  }
571 
572  _declarations.push_back(dswitch);
573 
574  return true;
575 }
576 
577 ////////////////////////////////////////////////////////////////////
578 // Function: DCFile::add_import_module
579 // Access: Public
580 // Description: Adds a new name to the list of names of Python
581 // modules that are to be imported by the client or AI
582 // to define the code that is associated with the class
583 // interfaces named within the .dc file.
584 ////////////////////////////////////////////////////////////////////
585 void DCFile::
586 add_import_module(const string &import_module) {
587  Import import;
588  import._module = import_module;
589  _imports.push_back(import);
590 }
591 
592 ////////////////////////////////////////////////////////////////////
593 // Function: DCFile::add_import_symbol
594 // Access: Public
595 // Description: Adds a new name to the list of symbols that are to be
596 // explicitly imported from the most-recently added
597 // module, e.g. "from module_name import symbol". If
598 // the list of symbols is empty, the syntax is taken to
599 // be "import module_name".
600 ////////////////////////////////////////////////////////////////////
601 void DCFile::
602 add_import_symbol(const string &import_symbol) {
603  nassertv(!_imports.empty());
604  _imports.back()._symbols.push_back(import_symbol);
605 }
606 
607 ////////////////////////////////////////////////////////////////////
608 // Function: DCFile::add_typedef
609 // Access: Public
610 // Description: Adds the newly-allocated distributed typedef definition
611 // to the file. The DCFile becomes the owner of the
612 // pointer and will delete it when it destructs.
613 // Returns true if the typedef is successfully added, or
614 // false if there was a name conflict.
615 ////////////////////////////////////////////////////////////////////
616 bool DCFile::
617 add_typedef(DCTypedef *dtypedef) {
618  bool inserted = _typedefs_by_name.insert
619  (TypedefsByName::value_type(dtypedef->get_name(), dtypedef)).second;
620 
621  if (!inserted) {
622  return false;
623  }
624 
625  dtypedef->set_number(get_num_typedefs());
626  _typedefs.push_back(dtypedef);
627 
628  if (dtypedef->is_bogus_typedef()) {
629  _all_objects_valid = false;
630  }
631 
632  if (!dtypedef->is_bogus_typedef() && !dtypedef->is_implicit_typedef()) {
633  _declarations.push_back(dtypedef);
634  } else {
635  _things_to_delete.push_back(dtypedef);
636  }
637 
638  return true;
639 }
640 
641 ////////////////////////////////////////////////////////////////////
642 // Function: DCFile::add_keyword
643 // Access: Public
644 // Description: Adds the indicated keyword string to the list of
645 // keywords known to the DCFile. These keywords may
646 // then be added to DCFields. It is not an error to add
647 // a particular keyword more than once.
648 ////////////////////////////////////////////////////////////////////
649 bool DCFile::
650 add_keyword(const string &name) {
651  DCKeyword *keyword = new DCKeyword(name);
652  bool added = _keywords.add_keyword(keyword);
653 
654  if (added) {
655  _declarations.push_back(keyword);
656  } else {
657  delete keyword;
658  }
659 
660  return added;
661 }
662 
663 ////////////////////////////////////////////////////////////////////
664 // Function: DCFile::add_thing_to_delete
665 // Access: Public
666 // Description: Adds the indicated declaration to the list of
667 // declarations that are not reported with the file, but
668 // will be deleted when the DCFile object destructs.
669 // That is, transfers ownership of the indicated pointer
670 // to the DCFile.
671 ////////////////////////////////////////////////////////////////////
672 void DCFile::
674  _things_to_delete.push_back(decl);
675 }
676 
677 ////////////////////////////////////////////////////////////////////
678 // Function: DCFile::set_new_index_number
679 // Access: Public
680 // Description: Sets the next sequential available index number on
681 // the indicated field. This is only meant to be called
682 // by DCClass::add_field(), while the dc file is being
683 // parsed.
684 ////////////////////////////////////////////////////////////////////
685 void DCFile::
687  field->set_number((int)_fields_by_index.size());
688  _fields_by_index.push_back(field);
689 }
690 
691 ////////////////////////////////////////////////////////////////////
692 // Function: DCFile::setup_default_keywords
693 // Access: Private
694 // Description: Adds an entry for each of the default keywords that
695 // are defined for every DCFile for legacy reasons.
696 ////////////////////////////////////////////////////////////////////
697 void DCFile::
698 setup_default_keywords() {
699  struct KeywordDef {
700  const char *name;
701  int flag;
702  };
703  static KeywordDef default_keywords[] = {
704  { "required", 0x0001 },
705  { "broadcast", 0x0002 },
706  { "ownrecv", 0x0004 },
707  { "ram", 0x0008 },
708  { "db", 0x0010 },
709  { "clsend", 0x0020 },
710  { "clrecv", 0x0040 },
711  { "ownsend", 0x0080 },
712  { "airecv", 0x0100 },
713  { NULL, 0 }
714  };
715 
716  _default_keywords.clear_keywords();
717  for (int i = 0; default_keywords[i].name != NULL; ++i) {
718  DCKeyword *keyword =
719  new DCKeyword(default_keywords[i].name,
720  default_keywords[i].flag);
721 
722  _default_keywords.add_keyword(keyword);
723  _things_to_delete.push_back(keyword);
724  }
725 }
726 
727 ////////////////////////////////////////////////////////////////////
728 // Function: DCFile::rebuild_inherited_fields
729 // Access: Private
730 // Description: Reconstructs the inherited fields table of all
731 // classes.
732 ////////////////////////////////////////////////////////////////////
733 void DCFile::
734 rebuild_inherited_fields() {
735  _inherited_fields_stale = false;
736 
737  Classes::iterator ci;
738  for (ci = _classes.begin(); ci != _classes.end(); ++ci) {
739  (*ci)->clear_inherited_fields();
740  }
741  for (ci = _classes.begin(); ci != _classes.end(); ++ci) {
742  (*ci)->rebuild_inherited_fields();
743  }
744 }
bool is_struct() const
Returns true if the class has been identified with the &quot;struct&quot; keyword in the dc file...
Definition: dcClass.I:56
This represents a single keyword declaration in the dc file.
Definition: dcKeyword.h:31
void add_import_symbol(const string &import_symbol)
Adds a new name to the list of symbols that are to be explicitly imported from the most-recently adde...
Definition: dcFile.cxx:602
void set_number(int number)
Assigns the unique number to this typedef.
Definition: dcTypedef.cxx:144
const DCKeyword * get_keyword_by_name(const string &name) const
Returns the keyword that has the indicated name, or NULL if there is no such keyword name...
Definition: dcFile.cxx:460
const DCKeyword * get_keyword(int n) const
Returns the nth keyword in the list.
This represents a single typedef declaration in the dc file.
Definition: dcTypedef.h:29
int get_num_import_symbols(int n) const
Returns the number of symbols explicitly imported by the nth import line.
Definition: dcFile.cxx:375
DCField * get_field_by_index(int index_number) const
Returns a pointer to the one DCField that has the indicated index number, of all the DCFields across ...
Definition: dcFile.cxx:333
int get_num_keywords() const
Returns the number of keywords read from the .dc file(s).
Definition: dcFile.cxx:439
const string & get_name() const
Returns the name of this class.
Definition: dcClass.I:32
int get_num_keywords() const
Returns the number of keywords in the list.
void add_int(int num)
Adds another integer to the hash so far.
DCTypedef * get_typedef(int n) const
Returns the nth typedef read from the .dc file(s).
Definition: dcFile.cxx:410
A single field of a Distributed Class, either atomic or molecular.
Definition: dcField.h:40
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS&#39;s file system.
DCTypedef * get_typedef_by_name(const string &name) const
Returns the typedef that has the indicated name, or NULL if there is no such typedef name...
Definition: dcFile.cxx:422
bool add_class(DCClass *dclass)
Adds the newly-allocated distributed class definition to the file.
Definition: dcFile.cxx:524
void set_text()
Indicates that the filename represents a text file.
Definition: filename.I:507
void set_number(int number)
Assigns the unique number to this field.
Definition: dcField.I:210
bool read(Filename filename)
Opens and reads the indicated .dc file by name.
Definition: dcFile.cxx:135
This represents a switch statement, which can appear inside a class body and represents two or more a...
Definition: dcSwitch.h:33
Defines a particular DistributedClass as read from an input .dc file.
Definition: dcClass.h:47
unsigned long get_hash() const
Returns a 32-bit hash index associated with this file.
Definition: dcFile.cxx:484
string get_import_module(int n) const
Returns the module named by the nth import line read from the .dc file(s).
Definition: dcFile.cxx:361
DCSwitch * get_switch_by_name(const string &name) const
Returns the switch that has the indicated name, or NULL if there is no such switch.
Definition: dcFile.cxx:310
bool add_typedef(DCTypedef *dtypedef)
Adds the newly-allocated distributed typedef definition to the file.
Definition: dcFile.cxx:617
void set_new_index_number(DCField *field)
Sets the next sequential available index number on the indicated field.
Definition: dcFile.cxx:686
string get_import_symbol(int n, int i) const
Returns the ith symbol named by the nth import line read from the .dc file(s).
Definition: dcFile.cxx:387
bool is_implicit_typedef() const
Returns true if the typedef has been flagged as an implicit typedef, meaning it was created for a DCC...
Definition: dcTypedef.cxx:118
This class is similar to ConfigVariable, but it reports its value as a list of strings.
static void close_read_file(istream *stream)
Closes a file opened by a previous call to open_read_file().
Represents the complete list of Distributed Class descriptions as read from a .dc file...
Definition: dcFile.h:34
DCClass * get_class(int n) const
Returns the nth class read from the .dc file(s).
Definition: dcFile.cxx:281
bool add_switch(DCSwitch *dswitch)
Adds the newly-allocated switch definition to the file.
Definition: dcFile.cxx:562
int get_num_classes() const
Returns the number of classes read from the .dc file(s).
Definition: dcFile.cxx:271
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this file into the hash.
Definition: dcFile.cxx:497
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
int get_num_import_modules() const
Returns the number of import lines read from the .dc file(s).
Definition: dcFile.cxx:350
This is a common interface for a declaration in a DC file.
Definition: dcDeclaration.h:33
const string & get_name() const
Returns the name of this typedef.
Definition: dcTypedef.cxx:79
void add_thing_to_delete(DCDeclaration *decl)
Adds the indicated declaration to the list of declarations that are not reported with the file...
Definition: dcFile.cxx:673
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
void add_import_module(const string &import_module)
Adds a new name to the list of names of Python modules that are to be imported by the client or AI to...
Definition: dcFile.cxx:586
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:26
bool is_bogus_typedef() const
Returns true if the typedef has been flagged as a bogus typedef.
Definition: dcTypedef.cxx:106
const string & get_name() const
Returns the name of this switch.
Definition: dcSwitch.cxx:93
istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read...
bool add_keyword(const DCKeyword *keyword)
Adds the indicated keyword to the list.
bool write(Filename filename, bool brief) const
Opens the indicated filename for output and writes a parseable description of all the known distribut...
Definition: dcFile.cxx:206
void clear()
Removes all of the classes defined within the DCFile and prepares it for reading a new file...
Definition: dcFile.cxx:63
void clear_keywords()
Removes all keywords from the field.
bool is_bogus_class() const
Returns true if the class has been flagged as a bogus class.
Definition: dcClass.I:70
int get_num_typedefs() const
Returns the number of typedefs read from the .dc file(s).
Definition: dcFile.cxx:400
DCClass * get_class_by_name(const string &name) const
Returns the class that has the indicated name, or NULL if there is no such class. ...
Definition: dcFile.cxx:293
unsigned long get_hash() const
Returns the hash number generated.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
Definition: filename.cxx:2045
static string expand_string(const string &str)
Reads the string, looking for environment variable names marked by a $.
bool add_keyword(const string &name)
Adds the indicated keyword string to the list of keywords known to the DCFile.
Definition: dcFile.cxx:650
const DCKeyword * get_keyword_by_name(const string &name) const
Returns the keyword in the list with the indicated name, or NULL if there is no keyword in the list w...
const DCKeyword * get_keyword(int n) const
Returns the nth keyword read from the .dc file(s).
Definition: dcFile.cxx:449
void set_number(int number)
Assigns the unique number to this class.
Definition: dcClass.cxx:1538
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Definition: filename.cxx:332