Points&Forces (core)
Software tools facilitating the task of surveying architecture
dxf
a_dxf_group.cxx
Go to the documentation of this file.
1
/*
2
Copyright 2011 Pierre SMARS (smars@yuntech.edu.tw)
3
This program is free software: you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation, either version 2 of the License, or
6
(at your option) any later version.
7
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License
14
along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
#include "
a_dxf_group.h
"
17
#include <sstream>
18
#include <string.h>
19
std::string
a_dxf_group::eof_
=
"EOF"
;
20
//---------------------------------------------------------------------------
21
bool
a_dxf_group::read
()
22
{
23
const
int
buffer_size = 254;
24
if
(
file_
->eof())
throw
file_error
();
25
char
buf
[buffer_size];
char
c;
//the size of the buffer is critical, check if problem
26
file_
->getline(
buf
,buffer_size,
'\n'
);
//gives problems when there's an empty line
27
int
n = strlen(
buf
)-1;
28
if
(
buf
[n]==
'\r'
)
//possibly eliminate the extra CR if file was created in windows and read in *nix
29
buf
[n] =
'\0'
;
30
std::istringstream ss(
buf
);
31
ss >>
code_
;
32
if
(ss.fail())
33
{
34
std::cerr <<
"a_dxf_group::read() invalid code line"
<< std::endl;
35
throw
file_error
();
//not an integer
36
}
37
if
(
file_
->eof())
throw
file_error
();
//file not properly finished
38
file_
->getline(
buf
,buffer_size,
'\n'
);
//gives problems when there's an empty line
39
n = strlen(
buf
)-1;
40
if
(
buf
[n]==
'\r'
)
//possibly eliminate the extra CR if file was created in windows and read in *nix
41
buf
[n] =
'\0'
;
42
if
(
file_
->fail()) {
file_
->clear();}
//line is empty
43
data_
= std::string(
buf
);
44
if
(
data_
!=
""
)
45
{
46
if
(
data_
.length() == buffer_size-1)
//long data line
47
{
48
while
(c !=
'\n'
)
49
{
50
data_
=
data_
+ c;
51
file_
->get(c);
52
}
53
}
54
std::string::size_type ii=
data_
.find_first_not_of(
" "
);
55
std::string::size_type ie=
data_
.find_last_not_of(
" "
);
56
data_
=
data_
.substr(ii,++ie);
//suppress the spacies around
57
}
58
if
(
data_
==
eof_
)
return
false
;
59
return
true
;
60
}
61
//---------------------------------------------------------------------------
62
void
a_dxf_group::write
()
63
{
64
std::cout <<
code_
<< std::endl;
65
std::cout <<
data_
<< std::endl;
66
}
67
//---------------------------------------------------------------------------
68
void
a_dxf_group::putback
()
69
{
70
file_
->putback(
'\n'
);
71
for
(
int
i=
data_
.length()-1;i>=0; i--)
72
file_
->putback(
data_
[i]);
73
std::ostringstream o;
74
o <<
code_
;
75
std::string
code
(o.str());
76
file_
->putback(
'\n'
);
77
for
(
int
i=
code
.length()-1;i>=0; i--)
78
file_
->putback(
code
[i]);
79
}
80
//---------------------------------------------------------------------------
81
int
a_dxf_group::data_int
()
82
{
83
int
result;
84
std::istringstream ss(
data_
);
85
ss >> result;
86
if
(ss.fail())
throw
file_error
();
87
return
result;
88
}
89
//---------------------------------------------------------------------------
90
double
a_dxf_group::data_double
()
91
{
92
double
result;
93
std::istringstream ss(
data_
);
94
ss >> result;
95
if
(ss.fail())
throw
file_error
();
96
return
result;
97
}
a_dxf_group.h
a_dxf_group::file_error
Definition:
a_dxf_group.h:43
a_dxf_group::data_double
double data_double()
Definition:
a_dxf_group.cxx:90
a_dxf_group::code
int code()
Definition:
a_dxf_group.h:36
a_dxf_group::code_
int code_
Definition:
a_dxf_group.h:47
a_dxf_group::data_int
int data_int()
Definition:
a_dxf_group.cxx:81
a_dxf_group::eof_
static std::string eof_
Definition:
a_dxf_group.h:49
a_dxf_group::write
void write()
Definition:
a_dxf_group.cxx:62
a_dxf_group::putback
void putback()
Definition:
a_dxf_group.cxx:68
a_dxf_group::file_
std::istream * file_
Definition:
a_dxf_group.h:46
a_dxf_group::data_
std::string data_
Definition:
a_dxf_group.h:48
a_dxf_group::read
bool read()
Definition:
a_dxf_group.cxx:21
buf
char buf[256]
Definition:
copy.h:17
Generated on Tue Sep 6 2022 18:50:16 for Points&Forces (core) by
1.9.1