Panda3D
Public Member Functions | Protected Member Functions
DCSimpleParameter Class Reference

This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomicType elements. More...

#include "dcSimpleParameter.h"

Inheritance diagram for DCSimpleParameter:
DCParameter DCField DCPackerInterface DCKeywordList

List of all members.

Public Member Functions

 DCSimpleParameter (DCSubatomicType type, unsigned int divisor=1)
 DCSimpleParameter (const DCSimpleParameter &copy)
virtual DCSimpleParameteras_simple_parameter ()
virtual const DCSimpleParameteras_simple_parameter () const
virtual int calc_num_nested_fields (size_t length_bytes) const
 This flavor of get_num_nested_fields is used during unpacking.
virtual void generate_hash (HashGenerator &hashgen) const
 Accumulates the properties of this type into the hash.
int get_divisor () const
 Returns the divisor associated with this type.
double get_modulus () const
 Returns the modulus associated with this type, if any.
virtual DCPackerInterfaceget_nested_field (int n) const
 Returns the DCPackerInterface object that represents the nth nested field.
DCSubatomicType get_type () const
 Returns the particular subatomic type represented by this instance.
bool has_modulus () const
 Returns true if there is a modulus associated, false otherwise.,.
bool is_numeric_type () const
 Returns true if the type is a numeric type (and therefore can accept a divisor and/or a modulus), or false if it is some string-based type.
virtual bool is_valid () const
 Returns false if the type is an invalid type (e.g.
virtual DCParametermake_copy () const
virtual void output_instance (ostream &out, bool brief, const string &prename, const string &name, const string &postname) const
 Formats the parameter in the C++-like dc syntax as a typename and identifier.
virtual bool pack_default_value (DCPackData &pack_data, bool &pack_error) const
 Packs the simpleParameter's specified default value (or a sensible default if no value is specified) into the stream.
virtual void pack_double (DCPackData &pack_data, double value, bool &pack_error, bool &range_error) const
 Packs the indicated numeric or string value into the stream.
virtual void pack_int (DCPackData &pack_data, int value, bool &pack_error, bool &range_error) const
 Packs the indicated numeric or string value into the stream.
virtual void pack_int64 (DCPackData &pack_data, PN_int64 value, bool &pack_error, bool &range_error) const
 Packs the indicated numeric or string value into the stream.
virtual void pack_string (DCPackData &pack_data, const string &value, bool &pack_error, bool &range_error) const
 Packs the indicated numeric or string value into the stream.
virtual void pack_uint (DCPackData &pack_data, unsigned int value, bool &pack_error, bool &range_error) const
 Packs the indicated numeric or string value into the stream.
virtual void pack_uint64 (DCPackData &pack_data, PN_uint64 value, bool &pack_error, bool &range_error) const
 Packs the indicated numeric or string value into the stream.
bool set_divisor (unsigned int divisor)
 Assigns the indicated divisor to the simple type.
bool set_modulus (double modulus)
 Assigns the indicated modulus to the simple type.
bool set_range (const DCDoubleRange &range)
 Sets the parameter with the indicated range.
virtual void unpack_double (const char *data, size_t length, size_t &p, double &value, bool &pack_error, bool &range_error) const
 Unpacks the current numeric or string value from the stream.
virtual void unpack_int (const char *data, size_t length, size_t &p, int &value, bool &pack_error, bool &range_error) const
 Unpacks the current numeric or string value from the stream.
virtual void unpack_int64 (const char *data, size_t length, size_t &p, PN_int64 &value, bool &pack_error, bool &range_error) const
 Unpacks the current numeric or string value from the stream.
virtual bool unpack_skip (const char *data, size_t length, size_t &p, bool &pack_error) const
 Increments p to the end of the current field without actually unpacking any data or performing any range validation.
virtual void unpack_string (const char *data, size_t length, size_t &p, string &value, bool &pack_error, bool &range_error) const
 Unpacks the current numeric or string value from the stream.
virtual void unpack_uint (const char *data, size_t length, size_t &p, unsigned int &value, bool &pack_error, bool &range_error) const
 Unpacks the current numeric or string value from the stream.
virtual void unpack_uint64 (const char *data, size_t length, size_t &p, PN_uint64 &value, bool &pack_error, bool &range_error) const
 Unpacks the current numeric or string value from the stream.
virtual bool unpack_validate (const char *data, size_t length, size_t &p, bool &pack_error, bool &range_error) const
 Internally unpacks the current numeric or string value and validates it against the type range limits, but does not return the value.

Protected Member Functions

virtual bool do_check_match (const DCPackerInterface *other) const
 Returns true if the other interface is bitwise the same as this one--that is, a uint32 only matches a uint32, etc.
virtual bool do_check_match_array_parameter (const DCArrayParameter *other) const
 Returns true if this field matches the indicated array parameter, false otherwise.
virtual bool do_check_match_simple_parameter (const DCSimpleParameter *other) const
 Returns true if this field matches the indicated simple parameter, false otherwise.

Detailed Description

This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomicType elements.

It may also optionally have a divisor, which is meaningful only for the numeric type elements (and represents a fixed-point numeric convention).

Definition at line 32 of file dcSimpleParameter.h.


Member Function Documentation

int DCSimpleParameter::calc_num_nested_fields ( size_t  length_bytes) const [virtual]

This flavor of get_num_nested_fields is used during unpacking.

It returns the number of nested fields to expect, given a certain length in bytes (as read from the _num_length_bytes stored in the stream on the push). This will only be called if _num_length_bytes is nonzero.

Reimplemented from DCPackerInterface.

Definition at line 619 of file dcSimpleParameter.cxx.

bool DCSimpleParameter::do_check_match ( const DCPackerInterface other) const [protected, virtual]

Returns true if the other interface is bitwise the same as this one--that is, a uint32 only matches a uint32, etc.

Names of components, and range limits, are not compared.

Implements DCPackerInterface.

Definition at line 2386 of file dcSimpleParameter.cxx.

References DCPackerInterface::do_check_match_simple_parameter().

bool DCSimpleParameter::do_check_match_array_parameter ( const DCArrayParameter other) const [protected, virtual]

Returns true if this field matches the indicated array parameter, false otherwise.

Reimplemented from DCPackerInterface.

Definition at line 2445 of file dcSimpleParameter.cxx.

References DCArrayParameter::get_array_size(), and DCArrayParameter::get_element_type().

bool DCSimpleParameter::do_check_match_simple_parameter ( const DCSimpleParameter other) const [protected, virtual]

Returns true if this field matches the indicated simple parameter, false otherwise.

Reimplemented from DCPackerInterface.

Definition at line 2397 of file dcSimpleParameter.cxx.

void DCSimpleParameter::generate_hash ( HashGenerator hashgen) const [virtual]

Accumulates the properties of this type into the hash.

Reimplemented from DCParameter.

Definition at line 2361 of file dcSimpleParameter.cxx.

References HashGenerator::add_int(), and DCParameter::generate_hash().

Returns the divisor associated with this type.

This is 1 by default, but if this is other than one it represents the scale to apply when packing and unpacking numeric values (to store fixed-point values in an integer field). It is only meaningful for numeric-type fields.

Definition at line 315 of file dcSimpleParameter.cxx.

Returns the modulus associated with this type, if any.

It is an error to call this if has_modulus() returned false.

If present, this is the modulus that is used to constrain the numeric value of the field before it is packed (and range-checked).

Definition at line 300 of file dcSimpleParameter.cxx.

Returns the DCPackerInterface object that represents the nth nested field.

This may return NULL if there is no such field (but it shouldn't do this if n is in the range 0 <= n < get_num_nested_fields()).

Reimplemented from DCPackerInterface.

Definition at line 635 of file dcSimpleParameter.cxx.

DCSubatomicType DCSimpleParameter::get_type ( ) const

Returns the particular subatomic type represented by this instance.

Definition at line 273 of file dcSimpleParameter.cxx.

Referenced by DCArrayParameter::pack_string(), and DCArrayParameter::unpack_string().

Returns true if there is a modulus associated, false otherwise.,.

Definition at line 284 of file dcSimpleParameter.cxx.

Returns true if the type is a numeric type (and therefore can accept a divisor and/or a modulus), or false if it is some string-based type.

Definition at line 327 of file dcSimpleParameter.cxx.

bool DCSimpleParameter::is_valid ( ) const [virtual]

Returns false if the type is an invalid type (e.g.

declared from an undefined typedef), true if it is valid.

Implements DCParameter.

Definition at line 262 of file dcSimpleParameter.cxx.

void DCSimpleParameter::output_instance ( ostream &  out,
bool  brief,
const string &  prename,
const string &  name,
const string &  postname 
) const [virtual]

Formats the parameter in the C++-like dc syntax as a typename and identifier.

Implements DCParameter.

Definition at line 2270 of file dcSimpleParameter.cxx.

bool DCSimpleParameter::pack_default_value ( DCPackData pack_data,
bool &  pack_error 
) const [virtual]

Packs the simpleParameter's specified default value (or a sensible default if no value is specified) into the stream.

Returns true if the default value is packed, false if the simpleParameter doesn't know how to pack its default value.

Reimplemented from DCField.

Definition at line 1147 of file dcSimpleParameter.cxx.

References DCPackData::append_data(), DCPacker::begin_pack(), DCPacker::end_pack(), DCPacker::get_data(), DCPacker::get_length(), DCPacker::pack_default_value(), DCField::pack_default_value(), DCPacker::pop(), and DCPacker::push().

void DCSimpleParameter::pack_double ( DCPackData pack_data,
double  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Packs the indicated numeric or string value into the stream.

Reimplemented from DCPackerInterface.

Definition at line 646 of file dcSimpleParameter.cxx.

References DCPackData::get_write_pointer().

void DCSimpleParameter::pack_int ( DCPackData pack_data,
int  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Packs the indicated numeric or string value into the stream.

Reimplemented from DCPackerInterface.

Definition at line 747 of file dcSimpleParameter.cxx.

References DCPackData::get_write_pointer().

void DCSimpleParameter::pack_int64 ( DCPackData pack_data,
PN_int64  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Packs the indicated numeric or string value into the stream.

Reimplemented from DCPackerInterface.

Definition at line 923 of file dcSimpleParameter.cxx.

References DCPackData::get_write_pointer().

void DCSimpleParameter::pack_string ( DCPackData pack_data,
const string &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Packs the indicated numeric or string value into the stream.

Reimplemented from DCPackerInterface.

Definition at line 1095 of file dcSimpleParameter.cxx.

References DCPackData::append_data(), and DCPackData::get_write_pointer().

void DCSimpleParameter::pack_uint ( DCPackData pack_data,
unsigned int  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Packs the indicated numeric or string value into the stream.

Reimplemented from DCPackerInterface.

Definition at line 841 of file dcSimpleParameter.cxx.

References DCPackData::get_write_pointer().

void DCSimpleParameter::pack_uint64 ( DCPackData pack_data,
PN_uint64  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Packs the indicated numeric or string value into the stream.

Reimplemented from DCPackerInterface.

Definition at line 1011 of file dcSimpleParameter.cxx.

References DCPackData::get_write_pointer().

bool DCSimpleParameter::set_divisor ( unsigned int  divisor)

Assigns the indicated divisor to the simple type.

Returns true if assigned, false if this type cannot accept a divisor or if the divisor is invalid.

Definition at line 412 of file dcSimpleParameter.cxx.

bool DCSimpleParameter::set_modulus ( double  modulus)

Assigns the indicated modulus to the simple type.

Any packed value will be constrained to be within [0, modulus).

Returns true if assigned, false if this type cannot accept a modulus or if the modulus is invalid.

Definition at line 342 of file dcSimpleParameter.cxx.

Sets the parameter with the indicated range.

A DCDoubleRange is used for specification, since this is the most generic type; but it is converted to the appropriate type internally. The return value is true if successful, or false if the range is inappropriate for the type.

Definition at line 445 of file dcSimpleParameter.cxx.

References DCNumericRange< NUM >::get_max(), DCNumericRange< NUM >::get_min(), and DCNumericRange< NUM >::get_num_ranges().

void DCSimpleParameter::unpack_double ( const char *  data,
size_t  length,
size_t &  p,
double &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Unpacks the current numeric or string value from the stream.

Reimplemented from DCPackerInterface.

Definition at line 1241 of file dcSimpleParameter.cxx.

void DCSimpleParameter::unpack_int ( const char *  data,
size_t  length,
size_t &  p,
int &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Unpacks the current numeric or string value from the stream.

Reimplemented from DCPackerInterface.

Definition at line 1380 of file dcSimpleParameter.cxx.

void DCSimpleParameter::unpack_int64 ( const char *  data,
size_t  length,
size_t &  p,
PN_int64 &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Unpacks the current numeric or string value from the stream.

Reimplemented from DCPackerInterface.

Definition at line 1670 of file dcSimpleParameter.cxx.

bool DCSimpleParameter::unpack_skip ( const char *  data,
size_t  length,
size_t &  p,
bool &  pack_error 
) const [virtual]

Increments p to the end of the current field without actually unpacking any data or performing any range validation.

Returns true on success, false on failure (e.g. we don't know how to skip this field).

Reimplemented from DCPackerInterface.

Definition at line 2198 of file dcSimpleParameter.cxx.

void DCSimpleParameter::unpack_string ( const char *  data,
size_t  length,
size_t &  p,
string &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Unpacks the current numeric or string value from the stream.

Reimplemented from DCPackerInterface.

Definition at line 1959 of file dcSimpleParameter.cxx.

void DCSimpleParameter::unpack_uint ( const char *  data,
size_t  length,
size_t &  p,
unsigned int &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Unpacks the current numeric or string value from the stream.

Reimplemented from DCPackerInterface.

Definition at line 1521 of file dcSimpleParameter.cxx.

void DCSimpleParameter::unpack_uint64 ( const char *  data,
size_t  length,
size_t &  p,
PN_uint64 &  value,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Unpacks the current numeric or string value from the stream.

Reimplemented from DCPackerInterface.

Definition at line 1810 of file dcSimpleParameter.cxx.

bool DCSimpleParameter::unpack_validate ( const char *  data,
size_t  length,
size_t &  p,
bool &  pack_error,
bool &  range_error 
) const [virtual]

Internally unpacks the current numeric or string value and validates it against the type range limits, but does not return the value.

Returns true on success, false on failure (e.g. we don't know how to validate this field).

Reimplemented from DCPackerInterface.

Definition at line 2036 of file dcSimpleParameter.cxx.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations