Panda3D

Loading...
Searching...
No Matches
dcFile.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file dcFile.h
10 * @author drose
11 * @date 2000-10-05
12 */
13
14#ifndef DCFILE_H
15#define DCFILE_H
16
17#include "dcbase.h"
18#include "dcKeywordList.h"
19
20 class DCClass;
21 class DCSwitch;
22 class DCField;
23 class HashGenerator;
24 class DCTypedef;
25 class DCKeyword;
26 class DCDeclaration;
27
28/**
29 * Represents the complete list of Distributed Class descriptions as read from
30 * a .dc file.
31 */
32 class EXPCL_DIRECT_DCPARSER DCFile {
33PUBLISHED:
34 DCFile();
35 ~DCFile();
36
37 void clear();
38
39#ifdef WITHIN_PANDA
40 bool read_all();
41#endif
42
43 bool read(Filename filename);
44 bool read(std::istream &in, const std::string &filename = std::string());
45
46 bool write(Filename filename, bool brief) const;
47 bool write(std::ostream &out, bool brief) const;
48
49 int get_num_classes() const;
50 DCClass *get_class(int n) const;
51 DCClass *get_class_by_name(const std::string &name) const;
52 DCSwitch *get_switch_by_name(const std::string &name) const;
53
54 DCField *get_field_by_index(int index_number) const;
55
56 INLINE bool all_objects_valid() const;
57
58 int get_num_import_modules() const;
59 std::string get_import_module(int n) const;
60 int get_num_import_symbols(int n) const;
61 std::string get_import_symbol(int n, int i) const;
62
63 int get_num_typedefs() const;
64 DCTypedef *get_typedef(int n) const;
65 DCTypedef *get_typedef_by_name(const std::string &name) const;
66
67 int get_num_keywords() const;
68 const DCKeyword *get_keyword(int n) const;
69 const DCKeyword *get_keyword_by_name(const std::string &name) const;
70
71 unsigned long get_hash() const;
72
73 public:
74 void generate_hash(HashGenerator &hashgen) const;
75 bool add_class(DCClass *dclass);
76 bool add_switch(DCSwitch *dswitch);
77 void add_import_module(const std::string &import_module);
78 void add_import_symbol(const std::string &import_symbol);
79 bool add_typedef(DCTypedef *dtypedef);
80 bool add_keyword(const std::string &name);
81 void add_thing_to_delete(DCDeclaration *decl);
82
83 void set_new_index_number(DCField *field);
84 INLINE void check_inherited_fields();
85 INLINE void mark_inherited_fields_stale();
86
87 private:
88 void setup_default_keywords();
89 void rebuild_inherited_fields();
90
91 typedef pvector<DCClass *> Classes;
92 Classes _classes;
93
94 typedef pmap<std::string, DCDeclaration *> ThingsByName;
95 ThingsByName _things_by_name;
96
97 typedef pvector<std::string> ImportSymbols;
98 class Import {
99 public:
100 std::string _module;
101 ImportSymbols _symbols;
102 };
103
104 typedef pvector<Import> Imports;
105 Imports _imports;
106
107 typedef pvector<DCTypedef *> Typedefs;
108 Typedefs _typedefs;
109
110 typedef pmap<std::string, DCTypedef *> TypedefsByName;
111 TypedefsByName _typedefs_by_name;
112
113 DCKeywordList _keywords;
114 DCKeywordList _default_keywords;
115
116 typedef pvector<DCDeclaration *> Declarations;
117 Declarations _declarations;
118 Declarations _things_to_delete;
119
120 typedef pvector<DCField *> FieldsByIndex;
121 FieldsByIndex _fields_by_index;
122
123 bool _all_objects_valid;
124 bool _inherited_fields_stale;
125};
126
127#include "dcFile.I"
128
129#endif
DCClass
Defines a particular DistributedClass as read from an input .dc file.
Definition dcClass.h:44
DCDeclaration
This is a common interface for a declaration in a DC file.
Definition dcDeclaration.h:29
DCField
A single field of a Distributed Class, either atomic or molecular.
Definition dcField.h:37
DCFile::add_class
bool add_class(DCClass *dclass)
Adds the newly-allocated distributed class definition to the file.
Definition dcFile.cxx:453
DCFile::add_switch
bool add_switch(DCSwitch *dswitch)
Adds the newly-allocated switch definition to the file.
Definition dcFile.cxx:488
DCFile::get_class_by_name
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.
Definition dcFile.cxx:262
DCFile::get_hash
unsigned long get_hash() const
Returns a 32-bit hash index associated with this file.
Definition dcFile.cxx:419
DCFile::get_import_module
std::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:318
DCFile::all_objects_valid
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...
Definition dcFile.I:20
DCFile::get_num_typedefs
int get_num_typedefs() const
Returns the number of typedefs read from the .dc file(s).
Definition dcFile.cxx:349
DCFile::mark_inherited_fields_stale
void mark_inherited_fields_stale()
Indicates that something has changed in one or more of the inheritance chains or the set of fields; t...
Definition dcFile.I:40
DCFile::get_keyword
const DCKeyword * get_keyword(int n) const
Returns the nth keyword read from the .dc file(s).
Definition dcFile.cxx:389
DCFile::add_thing_to_delete
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:584
DCFile::set_new_index_number
void set_new_index_number(DCField *field)
Sets the next sequential available index number on the indicated field.
Definition dcFile.cxx:593
DCFile::get_typedef
DCTypedef * get_typedef(int n) const
Returns the nth typedef read from the .dc file(s).
Definition dcFile.cxx:357
DCFile::get_typedef_by_name
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.
Definition dcFile.cxx:367
DCFile::get_field_by_index
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:296
DCFile::get_num_import_symbols
int get_num_import_symbols(int n) const
Returns the number of symbols explicitly imported by the nth import line.
Definition dcFile.cxx:329
DCFile::get_num_classes
int get_num_classes() const
Returns the number of classes read from the .dc file(s).
Definition dcFile.cxx:244
DCFile::get_num_import_modules
int get_num_import_modules() const
Returns the number of import lines read from the .dc file(s).
Definition dcFile.cxx:310
DCFile::add_import_module
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...
Definition dcFile.cxx:509
DCFile::get_keyword_by_name
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.
Definition dcFile.cxx:398
DCFile::check_inherited_fields
void check_inherited_fields()
Rebuilds all of the inherited fields tables, if necessary.
Definition dcFile.I:28
DCFile::add_import_symbol
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...
Definition dcFile.cxx:522
DCFile::add_keyword
bool add_keyword(const std::string &name)
Adds the indicated keyword string to the list of keywords known to the DCFile.
Definition dcFile.cxx:564
DCFile::write
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:185
DCFile::read
bool read(Filename filename)
Opens and reads the indicated .dc file by name.
Definition dcFile.cxx:124
DCFile::get_class
DCClass * get_class(int n) const
Returns the nth class read from the .dc file(s).
Definition dcFile.cxx:252
DCFile::get_num_keywords
int get_num_keywords() const
Returns the number of keywords read from the .dc file(s).
Definition dcFile.cxx:381
DCFile::add_typedef
bool add_typedef(DCTypedef *dtypedef)
Adds the newly-allocated distributed typedef definition to the file.
Definition dcFile.cxx:534
DCFile::get_switch_by_name
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.
Definition dcFile.cxx:277
DCFile::clear
void clear()
Removes all of the classes defined within the DCFile and prepares it for reading a new file.
Definition dcFile.cxx:59
DCFile::get_import_symbol
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).
Definition dcFile.cxx:339
DCFile::generate_hash
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this file into the hash.
Definition dcFile.cxx:429
DCKeywordList
This is a list of keywords (see DCKeyword) that may be set on a particular field.
Definition dcKeywordList.h:26
DCKeyword
This represents a single keyword declaration in the dc file.
Definition dcKeyword.h:28
DCSwitch
This represents a switch statement, which can appear inside a class body and represents two or more a...
Definition dcSwitch.h:30
DCTypedef
This represents a single typedef declaration in the dc file.
Definition dcTypedef.h:26
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
HashGenerator
This class generates an arbitrary hash number from a sequence of ints.
Definition hashGenerator.h:23
dcFile.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcKeywordList.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.