mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
parse_string, format_data
This commit is contained in:
parent
ec4539137a
commit
0b2be8bf9c
@ -57,6 +57,49 @@ as_molecular_field() {
|
|||||||
return (DCMolecularField *)NULL;
|
return (DCMolecularField *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCField::format_data
|
||||||
|
// Access: Published
|
||||||
|
// Description: Given a blob that represents the packed data for this
|
||||||
|
// field, returns a string formatting it for human
|
||||||
|
// consumption. Returns empty string if there is an error.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
string DCField::
|
||||||
|
format_data(const string &packed_data) {
|
||||||
|
DCPacker packer;
|
||||||
|
packer.begin_unpack(packed_data, this);
|
||||||
|
string result = packer.unpack_and_format();
|
||||||
|
if (!packer.end_unpack()) {
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCField::parse_string
|
||||||
|
// Access: Published
|
||||||
|
// Description: Given a human-formatted string (for instance, as
|
||||||
|
// returned by format_data(), above) that represents the
|
||||||
|
// value of this field, parse the string and return the
|
||||||
|
// corresponding packed data. Returns empty string if
|
||||||
|
// there is an error.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
string DCField::
|
||||||
|
parse_string(const string &formatted_string) {
|
||||||
|
DCPacker packer;
|
||||||
|
packer.begin_pack(this);
|
||||||
|
if (!packer.parse_and_pack(formatted_string)) {
|
||||||
|
// Parse error.
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
if (!packer.end_pack()) {
|
||||||
|
// Data type mismatch.
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return packer.get_string();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCField::pack_args
|
// Function: DCField::pack_args
|
||||||
|
@ -49,6 +49,9 @@ PUBLISHED:
|
|||||||
virtual DCAtomicField *as_atomic_field();
|
virtual DCAtomicField *as_atomic_field();
|
||||||
virtual DCMolecularField *as_molecular_field();
|
virtual DCMolecularField *as_molecular_field();
|
||||||
|
|
||||||
|
string format_data(const string &packed_data);
|
||||||
|
string parse_string(const string &formatted_string);
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
bool pack_args(Datagram &datagram, PyObject *sequence) const;
|
bool pack_args(Datagram &datagram, PyObject *sequence) const;
|
||||||
PyObject *unpack_args(DatagramIterator &iterator) const;
|
PyObject *unpack_args(DatagramIterator &iterator) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user