Virtual Testbed
Ship dynamics simulator for extreme conditions
stream.cc
1 #include <vtestbed/iges/stream.hh>
2 
3 #include <iostream>
4 
5 void
7  if (s == this->_section) {
8  return;
9  }
10  this->finish();
11  this->_section = s;
12  this->_maxsize = (s == Section::ParameterData) ? 64 : 72;
13  this->_lineno = 0;
14  auto offset = pptr() - pbase();
15  reset();
16  pbump(offset);
17 }
18 
19 auto
20 vtb::iges::iges_ostreambuf::overflow(int_type ch) -> int_type {
21  newline();
22  if (!traits_type::eq_int_type(ch, traits_type::eof())) {
23  *pptr() = ch;
24  pbump(1);
25  }
26  return ch;
27 }
28 
30 vtb::iges::iges_ostreambuf::xsputn(const char_type* first, std::streamsize n) {
31  if (epptr()-pptr() < n && n <= max_size()) {
32  newline();
33  }
34  auto old = first;
35  auto last = first + n;
36  while (first != last) {
37  auto m = std::min(epptr()-pptr(), last-first);
38  traits_type::copy(pptr(), first, m);
39  first += m;
40  pbump(m);
41  if (pptr() == epptr()) {
42  newline();
43  }
44  }
45  return first - old;
46 }
47 
48 auto
49 vtb::iges::iges_ostreambuf::sync() -> int_type {
50  this->finish();
51  return this->_sink->pubsync();
52 }
53 
54 void
55 vtb::iges::iges_ostreambuf::newline() {
56  auto n = this->epptr() - this->pptr();
57  if (n > 0) {
58  traits_type::assign(this->pptr(), n, ' ');
59  }
60  auto line_no = line_number();
61  if (this->_section == Section::ParameterData) {
62  std::snprintf(
63  this->epptr(),
64  2*8+2,
65  "%8zd%c%7zd\n",
66  2*this->_number - 1,
67  section_character(),
68  line_no
69  );
70  } else {
71  std::snprintf(
72  this->epptr(),
73  8+2,
74  "%c%7zd\n",
75  section_character(),
76  line_no
77  );
78  }
79  this->_sink->sputn(this->data(), 81);
80  reset();
81  ++this->_lineno;
82 }
Section
Section codes.
Definition: section.hh:9
T pptr(T... args)
T pbump(T... args)
void section(Section s)
Set section code to s.
Definition: stream.cc:6