Panda3D
 All Classes Functions Variables Enumerations
dcPackerCatalog.h
00001 // Filename: dcPackerCatalog.h
00002 // Created by:  drose (21Jun04)
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 DCPACKERCATALOG_H
00016 #define DCPACKERCATALOG_H
00017 
00018 #include "dcbase.h"
00019 
00020 class DCPackerInterface;
00021 class DCPacker;
00022 class DCSwitchParameter;
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : DCPackerCatalog
00026 // Description : This object contains the names of all of the nested
00027 //               fields available within a particular field.  It is
00028 //               created on demand when a catalog is first requested
00029 //               from a particular field; its ownership is retained by
00030 //               the field so it must not be deleted.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_DIRECT DCPackerCatalog {
00033 private:
00034   DCPackerCatalog(const DCPackerInterface *root);
00035   DCPackerCatalog(const DCPackerCatalog &copy);
00036   ~DCPackerCatalog();
00037 
00038 public:
00039   // The Entry class records the static catalog data: the name of each
00040   // field and its relationship to its parent.
00041   class Entry {
00042   public:
00043     string _name;
00044     const DCPackerInterface *_field;
00045     const DCPackerInterface *_parent;
00046     int _field_index;
00047   };
00048 
00049   // The LiveCatalog class adds the dynamic catalog data: the actual
00050   // location of each field within the data record.  This might be
00051   // different for different data records (since some data fields have
00052   // a dynamic length).
00053   class LiveCatalogEntry {
00054   public:
00055     size_t _begin;
00056     size_t _end;
00057   };
00058   class LiveCatalog {
00059   public:
00060     INLINE size_t get_begin(int n) const;
00061     INLINE size_t get_end(int n) const;
00062 
00063     INLINE int get_num_entries() const;
00064     INLINE const Entry &get_entry(int n) const;
00065     INLINE int find_entry_by_name(const string &name) const;
00066     INLINE int find_entry_by_field(const DCPackerInterface *field) const;
00067 
00068   private:
00069     typedef pvector<LiveCatalogEntry> LiveEntries;
00070     LiveEntries _live_entries;
00071 
00072     const DCPackerCatalog *_catalog;
00073     friend class DCPackerCatalog;
00074   };
00075 
00076   INLINE int get_num_entries() const;
00077   INLINE const Entry &get_entry(int n) const;
00078   int find_entry_by_name(const string &name) const;
00079   int find_entry_by_field(const DCPackerInterface *field) const;
00080 
00081   const LiveCatalog *get_live_catalog(const char *data, size_t length) const;
00082   void release_live_catalog(const LiveCatalog *live_catalog) const;
00083 
00084 private:
00085   void add_entry(const string &name, const DCPackerInterface *field,
00086                  const DCPackerInterface *parent, int field_index);
00087   
00088   void r_fill_catalog(const string &name_prefix, const DCPackerInterface *field,
00089                       const DCPackerInterface *parent, int field_index);
00090   void r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
00091                            const DCSwitchParameter *&last_switch) const;
00092 
00093   const DCPackerCatalog *update_switch_fields(const DCSwitchParameter *dswitch,
00094                                               const DCPackerInterface *switch_case) const;
00095     
00096 
00097   const DCPackerInterface *_root;
00098   LiveCatalog *_live_catalog;
00099   
00100   typedef pvector<Entry> Entries;
00101   Entries _entries;
00102 
00103   typedef pmap<string, int> EntriesByName;
00104   EntriesByName _entries_by_name;
00105 
00106   typedef pmap<const DCPackerInterface *, int> EntriesByField;
00107   EntriesByField _entries_by_field;
00108 
00109   typedef pmap<const DCPackerInterface *, DCPackerCatalog *> SwitchCatalogs;
00110   SwitchCatalogs _switch_catalogs;
00111 
00112   typedef pmap<const DCSwitchParameter *, string> SwitchPrefixes;
00113   SwitchPrefixes _switch_prefixes;
00114 
00115   friend class DCPackerInterface;
00116 };
00117 
00118 #include "dcPackerCatalog.I"
00119 
00120 #endif
 All Classes Functions Variables Enumerations