KiCad PCB EDA Suite
wrlproc.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
30 #ifndef WRLPROC_H
31 #define WRLPROC_H
32 
33 #include <fstream>
34 #include <string>
35 #include <vector>
36 
37 #include "richio.h"
38 #include "wrltypes.h"
39 
40 class WRLPROC
41 {
42 private:
44  std::string m_buf; // string being parsed
45  bool m_eof;
46  unsigned int m_fileline;
47  unsigned int m_bufpos;
48 
49  WRLVERSION m_fileVersion; // VRML file version
50  std::string m_error; // error message
51  std::string m_badchars; // characters forbidden in VRML{1|2} names
52  std::string m_filename; // current file
53  std::string m_filedir; // parent directory of the file
54 
55  // getRawLine reads a single non-blank line and in the case of a VRML1 file
56  // it checks for invalid characters (bit 8 set). If m_buf is not empty and
57  // not completely parsed the function returns 'true'. The file position
58  // parameters are updated as appropriate.
59  bool getRawLine( void );
60 
61 public:
62  WRLPROC( LINE_READER* aLineReader );
63  ~WRLPROC();
64 
65  bool eof( void );
66 
67  // return the VRML Version
68  WRLVERSION GetVRMLType( void );
69 
70  // return the parent directory of the current file
71  const char* GetParentDir( void );
72 
73  // helper routines
74  std::string GetError( void );
75  bool GetFilePosData( size_t& line, size_t& column );
76  std::string GetFileName( void );
77  // eatSpace discards all leading white space from the current m_linepos
78  // and continues until a non-empty line is found which contains non-blank
79  // characters
80  bool EatSpace( void );
81  // Peek returns the next non-white char in the file or '\0' on failure
82  char Peek( void );
83  // Pop removes the current char from the buffer
84  void Pop( void );
85 
86  // read up to the next whitespace or comma
87  bool ReadGlob( std::string& aGlob );
88  // read a VRML name; is similar to ReadGlob except that it enforces
89  // name checking rules, does not allow a comma at the end, and
90  // stops when a left/right brace or bracket is found.
91  bool ReadName( std::string& aName );
92  bool DiscardNode( void ); // discard node data in a matched '{}' set
93  bool DiscardList( void ); // discard list data in a matched '[]' set
94 
95  // single variable readers
96  bool ReadString( std::string& aSFString ); // read a VRML string
97  bool ReadSFBool( bool& aSFBool );
98  bool ReadSFColor( WRLVEC3F& aSFColor );
99  bool ReadSFFloat( float& aSFFloat );
100  bool ReadSFInt( int& aSFInt32 );
101  bool ReadSFRotation( WRLROTATION& aSFRotation );
102  bool ReadSFVec2f( WRLVEC2F& aSFVec2f );
103  bool ReadSFVec3f( WRLVEC3F& aSFVec3f );
104 
105  // array readers
106  bool ReadMFString( std::vector< std::string >& aMFString );
107  bool ReadMFColor( std::vector< WRLVEC3F >& aMFColor );
108  bool ReadMFFloat( std::vector< float >& aMFFloat );
109  bool ReadMFInt( std::vector< int >& aMFInt32 );
110  bool ReadMFRotation( std::vector< WRLROTATION >& aMFRotation );
111  bool ReadMFVec2f( std::vector< WRLVEC2F >& aMFVec2f );
112  bool ReadMFVec3f( std::vector< WRLVEC3F >& aMFVec3f );
113 };
114 
115 #endif // WRLPROC_H
bool ReadMFFloat(std::vector< float > &aMFFloat)
Definition: wrlproc.cpp:1376
bool ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition: wrlproc.cpp:1824
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:82
bool ReadSFRotation(WRLROTATION &aSFRotation)
Definition: wrlproc.cpp:920
void Pop(void)
Definition: wrlproc.cpp:2007
glm::vec3 WRLVEC3F
Definition: wrltypes.h:185
WRLVERSION
Definition: wrltypes.h:40
bool GetFilePosData(size_t &line, size_t &column)
Definition: wrlproc.cpp:1951
bool ReadSFVec3f(WRLVEC3F &aSFVec3f)
Definition: wrlproc.cpp:1065
WRLVERSION GetVRMLType(void)
Definition: wrlproc.cpp:221
unsigned int m_bufpos
Definition: wrlproc.h:47
std::string m_filedir
Definition: wrlproc.h:53
bool ReadMFInt(std::vector< int > &aMFInt32)
Definition: wrlproc.cpp:1488
glm::vec2 WRLVEC2F
Definition: wrltypes.h:184
glm::vec4 WRLROTATION
Definition: wrltypes.h:186
bool ReadMFVec2f(std::vector< WRLVEC2F > &aMFVec2f)
Definition: wrlproc.cpp:1712
bool ReadGlob(std::string &aGlob)
Definition: wrlproc.cpp:236
~WRLPROC()
Definition: wrlproc.cpp:127
LINE_READER * m_file
Definition: wrlproc.h:43
bool ReadMFColor(std::vector< WRLVEC3F > &aMFColor)
Definition: wrlproc.cpp:1264
unsigned int m_fileline
Definition: wrlproc.h:46
std::string m_badchars
Definition: wrlproc.h:51
std::string m_error
Definition: wrlproc.h:50
bool DiscardNode(void)
Definition: wrlproc.cpp:359
std::string m_buf
Definition: wrlproc.h:44
bool ReadSFFloat(float &aSFFloat)
Definition: wrlproc.cpp:789
std::string m_filename
Definition: wrlproc.h:52
bool ReadSFColor(WRLVEC3F &aSFColor)
Definition: wrlproc.cpp:757
bool ReadSFBool(bool &aSFBool)
Definition: wrlproc.cpp:720
bool m_eof
Definition: wrlproc.h:45
bool ReadString(std::string &aSFString)
Definition: wrlproc.cpp:603
char Peek(void)
Definition: wrlproc.cpp:1979
const char * GetParentDir(void)
Definition: wrlproc.cpp:227
std::string GetFileName(void)
Definition: wrlproc.cpp:1967
WRLPROC(LINE_READER *aLineReader)
Definition: wrlproc.cpp:49
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:280
bool ReadSFInt(int &aSFInt32)
Definition: wrlproc.cpp:850
bool ReadMFRotation(std::vector< WRLROTATION > &aMFRotation)
Definition: wrlproc.cpp:1600
declares some compound types used for VRML
std::string GetError(void)
Definition: wrlproc.cpp:1945
bool DiscardList(void)
Definition: wrlproc.cpp:482
bool eof(void)
Definition: wrlproc.cpp:1939
bool ReadSFVec2f(WRLVEC2F &aSFVec2f)
Definition: wrlproc.cpp:994
bool EatSpace(void)
Definition: wrlproc.cpp:182
bool getRawLine(void)
Definition: wrlproc.cpp:133
bool ReadMFString(std::vector< std::string > &aMFString)
Definition: wrlproc.cpp:1145
WRLVERSION m_fileVersion
Definition: wrlproc.h:49