source: OGRE/trunk/ogrenew/Tools/VRMLConverter/vrmllib/src/commentstream.cpp @ 657

Revision 657, 1.1 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1#include "commentstream.h"
2
3namespace utillib {
4
5class commentstreambuf : public std::streambuf {
6        std::streambuf * const m_sbuf;
7        char m_buf[512];
8        const int m_start;
9        const int m_end;
10        bool m_comment;
11public:
12        commentstreambuf(std::streambuf *, char start, char end);
13
14        int underflow();
15};
16
17commentstreambuf::commentstreambuf(std::streambuf *sb, char start, char end)
18        :       m_sbuf(sb), m_start(static_cast<unsigned char>(start)),
19                m_end(static_cast<unsigned char>(end)), m_comment(false)
20{
21        setg(m_buf, m_buf, m_buf);
22}
23
24int commentstreambuf::underflow()
25{
26        char *p = m_buf;
27        int ch;
28        while (p != m_buf + sizeof m_buf && (ch = m_sbuf->sgetc()) != EOF) {
29                m_sbuf->sbumpc();
30
31                if (ch == m_start) m_comment = true;
32                else if (ch == m_end) m_comment = false;
33
34                if (!m_comment)
35                        *p++ = ch;
36        }
37
38        if (p == m_buf)
39                return EOF;
40
41        setg(m_buf, m_buf, p);
42        return *m_buf;
43}
44
45commentstream::commentstream(std::istream &s, char start, char end)
46        :       std::basic_istream(new commentstreambuf(s.rdbuf(), start, end))
47{
48}
49
50commentstream::~commentstream()
51{
52        delete rdbuf();
53}
54
55} // namespace utillib
Note: See TracBrowser for help on using the repository browser.