26 _live_catalog =
nullptr;
35 _entries(copy._entries),
36 _entries_by_name(copy._entries_by_name),
37 _entries_by_field(copy._entries_by_field)
39 _live_catalog =
nullptr;
47 if (_live_catalog !=
nullptr) {
51 SwitchCatalogs::iterator si;
52 for (si = _switch_catalogs.begin(); si != _switch_catalogs.end(); ++si) {
64 EntriesByName::const_iterator ni;
65 ni = _entries_by_name.find(name);
66 if (ni != _entries_by_name.end()) {
79 EntriesByField::const_iterator ni;
80 ni = _entries_by_field.find(field);
81 if (ni != _entries_by_field.end()) {
97 if (_live_catalog !=
nullptr) {
100 return _live_catalog;
104 live_catalog->_catalog =
this;
105 live_catalog->_live_entries.reserve(_entries.size());
107 zero_entry._begin = 0;
109 for (
size_t i = 0; i < _entries.size(); i++) {
110 live_catalog->_live_entries.push_back(zero_entry);
117 r_fill_live_catalog(live_catalog, packer, last_switch);
145 if (live_catalog != _live_catalog) {
154void DCPackerCatalog::
159 entry._field = field;
160 entry._parent = parent;
161 entry._field_index = field_index;
163 int entry_index = (int)_entries.size();
164 _entries.push_back(entry);
165 _entries_by_field.insert(EntriesByField::value_type(field, entry_index));
171 _entries_by_name[name] = entry_index;
177 string local_name = field->
get_name();
178 if (local_name != name) {
179 _entries_by_name.insert(EntriesByName::value_type(local_name, entry_index));
188void DCPackerCatalog::
191 string next_name_prefix = name_prefix;
193 if (parent !=
nullptr && !field->
get_name().empty()) {
195 next_name_prefix += field->
get_name();
196 add_entry(next_name_prefix, field, parent, field_index);
198 next_name_prefix +=
".";
202 if (switch_parameter !=
nullptr) {
207 _switch_prefixes[switch_parameter] = next_name_prefix;
214 for (
int i = 0; i < num_nested; i++) {
216 if (nested !=
nullptr) {
217 r_fill_catalog(next_name_prefix, nested, field, i);
227void DCPackerCatalog::
228r_fill_live_catalog(LiveCatalog *live_catalog,
DCPacker &packer,
232 int field_index = live_catalog->find_entry_by_field(current_field);
233 if (field_index >= 0) {
234 nassertv(field_index < (
int)live_catalog->_live_entries.size());
242 r_fill_live_catalog(live_catalog, packer, last_switch);
250 if (field_index >= 0) {
260 nassertv(switch_case !=
nullptr);
262 live_catalog->_catalog->update_switch_fields(last_switch, switch_case);
263 nassertv(switch_catalog !=
nullptr);
264 live_catalog->_catalog = switch_catalog;
267 LiveCatalogEntry zero_entry;
268 zero_entry._begin = 0;
270 for (
size_t i = live_catalog->_live_entries.size();
271 i < switch_catalog->_entries.size();
273 live_catalog->_live_entries.push_back(zero_entry);
294 SwitchCatalogs::const_iterator si = _switch_catalogs.find(switch_case);
295 if (si != _switch_catalogs.end()) {
302 SwitchPrefixes::const_iterator pi = _switch_prefixes.find(switch_parameter);
303 if (pi == _switch_prefixes.end()) {
309 string name_prefix = (*pi).second;
320 for (
int i = 1; i < num_nested; i++) {
322 if (nested !=
nullptr) {
323 switch_catalog->r_fill_catalog(name_prefix, nested, switch_case, i);
329 ((
DCPackerCatalog *)
this)->_switch_catalogs[switch_case] = switch_catalog;
331 return switch_catalog;
This object contains the names of all of the nested fields available within a particular field.
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().
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 ...
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 defines the internal interface for packing values into a DCField.
bool has_fixed_structure() const
Returns true if this field type always has the same structure regardless of the data in the stream,...
const std::string & get_name() const
Returns the name of this field, or empty string if the field is unnamed.
bool has_nested_fields() const
Returns true if this field type has any nested fields (and thus expects a push() .
int get_num_nested_fields() const
Returns the number of nested fields required by this field type.
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
This class can be used for packing a series of numeric and string data into a binary stream,...
const DCPackerInterface * get_current_field() const
Returns the field that will be referenced by the next call to pack_*() or unpack_*().
void push()
Marks the beginning of a nested series of fields.
bool more_nested_fields() const
Returns true if there are more nested fields to pack or unpack in the current push sequence,...
void begin_unpack(const DCPackerInterface *root)
Begins an unpacking session.
DCPackType get_pack_type() const
Returns the type of value expected by the current field.
bool end_unpack()
Finishes the unpacking session.
const DCSwitchParameter * get_last_switch() const
Returns a pointer to the last DCSwitch instance that we have passed by and selected one case of durin...
bool has_nested_fields() const
Returns true if the current field has any nested fields (and thus expects a push() .
void pop()
Marks the end of a nested series of fields.
void unpack_skip()
Skips the current field without unpacking it and advances to the next field.
const DCPackerInterface * get_current_parent() const
Returns the field that we left in our last call to push(): the owner of the current level of fields.
void set_unpack_data(const std::vector< unsigned char > &data)
Sets up the unpack_data pointer.
size_t get_num_unpacked_bytes() const
Returns the number of bytes that have been unpacked so far, or after unpack_end(),...
This represents a switch object used as a parameter itself, which packs the appropriate fields of the...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.