]> git.tdb.fi Git - libs/datafile.git/blob - source/loader.cpp
Add missing virtual destructor to Collection::ItemKeywordBase
[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         finish();
20 }
21
22 void Loader::load(Parser &p)
23 {
24         while(p)
25         {
26                 Statement st=p.parse();
27                 if(st.valid)
28                         load_statement(st);
29         }
30         finish();
31 }
32
33 Loader::~Loader()
34 {
35         for(ActionMap::iterator i=actions.begin(); i!=actions.end(); ++i)
36                 delete i->second;
37 }
38
39 void Loader::add(const string &k, LoaderAction *a)
40 {
41         ActionMap::iterator i=actions.find(k);
42         if(i!=actions.end())
43         {
44                 delete i->second;
45                 i->second=a;
46         }
47         else
48                 actions[k]=a;
49 }
50
51 void Loader::load_statement(const Statement &st)
52 {
53         cur_st=&st;
54         ActionMap::iterator j=actions.find(st.keyword);
55         if(j==actions.end())
56                 throw KeyError(st.get_location()+": Unknown keyword", st.keyword);
57         if(j->second)
58                 j->second->execute(*this, st);
59         cur_st=0;
60 }
61
62 } // namespace DataFile
63 } // namespace Msp