Panda3D
|
00001 // Filename: xFileDataObjectDouble.cxx 00002 // Created by: drose (07Oct04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "xFileDataObjectDouble.h" 00016 #include "string_utils.h" 00017 #include "indent.h" 00018 00019 TypeHandle XFileDataObjectDouble::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: XFileDataObjectDouble::Constructor 00023 // Access: Public 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 XFileDataObjectDouble:: 00027 XFileDataObjectDouble(const XFileDataDef *data_def, double value) : 00028 XFileDataObject(data_def), 00029 _value(value) 00030 { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: XFileDataObjectDouble::output_data 00035 // Access: Public, Virtual 00036 // Description: Writes a suitable representation of this node to an 00037 // .x file in text mode. 00038 //////////////////////////////////////////////////////////////////// 00039 void XFileDataObjectDouble:: 00040 output_data(ostream &out) const { 00041 out << get_string_value(); 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: XFileDataObjectDouble::write_data 00046 // Access: Public, Virtual 00047 // Description: Writes a suitable representation of this node to an 00048 // .x file in text mode. 00049 //////////////////////////////////////////////////////////////////// 00050 void XFileDataObjectDouble:: 00051 write_data(ostream &out, int indent_level, const char *separator) const { 00052 indent(out, indent_level) 00053 << get_string_value() << separator << "\n"; 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: XFileDataObjectDouble::set_int_value 00058 // Access: Protected, Virtual 00059 // Description: Sets the object's value as an integer, if this is 00060 // legal. 00061 //////////////////////////////////////////////////////////////////// 00062 void XFileDataObjectDouble:: 00063 set_int_value(int int_value) { 00064 _value = (double)int_value; 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: XFileDataObjectDouble::set_double_value 00069 // Access: Protected, Virtual 00070 // Description: Sets the object's value as a floating-point number, 00071 // if this is legal. 00072 //////////////////////////////////////////////////////////////////// 00073 void XFileDataObjectDouble:: 00074 set_double_value(double double_value) { 00075 _value = double_value; 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: XFileDataObjectDouble::get_int_value 00080 // Access: Protected, Virtual 00081 // Description: Returns the object's representation as an integer, if 00082 // it has one. 00083 //////////////////////////////////////////////////////////////////// 00084 int XFileDataObjectDouble:: 00085 get_int_value() const { 00086 return (int)_value; 00087 } 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function: XFileDataObjectDouble::get_double_value 00091 // Access: Protected, Virtual 00092 // Description: Returns the object's representation as a double, if 00093 // it has one. 00094 //////////////////////////////////////////////////////////////////// 00095 double XFileDataObjectDouble:: 00096 get_double_value() const { 00097 return _value; 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: XFileDataObjectDouble::get_string_value 00102 // Access: Protected, Virtual 00103 // Description: Returns the object's representation as a string, if 00104 // it has one. 00105 //////////////////////////////////////////////////////////////////// 00106 string XFileDataObjectDouble:: 00107 get_string_value() const { 00108 // It's important to format with a decimal point, even if the value 00109 // is integral, since the DirectX .x reader differentiates betweens 00110 // doubles and integers on parsing. 00111 char buffer[128]; 00112 sprintf(buffer, "%f", _value); 00113 00114 return buffer; 00115 }