Panda3D

Loading...
Searching...
No Matches
xFileDataObjectDouble.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 xFileDataObjectDouble.cxx
10 * @author drose
11 * @date 2004-10-07
12 */
13
14#include "xFileDataObjectDouble.h"
15#include "string_utils.h"
16#include "indent.h"
17
18 TypeHandle XFileDataObjectDouble::_type_handle;
19
20/**
21 *
22 */
23XFileDataObjectDouble::
24XFileDataObjectDouble(const XFileDataDef *data_def, double 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 */
33 void XFileDataObjectDouble::
34 output_data(std::ostream &out) const {
35 out << get_string_value();
36}
37
38/**
39 * Writes a suitable representation of this node to an .x file in text mode.
40 */
41 void XFileDataObjectDouble::
42 write_data(std::ostream &out, int indent_level, const char *separator) const {
43 indent(out, indent_level)
44 << get_string_value() << separator << "\n";
45}
46
47/**
48 * Sets the object's value as an integer, if this is legal.
49 */
50 void XFileDataObjectDouble::
51set_int_value(int int_value) {
52 _value = (double)int_value;
53}
54
55/**
56 * Sets the object's value as a floating-point number, if this is legal.
57 */
58 void XFileDataObjectDouble::
59set_double_value(double double_value) {
60 _value = double_value;
61}
62
63/**
64 * Returns the object's representation as an integer, if it has one.
65 */
66 int XFileDataObjectDouble::
67get_int_value() const {
68 return (int)_value;
69}
70
71/**
72 * Returns the object's representation as a double, if it has one.
73 */
74 double XFileDataObjectDouble::
75get_double_value() const {
76 return _value;
77}
78
79/**
80 * Returns the object's representation as a string, if it has one.
81 */
82std::string XFileDataObjectDouble::
83get_string_value() const {
84 // It's important to format with a decimal point, even if the value is
85 // integral, since the DirectX .x reader differentiates betweens doubles and
86 // integers on parsing.
87 char buffer[128];
88 sprintf(buffer, "%f", _value);
89
90 return buffer;
91}
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
XFileDataDef
A definition of a single data element appearing within a template record.
Definition xFileDataDef.h:31
XFileDataObjectDouble::write_data
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.
Definition xFileDataObjectDouble.cxx:42
XFileDataObjectDouble::output_data
virtual void output_data(std::ostream &out) const
Writes a suitable representation of this node to an .x file in text mode.
Definition xFileDataObjectDouble.cxx:34
XFileDataObject
The abstract base class for a number of different types of data elements that may be stored in the X ...
Definition xFileDataObject.h:30
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
string_utils.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
xFileDataObjectDouble.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.