Panda3D

dcFile.h

00001 // Filename: dcFile.h
00002 // Created by:  drose (05Oct00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef DCFILE_H
00016 #define DCFILE_H
00017 
00018 #include "dcbase.h"
00019 #include "dcKeywordList.h"
00020 
00021 class DCClass;
00022 class DCSwitch;
00023 class DCField;
00024 class HashGenerator;
00025 class DCTypedef;
00026 class DCKeyword;
00027 class DCDeclaration;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : DCFile
00031 // Description : Represents the complete list of Distributed Class
00032 //               descriptions as read from a .dc file.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_DIRECT DCFile {
00035 PUBLISHED:
00036   DCFile();
00037   ~DCFile();
00038 
00039   void clear();
00040 
00041 #ifdef WITHIN_PANDA
00042   bool read_all();
00043 #endif
00044 
00045   bool read(Filename filename);
00046   bool read(istream &in, const string &filename = string());
00047 
00048   bool write(Filename filename, bool brief) const;
00049   bool write(ostream &out, bool brief) const;
00050 
00051   int get_num_classes() const;
00052   DCClass *get_class(int n) const;
00053   DCClass *get_class_by_name(const string &name) const;
00054   DCSwitch *get_switch_by_name(const string &name) const;
00055 
00056   DCField *get_field_by_index(int index_number) const;
00057 
00058   INLINE bool all_objects_valid() const;
00059 
00060   int get_num_import_modules() const;
00061   string get_import_module(int n) const;
00062   int get_num_import_symbols(int n) const;
00063   string get_import_symbol(int n, int i) const;
00064 
00065   int get_num_typedefs() const;
00066   DCTypedef *get_typedef(int n) const;
00067   DCTypedef *get_typedef_by_name(const string &name) const;
00068 
00069   int get_num_keywords() const;
00070   const DCKeyword *get_keyword(int n) const;
00071   const DCKeyword *get_keyword_by_name(const string &name) const;
00072 
00073   unsigned long get_hash() const;
00074 
00075 public:
00076   void generate_hash(HashGenerator &hashgen) const;
00077   bool add_class(DCClass *dclass);
00078   bool add_switch(DCSwitch *dswitch);
00079   void add_import_module(const string &import_module);
00080   void add_import_symbol(const string &import_symbol);
00081   bool add_typedef(DCTypedef *dtypedef);
00082   bool add_keyword(const string &name);
00083   void add_thing_to_delete(DCDeclaration *decl);
00084 
00085   void set_new_index_number(DCField *field);
00086   INLINE void check_inherited_fields();
00087   INLINE void mark_inherited_fields_stale();
00088 
00089 private:
00090   void setup_default_keywords();
00091   void rebuild_inherited_fields();
00092 
00093   typedef pvector<DCClass *> Classes;
00094   Classes _classes;
00095 
00096   typedef pmap<string, DCDeclaration *> ThingsByName;
00097   ThingsByName _things_by_name;
00098 
00099   typedef pvector<string> ImportSymbols;
00100   class Import {
00101   public:
00102     string _module;
00103     ImportSymbols _symbols;
00104   };
00105 
00106   typedef pvector<Import> Imports;
00107   Imports _imports;
00108 
00109   typedef pvector<DCTypedef *> Typedefs;
00110   Typedefs _typedefs;
00111 
00112   typedef pmap<string, DCTypedef *> TypedefsByName;
00113   TypedefsByName _typedefs_by_name;
00114 
00115   DCKeywordList _keywords;
00116   DCKeywordList _default_keywords;
00117 
00118   typedef pvector<DCDeclaration *> Declarations;
00119   Declarations _declarations;
00120   Declarations _things_to_delete;
00121 
00122   typedef pvector<DCField *> FieldsByIndex;
00123   FieldsByIndex _fields_by_index;
00124 
00125   bool _all_objects_valid;
00126   bool _inherited_fields_stale;
00127 };
00128 
00129 #include "dcFile.I"
00130 
00131 #endif
00132 
00133 
 All Classes Functions Variables Enumerations