25 enum DatagramElement {
38 std::getline(in, line);
42 while (p < line.length()) {
44 while (p < line.length() && isspace(line[p])) {
49 if (p < line.length()) {
50 if (isdigit(line[p]) || line[p] ==
'-') {
54 while (p < line.length() && isdigit(line[p])) {
57 if (p < line.length() && line[p] ==
'.') {
60 while (p < line.length() && isdigit(line[p])) {
63 double num =
patof(line.substr(start, p - start).c_str());
68 int num = atoi(line.substr(start, p - start).c_str());
73 }
else if (line[p] ==
'"') {
77 while (p < line.length() && line[p] !=
'"') {
80 std::string str = line.substr(start, p - start);
88 while (p < line.length() && !isspace(line[p])) {
91 std::string str = line.substr(start, p - start);
102 operator << (ostream &out,
const NetDatagram &datagram) {
105 DatagramElement de = (DatagramElement)di.get_int8();
106 while (de != DE_end) {
109 out << di.get_int32() <<
" ";
113 out << di.get_float64() <<
" ";
117 out <<
"\"" << di.get_string() <<
"\" ";
121 out <<
"(invalid datagram)";
124 de = (DatagramElement)di.get_int8();
A specific kind of Datagram, especially for sending across or receiving from a network.
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
double patof(const char *str)
This function re-implements atof, to avoid the problems that occur when the LC_NUMERIC locale gets se...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.