Panda3D
dcPackerCatalog.h
1 // Filename: dcPackerCatalog.h
2 // Created by: drose (21Jun04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef DCPACKERCATALOG_H
16 #define DCPACKERCATALOG_H
17 
18 #include "dcbase.h"
19 
20 class DCPackerInterface;
21 class DCPacker;
22 class DCSwitchParameter;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : DCPackerCatalog
26 // Description : This object contains the names of all of the nested
27 // fields available within a particular field. It is
28 // created on demand when a catalog is first requested
29 // from a particular field; its ownership is retained by
30 // the field so it must not be deleted.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_DIRECT DCPackerCatalog {
33 private:
35  DCPackerCatalog(const DCPackerCatalog &copy);
36  ~DCPackerCatalog();
37 
38 public:
39  // The Entry class records the static catalog data: the name of each
40  // field and its relationship to its parent.
41  class Entry {
42  public:
43  string _name;
44  const DCPackerInterface *_field;
45  const DCPackerInterface *_parent;
46  int _field_index;
47  };
48 
49  // The LiveCatalog class adds the dynamic catalog data: the actual
50  // location of each field within the data record. This might be
51  // different for different data records (since some data fields have
52  // a dynamic length).
54  public:
55  size_t _begin;
56  size_t _end;
57  };
58  class LiveCatalog {
59  public:
60  INLINE size_t get_begin(int n) const;
61  INLINE size_t get_end(int n) const;
62 
63  INLINE int get_num_entries() const;
64  INLINE const Entry &get_entry(int n) const;
65  INLINE int find_entry_by_name(const string &name) const;
66  INLINE int find_entry_by_field(const DCPackerInterface *field) const;
67 
68  private:
69  typedef pvector<LiveCatalogEntry> LiveEntries;
70  LiveEntries _live_entries;
71 
72  const DCPackerCatalog *_catalog;
73  friend class DCPackerCatalog;
74  };
75 
76  INLINE int get_num_entries() const;
77  INLINE const Entry &get_entry(int n) const;
78  int find_entry_by_name(const string &name) const;
79  int find_entry_by_field(const DCPackerInterface *field) const;
80 
81  const LiveCatalog *get_live_catalog(const char *data, size_t length) const;
82  void release_live_catalog(const LiveCatalog *live_catalog) const;
83 
84 private:
85  void add_entry(const string &name, const DCPackerInterface *field,
86  const DCPackerInterface *parent, int field_index);
87 
88  void r_fill_catalog(const string &name_prefix, const DCPackerInterface *field,
89  const DCPackerInterface *parent, int field_index);
90  void r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
91  const DCSwitchParameter *&last_switch) const;
92 
93  const DCPackerCatalog *update_switch_fields(const DCSwitchParameter *dswitch,
94  const DCPackerInterface *switch_case) const;
95 
96 
97  const DCPackerInterface *_root;
98  LiveCatalog *_live_catalog;
99 
100  typedef pvector<Entry> Entries;
101  Entries _entries;
102 
103  typedef pmap<string, int> EntriesByName;
104  EntriesByName _entries_by_name;
105 
106  typedef pmap<const DCPackerInterface *, int> EntriesByField;
107  EntriesByField _entries_by_field;
108 
110  SwitchCatalogs _switch_catalogs;
111 
112  typedef pmap<const DCSwitchParameter *, string> SwitchPrefixes;
113  SwitchPrefixes _switch_prefixes;
114 
115  friend class DCPackerInterface;
116 };
117 
118 #include "dcPackerCatalog.I"
119 
120 #endif
void release_live_catalog(const LiveCatalog *live_catalog) const
Releases the LiveCatalog object that was returned by an earlier call to get_live_catalog().
This represents a switch object used as a parameter itself, which packs the appropriate fields of the...
int find_entry_by_field(const DCPackerInterface *field) const
Returns the index number of the entry with the indicated field, or -1 if no entry has the indicated f...
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
int get_num_entries() const
Returns the number of entries in the catalog.
const Entry & get_entry(int n) const
Returns the nth entry in the catalog.
This class can be used for packing a series of numeric and string data into a binary stream...
Definition: dcPacker.h:38
int find_entry_by_name(const string &name) const
Returns the index number of the entry with the indicated name, or -1 if no entry has the indicated na...
This object contains the names of all of the nested fields available within a particular field...
const LiveCatalog * get_live_catalog(const char *data, size_t length) const
Returns a LiveCatalog object indicating the positions within the indicated data record of each field ...
This defines the internal interface for packing values into a DCField.