18 #include "dcTypedef.h" 19 #include "memoryUsage.h" 21 #include "panda_getopt.h" 28 "dcparse [options] [file1 file2 ...]\n" 36 "This program reads one or more DC files, which are used to describe the\n" 37 "communication channels in the distributed class system. By default,\n" 38 "the file(s) are read and concatenated, and a single hash code is printed\n" 39 "corresponding to the file's contents.\n\n" 43 " -v Writes a complete parseable version of the file to standard\n" 44 " output instead of printing a hash code.\n\n" 46 " -b Writes a brief parseable version of the file instead of a full\n" 47 " version. This is semantically the same as the output produced\n" 48 " the above -v option--reading it would produce exactly the same\n" 49 " results--but it is designed to be slightly obfuscated. The\n" 50 " comments and parameter names are not included.\n\n" 52 " -c Write a list of class names, showing the inheritance hierarchy.\n" 53 " Some class names will be listed twice in the presence of multiple\n" 56 " -f Write a complete list of field names available for each class,\n" 57 " including all inherited fields.\n\n";
61 write_class_hierarchy(
int indent_level,
const DCFile &file,
63 indent(cout, indent_level)
67 for (
int i = 0; i < num_classes; ++i) {
69 bool is_my_child =
false;
71 for (
int j = 0; j < num_parents && !is_my_child; ++j) {
72 is_my_child = (dclass->
get_parent(j) == this_dclass);
76 write_class_hierarchy(indent_level + 2, file, dclass);
82 write_class_hierarchy(
const DCFile &file) {
84 for (
int i = 0; i < num_classes; ++i) {
87 write_class_hierarchy(0, file, dclass);
94 write_complete_field_list(
const DCFile &file) {
96 for (
int i = 0; i < num_classes; ++i) {
98 cout <<
"\n" << dclass->
get_name() <<
"\n";
100 for (
int j = 0; j < num_inherited_fields; ++j) {
112 field->output_keywords(cout);
119 main(
int argc,
char *argv[]) {
122 const char *optstr =
"bvcfh";
124 bool dump_verbose =
false;
125 bool dump_brief =
false;
126 bool dump_classes =
false;
127 bool dump_fields =
false;
129 int flag = getopt(argc, argv, optstr);
131 while (flag != EOF) {
156 flag = getopt(argc, argv, optstr);
168 for (
int i = 1; i < argc; i++) {
169 if (!file.
read(argv[i])) {
175 cerr <<
"File is incomplete. The following objects are undefined:\n";
179 for (i = 0; i < num_typedefs; i++) {
182 cerr <<
" " << dtypedef->
get_name() <<
"\n";
187 for (i = 0; i < num_classes; i++) {
190 cerr <<
" " << dclass->
get_name() <<
"\n";
197 if (dump_verbose || dump_brief) {
198 if (!file.
write(cout, dump_brief)) {
202 }
else if (dump_classes) {
203 write_class_hierarchy(file);
205 }
else if (dump_fields) {
206 write_complete_field_list(file);
209 unsigned long hash = file.
get_hash();
210 cerr <<
"File hash is " << hash <<
" (signed " << (long)hash <<
")\n";
213 #ifdef DO_MEMORY_USAGE 214 if (MemoryUsage::is_tracking()) {
216 MemoryUsage::show_current_types();
217 for (
int i = 1; i < argc; i++) {
221 MemoryUsage::show_current_types();
This represents a single typedef declaration in the dc file.
DCClass * get_class() const
Returns the DCClass pointer for the class that contains this field.
DCClass * get_parent(int n) const
Returns the nth parent class this class inherits from.
A single field of a Distributed Class, either atomic or molecular.
const string & get_name() const
Returns the name of this field, or empty string if the field is unnamed.
virtual DCAtomicField * as_atomic_field()
Returns the same field pointer converted to an atomic field pointer, if this is in fact an atomic fie...
bool read(Filename filename)
Opens and reads the indicated .dc file by name.
Defines a particular DistributedClass as read from an input .dc file.
int get_num_typedefs() const
Returns the number of typedefs read from the .dc file(s).
bool write(Filename filename, bool brief) const
Opens the indicated filename for output and writes a parseable description of all the known distribut...
A single atomic field of a Distributed Class, as read from a .dc file.
virtual DCMolecularField * as_molecular_field()
Returns the same field pointer converted to a molecular field pointer, if this is in fact a molecular...
DCTypedef * get_typedef(int n) const
Returns the nth typedef read from the .dc file(s).
bool all_objects_valid() const
Returns true if all of the classes read from the DC file were defined and valid, or false if any of t...
Represents the complete list of Distributed Class descriptions as read from a .dc file...
DCClass * get_class(int n) const
Returns the nth class read from the .dc file(s).
DCField * get_inherited_field(int n) const
Returns the nth field field in the class and all of its ancestors.
unsigned long get_hash() const
Returns a 32-bit hash index associated with this file.
bool is_bogus_typedef() const
Returns true if the typedef has been flagged as a bogus typedef.
const string & get_name() const
Returns the name of this typedef.
int get_num_parents() const
Returns the number of base classes this class inherits from.
int get_num_inherited_fields() const
Returns the total number of field fields defined in this class and all ancestor classes.
void clear()
Removes all of the classes defined within the DCFile and prepares it for reading a new file...
int get_num_classes() const
Returns the number of classes read from the .dc file(s).
A single molecular field of a Distributed Class, as read from a .dc file.
const string & get_name() const
Returns the name of this class.
bool is_bogus_class() const
Returns true if the class has been flagged as a bogus class.