Bitstream Interpretation Library (BIL)  0.1
XDLRCParserImp0.cpp
Go to the documentation of this file.
1 
10 
11 using namespace bil;
12 using namespace bil::xdlrcparser_detail;
13 
14 
15 const size_t TILETYPE_RESERVE_COUNT = 100;
16 
17 
18 XDLRCParserImp::XDLRCParserImp():
19  m_secondPassEnabled(false),
20  m_tileMap(),
21  m_tileTypeMap(),
22  m_tileTypesEx(),
23  m_primitiveTypeMap(),
24  m_pinMaps()
25 {
26 
27 }
28 
29 
31 {
32  // clearAll out everything (temporary data and pointers)
33  clearAll();
34 
35  // store pointer to tokenizer and prepare it
36  m_tok = &tokenizer;
37  setupSyntax();
38 
39  // clear destination object and store pointers to its sub-objects
40  device.clear();
41  m_device = &device;
42  m_tiles = &(device.tiles());
43  m_tileTypes = &(device.tileTypes());
44  m_primitiveTypes = &(device.primitiveTypes());
45 
46  // reserve memory beforehand for tile types, since they are not directly
47  // mentioned in XDLRC and will be inferred
48  m_tileTypes->reserve(TILETYPE_RESERVE_COUNT);
49  m_tileTypesEx.reserve(TILETYPE_RESERVE_COUNT);
50 
51  // skip opening parenthesis
52  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
53  if ('(' != m_tok->separatorToken()) throw Exception();
54  // skip keyword
55  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
56  if (strcmp(m_tok->wordToken(), XDLRCKeywords::RESOURCE_REPORT) != 0) throw Exception();
57  // skip version string
58  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
59  // read device name
60  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
61  (m_device->name()).assign(m_tok->wordToken());
62  // skip family name
63  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
64 
65  // skip opening parenthesis
66  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
67  if ('(' != m_tok->separatorToken()) throw Exception();
68  // skip keyword
69  if (StreamTokenizer::TT_WORD !=m_tok->nextToken()) throw Exception();
70  if (strcmp(m_tok->wordToken(), XDLRCKeywords::TILES) != 0) throw Exception();
71  parse1stTiles();
72 
73  // skip opening parenthesis
74  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
75  if ('(' != m_tok->separatorToken()) throw Exception();
76  // skip keyword
77  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
78  if (strcmp(m_tok->wordToken(), XDLRCKeywords::PRIMITIVE_DEFS) != 0) throw Exception();
79  parse1stPrimitiveDefs();
80 
81  // skip opening parenthesis
82  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
83  if ('(' != m_tok->separatorToken()) throw Exception();
84  // skip keyword
85  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
86  if (strcmp(m_tok->wordToken(), XDLRCKeywords::SUMMARY) != 0) throw Exception();
87  parseSummary();
88 
89  // skip opening parenthesis
90  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
91  if (')' != m_tok->separatorToken()) throw Exception();
92 
93  // reset pointers for safety
94  resetTempPointers();
95  // everything ok, second pass possible
96  m_secondPassEnabled = true;
97 }
98 
99 
101 {
102  // check if second pass can be made
103  if (!m_secondPassEnabled) throw Exception();
104  m_secondPassEnabled = false;
105  // reset pointers for safety
106  resetTempPointers();
107 
108  // prepare tokenizer
109  setupSyntax();
110 
111  // skip opening parenthesis
112  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
113  if ('(' != m_tok->separatorToken()) throw Exception();
114  // skip keyword
115  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
116  if (strcmp(m_tok->wordToken(), XDLRCKeywords::RESOURCE_REPORT) != 0) throw Exception();
117  // skip version string
118  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
119  // read and check device name
120  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
121  if ((m_device->name()).compare(m_tok->wordToken()) != 0) throw Exception();
122  // skip family name
123  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
124 
125  // skip opening parenthesis
126  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
127  if ('(' != m_tok->separatorToken()) throw Exception();
128  // skip keyword
129  if (StreamTokenizer::TT_WORD !=m_tok->nextToken()) throw Exception();
130  if (strcmp(m_tok->wordToken(), XDLRCKeywords::TILES) != 0) throw Exception();
131  parse2ndTiles();
132 
133  // clearAll out everything (temporary data and pointers)
134  clearAll();
135 }