root/OpenSceneGraph/trunk/src/osgPlugins/dxf/dxfReader.h @ 13041

Revision 13041, 3.3 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* dxfReader for OpenSceneGraph  Copyright (C) 2005 by GraphArchitecture ( grapharchitecture.com )
2 * Programmed by Paul de Repentigny <pdr@grapharchitecture.com>
3 *
4 * OpenSceneGraph is (C) 2004 Robert Osfield
5 *
6 * This library is provided as-is, without support of any kind.
7 *
8 * Read DXF docs or OSG docs for any related questions.
9 *
10 * You may contact the author if you have suggestions/corrections/enhancements.
11 */
12
13/*      File handling.
14        dxfFile creates a dxfReader, which in turn create a readerText or a readerBinary
15        depending on file type.
16*/
17#ifndef DXF_READER
18#define DXF_READER 1
19
20#include <string>
21#include <sstream>
22
23#include <osg/Referenced>
24#include <osg/ref_ptr>
25
26#include <osgDB/fstream>
27
28class codeValue;
29
30/// readerBase. abstract base class for reading a dxf file
31/// and interpreting data types
32class readerBase :public osg::Referenced
33{
34public:
35    readerBase() {}
36    virtual ~readerBase() {}
37    bool readGroup(std::ifstream& f, codeValue& cv);
38
39protected:
40    virtual bool readGroupCode(std::ifstream& f, int &groupcode)  = 0;
41    virtual bool readValue(std::ifstream& f, std::string &s)  = 0;
42    virtual bool readValue(std::ifstream& f, bool &b)  = 0;
43    virtual bool readValue(std::ifstream& f, short &s)  = 0;
44    virtual bool readValue(std::ifstream& f, int &i)  = 0;
45    virtual bool readValue(std::ifstream& f, long &l)  = 0;
46    virtual bool readValue(std::ifstream& f, double &d)  = 0;
47};
48
49/// readerText. convert data using stringstream.
50class readerText : public readerBase
51{
52public:
53    readerText(char delim = '\n') : readerBase(), _lineCount(0), _delim(delim) {}
54    virtual ~readerText() {}
55
56protected:
57    bool success(bool inSuccess, std::string type);
58    bool getTrimmedLine(std::ifstream& f);
59
60    virtual bool readGroupCode(std::ifstream& f, int &groupcode);
61    virtual bool readValue(std::ifstream& f, std::string &s);
62    virtual bool readValue(std::ifstream& f, bool &b);
63    virtual bool readValue(std::ifstream& f, short &s);
64    virtual bool readValue(std::ifstream& f, int &i);
65    virtual bool readValue(std::ifstream& f, long &l);
66    virtual bool readValue(std::ifstream& f, double &d);
67    std::stringstream _str;
68    unsigned long _lineCount;
69    char _delim;
70};
71
72
73/// readerBinary. to be implemented
74class readerBinary : public readerBase
75{
76public:
77    readerBinary() : readerBase() {}
78    virtual ~readerBinary() {}
79protected:
80    virtual bool readGroupCode(std::ifstream& /*f*/, int& /*groupcode*/) { return false; }
81    virtual bool readValue(std::ifstream& /*f*/, std::string& /*s*/) { return false; }
82    virtual bool readValue(std::ifstream& /*f*/, bool& /*b*/) { return false; }
83    virtual bool readValue(std::ifstream& /*f*/, short& /*s*/) { return false; }
84    virtual bool readValue(std::ifstream& /*f*/, int& /*i*/) { return false; }
85    virtual bool readValue(std::ifstream& /*f*/, long& /*l*/) { return false; }
86    virtual bool readValue(std::ifstream& /*f*/, double& /*d*/) { return false; }
87};
88
89/// dxfReader. gets you through the dxf file, one group code/value pair at a time.
90/// just instantiate, openFile(), then loop while(nextGroupCode())
91class dxfReader : public osg::Referenced
92{
93public:
94    dxfReader() {}
95    virtual ~dxfReader() {}
96    bool    openFile(std::string fileName);
97    bool    nextGroupCode(codeValue& cv);
98protected:
99    osgDB::ifstream                _ifs;
100    osg::ref_ptr<readerBase>    _reader;
101};
102
103#endif
Note: See TracBrowser for help on using the browser.