1 /****************************************************************************
2 ** $Id: dl_writer_ascii.cpp 242 2004-04-12 22:39:43Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 ** Copyright (C) 2001 Robert J. Campbell Jr.
7 ** This file is part of the dxflib project.
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file LICENSE.GPL included in the
12 ** packaging of this file.
14 ** Licensees holding valid dxflib Professional Edition licenses may use
15 ** this file in accordance with the dxflib Commercial License
16 ** Agreement provided with the Software.
18 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 ** See http://www.ribbonsoft.com for further details.
23 ** Contact info@ribbonsoft.com if any conditions of this licensing are
26 **********************************************************************/
30 #endif // _MSC_VER > 1000
34 #include "dl_writer_ascii.h"
35 #include "dl_exception.h"
39 * Closes the output file.
41 void DL_WriterA::close() const {
47 * @retval true Opening file has failed.
48 * @retval false Otherwise.
50 bool DL_WriterA::openFailed() const {
51 return m_ofile.fail();
57 * Writes a real (double) variable to the DXF file.
59 * @param gc Group code.
60 * @param value Double value
62 void DL_WriterA::dxfReal(int gc, double value) const {
64 sprintf(str, "%.16lf", value);
66 // fix for german locale:
67 strReplace(str, ',', '.');
69 // Cut away those zeros at the end:
72 for (unsigned int i=0; i<strlen(str); ++i) {
77 } else if (dot && str[i]!='0') {
81 if (end>0 && end<(int)strlen(str)) {
92 * Writes an int variable to the DXF file.
94 * @param gc Group code.
95 * @param value Int value
97 void DL_WriterA::dxfInt(int gc, int value) const {
98 m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
105 * Writes a hex int variable to the DXF file.
107 * @param gc Group code.
108 * @param value Int value
110 void DL_WriterA::dxfHex(int gc, int value) const {
112 sprintf(str, "%0X", value);
119 * Writes a string variable to the DXF file.
121 * @param gc Group code.
122 * @param value String
124 void DL_WriterA::dxfString(int gc, const char* value) const {
127 throw DL_NullStrExc();
130 m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
136 void DL_WriterA::dxfString(int gc, const string& value) const {
137 m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
143 * Replaces every occurence of src with dest in the null terminated str.
145 void DL_WriterA::strReplace(char* str, char src, char dest) {
147 for (i=0; i<strlen(str); i++) {