Panda3D
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 {
33 PUBLISHED:
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
This represents a single keyword declaration in the dc file.
Definition: dcKeyword.h:28
This represents a single typedef declaration in the dc file.
Definition: dcTypedef.h:26
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
This is a list of keywords (see DCKeyword) that may be set on a particular field.
Definition: dcKeywordList.h:26
A single field of a Distributed Class, either atomic or molecular.
Definition: dcField.h:37
This represents a switch statement, which can appear inside a class body and represents two or more a...
Definition: dcSwitch.h:30
Defines a particular DistributedClass as read from an input .dc file.
Definition: dcClass.h:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents the complete list of Distributed Class descriptions as read from a .dc file.
Definition: dcFile.h:32
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
This is a common interface for a declaration in a DC file.
Definition: dcDeclaration.h:29
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:24