Panda3D
xFileDataObjectInteger.cxx
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 xFileDataObjectInteger.cxx
10  * @author drose
11  * @date 2004-10-07
12  */
13 
14 #include "xFileDataObjectInteger.h"
15 #include "string_utils.h"
16 #include "indent.h"
17 
18 TypeHandle XFileDataObjectInteger::_type_handle;
19 
20 /**
21  *
22  */
23 XFileDataObjectInteger::
24 XFileDataObjectInteger(const XFileDataDef *data_def, int value) :
25  XFileDataObject(data_def),
26  _value(value)
27 {
28 }
29 
30 /**
31  * Writes a suitable representation of this node to an .x file in text mode.
32  */
34 output_data(std::ostream &out) const {
35  out << _value;
36 }
37 
38 /**
39  * Writes a suitable representation of this node to an .x file in text mode.
40  */
42 write_data(std::ostream &out, int indent_level, const char *separator) const {
43  indent(out, indent_level)
44  << _value << separator << "\n";
45 }
46 
47 /**
48  * Sets the object's value as an integer, if this is legal.
49  */
50 void XFileDataObjectInteger::
51 set_int_value(int int_value) {
52  _value = int_value;
53 }
54 
55 /**
56  * Returns the object's representation as an integer, if it has one.
57  */
58 int XFileDataObjectInteger::
59 get_int_value() const {
60  return _value;
61 }
62 
63 /**
64  * Returns the object's representation as a double, if it has one.
65  */
66 double XFileDataObjectInteger::
67 get_double_value() const {
68  return _value;
69 }
70 
71 /**
72  * Returns the object's representation as a string, if it has one.
73  */
74 std::string XFileDataObjectInteger::
75 get_string_value() const {
76  return format_string(_value);
77 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:31
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
virtual void output_data(std::ostream &out) const
Writes a suitable representation of this node to an .x file in text mode.
virtual void write_data(std::ostream &out, int indent_level, const char *separator) const
Writes a suitable representation of this node to an .x file in text mode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for a number of different types of data elements that may be stored in the X ...