Go to the documentation of this file.
40 _all_objects_valid =
true;
41 _inherited_fields_stale =
false;
43 setup_default_keywords();
60 Declarations::iterator di;
61 for (di = _declarations.begin(); di != _declarations.end(); ++di) {
64 for (di = _things_to_delete.begin(); di != _things_to_delete.end(); ++di) {
70 _things_by_name.clear();
72 _typedefs_by_name.clear();
74 _declarations.clear();
75 _things_to_delete.clear();
76 setup_default_keywords();
78 _all_objects_valid =
true;
79 _inherited_fields_stale =
false;
91 (
"dc-file", PRC_DESC(
"The list of dc files to load."));
93 if (dc_files.size() == 0) {
94 cerr <<
"No files specified via dc-file Config.prc variable!\n";
98 int size = dc_files.size();
102 for (
int i = size - 1; i >= 0; --i) {
105 if (!
read(filename)) {
113 #endif // WITHIN_PANDA
130 cerr <<
"Cannot open " << filename <<
" for reading.\n";
133 bool okflag =
read(*in, filename);
143 #else // WITHIN_PANDA
146 in.open(filename.c_str());
149 cerr <<
"Cannot open " << filename <<
" for reading.\n";
153 return read(in, filename);
155 #endif // WITHIN_PANDA
169 read(std::istream &in,
const string &filename) {
170 cerr <<
"DCFile::read of " << filename <<
"\n";
171 dc_init_parser(in, filename, *
this);
175 return (dc_error_count() == 0);
192 out.open(filename.c_str());
196 cerr <<
"Can't open " << filename <<
" for output.\n";
199 return write(out, brief);
209 write(std::ostream &out,
bool brief)
const {
210 if (!_imports.empty()) {
211 Imports::const_iterator ii;
212 for (ii = _imports.begin(); ii != _imports.end(); ++ii) {
213 const Import &
import = (*ii);
214 if (
import._symbols.empty()) {
215 out <<
"import " <<
import._module <<
"\n";
217 out <<
"from " <<
import._module <<
" import ";
218 ImportSymbols::const_iterator si =
import._symbols.begin();
221 while (si !=
import._symbols.end()) {
231 Declarations::const_iterator di;
232 for (di = _declarations.begin(); di != _declarations.end(); ++di) {
233 (*di)->write(out, brief, 0);
245 return _classes.size();
253 nassertr(n >= 0 && n < (
int)_classes.size(),
nullptr);
263 ThingsByName::const_iterator ni;
264 ni = _things_by_name.find(name);
265 if (ni != _things_by_name.end()) {
266 return (*ni).second->as_class();
278 ThingsByName::const_iterator ni;
279 ni = _things_by_name.find(name);
280 if (ni != _things_by_name.end()) {
281 return (*ni).second->as_switch();
297 nassertr(dc_multiple_inheritance,
nullptr);
299 if (index_number >= 0 && index_number < (
int)_fields_by_index.size()) {
300 return _fields_by_index[index_number];
311 return _imports.size();
319 nassertr(n >= 0 && n < (
int)_imports.size(),
string());
320 return _imports[n]._module;
330 nassertr(n >= 0 && n < (
int)_imports.size(), 0);
331 return _imports[n]._symbols.size();
340 nassertr(n >= 0 && n < (
int)_imports.size(),
string());
341 nassertr(i >= 0 && i < (
int)_imports[n]._symbols.size(),
string());
342 return _imports[n]._symbols[i];
350 return _typedefs.size();
358 nassertr(n >= 0 && n < (
int)_typedefs.size(),
nullptr);
368 TypedefsByName::const_iterator ni;
369 ni = _typedefs_by_name.find(name);
370 if (ni != _typedefs_by_name.end()) {
400 if (keyword ==
nullptr) {
402 if (keyword !=
nullptr) {
405 ((
DCFile *)
this)->_keywords.add_keyword(keyword);
430 if (dc_virtual_inheritance) {
432 if (dc_sort_inheritance_by_file) {
439 hashgen.
add_int(_classes.size());
440 Classes::const_iterator ci;
441 for (ci = _classes.begin(); ci != _classes.end(); ++ci) {
442 (*ci)->generate_hash(hashgen);
455 bool inserted = _things_by_name.insert
456 (ThingsByName::value_type(dclass->
get_name(), dclass)).second;
466 _classes.push_back(dclass);
469 _all_objects_valid =
false;
473 _declarations.push_back(dclass);
475 _things_to_delete.push_back(dclass);
490 bool inserted = _things_by_name.insert
491 (ThingsByName::value_type(dswitch->
get_name(), dswitch)).second;
498 _declarations.push_back(dswitch);
511 import._module = import_module;
512 _imports.push_back(
import);
523 nassertv(!_imports.empty());
524 _imports.back()._symbols.push_back(import_symbol);
535 bool inserted = _typedefs_by_name.insert
536 (TypedefsByName::value_type(dtypedef->
get_name(), dtypedef)).second;
543 _typedefs.push_back(dtypedef);
546 _all_objects_valid =
false;
550 _declarations.push_back(dtypedef);
552 _things_to_delete.push_back(dtypedef);
569 _declarations.push_back(keyword);
585 _things_to_delete.push_back(decl);
594 field->
set_number((
int)_fields_by_index.size());
595 _fields_by_index.push_back(field);
603 setup_default_keywords() {
608 static KeywordDef default_keywords[] = {
609 {
"required", 0x0001 },
610 {
"broadcast", 0x0002 },
611 {
"ownrecv", 0x0004 },
614 {
"clsend", 0x0020 },
615 {
"clrecv", 0x0040 },
616 {
"ownsend", 0x0080 },
617 {
"airecv", 0x0100 },
622 for (
int i = 0; default_keywords[i].name !=
nullptr; ++i) {
625 default_keywords[i].flag);
628 _things_to_delete.push_back(keyword);
636 rebuild_inherited_fields() {
637 _inherited_fields_stale =
false;
639 Classes::iterator ci;
640 for (ci = _classes.begin(); ci != _classes.end(); ++ci) {
641 (*ci)->clear_inherited_fields();
643 for (ci = _classes.begin(); ci != _classes.end(); ++ci) {
644 (*ci)->rebuild_inherited_fields();
void set_text()
Indicates that the filename represents a text file.
This is a common interface for a declaration in a DC file.
bool is_bogus_class() const
Returns true if the class has been flagged as a bogus class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
bool read(Filename filename)
Opens and reads the indicated .dc file by name.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
void set_new_index_number(DCField *field)
Sets the next sequential available index number on the indicated field.
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this file into the hash.
void set_number(int number)
Assigns the unique number to this typedef.
bool write(Filename filename, bool brief) const
Opens the indicated filename for output and writes a parseable description of all the known distribut...
std::string get_import_module(int n) const
Returns the module named by the nth import line read from the .dc file(s).
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 ...
This represents a single keyword declaration in the dc file.
void add_int(int num)
Adds another integer to the hash so far.
Represents the complete list of Distributed Class descriptions as read from a .dc file.
bool add_switch(DCSwitch *dswitch)
Adds the newly-allocated switch definition to the file.
const DCKeyword * get_keyword(int n) const
Returns the nth keyword in the list.
void set_number(int number)
Assigns the unique number to this field.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A single field of a Distributed Class, either atomic or molecular.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const std::string & get_name() const
Returns the name of this switch.
unsigned long get_hash() const
Returns a 32-bit hash index associated with this file.
DCSwitch * get_switch_by_name(const std::string &name) const
Returns the switch that has the indicated name, or NULL if there is no such switch.
bool add_typedef(DCTypedef *dtypedef)
Adds the newly-allocated distributed typedef definition to the file.
const DCKeyword * get_keyword_by_name(const std::string &name) const
Returns the keyword that has the indicated name, or NULL if there is no such keyword name.
int get_num_import_symbols(int n) const
Returns the number of symbols explicitly imported by the nth import line.
int get_num_typedefs() const
Returns the number of typedefs read from the .dc file(s).
A hierarchy of directories and files that appears to be one continuous file system,...
DCTypedef * get_typedef(int n) const
Returns the nth typedef read from the .dc file(s).
DCClass * get_class(int n) const
Returns the nth class read from the .dc file(s).
static std::string expand_string(const std::string &str)
Reads the string, looking for environment variable names marked by a $.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_keywords() const
Returns the number of keywords in the list.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_keywords() const
Returns the number of keywords read from the .dc file(s).
void add_import_module(const std::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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_number(int number)
Assigns the unique number to this class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a switch statement, which can appear inside a class body and represents two or more a...
bool is_bogus_typedef() const
Returns true if the typedef has been flagged as a bogus typedef.
void add_thing_to_delete(DCDeclaration *decl)
Adds the indicated declaration to the list of declarations that are not reported with the file,...
This class is similar to ConfigVariable, but it reports its value as a list of strings.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_implicit_typedef() const
Returns true if the typedef has been flagged as an implicit typedef, meaning it was created for a DCC...
void clear_keywords()
Removes all keywords from the field.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
bool add_keyword(const DCKeyword *keyword)
Adds the indicated keyword to the list.
void add_import_symbol(const std::string &import_symbol)
Adds a new name to the list of symbols that are to be explicitly imported from the most-recently adde...
const std::string & get_name() const
Returns the name of this class.
void clear()
Removes all of the classes defined within the DCFile and prepares it for reading a new file.
std::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).
const DCKeyword * get_keyword(int n) const
Returns the nth keyword read from the .dc file(s).
const DCKeyword * get_keyword_by_name(const std::string &name) const
Returns the keyword in the list with the indicated name, or NULL if there is no keyword in the list w...
std::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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DCClass * get_class_by_name(const std::string &name) const
Returns the class that has the indicated name, or NULL if there is no such class.
int get_num_import_modules() const
Returns the number of import lines read from the .dc file(s).
This represents a single typedef declaration in the dc file.
This class generates an arbitrary hash number from a sequence of ints.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_classes() const
Returns the number of classes read from the .dc file(s).
const std::string & get_name() const
Returns the name of this typedef.
bool add_keyword(const std::string &name)
Adds the indicated keyword string to the list of keywords known to the DCFile.
bool is_struct() const
Returns true if the class has been identified with the "struct" keyword in the dc file,...
Defines a particular DistributedClass as read from an input .dc file.
The name of a file, such as a texture file or an Egg file.
DCTypedef * get_typedef_by_name(const std::string &name) const
Returns the typedef that has the indicated name, or NULL if there is no such typedef name.
unsigned long get_hash() const
Returns the hash number generated.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool add_class(DCClass *dclass)
Adds the newly-allocated distributed class definition to the file.