]> git.tdb.fi Git - libs/datafile.git/blob - source/loader.cpp
cf1a5acae89dc0e4abe7583358e3926ab629277c
[libs/datafile.git] / source / loader.cpp
1 /* $Id$
2
3 This file is part of libmspdatafile
4 Copyright © 2006  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "loader.h"
9
10 using namespace std;
11
12 namespace Msp {
13 namespace DataFile {
14
15 void Loader::load(const Statement &st)
16 {
17         for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
18                 load_statement(*i);
19 }
20
21 void Loader::load(Parser &p)
22 {
23         while(p)
24         {
25                 Statement st=p.parse();
26                 if(st.valid)
27                         load_statement(st);
28         }
29 }
30
31 Loader::~Loader()
32 {
33         for(ActionMap::iterator i=actions.begin(); i!=actions.end(); ++i)
34                 delete i->second;
35 }
36
37 void Loader::load_statement(const Statement &st)
38 {
39         cur_st=&st;
40         ActionMap::iterator j=actions.find(st.keyword);
41         if(j==actions.end())
42                 throw KeyError(st.get_location()+": Unknown keyword '"+st.keyword+"'");
43         if(j->second)
44                 j->second->execute(*this, st);
45         cur_st=0;
46 }
47
48 } // namespace DataFile
49 } // namespace Msp