Panda3D
dcPackerCatalog.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 dcPackerCatalog.h
10  * @author drose
11  * @date 2004-06-21
12  */
13 
14 #ifndef DCPACKERCATALOG_H
15 #define DCPACKERCATALOG_H
16 
17 #include "dcbase.h"
18 
19 class DCPackerInterface;
20 class DCPacker;
21 class DCSwitchParameter;
22 
23 /**
24  * This object contains the names of all of the nested fields available within
25  * a particular field. It is created on demand when a catalog is first
26  * requested from a particular field; its ownership is retained by the field
27  * so it must not be deleted.
28  */
29 class EXPCL_DIRECT_DCPARSER DCPackerCatalog {
30 private:
32  DCPackerCatalog(const DCPackerCatalog &copy);
33  ~DCPackerCatalog();
34 
35 public:
36  // The Entry class records the static catalog data: the name of each field
37  // and its relationship to its parent.
38  class Entry {
39  public:
40  std::string _name;
41  const DCPackerInterface *_field;
42  const DCPackerInterface *_parent;
43  int _field_index;
44  };
45 
46  // The LiveCatalog class adds the dynamic catalog data: the actual location
47  // of each field within the data record. This might be different for
48  // different data records (since some data fields have a dynamic length).
50  public:
51  size_t _begin;
52  size_t _end;
53  };
54  class LiveCatalog {
55  public:
56  INLINE size_t get_begin(int n) const;
57  INLINE size_t get_end(int n) const;
58 
59  INLINE int get_num_entries() const;
60  INLINE const Entry &get_entry(int n) const;
61  INLINE int find_entry_by_name(const std::string &name) const;
62  INLINE int find_entry_by_field(const DCPackerInterface *field) const;
63 
64  private:
65  typedef pvector<LiveCatalogEntry> LiveEntries;
66  LiveEntries _live_entries;
67 
68  const DCPackerCatalog *_catalog;
69  friend class DCPackerCatalog;
70  };
71 
72  INLINE int get_num_entries() const;
73  INLINE const Entry &get_entry(int n) const;
74  int find_entry_by_name(const std::string &name) const;
75  int find_entry_by_field(const DCPackerInterface *field) const;
76 
77  const LiveCatalog *get_live_catalog(const char *data, size_t length) const;
78  void release_live_catalog(const LiveCatalog *live_catalog) const;
79 
80 private:
81  void add_entry(const std::string &name, const DCPackerInterface *field,
82  const DCPackerInterface *parent, int field_index);
83 
84  void r_fill_catalog(const std::string &name_prefix, const DCPackerInterface *field,
85  const DCPackerInterface *parent, int field_index);
86  void r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
87  const DCSwitchParameter *&last_switch) const;
88 
89  const DCPackerCatalog *update_switch_fields(const DCSwitchParameter *dswitch,
90  const DCPackerInterface *switch_case) const;
91 
92 
93  const DCPackerInterface *_root;
94  LiveCatalog *_live_catalog;
95 
96  typedef pvector<Entry> Entries;
97  Entries _entries;
98 
99  typedef pmap<std::string, int> EntriesByName;
100  EntriesByName _entries_by_name;
101 
102  typedef pmap<const DCPackerInterface *, int> EntriesByField;
103  EntriesByField _entries_by_field;
104 
106  SwitchCatalogs _switch_catalogs;
107 
108  typedef pmap<const DCSwitchParameter *, std::string> SwitchPrefixes;
109  SwitchPrefixes _switch_prefixes;
110 
111  friend class DCPackerInterface;
112 };
113 
114 #include "dcPackerCatalog.I"
115 
116 #endif
int find_entry_by_name(const std::string &name) const
Returns the index number of the entry with the indicated name, or -1 if no entry has the indicated na...
void release_live_catalog(const LiveCatalog *live_catalog) const
Releases the LiveCatalog object that was returned by an earlier call to get_live_catalog().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
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:34
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.