+/* $Id$
+
+This file is part of libmspdatafile
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "loader.h"
+
+using namespace std;
+
+namespace Msp {
+namespace DataFile {
+
+void Loader::load(const Statement &st)
+{
+ for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
+ load_statement(*i);
+}
+
+void Loader::load(Parser &p)
+{
+ while(p)
+ {
+ Statement st=p.parse();
+ if(st.valid)
+ load_statement(st);
+ }
+}
+
+Loader::~Loader()
+{
+ for(ActionMap::iterator i=actions.begin(); i!=actions.end(); ++i)
+ delete i->second;
+}
+
+void Loader::load_statement(const Statement &st)
+{
+ cur_st=&st;
+ ActionMap::iterator j=actions.find(st.keyword);
+ if(j==actions.end())
+ throw KeyError(st.get_location()+": Unknown keyword '"+st.keyword+"'");
+ if(j->second)
+ j->second->execute(*this, st);
+ cur_st=0;
+}
+
+} // namespace DataFile
+} // namespace Msp