ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
dl_writer_ascii.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
3 ** Copyright (C) 2001 Robert J. Campbell Jr.
4 **
5 ** This file is part of the dxflib project.
6 **
7 ** This file is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
11 **
12 ** Licensees holding valid dxflib Professional Edition licenses may use
13 ** this file in accordance with the dxflib Commercial License
14 ** Agreement provided with the Software.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** See http://www.ribbonsoft.com for further details.
20 **
21 ** Contact info@ribbonsoft.com if any conditions of this licensing are
22 ** not clear to you.
23 **
24 **********************************************************************/
25 
26 #if _MSC_VER > 1000
27 #pragma once
28 #endif // _MSC_VER > 1000
29 
30 #include "dl_writer_ascii.h"
31 
32 #include <stdio.h>
33 #include <string.h>
34 
35 #include "dl_exception.h"
36 
40 void DL_WriterA::close() const { m_ofile.close(); }
41 
46 bool DL_WriterA::openFailed() const { return m_ofile.fail(); }
47 
54 void DL_WriterA::dxfReal(int gc, double value) const {
55  char str[256];
57  sprintf(str, "%.6lf", value);
58  } else {
59  sprintf(str, "%.16lf", value);
60  }
61 
62  // fix for german locale:
63  strReplace(str, ',', '.');
64 
65  // Cut away those zeros at the end:
66  bool dot = false;
67  int end = -1;
68  for (unsigned int i = 0; i < strlen(str); ++i) {
69  if (str[i] == '.') {
70  dot = true;
71  end = i + 2;
72  continue;
73  } else if (dot && str[i] != '0') {
74  end = i + 1;
75  }
76  }
77  if (end > 0 && end < (int)strlen(str)) {
78  str[end] = '\0';
79  }
80 
81  dxfString(gc, str);
82  m_ofile.flush();
83 }
84 
91 void DL_WriterA::dxfInt(int gc, int value) const {
92  m_ofile << (gc < 10 ? " " : (gc < 100 ? " " : "")) << gc << "\n"
93  << value << "\n";
94 }
95 
102 void DL_WriterA::dxfHex(int gc, int value) const {
103  char str[12];
104  sprintf(str, "%0X", value);
105  dxfString(gc, str);
106 }
107 
114 void DL_WriterA::dxfString(int gc, const char* value) const {
115  if (value == NULL) {
116 #ifndef __GCC2x__
117  // throw DL_NullStrExc();
118 #endif
119  }
120  m_ofile << (gc < 10 ? " " : (gc < 100 ? " " : "")) << gc << "\n"
121  << value << "\n";
122 }
123 
124 void DL_WriterA::dxfString(int gc, const std::string& value) const {
125  m_ofile << (gc < 10 ? " " : (gc < 100 ? " " : "")) << gc << "\n"
126  << value << "\n";
127 }
128 
132 void DL_WriterA::strReplace(char* str, char src, char dest) {
133  size_t i;
134  for (i = 0; i < strlen(str); i++) {
135  if (str[i] == src) {
136  str[i] = dest;
137  }
138  }
139 }
#define NULL
@ AC1009_MIN
Definition: dl_codes.h:96
void dxfReal(int gc, double value) const
void dxfInt(int gc, int value) const
void dxfString(int gc, const char *value) const
bool openFailed() const
void dxfHex(int gc, int value) const
static void strReplace(char *str, char src, char dest)
void close() const
DL_Codes::version version
Definition: dl_writer.h:590