]> git.tdb.fi Git - libs/datafile.git/commitdiff
Use C++11 features to manipulate containers
authorMikko Rasa <tdb@tdb.fi>
Sun, 29 Aug 2021 18:29:32 +0000 (21:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 29 Aug 2021 18:29:32 +0000 (21:29 +0300)
15 files changed:
source/binaryparser.cpp
source/binarywriter.cpp
source/builtinsource.cpp
source/builtinsource.h
source/collection.cpp
source/collection.h
source/directorysource.cpp
source/jsonparser.cpp
source/loader.cpp
source/loaderaction.h
source/packsource.cpp
source/statement.cpp
source/textparser.cpp
source/textwriter.cpp
tool/compiler.cpp

index 4ed2877a4424c2389c890473a0e71918418516ba..e4282aea8f64ae3cf23eec698f885ab2bcd823b6 100644 (file)
@@ -91,8 +91,8 @@ void BinaryParser::process_control_statement(const Statement &st)
 
                const string &kw = st.args[1].get<const string &>();
                const string &args = st.args[2].get<const string &>();
-               for(string::const_iterator i=args.begin(); i!=args.end(); ++i)
-                       for(unsigned j=0; valid_signatures[j]!=*i; ++j)
+               for(char c: args)
+                       for(unsigned j=0; valid_signatures[j]!=c; ++j)
                                if(!valid_signatures[j])
                                        throw bad_definition("__kwd");
 
index 0fbf8ce503058f5aaa89734250856777e083409e..be548446f2f1fca9fb564661d17bec4d686d6d97 100644 (file)
@@ -43,19 +43,19 @@ void BinaryWriter::write_(const Statement &st)
        int id = get_item(dict, StatementKey(st.keyword, st.get_signature()));
 
        write_int(id);
-       for(Statement::Arguments::const_iterator j = st.args.begin(); j!=st.args.end(); ++j)
-               switch(j->get_signature())
+       for(const Value &a: st.args)
+               switch(a.get_signature())
                {
-               case IntType::signature:    write_int   (j->get<IntType::Store>()); break;
-               case StringType::signature: write_string(j->get<StringType::Store>()); break;
-               case BoolType::signature:   write_int   (j->get<BoolType::Store>()); break;
-               case FloatType::signature:  write_float (j->get<FloatType::Store>()); break;
-               case SymbolType::signature: write_symbol(j->get<SymbolType::Store>()); break;
+               case IntType::signature:    write_int   (a.get<IntType::Store>()); break;
+               case StringType::signature: write_string(a.get<StringType::Store>()); break;
+               case BoolType::signature:   write_int   (a.get<BoolType::Store>()); break;
+               case FloatType::signature:  write_float (a.get<FloatType::Store>()); break;
+               case SymbolType::signature: write_symbol(a.get<SymbolType::Store>()); break;
                }
 
        write_int(st.sub.size());
-       for(list<Statement>::const_iterator j = st.sub.begin(); j!=st.sub.end(); ++j)
-               write(*j);
+       for(const Statement &s: st.sub)
+               write(s);
 }
 
 void BinaryWriter::collect_keywords(const Statement &st)
@@ -74,15 +74,15 @@ void BinaryWriter::collect_keywords(const Statement &st)
                dict[key] = next_kwd_id++;
        }
 
-       for(vector<Value>::const_iterator i = st.args.begin(); i!=st.args.end(); ++i)
+       for(const Value &a: st.args)
        {
-               char sig = i->get_signature();
+               char sig = a.get_signature();
                string str;
                if(sig==SymbolType::signature)
-                       str = i->get<Symbol>().name;
+                       str = a.get<Symbol>().name;
                else if(sig==StringType::signature)
                {
-                       str = i->get<string>();
+                       str = a.get<string>();
                        if(str.size()>32)
                                continue;
                }
@@ -101,8 +101,8 @@ void BinaryWriter::collect_keywords(const Statement &st)
                strings[str] = next_str_id++;
        }
 
-       for(list<Statement>::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i)
-               collect_keywords(*i);
+       for(const Statement &s: st.sub)
+               collect_keywords(s);
 }
 
 void BinaryWriter::write_int(IntType::Store n)
index bdccd7741c5a7f250585c6058c47d7ee066c9aad..65b2718b80357660e8664ac803e6d855badf382b 100644 (file)
@@ -26,15 +26,15 @@ bool BuiltinSource::is_loadable(const CollectionItemTypeBase &, const string &na
 CollectionSource::NameList BuiltinSource::get_names(const CollectionItemTypeBase &type) const
 {
        NameList names;
-       for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
-               if(type.match_name(i->first))
-                       names.push_back(i->first);
+       for(const auto &kvp: objects)
+               if(type.match_name(kvp.first))
+                       names.push_back(kvp.first);
        return names;
 }
 
 void BuiltinSource::load(Collection &coll, const CollectionItemTypeBase &type, const string &name) const
 {
-       ObjectMap::const_iterator i = objects.find(name);
+       auto i = objects.find(name);
        if(i!=objects.end())
        {
                IO::Memory in(i->second.data, i->second.size);
@@ -45,7 +45,7 @@ void BuiltinSource::load(Collection &coll, const CollectionItemTypeBase &type, c
 
 IO::Seekable *BuiltinSource::open(const string &name) const
 {
-       ObjectMap::const_iterator i = objects.find(name);
+       auto i = objects.find(name);
        if(i!=objects.end())
                return new IO::Memory(i->second.data, i->second.size);
 
index 244191c3e6a728b8dab42d2a97b2264635113007..ec5396334d65282fb2065a069b72e946a52683c0 100644 (file)
@@ -18,9 +18,7 @@ private:
                Object(const char *, unsigned);
        };
 
-       typedef std::map<std::string, Object> ObjectMap;
-
-       ObjectMap objects;
+       std::map<std::string, Object> objects;
 
 public:
        void add_object(const std::string &, const char *, unsigned);
index f86adf65c71ace3370e7a57537eaa4fe6cd8243a..c168d8abd002a5bd82134914a9ee9205a1ab06fb 100644 (file)
@@ -1,4 +1,5 @@
 #include <set>
+#include <msp/core/algorithm.h>
 #include "collection.h"
 
 using namespace std;
@@ -12,8 +13,8 @@ Collection::Collection():
 
 Collection::~Collection()
 {
-       for(TypeList::iterator i = types.begin(); i!=types.end(); ++i)
-               delete *i;
+       for(CollectionItemTypeBase *t: types)
+               delete t;
 }
 
 void Collection::add_var(const string &name, const CollectionItemTypeBase *type, const Variant &var)
@@ -46,7 +47,7 @@ const Variant *Collection::find_var(const string &name, const CollectionItemType
                        type->create_item(*this, name);
                        loaded = items.count(name);
                }
-               for(SourceList::iterator j=sources.begin(); (!loaded && j!=sources.end()); ++j)
+               for(auto j=sources.begin(); (!loaded && j!=sources.end()); ++j)
                {
                        (*j)->load(*this, *type, name);
                        loaded = items.count(name);
@@ -63,13 +64,13 @@ const Variant *Collection::find_var(const string &name, const CollectionItemType
 
 void Collection::gather_items(vector<const Variant *> *vars, list<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
 {
-       for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i)
-               if(type.check_item_type(i->second))
+       for(const auto &kvp: items)
+               if(type.check_item_type(kvp.second))
                {
                        if(vars)
-                               vars->push_back(&i->second);
+                               vars->push_back(&kvp.second);
                        if(names)
-                               names->push_back(i->first);
+                               names->push_back(kvp.first);
                }
 
        if(include_sources && names)
@@ -81,9 +82,9 @@ unsigned Collection::get_status(const string &name, const CollectionItemTypeBase
        ItemMap::const_iterator i = items.find(name);
        if(i==items.end())
        {
-               for(SourceList::const_iterator j=sources.begin(); j!=sources.end(); ++j)
-                       if((*j)->is_loadable(type, name))
-                               return 2;
+               auto j = find_if(sources, [&name, &type](const CollectionSource *s){ return s->is_loadable(type, name); });
+               if(j!=sources.end())
+                       return 2;
                if(fallback)
                        if(CollectionItemTypeBase *fb_type = fallback->get_type(type))
                                return fallback->get_status(name, *fb_type);
@@ -95,17 +96,17 @@ unsigned Collection::get_status(const string &name, const CollectionItemTypeBase
 
 CollectionItemTypeBase *Collection::get_type(const CollectionItemTypeBase &type) const
 {
-       for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
-               if((*j)->is_same_type(type))
-                       return *j;
+       for(CollectionItemTypeBase *t: types)
+               if(t->is_same_type(type))
+                       return t;
        return 0;
 }
 
 CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const
 {
-       for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i)
-               if((*i)->check_item_type(var))
-                       return *i;
+       for(CollectionItemTypeBase *t: types)
+               if(t->check_item_type(var))
+                       return t;
        return 0;
 }
 
@@ -116,8 +117,8 @@ void Collection::add_source(const CollectionSource &s)
 
 IO::Seekable *Collection::open_raw(const string &name) const
 {
-       for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-               if(IO::Seekable *io = (*i)->open(name))
+       for(const CollectionSource *s: sources)
+               if(IO::Seekable *io = s->open(name))
                        return io;
 
        return 0;
@@ -126,34 +127,28 @@ IO::Seekable *Collection::open_raw(const string &name) const
 void Collection::gather_names_from_sources(list<string> &names, const CollectionItemTypeBase &type) const
 {
        set<string> new_names;
-       for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-       {
-               std::list<std::string> available_names = (*i)->get_names(type);
-               for(std::list<std::string>::iterator j=available_names.begin(); j!=available_names.end(); ++j)
-                       if(!items.count(*j))
-                               new_names.insert(*j);
-       }
+       for(const CollectionSource *s: sources)
+               for(const string &n: s->get_names(type))
+                       if(!items.count(n))
+                               new_names.insert(n);
        names.insert(names.end(), new_names.begin(), new_names.end());
 }
 
 void Collection::load_items_from_sources(const CollectionItemTypeBase &type)
 {
-       for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-       {
-               std::list<std::string> available_names = (*i)->get_names(type);
-               for(std::list<std::string>::iterator j=available_names.begin(); j!=available_names.end(); ++j)
-                       if(!items.count(*j))
+       for(const CollectionSource *s: sources)
+               for(const string &n: s->get_names(type))
+                       if(!items.count(n))
                        {
                                bool loaded = false;
                                if(type.can_create())
                                {
-                                       type.create_item(*this, *j);
-                                       loaded = items.count(*j);
+                                       type.create_item(*this, n);
+                                       loaded = items.count(n);
                                }
                                if(!loaded)
-                                       (*i)->load(*this, type, *j);
+                                       s->load(*this, type, n);
                        }
-       }
 }
 
 void Collection::set_fallback(Collection *f)
@@ -165,15 +160,15 @@ void Collection::set_fallback(Collection *f)
 Collection::Loader::Loader(Collection &c):
        coll(c)
 {      
-       for(TypeList::const_iterator i = coll.types.begin(); i!=coll.types.end(); ++i)
-               (*i)->add_to_loader(*this);
+       for(const CollectionItemTypeBase *t: coll.types)
+               t->add_to_loader(*this);
 }
 
 
 CollectionItemTypeBase::~CollectionItemTypeBase()
 {
-       for(vector<ExtractorBase *>::iterator i=extractors.begin(); i!=extractors.end(); ++i)
-               delete *i;
+       for(ExtractorBase *e: extractors)
+               delete e;
 }
 
 void CollectionItemTypeBase::set_keyword(const string &k)
@@ -190,8 +185,8 @@ void CollectionItemTypeBase::add_suffix(const string &s)
 
 bool CollectionItemTypeBase::match_name(const string &name) const
 {
-       for(vector<string>::const_iterator i=suffixes.begin(); i!=suffixes.end(); ++i)
-               if(name.size()>i->size() && !name.compare(name.size()-i->size(), string::npos, *i))
+       for(const string &s: suffixes)
+               if(name.size()>s.size() && !name.compare(name.size()-s.size(), string::npos, s))
                        return true;
        return false;
 }
index 473b58ed76329cf72d971f728d29ba0aae296760..98b359e5eaedd28604a5d1f0a0085f470a657219 100644 (file)
@@ -85,12 +85,10 @@ public:
 
 private:
        typedef std::map<std::string, Variant> ItemMap;
-       typedef std::vector<CollectionItemTypeBase *> TypeList;
-       typedef std::vector<const CollectionSource *> SourceList;
 
-       TypeList types;
+       std::vector<CollectionItemTypeBase *> types;
        ItemMap items;
-       SourceList sources;
+       std::vector<const CollectionSource *> sources;
        Collection *fallback;
 
 public:
@@ -166,8 +164,8 @@ private:
        std::list<T *> extract_list(const std::vector<const Variant *> &vars) const
        {
                std::list<T *> result;
-               for(std::vector<const Variant *>::const_iterator i=vars.begin(); i!=vars.end(); ++i)
-                       result.push_back(&extract<T>(**i));
+               for(const Variant *v: vars)
+                       result.push_back(&extract<T>(*v));
                return result;
        }
 
@@ -257,10 +255,10 @@ public:
        {
                typedef RefPtr<typename std::remove_cv<T>::type> RPNCT;
 
-               for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i)
-                       if(i->second.check_type<RPNCT>())
-                               if(i->second.value<RPNCT>().get()==d)
-                                       return i->first;
+               for(const auto &kvp: items)
+                       if(kvp.second.check_type<RPNCT>())
+                               if(kvp.second.value<RPNCT>().get()==d)
+                                       return kvp.first;
        
                // XXX Need better exception class
                throw std::runtime_error("Item not found in collection");
@@ -371,8 +369,8 @@ public:
        template<typename T>
        bool can_extract() const
        {
-               for(std::vector<ExtractorBase *>::const_iterator i=extractors.begin(); i!=extractors.end(); ++i)
-                       if(dynamic_cast<Extractor<T> *>(*i))
+               for(ExtractorBase *e: extractors)
+                       if(dynamic_cast<Extractor<T> *>(e))
                                return true;
                return false;
        }
@@ -380,8 +378,8 @@ public:
        template<typename T>
        T *extract(const Variant &var) const
        {
-               for(std::vector<ExtractorBase *>::const_iterator i=extractors.begin(); i!=extractors.end(); ++i)
-                       if(Extractor<T> *ex = dynamic_cast<Extractor<T> *>(*i))
+               for(ExtractorBase *e: extractors)
+                       if(Extractor<T> *ex = dynamic_cast<Extractor<T> *>(e))
                                return &ex->extract(var);
                return 0;
        }
@@ -454,8 +452,8 @@ public:
        ~CollectionItemType()
        {
                delete creat;
-               for(typename std::vector<NotifyeeBase *>::const_iterator i=notif.begin(); i!=notif.end(); ++i)
-                       delete *i;
+               for(NotifyeeBase *n: notif)
+                       delete n;
        }
 
        /** Sets a datafile keyword for this item type.  The Collection's loader
@@ -535,8 +533,8 @@ public:
        virtual void notify_item(Collection &coll, const std::string &name, const Variant &var) const
        {
                RefPtr<T> obj = var.value<RefPtr<T> >();
-               for(typename std::vector<NotifyeeBase *>::const_iterator i=notif.begin(); i!=notif.end(); ++i)
-                       (*i)->notify(coll, name, *obj);
+               for(NotifyeeBase *n: notif)
+                       n->notify(coll, name, *obj);
        }
 };
 
@@ -581,9 +579,9 @@ typename CollectionItemTypeChooser<T>::Type &Collection::add_type()
 template<typename T>
 typename CollectionItemTypeChooser<T>::Type &Collection::modify_type()
 {
-       for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
-               if(CollectionItemType<T> *t = dynamic_cast<CollectionItemType<T> *>(*j))
-                       return *t;
+       for(CollectionItemTypeBase *t: types)
+               if(CollectionItemType<T> *tt = dynamic_cast<CollectionItemType<T> *>(t))
+                       return *tt;
 
        throw std::logic_error("type not found in collection");
 }
@@ -591,16 +589,16 @@ typename CollectionItemTypeChooser<T>::Type &Collection::modify_type()
 template<typename T>
 CollectionItemTypeBase *Collection::get_type(const std::string &name) const
 {
-       for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
-               if(dynamic_cast<CollectionItemType<T> *>(*j))
-                       return *j;
+       for(CollectionItemTypeBase *t: types)
+               if(dynamic_cast<CollectionItemType<T> *>(t))
+                       return t;
        CollectionItemTypeBase *type = 0;
-       for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
-               if((*j)->can_extract<T>())
+       for(CollectionItemTypeBase *t: types)
+               if(t->can_extract<T>())
                {
-                       if(!name.empty() && (*j)->match_name(name))
-                               return *j;
-                       type = *j;
+                       if(!name.empty() && t->match_name(name))
+                               return t;
+                       type = t;
                }
        return type;
 }
index 207f30d0e31716c310f0927b82f5ba14fe456b6a..e9f95fc830c9686997bc13088460c0da38847642 100644 (file)
@@ -10,12 +10,9 @@ namespace DataFile {
 
 void DirectorySource::add_directory(const FS::Path &d, bool replace)
 {
-       list<string> files = FS::list_files(d);
-       for(list<string>::const_iterator i=files.begin(); i!=files.end(); ++i)
-       {
-               if(!objects.count(*i) || replace)
-                       objects[*i] = d / *i;
-       }
+       for(const string &f: FS::list_files(d))
+               if(!objects.count(f) || replace)
+                       objects[f] = d/f;
 }
 
 bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &name) const
@@ -26,9 +23,9 @@ bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &
 CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const
 {
        NameList names;
-       for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
-               if(type.match_name(i->first))
-                       names.push_back(i->first);
+       for(const auto &kvp: objects)
+               if(type.match_name(kvp.first))
+                       names.push_back(kvp.first);
        return names;
 }
 
index 4b937035b81fbcb5412efd216a8d74de779150bb..44c7b06d64c7da744154f3d658cc153427d84826 100644 (file)
@@ -312,7 +312,7 @@ string JsonParser::unescape(const string &str)
        StringCodec::Utf8::Encoder enc;
        bool escape = false;
 
-       for(string::const_iterator i=str.begin(); i!=str.end(); )
+       for(auto i=str.begin(); i!=str.end(); )
        {
                StringCodec::unichar c = dec.decode_char(str, i);
 
index 3484799a3e4891b12b622139b646e27a582690a1..98a0234961d2029d0b665450a314c120bf90e35f 100644 (file)
@@ -24,7 +24,7 @@ int signature_match(const string &st_sig, const string &act_sig)
        else if(act_sig.size()==2 && act_sig[1]=='*')
        {
                int match = 3;
-               for(string::const_iterator i=st_sig.begin(); (i!=st_sig.end() && match); ++i)
+               for(auto i=st_sig.begin(); (i!=st_sig.end() && match); ++i)
                        match = min(match, signature_match(*i, act_sig[0]));
 
                return match;
@@ -79,8 +79,8 @@ void Loader::load(const Statement &st)
        if(!actions)
                throw logic_error("no actions");
 
-       for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
-               load_statement(*i);
+       for(const Statement &s: st.sub)
+               load_statement(s);
        finish();
 }
 
@@ -117,9 +117,9 @@ void Loader::load_statement(const Statement &st)
 
                if(!aux_loaders.empty() && !has_action(key))
                {
-                       for(vector<Loader *>::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i)
-                               if((*i)->has_action(key))
-                                       return (*i)->load_statement(st);
+                       for(Loader *l: aux_loaders)
+                               if(l->has_action(key))
+                                       return l->load_statement(st);
                }
 
                LoaderAction *act = find_action(key);
@@ -196,7 +196,7 @@ bool Loader::has_action(const StatementKey &key) const
        if(!actions)
                return false;
 
-       ActionMap::const_iterator i = actions->lower_bound(StatementKey(key.keyword, string()));
+       auto i = actions->lower_bound(StatementKey(key.keyword, string()));
        for(; (i!=actions->end() && i->first.keyword==key.keyword); ++i)
                if(signature_match(key.signature, i->first.signature))
                        return true;
@@ -208,15 +208,15 @@ LoaderAction *Loader::find_action(const StatementKey &key) const
        if(!actions)
                return 0;
 
-       ActionMap::const_iterator begin = actions->lower_bound(StatementKey(key.keyword, string()));
-       ActionMap::const_iterator end = actions->upper_bound(StatementKey(key.keyword, "~"));
+       auto begin = actions->lower_bound(StatementKey(key.keyword, string()));
+       auto end = actions->upper_bound(StatementKey(key.keyword, "~"));
 
        if(begin==end)
                throw unknown_keyword(key.keyword);
 
        LoaderAction *act = 0;
        int match = 0;
-       for(ActionMap::const_iterator i=begin; i!=end; ++i)
+       for(auto i=begin; i!=end; ++i)
        {
                int m = signature_match(key.signature, i->first.signature);
                if(m>match)
@@ -249,8 +249,8 @@ const string &Loader::get_keyword() const
 
 Loader::ActionMap::~ActionMap()
 {
-       for(iterator i=begin(); i!=end(); ++i)
-               delete i->second;
+       for(const auto &kvp: *this)
+               delete kvp.second;
 }
 
 } // namespace DataFile
index 6931f4849ff21ff6fee354fb9ac904011422e284..4666687e71534fd15d63499898ce9217250f4ee9 100644 (file)
@@ -113,8 +113,8 @@ public:
        {
                std::vector<A0> values;
                values.reserve(st.args.size());
-               for(Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
-                       values.push_back(i->get<A0>());
+               for(const Value &a: st.args)
+                       values.push_back(a.get<A0>());
                (dynamic_cast<L &>(l).*func)(values);
        }
 
index b9f601668e44f13be8f7b5ae017d5dc13ed5be1d..b2fb17abc5ae9393feabf2f223130b547a3c072e 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/io/slice.h>
 #include <msp/strings/format.h>
 #include <msp/strings/regex.h>
@@ -65,44 +66,41 @@ void PackSource::add_pack_io(IO::Seekable &io, const string &fn, const string &f
 
 void PackSource::add_pack(IO::Seekable *io, const string &fn, const string &filter)
 {
-       Pack *pack = 0;
-       for(list<Pack>::iterator i=packs.begin(); (!pack && i!=packs.end()); ++i)
-               if(i->get_filename()==fn || (io && i->get_io()==io))
-                       pack = &*i;
-       if(!pack)
+       auto i = find_if(packs, [io, &fn](const Pack &p){ return p.get_filename()==fn || (io && p.get_io()==io); });
+       if(i==packs.end())
        {
                packs.push_back(Pack(io, fn));
-               pack = &packs.back();
+               i = prev(packs.end());
                if(io)
                {
                        DataFile::Parser parser(*io, fn);
-                       Pack::Loader loader(*pack);
+                       Pack::Loader loader(*i);
                        loader.load(parser);
                }
                else
-                       DataFile::load(*pack, fn);
+                       DataFile::load(*i, fn);
        }
 
        FileMap pack_files;
-       pack->collect_files(pack_files, filter);
-       for(FileMap::const_iterator i=pack_files.begin(); i!=pack_files.end(); ++i)
+       i->collect_files(pack_files, filter);
+       for(const auto &kvp: pack_files)
        {
-               files[i->first] = i->second;
-               i->second->collect_objects(objects);
+               files[kvp.first] = kvp.second;
+               kvp.second->collect_objects(objects);
        }
 }
 
 list<PackSource::FileInfo> PackSource::list_files() const
 {
        list<FileInfo> result;
-       for(FileMap::const_iterator i=files.begin(); i!=files.end(); ++i)
-               result.push_back(i->second->get_info());
+       for(const auto &kvp: files)
+               result.push_back(kvp.second->get_info());
        return result;
 }
 
 bool PackSource::is_loadable(const CollectionItemTypeBase &type, const string &name) const
 {
-       ObjectMap::const_iterator i = objects.find(name);
+       auto i = objects.find(name);
        if(i==objects.end())
                return false;
 
@@ -116,17 +114,17 @@ bool PackSource::is_loadable(const CollectionItemTypeBase &type, const string &n
 CollectionSource::NameList PackSource::get_names(const CollectionItemTypeBase &type) const
 {
        NameList names;
-       for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+       for(const auto &kvp: objects)
        {
-               if(!i->second->get_keyword().empty())
+               if(!kvp.second->get_keyword().empty())
                {
-                       if(i->second->get_keyword()!=type.get_keyword())
+                       if(kvp.second->get_keyword()!=type.get_keyword())
                                continue;
                }
-               else if(!type.match_name(i->first))
+               else if(!type.match_name(kvp.first))
                        continue;
 
-               names.push_back(i->first);
+               names.push_back(kvp.first);
        }
 
        return names;
@@ -134,7 +132,7 @@ CollectionSource::NameList PackSource::get_names(const CollectionItemTypeBase &t
 
 void PackSource::load(Collection &coll, const CollectionItemTypeBase &type, const string &name) const
 {
-       ObjectMap::const_iterator i = objects.find(name);
+       auto i = objects.find(name);
        if(i==objects.end())
                return;
 
@@ -153,7 +151,7 @@ void PackSource::load(Collection &coll, const CollectionItemTypeBase &type, cons
 
 IO::Seekable *PackSource::open(const string &fn) const
 {
-       FileMap::const_iterator i = files.find(fn);
+       auto i = files.find(fn);
        if(i!=files.end())
                return i->second->open().release();
 
@@ -172,31 +170,31 @@ PackSource::Pack::Pack(const Pack &other):
        io(other.io),
        base_offset(other.base_offset)
 {
-       for(list<File>::const_iterator i=other.files.begin(); i!=other.files.end(); ++i)
-               files.push_back(File(*i, *this));
+       for(const File &f: other.files)
+               files.push_back(File(f, *this));
 }
 
 void PackSource::Pack::collect_files(FileMap &fm, const string &filter) const
 {
        if(filter.empty())
        {
-               for(list<File>::const_iterator i=files.begin(); i!=files.end(); ++i)
-                       fm[i->get_filename()] = &*i;
+               for(const File &f: files)
+                       fm[f.get_filename()] = &f;
        }
        else
        {
                Regex re(filter);
-               for(list<File>::const_iterator i=files.begin(); i!=files.end(); ++i)
-                       if(re.match(i->get_filename()))
-                               fm[i->get_filename()] = &*i;
+               for(const File &f: files)
+                       if(re.match(f.get_filename()))
+                               fm[f.get_filename()] = &f;
        }
 }
 
 void PackSource::Pack::translate_files(FileMap &fm, const Pack &source) const
 {
-       for(list<File>::const_iterator i=files.begin(), j=source.files.begin(); (i!=files.end() && j!=source.files.end()); ++i, ++j)
+       for(auto i=files.begin(), j=source.files.begin(); (i!=files.end() && j!=source.files.end()); ++i, ++j)
        {
-               FileMap::iterator k = fm.find(i->get_filename());
+               auto k = fm.find(i->get_filename());
                if(k!=fm.end() && k->second==&*j)
                        k->second = &*i;
        }
@@ -218,8 +216,8 @@ PackSource::File::File(const File &other, const Pack &p):
        length(other.length),
        collection(other.collection)
 {
-       for(list<Object>::const_iterator i=other.objects.begin(); i!=other.objects.end(); ++i)
-               objects.push_back(Object(*i, *this));
+       for(const Object &o: other.objects)
+               objects.push_back(Object(o, *this));
 }
 
 RefPtr<IO::Seekable> PackSource::File::open() const
@@ -251,15 +249,15 @@ string PackSource::File::get_full_name() const
 
 void PackSource::File::collect_objects(ObjectMap &objs) const
 {
-       for(list<Object>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
-               objs[i->get_name()] = &*i;
+       for(const Object &o: objects)
+               objs[o.get_name()] = &o;
 }
 
 void PackSource::File::translate_objects(ObjectMap &objs, const File &source) const
 {
-       for(list<Object>::const_iterator i=objects.begin(), j=source.objects.begin(); (i!=objects.end() && j!=source.objects.end()); ++i, ++j)
+       for(auto i=objects.begin(), j=source.objects.begin(); (i!=objects.end() && j!=source.objects.end()); ++i, ++j)
        {
-               ObjectMap::iterator k = objs.find(i->get_name());
+               auto k = objs.find(i->get_name());
                if(k!=objs.end() && k->second==&*j)
                        k->second = &*i;
        }
index 6d1c3b1f22767b5eba0d6cca5bb52b0ef0651794..baa9054e0cfb2f50cbb95ee17074d55dac3b9d0e 100644 (file)
@@ -32,8 +32,8 @@ string Statement::get_location() const
 string Statement::get_signature() const
 {
        string result;
-       for(Arguments::const_iterator i=args.begin(); i!=args.end(); ++i)
-               result += i->get_signature();
+       for(const Value &a: args)
+               result += a.get_signature();
        return result;
 }
 
@@ -67,10 +67,10 @@ StatementInfo::StatementInfo(const string &k, const string &s):
        key(k, s),
        args_size(0)
 {
-       for(string::const_iterator i=key.signature.begin(); i!=key.signature.end(); ++i)
+       for(char c: key.signature)
        {
                arg_offsets.push_back(args_size);
-               switch(*i)
+               switch(c)
                {
                case IntType::signature:
                        args_size += sizeof(IntType::Store);
index d467de8582ef323367538ec8dbfd8f03a5e54272..b8515a9b487fa2749d78c5c41a734c2f00c1b70f 100644 (file)
@@ -317,20 +317,20 @@ string TextParser::base64_decode(const string &data)
        bin.reserve(data.size()*3/4);
        unsigned accum = 0;
        unsigned a_bits = 0;
-       for(string::const_iterator i=data.begin(); i!=data.end(); ++i)
+       for(char c: data)
        {
                unsigned d;
-               if(*i>='A' && *i<='Z')
-                       d = *i-'A';
-               else if(*i>='a' && *i<='z')
-                       d = 26+(*i-'a');
-               else if(*i>='0' && *i<='9')
-                       d = 52+(*i-'0');
-               else if(*i=='+')
+               if(c>='A' && c<='Z')
+                       d = c-'A';
+               else if(c>='a' && c<='z')
+                       d = 26+(c-'a');
+               else if(c>='0' && c<='9')
+                       d = 52+(c-'0');
+               else if(c=='+')
                        d = 62;
-               else if(*i=='/')
+               else if(c=='/')
                        d = 63;
-               else if(*i=='=')
+               else if(c=='=')
                        continue;
                else
                        throw invalid_argument("TextParser::base64_decode");
index 921842279f133eabf555d57d97e609d563dacb72..04fccff5afaf43ae30f708be0870b1427dd67309 100644 (file)
@@ -30,20 +30,20 @@ void TextWriter::write_(const Statement &st, unsigned level)
        string indent(level, '\t');
 
        out.write(format("%s%s", indent, st.keyword));
-       for(vector<Value>::const_iterator i = st.args.begin(); i!=st.args.end(); ++i)
+       for(const Value &v: st.args)
        {
                out.put(' ');
-               if(i->get_signature()==StringType::signature)
-                       out.write(format("\"%s\"", c_escape(i->get<StringType::Store>(), false)));
-               else if(i->get_signature()==BoolType::signature)
-                       out.write(i->get<BoolType::Store>() ? "true" : "false");
-               else if(i->get_signature()==IntType::signature)
-                       out.write(lexical_cast<string>(i->get<IntType::Store>()));
-               else if(i->get_signature()==FloatType::signature)
-                       out.write(lexical_cast<string>(i->get<FloatType::Store>(), float_format));
-               else if(i->get_signature()==SymbolType::signature)
+               if(v.get_signature()==StringType::signature)
+                       out.write(format("\"%s\"", c_escape(v.get<StringType::Store>(), false)));
+               else if(v.get_signature()==BoolType::signature)
+                       out.write(v.get<BoolType::Store>() ? "true" : "false");
+               else if(v.get_signature()==IntType::signature)
+                       out.write(lexical_cast<string>(v.get<IntType::Store>()));
+               else if(v.get_signature()==FloatType::signature)
+                       out.write(lexical_cast<string>(v.get<FloatType::Store>(), float_format));
+               else if(v.get_signature()==SymbolType::signature)
                {
-                       string name = i->get<SymbolType::Store>().name;
+                       string name = v.get<SymbolType::Store>().name;
                        if(isdigit(name[0]))
                                out.write("\\"+name);
                        else
@@ -53,8 +53,8 @@ void TextWriter::write_(const Statement &st, unsigned level)
        if(!st.sub.empty())
        {
                out.write(format("\n%s{\n", indent));
-               for(list<Statement>::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i)
-                       write_(*i, level+1);
+               for(const Statement &s: st.sub)
+                       write_(s, level+1);
                out.write(format("%s}", indent));
        }
        out.write(";\n");
index 49dd19031cc0408fc958e84afd3fcfa4063bc403..8360ee6ce35931b52f5867bfb75ffdddeb713df1 100644 (file)
@@ -166,16 +166,15 @@ ForEach::ForEach(Compiler &c, const FS::Path &b, const list<string> &p):
 
 void ForEach::finish()
 {
-       list<string> files = FS::list_files(base);
-       for(list<string>::iterator i = files.begin(); i!=files.end(); ++i)
+       for(const string &f: FS::list_files(base))
        {
                bool match = false;
                for(list<string>::const_iterator j = patterns.begin(); (j!=patterns.end() && !match); ++j)
-                       match = Regex(*j).match(*i);
+                       match = Regex(*j).match(f);
                for(list<string>::const_iterator j = excludes.begin(); (j!=excludes.end() && match); ++j)
-                       match = !Regex(*j).match(*i);
+                       match = !Regex(*j).match(f);
                if(match)
-                       compiler.process_file(base / *i, write_st);
+                       compiler.process_file(base/f, write_st);
        }
 }