]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/loader.cpp
Style update: add spaces around assignments
[libs/datafile.git] / source / loader.cpp
index e4993868ab3adfac95c385ef7c5d9e6a3c638a1c..6b0557fc0b568f7a62eeeda60547697d137232b7 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspdatafile
-Copyright © 2006  Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2008  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -14,7 +14,7 @@ namespace DataFile {
 
 void Loader::load(const Statement &st)
 {
-       for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
+       for(list<Statement>::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i)
                load_statement(*i);
        finish();
 }
@@ -23,7 +23,7 @@ void Loader::load(Parser &p)
 {
        while(p)
        {
-               Statement st=p.parse();
+               Statement st = p.parse();
                if(st.valid)
                        load_statement(st);
        }
@@ -32,7 +32,7 @@ void Loader::load(Parser &p)
 
 Loader::~Loader()
 {
-       for(ActionMap::iterator i=actions.begin(); i!=actions.end(); ++i)
+       for(ActionMap::iterator i = actions.begin(); i!=actions.end(); ++i)
                delete i->second;
 }
 
@@ -46,25 +46,36 @@ void Loader::load_sub_with(Loader &ldr)
 
 void Loader::add(const string &k, LoaderAction *a)
 {
-       ActionMap::iterator i=actions.find(k);
+       ActionMap::iterator i = actions.find(k);
        if(i!=actions.end())
        {
                delete i->second;
-               i->second=a;
+               i->second = a;
        }
        else
-               actions[k]=a;
+               actions[k] = a;
 }
 
 void Loader::load_statement(const Statement &st)
 {
-       cur_st=&st;
-       ActionMap::iterator j=actions.find(st.keyword);
+       cur_st = &st;
+       ActionMap::iterator j = actions.find(st.keyword);
        if(j==actions.end())
-               throw KeyError(st.get_location()+": Unknown keyword", st.keyword);
+               throw_at(KeyError("Unknown keyword", st.keyword), st.get_location());
        if(j->second)
-               j->second->execute(*this, st);
-       cur_st=0;
+       {
+               try
+               {
+                       j->second->execute(*this, st);
+               }
+               catch(Exception &e)
+               {
+                       if(!e.where()[0])
+                               e.at(st.get_location());
+                       throw;
+               }
+       }
+       cur_st = 0;
 }
 
 } // namespace DataFile