]> git.tdb.fi Git - libs/gl.git/commitdiff
Use C++11 features with containers
authorMikko Rasa <tdb@tdb.fi>
Fri, 17 Sep 2021 22:57:58 +0000 (01:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 17 Sep 2021 22:57:58 +0000 (01:57 +0300)
56 files changed:
source/animation/animation.cpp
source/animation/animationplayer.cpp
source/animation/animationplayer.h
source/animation/armature.cpp
source/builders/font.cpp
source/builders/sequencebuilder.cpp
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/core/batch.cpp
source/core/clipping.cpp
source/core/framebuffer.cpp
source/core/mesh.cpp
source/core/module.cpp
source/core/pipelinestate.cpp
source/core/program.cpp
source/core/tag.cpp
source/core/vertexformat.cpp
source/glsl/builtin.cpp
source/glsl/compiler.cpp
source/glsl/debug.cpp
source/glsl/finalize.cpp
source/glsl/generate.cpp
source/glsl/modulecache.cpp
source/glsl/optimize.cpp
source/glsl/output.cpp
source/glsl/parser.cpp
source/glsl/reflect.cpp
source/glsl/resolve.cpp
source/glsl/sourcemap.cpp
source/glsl/spirv.cpp
source/glsl/syntax.cpp
source/glsl/tokenizer.cpp
source/glsl/validate.cpp
source/glsl/visitor.cpp
source/materials/lighting.cpp
source/materials/material.cpp
source/materials/renderpass.cpp
source/materials/technique.cpp
source/materials/technique.h
source/render/instancearray.cpp
source/render/object.cpp
source/render/occludedscene.cpp
source/render/occludedscene.h
source/render/orderedscene.cpp
source/render/orderedscene.h
source/render/programdata.cpp
source/render/renderer.cpp
source/render/rendertarget.cpp
source/render/sequence.cpp
source/render/simplescene.cpp
source/render/simplescene.h
source/render/zsortedscene.cpp
source/render/zsortedscene.h
source/resources/resourcemanager.cpp
source/resources/resourcemanager.h
tests/glsl/glslcompiler.cpp

index b62f5dd9c74e035ed7fe0ab39ef69c46b3cbf714..a9278e3de00836b3eb9e2ebe56ff908e2da207ed 100644 (file)
@@ -1,4 +1,5 @@
 #include <cmath>
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/datafile/collection.h>
 #include <msp/fs/utils.h>
@@ -22,11 +23,11 @@ Animation::Animation():
 
 Animation::~Animation()
 {
-       for(vector<TimedKeyFrame>::iterator i=keyframes.begin(); i!=keyframes.end(); ++i)
-               if(i->owned)
-                       delete i->keyframe;
-       for(vector<Curve *>::iterator i=curves.begin(); i!=curves.end(); ++i)
-               delete *i;
+       for(TimedKeyFrame &k: keyframes)
+               if(k.owned)
+                       delete k.keyframe;
+       for(Curve *c: curves)
+               delete c;
 }
 
 void Animation::set_armature(const Armature &a)
@@ -116,17 +117,17 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, float
                ctrn.set_scale(last_trn.get_scale()*(1-x)+trn.get_scale()*x);
                ckf->set_transform(ctrn);
 
-               for(KeyFrame::UniformMap::const_iterator j=kf_unis.begin(); j!=kf_unis.end(); ++j)
+               for(const auto &kvp: kf_unis)
                {
-                       KeyFrame::UniformMap::const_iterator k = last_unis.find(j->first);
+                       auto k = last_unis.find(kvp.first);
                        if(k==last_unis.end())
                                continue;
 
-                       KeyFrame::AnimatedUniform uni(j->second.size, 0.0f);
+                       KeyFrame::AnimatedUniform uni(kvp.second.size, 0.0f);
                        for(unsigned c=0; c<uni.size; ++c)
-                               uni.values[c] = k->second.values[c]*(1-x)+j->second.values[c]*x;
+                               uni.values[c] = k->second.values[c]*(1-x)+kvp.second.values[c]*x;
 
-                       ckf->set_uniform(j->first, uni);
+                       ckf->set_uniform(kvp.first, uni);
                }
 
                add_keyframe(t, ckf, true, true);
@@ -147,10 +148,10 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool
                throw invalid_argument("Animation::add_keyframe");
 
        const KeyFrame::UniformMap &kf_uniforms = kf->get_uniforms();
-       for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+       for(const UniformInfo &u: uniforms)
        {
-               KeyFrame::UniformMap::const_iterator j = kf_uniforms.find(i->name);
-               if(j!=kf_uniforms.end() && j->second.size!=i->size)
+               auto j = kf_uniforms.find(u.name);
+               if(j!=kf_uniforms.end() && j->second.size!=u.size)
                        throw invalid_argument("Animation::add_keyframe");
        }
 
@@ -165,21 +166,17 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool
 
        keyframes.push_back(tkf);
 
-       for(KeyFrame::UniformMap::const_iterator i=kf_uniforms.begin(); i!=kf_uniforms.end(); ++i)
+       for(const auto &kvp: kf_uniforms)
        {
-               bool found = false;
-               for(vector<UniformInfo>::const_iterator j=uniforms.begin(); (!found && j!=uniforms.end()); ++j)
-                       found = (j->name==i->first);
-
-               if(!found)
-                       uniforms.push_back(UniformInfo(i->first, i->second.size));
+               if(find_member(uniforms, kvp.first, &UniformInfo::name)==uniforms.end())
+                       uniforms.push_back(UniformInfo(kvp.first, kvp.second.size));
        }
 }
 
 void Animation::create_curves()
 {
-       for(vector<Curve *>::iterator i=curves.begin(); i!=curves.end(); ++i)
-               delete *i;
+       for(Curve *c: curves)
+               delete c;
        curves.clear();
 
        curves.reserve(6+uniforms.size());
@@ -188,16 +185,16 @@ void Animation::create_curves()
        create_curve(SCALE, Transform::SCALE, &extract_scale);
 
        uniform_curve_offset = curves.size();
-       for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+       for(const UniformInfo &u: uniforms)
        {
-               if(i->size==1)
-                       create_curve<1>(UNIFORM, -1, ExtractUniform<1>(i->name));
-               else if(i->size==2)
-                       create_curve<2>(UNIFORM, -1, ExtractUniform<2>(i->name));
-               else if(i->size==3)
-                       create_curve<3>(UNIFORM, -1, ExtractUniform<3>(i->name));
-               else if(i->size==4)
-                       create_curve<4>(UNIFORM, -1, ExtractUniform<4>(i->name));
+               if(u.size==1)
+                       create_curve<1>(UNIFORM, -1, ExtractUniform<1>(u.name));
+               else if(u.size==2)
+                       create_curve<2>(UNIFORM, -1, ExtractUniform<2>(u.name));
+               else if(u.size==3)
+                       create_curve<3>(UNIFORM, -1, ExtractUniform<3>(u.name));
+               else if(u.size==4)
+                       create_curve<4>(UNIFORM, -1, ExtractUniform<4>(u.name));
        }
 }
 
@@ -205,10 +202,10 @@ void Animation::create_curve(CurveTarget target, Transform::ComponentMask mask,
 {
        Transform::ComponentMask all = mask;
        Transform::ComponentMask any = Transform::NONE;
-       for(vector<TimedKeyFrame>::const_iterator i=keyframes.begin(); i!=keyframes.end(); ++i)
+       for(const TimedKeyFrame &k: keyframes)
        {
-               all = all&i->keyframe->get_transform().get_mask();
-               any = any|i->keyframe->get_transform().get_mask();
+               all = all&k.keyframe->get_transform().get_mask();
+               any = any|k.keyframe->get_transform().get_mask();
        }
 
        if(all==mask)
@@ -232,17 +229,17 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract
 
        vector<Knot> knots;
        unsigned n_control = 0;
-       for(vector<TimedKeyFrame>::const_iterator i=keyframes.begin(); i!=keyframes.end(); ++i)
+       for(const TimedKeyFrame &k: keyframes)
        {
-               if(i->control && knots.empty())
+               if(k.control && knots.empty())
                        continue;
 
                typename Interpolate::SplineValue<float, N>::Type value;
-               if(extract(*i->keyframe, value))
+               if(extract(*k.keyframe, value))
                {
                        typename Knot::Value dvalue = value;
-                       float x = i->time/Time::sec;
-                       if(i->control)
+                       float x = k.time/Time::sec;
+                       if(k.control)
                        {
                                ++n_control;
                                if(n_control>2)
@@ -414,7 +411,7 @@ template<unsigned N>
 bool Animation::ExtractUniform<N>::operator()(const KeyFrame &kf, typename Interpolate::SplineValue<float, N>::Type &value) const
 {
        const KeyFrame::UniformMap &kf_uniforms = kf.get_uniforms();
-       const KeyFrame::UniformMap::const_iterator i = kf_uniforms.find(name);
+       auto i = kf_uniforms.find(name);
        if(i==kf_uniforms.end())
                return false;
 
index ac16321874a7abd612ad6cf39fdb69cf1fdb8cf4..42605beaf8c1d86ce1bfb772293a126de8b80c2f 100644 (file)
@@ -11,11 +11,11 @@ namespace GL {
 
 AnimationPlayer::Target &AnimationPlayer::get_slot(Placeable &obj)
 {
-       ObjectMap::iterator i = objects.find(&obj);
+       auto i = objects.find(&obj);
        if(i!=objects.end())
                return i->second;
 
-       return objects.insert(ObjectMap::value_type(&obj, Target(obj))).first->second;
+       return objects.insert(make_pair(&obj, Target(obj))).first->second;
 }
 
 AnimationPlayer::Target &AnimationPlayer::play_(Placeable &obj, const Animation &anim, bool stacked, float speed)
@@ -59,7 +59,7 @@ void AnimationPlayer::play_stacked(Placeable &obj, const Animation &anim, float
 
 unsigned AnimationPlayer::get_n_active_animations(const AnimatedObject &obj) const
 {
-       ObjectMap::const_iterator i = objects.find(&obj);
+       auto i = objects.find(&obj);
        return (i!=objects.end() ? i->second.animations.size() : 0);
 }
 
@@ -72,22 +72,22 @@ void AnimationPlayer::observe_events(AnimatedObject &obj, AnimationEventObserver
 
 void AnimationPlayer::unobserve_events(AnimatedObject &obj, AnimationEventObserver &observer)
 {
-       ObjectMap::iterator i = objects.find(&obj);
+       auto i = objects.find(&obj);
        if(i==objects.end())
                return;
 
-       vector<AnimationEventObserver *>::iterator j = find(i->second.event_observers, &observer);
+       auto j = find(i->second.event_observers, &observer);
        if(j!=i->second.event_observers.end())
                i->second.event_observers.erase(j);
 }
 
 void AnimationPlayer::unobserve_events(AnimationEventObserver &observer)
 {
-       for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); ++i)
+       for(auto &kvp: objects)
        {
-               vector<AnimationEventObserver *>::iterator j = find(i->second.event_observers, &observer);
-               if(j!=i->second.event_observers.end())
-                       i->second.event_observers.erase(j);
+               auto j = find(kvp.second.event_observers, &observer);
+               if(j!=kvp.second.event_observers.end())
+                       kvp.second.event_observers.erase(j);
        }
 }
 
@@ -98,16 +98,13 @@ void AnimationPlayer::stop(Placeable &obj)
 
 void AnimationPlayer::stop(Placeable &obj, const Animation &anim)
 {
-       ObjectMap::iterator i = objects.find(&obj);
+       auto i = objects.find(&obj);
        if(i==objects.end())
                return;
 
-       for(vector<PlayingAnimation>::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j)
-               if(j->animation==&anim)
-               {
-                       i->second.animations.erase(j);
-                       break;
-               }
+       auto j = find_member(i->second.animations, &anim, &PlayingAnimation::animation);
+       if(j!=i->second.animations.end())
+               i->second.animations.erase(j);
 
        if(i->second.animations.empty())
                objects.erase(i);
@@ -115,7 +112,7 @@ void AnimationPlayer::stop(Placeable &obj, const Animation &anim)
 
 void AnimationPlayer::tick(const Time::TimeDelta &dt)
 {
-       for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); )
+       for(auto i=objects.begin(); i!=objects.end(); )
        {
                if(i->second.stacked)
                        tick_stacked(i->second, dt);
@@ -158,16 +155,16 @@ void AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
 void AnimationPlayer::tick_stacked(Target &target, const Time::TimeDelta &dt)
 {
        Matrix matrix = target.base_matrix;
-       for(vector<PlayingAnimation>::iterator i=target.animations.begin(); i!=target.animations.end(); ++i)
+       for(PlayingAnimation &a: target.animations)
        {
-               i->iterator += dt*i->speed;
-               matrix *= i->iterator.get_matrix();
+               a.iterator += dt*a.speed;
+               matrix *= a.iterator.get_matrix();
 
                if(target.object)
                {
-                       unsigned n_uniforms = i->animation->get_n_uniforms();
+                       unsigned n_uniforms = a.animation->get_n_uniforms();
                        for(unsigned j=0; j<n_uniforms; ++j)
-                               set_object_uniform(*target.object, i->animation->get_uniform_name(j), i->iterator.get_uniform(j));
+                               set_object_uniform(*target.object, a.animation->get_uniform_name(j), a.iterator.get_uniform(j));
                }
        }
        target.placeable.set_matrix(matrix);
@@ -180,14 +177,14 @@ void AnimationPlayer::tick_stacked(Target &target, const Time::TimeDelta &dt)
                        matrix = Matrix();
                        /* XXX This is in all likelihood incorrect.  The stacking should be
                        performed on local matrices. */
-                       for(vector<PlayingAnimation>::iterator j=target.animations.begin(); j!=target.animations.end(); ++j)
-                               if(j->animation->get_armature())
-                                       matrix *= j->iterator.get_pose_matrix(i);
+                       for(const PlayingAnimation &a: target.animations)
+                               if(a.animation->get_armature())
+                                       matrix *= a.iterator.get_pose_matrix(i);
                        target.object->set_pose_matrix(i, matrix);
                }
        }
 
-       for(vector<PlayingAnimation>::iterator i=target.animations.begin(); i!=target.animations.end(); )
+       for(auto i=target.animations.begin(); i!=target.animations.end(); )
        {
                i->iterator.dispatch_events(target);
 
@@ -232,8 +229,8 @@ AnimationPlayer::Target::Target(Placeable &p):
 
 void AnimationPlayer::Target::animation_event(Placeable *, const string &name, const Variant &value)
 {
-       for(vector<AnimationEventObserver *>::const_iterator i=event_observers.begin(); i!=event_observers.end(); ++i)
-               (*i)->animation_event(&placeable, name, value);
+       for(AnimationEventObserver *o: event_observers)
+               o->animation_event(&placeable, name, value);
 }
 
 } // namespace GL
index c45027d9e82bacfb0358981dfadcc0fded8c5eb9..4b0beb6c236f8b728df2f9f5a0382b128f773e1c 100644 (file)
@@ -42,9 +42,7 @@ private:
                virtual void animation_event(Placeable *, const std::string &, const Variant &);
        };
 
-       typedef std::map<const Placeable *, Target> ObjectMap;
-
-       ObjectMap objects;
+       std::map<const Placeable *, Target> objects;
 
 private:
        Target &get_slot(Placeable &);
index 6e921e3f8e9ea95246b8dae655ba54f701d0689d..f339ea2a447ba731c6d042458bb41984e81645bf 100644 (file)
@@ -14,25 +14,25 @@ Armature::Link &Armature::add_link()
 
 const Armature::Link &Armature::get_link(unsigned index) const
 {
-       for(vector<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
-               if(i->get_index()==index)
-                       return *i;
+       for(const Link &l: links)
+               if(l.get_index()==index)
+                       return l;
        throw key_error(typeid(list<Link>));
 }
 
 const Armature::Link &Armature::get_link(const string &name) const
 {
-       for(vector<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
-               if(i->get_name()==name)
-                       return *i;
+       for(const Link &l: links)
+               if(l.get_name()==name)
+                       return l;
        throw key_error(typeid(list<Link>));
 }
 
 unsigned Armature::get_max_link_index() const
 {
        unsigned max_index = 0;
-       for(vector<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
-               max_index = max(max_index, i->get_index());
+       for(const Link &l: links)
+               max_index = max(max_index, l.get_index());
        return max_index;
 }
 
index 44ffafa176142300c2e0eb07aab74290541bd904..dfa6bf9cf953685c2472c29b29788447e53e6642 100644 (file)
@@ -50,7 +50,7 @@ float Font::get_string_width(const string &str, StringCodec::Decoder &dec) const
        float x = 0;
 
        unsigned prev = 0;
-       for(string::const_iterator i=str.begin(); i!=str.end();)
+       for(auto i=str.begin(); i!=str.end();)
        {
                unsigned c = dec.decode_char(str, i);
                if(prev)
@@ -68,7 +68,7 @@ void Font::build_string(const string &str, StringCodec::Decoder &dec, PrimitiveB
 
        unsigned prev = 0;
        unsigned next = 0;
-       for(string::const_iterator i=str.begin(); (next || i!=str.end());)
+       for(auto i=str.begin(); (next || i!=str.end());)
        {
                unsigned c = (next ? next : dec.decode_char(str, i));
                next = (i!=str.end() ? dec.decode_char(str, i) : 0);
@@ -79,7 +79,7 @@ void Font::build_string(const string &str, StringCodec::Decoder &dec, PrimitiveB
                        next = 0;
                }
 
-               GlyphMap::const_iterator j = glyphs.find(c);
+               auto j = glyphs.find(c);
                if(j==glyphs.end())
                        continue;
 
@@ -107,7 +107,7 @@ void Font::create_glyph_quad(const Glyph &glyph, PrimitiveBuilder &bld) const
 
 float Font::get_glyph_advance(unsigned code, unsigned next) const
 {
-       GlyphMap::const_iterator i = glyphs.find(code);
+       auto i = glyphs.find(code);
        if(i==glyphs.end())
                return 0;
 
@@ -115,7 +115,7 @@ float Font::get_glyph_advance(unsigned code, unsigned next) const
 
        if(next)
        {
-               KerningMap::const_iterator j = kerning.find(CodePair(code, next));
+               auto j = kerning.find(CodePair(code, next));
                if(j!=kerning.end())
                        advance += j->second;
        }
@@ -125,7 +125,7 @@ float Font::get_glyph_advance(unsigned code, unsigned next) const
 
 unsigned Font::get_ligature(unsigned code, unsigned next) const
 {
-       LigatureMap::const_iterator i = ligatures.find(CodePair(code, next));
+       auto i = ligatures.find(CodePair(code, next));
        return (i!=ligatures.end() ? i->second : 0);
 }
 
index 5a68d4142a90bd777f058a9a3c3e4160c9367cf0..8fd4b956a3287efbc9dfc2cf19be92f1151e94b2 100644 (file)
@@ -15,13 +15,11 @@ namespace GL {
 SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
        tmpl(t)
 {
-       const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
-       for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
-               renderables[i->slot_name] = i->default_renderable;
-       const vector<SequenceTemplate::PostProcessor> &postprocs = tmpl.get_postprocessors();
-       for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
-               if(!i->slot_name.empty())
-                       postprocessors[i->slot_name] = 0;
+       for(const SequenceTemplate::Step &s: tmpl.get_steps())
+               renderables[s.slot_name] = s.default_renderable;
+       for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
+               if(!p.slot_name.empty())
+                       postprocessors[p.slot_name] = 0;
 }
 
 void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
@@ -50,36 +48,37 @@ void SequenceBuilder::build(Sequence &sequence) const
                sequence.set_debug_name(debug_name);
 #endif
 
-       const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
-       for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
+       for(const SequenceTemplate::Step &s: tmpl.get_steps())
        {
-               Renderable *renderable = get_item(renderables, i->slot_name);
+               Renderable *renderable = get_item(renderables, s.slot_name);
                if(!renderable)
                        continue;
 
-               Sequence::Step &step = sequence.add_step(i->tag, *renderable);
-               step.set_blend(i->blend);
-               step.set_depth_test(i->depth_test);
-               step.set_stencil_test(i->stencil_test);
-               step.set_lighting(i->lighting);
+               Sequence::Step &step = sequence.add_step(s.tag, *renderable);
+               step.set_blend(s.blend);
+               step.set_depth_test(s.depth_test);
+               step.set_stencil_test(s.stencil_test);
+               step.set_lighting(s.lighting);
        }
 
-       const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
-       for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
+#ifdef DEBUG
+       unsigned index = 0;
+#endif
+       for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
        {
                PostProcessor *proc = 0;
-               if(!i->slot_name.empty())
-                       proc = get_item(postprocessors, i->slot_name);
+               if(!p.slot_name.empty())
+                       proc = get_item(postprocessors, p.slot_name);
                if(proc)
                        sequence.add_postprocessor(*proc);
-               else if(i->postprocessor_template)
+               else if(p.postprocessor_template)
                {
-                       proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
+                       proc = p.postprocessor_template->create(sequence.get_width(), sequence.get_height());
                        if(proc)
                        {
 #ifdef DEBUG
                                if(!debug_name.empty())
-                                       proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
+                                       proc->set_debug_name(format("%s/%d.pproc", debug_name, index++));
 #endif
                                sequence.add_postprocessor_owned(proc);
                        }
index 13534d75d28e99f61d648e35f57f5c744dcb0676..be8f3d7186b3450018e04c5da50605bdb4d97467 100644 (file)
@@ -24,8 +24,8 @@ SequenceTemplate::SequenceTemplate():
 
 SequenceTemplate::~SequenceTemplate()
 {
-       for(PostProcessorArray::iterator i=postprocessors.begin(); i!=postprocessors.end(); ++i)
-               delete i->postprocessor_template;
+       for(const PostProcessor &p: postprocessors)
+               delete p.postprocessor_template;
 }
 
 
index 061fdfc39928f1b4ce8e2634ffe3e1d933ec1086..9de2082d9ab68bdba42b112da51e1e460fa6fd20 100644 (file)
@@ -108,8 +108,6 @@ public:
                PostProcessor(GL::PostProcessor::Template * = 0);
        };
 
-       typedef std::vector<PostProcessor> PostProcessorArray;
-
 private:
        typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
 
@@ -118,7 +116,7 @@ private:
        unsigned required_multisample;
        unsigned max_multisample;
        std::vector<Step> steps;
-       PostProcessorArray postprocessors;
+       std::vector<PostProcessor> postprocessors;
 
 public:
        SequenceTemplate();
@@ -129,7 +127,7 @@ public:
        unsigned get_required_multisample() const { return required_multisample; }
        unsigned get_maximum_multisample() const { return max_multisample; }
        const std::vector<Step> &get_steps() const { return steps; }
-       const PostProcessorArray &get_postprocessors() const { return postprocessors; }
+       const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
 
        template<typename T>
        static void register_postprocessor(const std::string &);
index 1469ab110ee61d1ec69c37616f43ed310d3315e5..d99bb95e24e53a2878143c949f5113fdfca980a5 100644 (file)
@@ -96,8 +96,8 @@ Batch &Batch::append(const vector<unsigned> &ind)
                return *this;
 
        data.reserve(data.size()+ind.size()*get_index_size());
-       for(vector<unsigned>::const_iterator i=ind.begin(); i!=ind.end(); ++i)
-               append_index(*i);
+       for(unsigned i: ind)
+               append_index(i);
 
        update_offset();
        dirty = true;
index 79e1aaf06a149912e0bef36e3ab54583bbcf0993..d23ecffc0c2549c5eb2d3fe837213a63e99b337e 100644 (file)
@@ -26,7 +26,7 @@ void Clipping::attach(const ClipPlane &p)
 
 void Clipping::detach(const ClipPlane &p)
 {
-       vector<AttachedPlane>::iterator i = find_member(planes, &p, &AttachedPlane::plane);
+       auto i = find_member(planes, &p, &AttachedPlane::plane);
        if(i!=planes.end())
                planes.erase(i);
 }
index 6e7d9dc9971878a7647f26ecf49be6f10fd54712..0ce00becd23d5503ca5f26fec5f13eab065f9f17 100644 (file)
@@ -201,33 +201,33 @@ void Framebuffer::update() const
 void Framebuffer::check_size()
 {
        bool first = true;
-       for(vector<Attachment>::iterator i=attachments.begin(); i!=attachments.end(); ++i)
-               if(i->tex)
+       for(Attachment &a: attachments)
+               if(a.tex)
                {
-                       GLenum type = i->tex->get_target();
+                       GLenum type = a.tex->get_target();
                        unsigned w = 0;
                        unsigned h = 0;
                        if(type==GL_TEXTURE_2D)
                        {
-                               Texture2D *tex = static_cast<Texture2D *>(i->tex);
-                               w = max(tex->get_width()>>i->level, 1U);
-                               h = max(tex->get_height()>>i->level, 1U);
+                               Texture2D *tex = static_cast<Texture2D *>(a.tex);
+                               w = max(tex->get_width()>>a.level, 1U);
+                               h = max(tex->get_height()>>a.level, 1U);
                        }
                        else if(type==GL_TEXTURE_2D_MULTISAMPLE)
                        {
-                               Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(i->tex);
+                               Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(a.tex);
                                w = tex->get_width();
                                h = tex->get_height();
                        }
                        else if(type==GL_TEXTURE_3D || type==GL_TEXTURE_2D_ARRAY)
                        {
-                               Texture3D *tex = static_cast<Texture3D *>(i->tex);
-                               w = max(tex->get_width()>>i->level, 1U);
-                               h = max(tex->get_height()>>i->level, 1U);
+                               Texture3D *tex = static_cast<Texture3D *>(a.tex);
+                               w = max(tex->get_width()>>a.level, 1U);
+                               h = max(tex->get_height()>>a.level, 1U);
                        }
                        else if(type==GL_TEXTURE_CUBE_MAP)
                        {
-                               w = max(static_cast<TextureCube *>(i->tex)->get_size()>>i->level, 1U);
+                               w = max(static_cast<TextureCube *>(a.tex)->get_size()>>a.level, 1U);
                                h = w;
                        }
 
index de05102a358a5665a51b12cd0c345c21441052d5..f6a060215692a01f73ba2f849f83cfdc6c82f9b2 100644 (file)
@@ -129,7 +129,7 @@ void Mesh::add_batch(const Batch &b)
                bool reallocate = (batches.size()==batches.capacity());
                if(reallocate)
                {
-                       for(vector<Batch>::iterator i=batches.end(); i!=batches.begin(); )
+                       for(auto i=batches.end(); i!=batches.begin(); )
                                (--i)->use_buffer(0);
                }
 
@@ -138,10 +138,10 @@ void Mesh::add_batch(const Batch &b)
                if(reallocate)
                {
                        prev = 0;
-                       for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
+                       for(Batch &a: batches)
                        {
-                               i->use_buffer(ibuf, prev);
-                               prev = &*i;
+                               a.use_buffer(ibuf, prev);
+                               prev = &a;
                        }
                }
                else
@@ -156,8 +156,8 @@ void Mesh::add_batch(const Batch &b)
                        batches.back().set_index_type(existing_type);
                else
                {
-                       for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
-                               i->set_index_type(added_type);
+                       for(Batch &a: batches)
+                               a.set_index_type(added_type);
                }
        }
 
@@ -202,13 +202,13 @@ void Mesh::draw(Renderer &renderer, const VertexSetup *vs, unsigned count) const
 
        if(!count)
        {
-               for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
-                       renderer.draw(*i);
+               for(const Batch &b: batches)
+                       renderer.draw(b);
        }
        else
        {
-               for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
-                       renderer.draw_instanced(*i, count);
+               for(const Batch &b: batches)
+                       renderer.draw_instanced(b, count);
        }
 }
 
@@ -274,14 +274,14 @@ Mesh::Loader::Loader(Mesh &m, bool g):
        add("winding",  &Mesh::face_winding);
 }
 
-void Mesh::Loader::storage(const vector<VertexAttribute> &a)
+void Mesh::Loader::storage(const vector<VertexAttribute> &attrs)
 {
-       if(a.empty())
+       if(attrs.empty())
                throw invalid_argument("No vertex attributes");
 
        VertexFormat fmt;
-       for(vector<VertexAttribute>::const_iterator i=a.begin(); i!=a.end(); ++i)
-               fmt = (fmt, *i);
+       for(VertexAttribute a: attrs)
+               fmt = (fmt, a);
        obj.storage(fmt);
 }
 
index 2474feaeb4cfffc8907caf4c1de730d40e5718cd..601aae99c8952e355016562d4589e333cfbd2798 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/io/print.h>
 #include "module.h"
 #include "resources.h"
@@ -100,18 +101,18 @@ SpirVModule &SpirVModule::operator=(const SpirVModule &other)
 
 void SpirVModule::remap_pointers_from(const SpirVModule &other)
 {
-       for(vector<EntryPoint>::iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
-               for(vector<const Variable *>::iterator j=i->globals.begin(); j!=i->globals.end(); ++j)
-                       *j = &variables[*j-&other.variables.front()];
+       for(EntryPoint &e: entry_points)
+               for(const Variable *&v: e.globals)
+                       v = &variables[v-&other.variables.front()];
 
-       for(vector<Variable>::iterator i=variables.begin(); i!=variables.end(); ++i)
-               if(i->struct_type)
-                       i->struct_type = &structs[i->struct_type-&other.structs.front()];
+       for(Variable &v: variables)
+               if(v.struct_type)
+                       v.struct_type = &structs[v.struct_type-&other.structs.front()];
 
-       for(vector<Structure>::iterator i=structs.begin(); i!=structs.end(); ++i)
-               for(vector<StructMember>::iterator j=i->members.begin(); j!=i->members.end(); ++j)
-                       if(j->struct_type)
-                               j->struct_type = &structs[j->struct_type-&other.structs.front()];
+       for(Structure &s: structs)
+               for(StructMember &m: s.members)
+                       if(m.struct_type)
+                               m.struct_type = &structs[m.struct_type-&other.structs.front()];
 }
 
 void SpirVModule::load_code(IO::Base &io)
@@ -144,8 +145,8 @@ void SpirVModule::reflect()
 
        if(code[0]==SPIRV_MAGIC_REVERSED)
        {
-               for(vector<UInt32>::iterator i=code.begin(); i!=code.end(); ++i)
-                       *i = ((*i&0xFF)<<24) || ((*i&0xFF00)<<8) | ((*i>>8)&0xFF00) | ((*i>>24)&0xFF);
+               for(UInt32 &c: code)
+                       c = ((c&0xFF)<<24) || ((c&0xFF00)<<8) | ((c>>8)&0xFF00) | ((c>>24)&0xFF);
        }
        else if(code[0]!=SPIRV_MAGIC)
                throw invalid_module("SPIR-V magic number not found");
@@ -154,38 +155,38 @@ void SpirVModule::reflect()
        reflection.reflect_code(code);
 
        map<const Constant *, unsigned> spec_indices;
-       for(map<unsigned, Constant>::const_iterator i=reflection.constants.begin(); i!=reflection.constants.end(); ++i)
-               if(i->second.constant_id>=0)
+       for(const auto &kvp: reflection.constants)
+               if(kvp.second.constant_id>=0)
                {
-                       spec_indices[&i->second] = spec_constants.size();
-                       spec_constants.push_back(i->second);
+                       spec_indices[&kvp.second] = spec_constants.size();
+                       spec_constants.push_back(kvp.second);
                }
 
        map<const Structure *, unsigned> struct_indices;
        structs.reserve(reflection.structs.size());
-       for(map<unsigned, Structure>::const_iterator i=reflection.structs.begin(); i!=reflection.structs.end(); ++i)
+       for(const auto &kvp: reflection.structs)
        {
-               struct_indices[&i->second] = structs.size();
-               structs.push_back(i->second);
+               struct_indices[&kvp.second] = structs.size();
+               structs.push_back(kvp.second);
        }
 
-       for(vector<Structure>::iterator i=structs.begin(); i!=structs.end(); ++i)
+       for(Structure &s: structs)
        {
-               for(vector<StructMember>::iterator j=i->members.begin(); j!=i->members.end(); ++j)
+               for(StructMember &m: s.members)
                {
-                       if(j->struct_type)
+                       if(m.struct_type)
                        {
-                               map<const Structure *, unsigned>::const_iterator k = struct_indices.find(j->struct_type);
-                               j->struct_type = (k!=struct_indices.end() ? &structs[k->second] : 0);
+                               auto i = struct_indices.find(m.struct_type);
+                               m.struct_type = (i!=struct_indices.end() ? &structs[i->second] : 0);
                        }
-                       if(j->array_size_spec)
+                       if(m.array_size_spec)
                        {
-                               map<const Constant *, unsigned>::const_iterator k = spec_indices.find(j->array_size_spec);
-                               j->array_size_spec = (k!=spec_indices.end() ? &spec_constants[k->second] : 0);
+                               auto i = spec_indices.find(m.array_size_spec);
+                               m.array_size_spec = (i!=spec_indices.end() ? &spec_constants[i->second] : 0);
                        }
                }
 
-               const StructMember *last_member = &i->members.back();
+               const StructMember *last_member = &s.members.back();
                unsigned last_offset = last_member->offset;
                while(last_member->struct_type)
                {
@@ -198,51 +199,47 @@ void SpirVModule::reflect()
                        last_member = lm;
                }
                
-               i->size = last_offset+get_type_size(last_member->type);
-               i->size = (i->size+15)&~15;
+               s.size = last_offset+get_type_size(last_member->type);
+               s.size = (s.size+15)&~15;
        }
 
        map<const Variable *, unsigned> var_indices;
        variables.reserve(reflection.variables.size());
-       for(map<unsigned, Variable>::const_iterator i=reflection.variables.begin(); i!=reflection.variables.end(); ++i)
+       for(const auto &kvp: reflection.variables)
        {
-               int dup_index = -1;
-               for(vector<Variable>::const_iterator j=variables.begin(); (dup_index<0 && j!=variables.end()); ++j)
-                       if(*j==i->second)
-                               dup_index = j-variables.begin();
-
-               if(dup_index>=0)
-                       var_indices[&i->second] = dup_index;
+               auto i = find_if(variables, [&kvp](const Variable &v){ return v==kvp.second; });
+               if(i!=variables.end())
+                       var_indices[&kvp.second] = i-variables.begin();
                else
                {
-                       var_indices[&i->second] = variables.size();
-                       variables.push_back(i->second);
+                       var_indices[&kvp.second] = variables.size();
+                       variables.push_back(kvp.second);
                }
        }
 
-       for(vector<Variable>::iterator i=variables.begin(); i!=variables.end(); ++i)
+       for(Variable &v: variables)
        {
-               if(i->struct_type)
+               if(v.struct_type)
                {
-                       map<const Structure *, unsigned>::const_iterator j = struct_indices.find(i->struct_type);
-                       i->struct_type = (j!=struct_indices.end() ? &structs[j->second] : 0);
+                       auto i = struct_indices.find(v.struct_type);
+                       v.struct_type = (i!=struct_indices.end() ? &structs[i->second] : 0);
                }
-               if(i->array_size_spec)
+               if(v.array_size_spec)
                {
-                       map<const Constant *, unsigned>::const_iterator j = spec_indices.find(i->array_size_spec);
-                       i->array_size_spec = (j!=spec_indices.end() ? &spec_constants[j->second] : 0);
+                       auto i = spec_indices.find(v.array_size_spec);
+                       v.array_size_spec = (i!=spec_indices.end() ? &spec_constants[i->second] : 0);
                }
        }
 
        entry_points.reserve(reflection.entry_points.size());
-       for(map<unsigned, EntryPoint>::const_iterator i=reflection.entry_points.begin(); i!=reflection.entry_points.end(); ++i)
+       for(const auto &kvp: reflection.entry_points)
        {
-               entry_points.push_back(i->second);
+               entry_points.push_back(kvp.second);
                EntryPoint &entry = entry_points.back();
-               for(vector<const Variable *>::iterator j=entry.globals.begin(); j!=entry.globals.end(); ++j)
+               for(const Variable *&v: entry.globals)
                {
-                       map<const Variable *, unsigned>::const_iterator k = var_indices.find(*j);
-                       *j = (k!=var_indices.end() ? &variables[k->second] : 0);
+                       auto i = var_indices.find(v);
+                       v = (i!=var_indices.end() ? &variables[i->second] : 0);
                }
        }
 }
@@ -479,7 +476,7 @@ void SpirVModule::Reflection::reflect_struct_type(CodeIterator op)
        op += 2;
 
        strct.members.resize(op_end-op);
-       vector<StructMember>::iterator mem = strct.members.begin();
+       auto mem = strct.members.begin();
        for(; op!=op_end; ++op, ++mem)
        {
                TypeInfo &type = types[*op];
index 318522d6563b547eebcf6b823ed3e5ddbb9c0305..30d2ab1c5ce5f5968f9c10f7e6fd0c204fa6bfe5 100644 (file)
@@ -110,7 +110,7 @@ void PipelineState::set_texture(unsigned binding, const Texture *tex, const Samp
        if((tex!=0)!=(samp!=0))
                throw invalid_argument("PipelineState::set_texture");
 
-       vector<BoundTexture>::iterator i = lower_bound_member(textures, binding, &BoundTexture::binding);
+       auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
        if(i==textures.end() || i->binding!=binding)
                i = textures.insert(i, BoundTexture(binding));
        if(tex!=i->texture || samp!=i->sampler)
@@ -134,7 +134,7 @@ void PipelineState::set_uniform_block(unsigned binding, const BufferBackedUnifor
 
 void PipelineState::set_uniform_block_(int binding, const UniformBlock *block)
 {
-       vector<BoundUniformBlock>::iterator i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
+       auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
        if(i==uniform_blocks.end() || i->binding!=binding)
                i = uniform_blocks.insert(i, BoundUniformBlock(binding));
        if(block!=i->block || binding<0)
@@ -248,49 +248,49 @@ void PipelineState::apply(unsigned mask) const
 
        if(mask&TEXTURES)
        {
-               for(vector<BoundTexture>::const_iterator i=textures.begin(); i!=textures.end(); ++i)
-                       if(i->changed || mask==~0U)
+               for(const BoundTexture &t: textures)
+                       if(t.changed || mask==~0U)
                        {
-                               if(i->texture && i->sampler)
+                               if(t.texture && t.sampler)
                                {
                                        if(ARB_direct_state_access)
-                                               glBindTextureUnit(i->binding, i->texture->get_id());
+                                               glBindTextureUnit(t.binding, t.texture->get_id());
                                        else
                                        {
-                                               glActiveTexture(GL_TEXTURE0+i->binding);
-                                               if(bound_tex_targets[i->binding] && static_cast<int>(i->texture->get_target())!=bound_tex_targets[i->binding])
-                                                       glBindTexture(bound_tex_targets[i->binding], 0);
-                                               glBindTexture(i->texture->get_target(), i->texture->get_id());
+                                               glActiveTexture(GL_TEXTURE0+t.binding);
+                                               if(bound_tex_targets[t.binding] && static_cast<int>(t.texture->get_target())!=bound_tex_targets[t.binding])
+                                                       glBindTexture(bound_tex_targets[t.binding], 0);
+                                               glBindTexture(t.texture->get_target(), t.texture->get_id());
                                        }
 
-                                       bound_tex_targets[i->binding] = i->texture->get_target();
+                                       bound_tex_targets[t.binding] = t.texture->get_target();
 
-                                       glBindSampler(i->binding, i->sampler->get_id());
-                                       i->sampler->refresh();
+                                       glBindSampler(t.binding, t.sampler->get_id());
+                                       t.sampler->refresh();
                                }
 
-                               i->changed = false;
+                               t.changed = false;
                        }
        }
 
        if(mask&UNIFORMS)
        {
-               for(vector<BoundUniformBlock>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
-                       if(i->changed || mask==~0U)
+               for(const BoundUniformBlock &u: uniform_blocks)
+                       if(u.changed || mask==~0U)
                        {
-                               if(i->block)
+                               if(u.block)
                                {
-                                       if(i->binding>=0)
+                                       if(u.binding>=0)
                                        {
-                                               const BufferBackedUniformBlock *block = static_cast<const BufferBackedUniformBlock *>(i->block);
-                                               glBindBufferRange(GL_UNIFORM_BUFFER, i->binding, block->get_buffer()->get_id(), block->get_offset(), block->get_data_size());
-                                               bound_uniform_blocks[i->binding] = 1;
+                                               const BufferBackedUniformBlock *block = static_cast<const BufferBackedUniformBlock *>(u.block);
+                                               glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, block->get_buffer()->get_id(), block->get_offset(), block->get_data_size());
+                                               bound_uniform_blocks[u.binding] = 1;
                                        }
                                        else
-                                               static_cast<const DefaultUniformBlock *>(i->block)->apply();
+                                               static_cast<const DefaultUniformBlock *>(u.block)->apply();
                                }
 
-                               i->changed = false;
+                               u.changed = false;
                        }
        }
 
index ed2455f86aa315ec79f97bf2860563f7d40cc243..468a40f5c8ba06025fe0729d4fc14bb8a536d227 100644 (file)
@@ -147,10 +147,10 @@ void Program::add_glsl_stages(const GlslModule &mod, const map<string, int> &spe
 #endif
 
        vector<SL::Stage::Type> stages = compiler.get_stages();
-       for(vector<SL::Stage::Type>::const_iterator i=stages.begin(); i!=stages.end(); ++i)
+       for(SL::Stage::Type st: stages)
        {
                unsigned stage_id = 0;
-               switch(*i)
+               switch(st)
                {
                case SL::Stage::VERTEX: stage_id = add_stage(VERTEX); break;
                case SL::Stage::GEOMETRY: stage_id = add_stage(GEOMETRY); break;
@@ -158,23 +158,21 @@ void Program::add_glsl_stages(const GlslModule &mod, const map<string, int> &spe
                default: throw invalid_operation("Program::add_glsl_stages");
                }
 
-               string stage_src = compiler.get_stage_glsl(*i);
+               string stage_src = compiler.get_stage_glsl(st);
                const char *src_ptr = stage_src.data();
                int src_len = stage_src.size();
                glShaderSource(stage_id, 1, &src_ptr, &src_len);
 
-               if(*i==SL::Stage::VERTEX)
+               if(st==SL::Stage::VERTEX)
                {
-                       const map<string, unsigned> &attribs = compiler.get_vertex_attributes();
-                       for(map<string, unsigned>::const_iterator j=attribs.begin(); j!=attribs.end(); ++j)
-                               glBindAttribLocation(id, j->second, j->first.c_str());
+                       for(const auto &kvp: compiler.get_vertex_attributes())
+                               glBindAttribLocation(id, kvp.second, kvp.first.c_str());
                }
 
-               if(*i==SL::Stage::FRAGMENT && EXT_gpu_shader4)
+               if(st==SL::Stage::FRAGMENT && EXT_gpu_shader4)
                {
-                       const map<string, unsigned> &frag_outs = compiler.get_fragment_outputs();
-                       for(map<string, unsigned>::const_iterator j=frag_outs.begin(); j!=frag_outs.end(); ++j)
-                               glBindFragDataLocation(id, j->second, j->first.c_str());
+                       for(const auto &kvp: compiler.get_fragment_outputs())
+                               glBindFragDataLocation(id, kvp.second, kvp.first.c_str());
                }
 
                compile_glsl_stage(stage_id);
@@ -213,13 +211,12 @@ void Program::add_spirv_stages(const SpirVModule &mod, const map<string, int> &s
 
        module = &mod;
 
-       const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
        unsigned n_stages = 0;
        unsigned used_stage_ids[MAX_STAGES];
-       for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
+       for(const SpirVModule::EntryPoint &e: mod.get_entry_points())
        {
                unsigned stage_id = 0;
-               switch(i->stage)
+               switch(e.stage)
                {
                case SpirVModule::VERTEX: stage_id = add_stage(VERTEX); break;
                case SpirVModule::GEOMETRY: stage_id = add_stage(GEOMETRY); break;
@@ -241,18 +238,18 @@ void Program::add_spirv_stages(const SpirVModule &mod, const map<string, int> &s
        vector<unsigned> spec_value_array;
        spec_id_array.reserve(spec_consts.size());
        spec_value_array.reserve(spec_consts.size());
-       for(vector<SpirVModule::Constant>::const_iterator i=spec_consts.begin(); i!=spec_consts.end(); ++i)
+       for(const SpirVModule::Constant &c: spec_consts)
        {
-               map<string, int>::const_iterator j = spec_values.find(i->name);
-               if(j!=spec_values.end())
+               auto i = spec_values.find(c.name);
+               if(i!=spec_values.end())
                {
-                       spec_id_array.push_back(i->constant_id);
-                       spec_value_array.push_back(j->second);
-                       transient->spec_values[i->constant_id] = j->second;
+                       spec_id_array.push_back(c.constant_id);
+                       spec_value_array.push_back(i->second);
+                       transient->spec_values[c.constant_id] = i->second;
                }
        }
 
-       vector<SpirVModule::EntryPoint>::const_iterator j=entry_points.begin();
+       auto j = mod.get_entry_points().begin();
        for(unsigned i=0; i<MAX_STAGES; ++i)
                if(stage_ids[i])
                        glSpecializeShader(stage_ids[i], j->name.c_str(), spec_id_array.size(), &spec_id_array[0], &spec_value_array[0]);
@@ -347,7 +344,7 @@ void Program::link()
                {
                        for(unsigned i=0; i<uniform_blocks.size(); ++i)
                        {
-                               map<string, unsigned>::const_iterator j = transient->blocks.find(uniform_blocks[i].name);
+                               auto j = transient->blocks.find(uniform_blocks[i].name);
                                if(j!=transient->blocks.end())
                                {
                                        glUniformBlockBinding(id, i, j->second);
@@ -357,15 +354,15 @@ void Program::link()
 
                        if(!ARB_separate_shader_objects)
                                glUseProgram(id);
-                       for(map<string, unsigned>::const_iterator i=transient->textures.begin(); i!=transient->textures.end(); ++i)
+                       for(const auto &kvp: transient->textures)
                        {
-                               int location = get_uniform_location(i->first);
+                               int location = get_uniform_location(kvp.first);
                                if(location>=0)
                                {
                                        if(ARB_separate_shader_objects)
-                                               glProgramUniform1i(id, location, i->second);
+                                               glProgramUniform1i(id, location, kvp.second);
                                        else
-                                               glUniform1i(location, i->second);
+                                               glUniform1i(location, kvp.second);
                                }
                        }
                }
@@ -379,10 +376,10 @@ void Program::link()
        delete transient;
        transient = 0;
 
-       for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               require_type(i->type);
-       for(vector<AttributeInfo>::const_iterator i=attributes.begin(); i!=attributes.end(); ++i)
-               require_type(i->type);
+       for(const UniformInfo &u: uniforms)
+               require_type(u.type);
+       for(const AttributeInfo &a: attributes)
+               require_type(a.type);
 }
 
 void Program::query_uniforms()
@@ -429,15 +426,15 @@ void Program::query_uniforms()
        uniform_blocks.push_back(UniformBlockInfo());
        UniformBlockInfo &default_block = uniform_blocks.back();
 
-       for(vector<UniformInfo>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               if(!i->block)
+       for(UniformInfo &u: uniforms)
+               if(!u.block)
                {
-                       i->location = glGetUniformLocation(id, i->name.c_str());
-                       i->block = &default_block;
-                       default_block.uniforms.push_back(&*i);
+                       u.location = glGetUniformLocation(id, u.name.c_str());
+                       u.block = &default_block;
+                       default_block.uniforms.push_back(&u);
 
-                       if(is_image(i->type) && i->location>=0)
-                               glGetUniformiv(id, i->location, &i->binding);
+                       if(is_image(u.type) && u.location>=0)
+                               glGetUniformiv(id, u.location, &u.binding);
                }
 
        default_block.layout_hash = compute_layout_hash(default_block.uniforms);
@@ -469,12 +466,12 @@ void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_inde
                glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &value);
                vector<int> indices(value);
                glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]);
-               for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
+               for(int j: indices)
                {
-                       if(!uniforms_by_index[*j])
+                       if(!uniforms_by_index[j])
                                throw logic_error("Program::link");
-                       info.uniforms.push_back(uniforms_by_index[*j]);
-                       uniforms_by_index[*j]->block = &info;
+                       info.uniforms.push_back(uniforms_by_index[j]);
+                       uniforms_by_index[j]->block = &info;
                }
 
                vector<unsigned> query_indices(indices.begin(), indices.end());
@@ -484,9 +481,9 @@ void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_inde
                        uniforms_by_index[indices[j]]->offset = values[j];
 
                query_indices.clear();
-               for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
-                       if(uniforms_by_index[*j]->array_size>1)
-                               query_indices.push_back(*j);
+               for(int j: indices)
+                       if(uniforms_by_index[j]->array_size>1)
+                               query_indices.push_back(j);
                if(!query_indices.empty())
                {
                        glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]);
@@ -495,11 +492,11 @@ void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_inde
                }
 
                query_indices.clear();
-               for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
+               for(int j: indices)
                {
-                       DataType t = uniforms_by_index[*j]->type;
+                       DataType t = uniforms_by_index[j]->type;
                        if(is_matrix(t))
-                               query_indices.push_back(*j);
+                               query_indices.push_back(j);
                }
                if(!query_indices.empty())
                {
@@ -547,34 +544,33 @@ void Program::collect_uniforms()
        uniform_blocks.push_back(UniformBlockInfo());
        vector<vector<string> > block_uniform_names(1);
 
-       const vector<SpirVModule::Variable> &variables = mod.get_variables();
-       for(vector<SpirVModule::Variable>::const_iterator i=variables.begin(); i!=variables.end(); ++i)
+       for(const SpirVModule::Variable &v: mod.get_variables())
        {
-               if(i->storage==SpirVModule::UNIFORM && i->struct_type)
+               if(v.storage==SpirVModule::UNIFORM && v.struct_type)
                {
                        uniform_blocks.push_back(UniformBlockInfo());
                        UniformBlockInfo &info = uniform_blocks.back();
-                       info.name = i->struct_type->name;
-                       info.bind_point = i->binding;
-                       info.data_size = i->struct_type->size;
+                       info.name = v.struct_type->name;
+                       info.bind_point = v.binding;
+                       info.data_size = v.struct_type->size;
 
                        string prefix;
-                       if(!i->name.empty())
-                               prefix = i->struct_type->name+".";
+                       if(!v.name.empty())
+                               prefix = v.struct_type->name+".";
                        block_uniform_names.push_back(vector<string>());
-                       collect_block_uniforms(*i->struct_type, prefix, 0, block_uniform_names.back());
+                       collect_block_uniforms(*v.struct_type, prefix, 0, block_uniform_names.back());
                }
-               else if(i->storage==SpirVModule::UNIFORM_CONSTANT && i->location>=0)
+               else if(v.storage==SpirVModule::UNIFORM_CONSTANT && v.location>=0)
                {
-                       block_uniform_names[0].push_back(i->name);
+                       block_uniform_names[0].push_back(v.name);
                        uniforms.push_back(UniformInfo());
                        UniformInfo &info = uniforms.back();
-                       info.name = i->name;
-                       info.tag = i->name;
-                       info.location = i->location;
-                       info.binding = i->binding;
-                       info.array_size = i->array_size;
-                       info.type = i->type;
+                       info.name = v.name;
+                       info.tag = v.name;
+                       info.location = v.location;
+                       info.binding = v.binding;
+                       info.array_size = v.array_size;
+                       info.type = v.type;
                }
        }
 
@@ -583,11 +579,10 @@ void Program::collect_uniforms()
        for(unsigned i=0; i<uniform_blocks.size(); ++i)
        {
                UniformBlockInfo &block = uniform_blocks[i];
-               const vector<string> &names = block_uniform_names[i];
-               for(vector<string>::const_iterator j=names.begin(); j!=names.end(); ++j)
+               for(const string &n: block_uniform_names[i])
                {
                        // The element is already known to be present
-                       UniformInfo &uni = *lower_bound_member(uniforms, Tag(*j), &UniformInfo::tag);
+                       UniformInfo &uni = *lower_bound_member(uniforms, Tag(n), &UniformInfo::tag);
                        block.uniforms.push_back(&uni);
                        uni.block = &block;
                }
@@ -600,18 +595,18 @@ void Program::collect_uniforms()
 
 void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, vector<string> &uniform_names)
 {
-       for(vector<SpirVModule::StructMember>::const_iterator i=strct.members.begin(); i!=strct.members.end(); ++i)
+       for(const SpirVModule::StructMember &m: strct.members)
        {
-               unsigned offset = base_offset+i->offset;
-               if(i->struct_type)
+               unsigned offset = base_offset+m.offset;
+               if(m.struct_type)
                {
-                       unsigned array_size = i->array_size;
-                       if(i->array_size_spec)
+                       unsigned array_size = m.array_size;
+                       if(m.array_size_spec)
                        {
-                               array_size = i->array_size_spec->i_value;
+                               array_size = m.array_size_spec->i_value;
                                if(transient)
                                {
-                                       map<unsigned, int>::const_iterator j = transient->spec_values.find(i->array_size_spec->constant_id);
+                                       auto j = transient->spec_values.find(m.array_size_spec->constant_id);
                                        if(j!=transient->spec_values.end())
                                                array_size = j->second;
                                }
@@ -619,25 +614,25 @@ void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const
 
                        if(array_size)
                        {
-                               for(unsigned j=0; j<array_size; ++j, offset+=i->array_stride)
-                                       collect_block_uniforms(*i->struct_type, format("%s%s[%d].", prefix, i->name, j), offset, uniform_names);
+                               for(unsigned j=0; j<array_size; ++j, offset+=m.array_stride)
+                                       collect_block_uniforms(*m.struct_type, format("%s%s[%d].", prefix, m.name, j), offset, uniform_names);
                        }
                        else
-                               collect_block_uniforms(*i->struct_type, prefix+i->name+".", offset, uniform_names);
+                               collect_block_uniforms(*m.struct_type, prefix+m.name+".", offset, uniform_names);
                }
                else
                {
-                       string name = prefix+i->name;
+                       string name = prefix+m.name;
                        uniform_names.push_back(name);
                        uniforms.push_back(UniformInfo());
                        UniformInfo &info = uniforms.back();
                        info.name = name;
                        info.tag = name;
                        info.offset = offset;
-                       info.array_size = i->array_size;
-                       info.array_stride = i->array_stride;
-                       info.matrix_stride = i->matrix_stride;
-                       info.type = i->type;
+                       info.array_size = m.array_size;
+                       info.array_stride = m.array_stride;
+                       info.matrix_stride = m.matrix_stride;
+                       info.type = m.type;
                }
        }
 }
@@ -646,19 +641,18 @@ void Program::collect_attributes()
 {
        const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
 
-       const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
-       for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
-               if(i->stage==SpirVModule::VERTEX && i->name=="main")
+       for(const SpirVModule::EntryPoint &e: mod.get_entry_points())
+               if(e.stage==SpirVModule::VERTEX && e.name=="main")
                {
-                       for(vector<const SpirVModule::Variable *>::const_iterator j=i->globals.begin(); j!=i->globals.end(); ++j)
-                               if((*j)->storage==SpirVModule::INPUT)
+                       for(const SpirVModule::Variable *v: e.globals)
+                               if(v->storage==SpirVModule::INPUT)
                                {
                                        attributes.push_back(AttributeInfo());
                                        AttributeInfo &info = attributes.back();
-                                       info.name = (*j)->name;
-                                       info.location = (*j)->location;
-                                       info.array_size = (*j)->array_size;
-                                       info.type = (*j)->type;
+                                       info.name = v->name;
+                                       info.location = v->location;
+                                       info.array_size = v->array_size;
+                                       info.type = v->type;
                                }
                }
 }
@@ -666,16 +660,16 @@ void Program::collect_attributes()
 void Program::update_layout_hash()
 {
        string layout_descriptor;
-       for(vector<UniformBlockInfo>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
-               layout_descriptor += format("%d:%x\n", i->bind_point, i->layout_hash);
+       for(const UniformBlockInfo &b: uniform_blocks)
+               layout_descriptor += format("%d:%x\n", b.bind_point, b.layout_hash);
        uniform_layout_hash = hash32(layout_descriptor);
 }
 
 Program::LayoutHash Program::compute_layout_hash(const vector<const UniformInfo *> &uniforms)
 {
        string layout_descriptor;
-       for(vector<const UniformInfo *>::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i)
-               layout_descriptor += format("%d:%s:%x:%d\n", (*i)->location, (*i)->name, (*i)->type, (*i)->array_size);
+       for(const UniformInfo *u: uniforms)
+               layout_descriptor += format("%d:%s:%x:%d\n", u->location, u->name, u->type, u->array_size);
        return hash32(layout_descriptor);
 }
 
@@ -695,15 +689,15 @@ string Program::get_info_log() const
 
 const Program::UniformBlockInfo &Program::get_uniform_block_info(const string &name) const
 {
-       for(vector<UniformBlockInfo>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
-               if(i->name==name)
-                       return *i;
-       throw key_error(name);
+       auto i = find_member(uniform_blocks, name, &UniformBlockInfo::name);
+       if(i==uniform_blocks.end())
+               throw key_error(name);
+       return *i;
 }
 
 const Program::UniformInfo &Program::get_uniform_info(const string &name) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
+       auto i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
        if(i==uniforms.end() || i->name!=name)
                throw key_error(name);
        return *i;
@@ -711,7 +705,7 @@ const Program::UniformInfo &Program::get_uniform_info(const string &name) const
 
 const Program::UniformInfo &Program::get_uniform_info(Tag tag) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
+       auto i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
        if(i==uniforms.end() || i->tag!=tag)
                throw key_error(tag);
        return *i;
@@ -722,25 +716,25 @@ int Program::get_uniform_location(const string &name) const
        if(name[name.size()-1]==']')
                throw invalid_argument("Program::get_uniform_location");
 
-       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
+       auto i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
        return i!=uniforms.end() && i->name==name && i->block->bind_point<0 ? i->location : -1;
 }
 
 int Program::get_uniform_location(Tag tag) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
+       auto i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
        return i!=uniforms.end() && i->tag==tag && i->block->bind_point<0 ? i->location : -1;
 }
 
 int Program::get_uniform_binding(Tag tag) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
+       auto i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
        return i!=uniforms.end() && i->tag==tag ? i->binding : -1;
 }
 
 const Program::AttributeInfo &Program::get_attribute_info(const string &name) const
 {
-       vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
+       auto i = lower_bound_member(attributes, name, &AttributeInfo::name);
        if(i==attributes.end() || i->name!=name)
                throw key_error(name);
        return *i;
@@ -751,7 +745,7 @@ int Program::get_attribute_location(const string &name) const
        if(name[name.size()-1]==']')
                throw invalid_argument("Program::get_attribute_location");
 
-       vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
+       auto i = lower_bound_member(attributes, name, &AttributeInfo::name);
        return i!=attributes.end() && i->name==name ? i->location : -1;
 }
 
index 538190f836fb66782e03a510d0ed2f758a15057d..44c7c8f86396837ebb73c9db0ca592a71dfbff56 100644 (file)
@@ -38,7 +38,7 @@ Tag::Tag(const string &s):
 string Tag::str() const
 {
 #ifdef DEBUG
-       map<Tag, string>::const_iterator i=tag_names.find(*this);
+       auto i=tag_names.find(*this);
        if(i!=tag_names.end())
                return i->second;
 #endif
index 7dcb7aba5472e9438671ef31da1036ef15276c8b..3d15705a01765c18abe9244dbd8ae0f39261f357 100644 (file)
@@ -125,7 +125,7 @@ VertexAttribute make_indexed_attribute(VertexAttribute attr, unsigned index)
 
 bool convert_attribute_type(string::const_iterator &i, string::const_iterator end, const char *name, VertexAttribute &attr, DataType type)
 {
-       string::const_iterator j = i;
+       auto j = i;
        for(; (j!=end && *j!='_' && *name); ++name, ++j)
                if(*j!=*name)
                        return false;
@@ -138,7 +138,7 @@ bool convert_attribute_type(string::const_iterator &i, string::const_iterator en
 
 bool convert_attribute(const string &str, const char *name, int min_size, int max_size, VertexAttribute &attr, VertexAttribute base_attr)
 {
-       string::const_iterator i = str.begin();
+       auto i = str.begin();
        for(; *name; ++name, ++i)
                if(*i!=*name)
                        return false;
index 83e480e5cf417b5943abb7841ebcb32256f8136e..8e18d6eb97d031e5f0becbef55a01c0fc782a22e 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/gl/resources.h>
 #include <msp/io/seekable.h>
 #include "builtin.h"
@@ -62,10 +63,8 @@ const Stage *get_builtins(Stage::Type type)
 
        if(type==Stage::SHARED)
                return &module->shared;
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               if(i->type==type)
-                       return &*i;
-       return 0;
+       auto i = find_member(module->stages, type, &Stage::type);
+       return (i!=module->stages.end() ? &*i : 0);
 }
 
 } // namespace SL
index 5b488f4d4a8f74ac1216e1f6be193b9510d95f63..4f2080ab9c59afb8c8b6018aed6cac2d60c40d09 100644 (file)
@@ -82,27 +82,27 @@ void Compiler::compile(Mode mode)
        if(specialized && mode!=PROGRAM)
                throw invalid_operation("Compiler::compile");
 
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               generate(*i);
+       for(Stage &s: module->stages)
+               generate(s);
        ConstantIdAssigner().apply(*module, features);
 
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               validate(*i);
+       for(Stage &s: module->stages)
+               validate(s);
        GlobalInterfaceValidator().apply(*module);
 
        bool valid = true;
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               if(!check_errors(*i))
+       for(Stage &s: module->stages)
+               if(!check_errors(s))
                        valid = false;
        if(!valid)
                throw invalid_shader_source(get_diagnostics());
 
        if(specialized)
        {
-               for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-                       ConstantSpecializer().apply(*i, spec_values);
+               for(Stage &s: module->stages)
+                       ConstantSpecializer().apply(s, spec_values);
        }
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); )
+       for(auto i=module->stages.begin(); i!=module->stages.end(); )
        {
                OptimizeResult result = optimize(*i);
                if(result==REDO_PREVIOUS)
@@ -112,8 +112,8 @@ void Compiler::compile(Mode mode)
        }
 
        LocationAllocator().apply(*module, features);
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               finalize(*i, mode);
+       for(Stage &s: module->stages)
+               finalize(s, mode);
 
        compiled = true;
 }
@@ -128,10 +128,10 @@ string Compiler::get_combined_glsl() const
        unsigned source_count = module->source_map.get_count();
        for(unsigned i=1; i<source_count; ++i)
                glsl += format("#pragma MSP source(%d, \"%s\")\n", i, module->source_map.get_name(i));
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+       for(Stage &s: module->stages)
        {
-               glsl += format("#pragma MSP stage(%s)\n", Stage::get_stage_name(i->type));
-               glsl += Formatter().apply(*i);
+               glsl += format("#pragma MSP stage(%s)\n", Stage::get_stage_name(s.type));
+               glsl += Formatter().apply(s);
                glsl += '\n';
        }
 
@@ -142,8 +142,8 @@ vector<Stage::Type> Compiler::get_stages() const
 {
        vector<Stage::Type> stage_types;
        stage_types.reserve(module->stages.size());
-       for(list<Stage>::const_iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               stage_types.push_back(i->type);
+       for(const Stage &s: module->stages)
+               stage_types.push_back(s.type);
        return stage_types;
 }
 
@@ -151,9 +151,9 @@ string Compiler::get_stage_glsl(Stage::Type stage_type) const
 {
        if(!compiled)
                throw invalid_operation("Compiler::get_stage_glsl");
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               if(i->type==stage_type)
-                       return Formatter().apply(*i);
+       auto i = find_member(module->stages, stage_type, &Stage::type);
+       if(i!=module->stages.end())
+               return Formatter().apply(*i);
        throw key_error(Stage::get_stage_name(stage_type));
 }
 
@@ -170,9 +170,9 @@ const map<string, unsigned> &Compiler::get_vertex_attributes() const
 {
        if(!compiled)
                throw invalid_operation("Compiler::get_vertex_attributes");
-       for(list<Stage>::const_iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               if(i->type==Stage::VERTEX)
-                       return i->locations;
+       auto i = find_member(module->stages, Stage::VERTEX, &Stage::type);
+       if(i!=module->stages.end())
+               return i->locations;
        throw invalid_operation("Compiler::get_vertex_attributes");
 }
 
@@ -180,9 +180,9 @@ const map<string, unsigned> &Compiler::get_fragment_outputs() const
 {
        if(!compiled)
                throw invalid_operation("Compiler::get_fragment_outputs");
-       for(list<Stage>::const_iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               if(i->type==Stage::FRAGMENT)
-                       return i->locations;
+       auto i = find_member(module->stages, Stage::FRAGMENT, &Stage::type);
+       if(i!=module->stages.end())
+               return i->locations;
        throw invalid_operation("Compiler::get_fragment_outputs");
 }
 
@@ -207,19 +207,19 @@ const SourceMap &Compiler::get_source_map() const
 
 string Compiler::get_stage_debug(Stage::Type stage_type) const
 {
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               if(i->type==stage_type)
-                       return DumpTree().apply(*i);
+       auto i = find_member(module->stages, stage_type, &Stage::type);
+       if(i!=module->stages.end())
+               return DumpTree().apply(*i);
        throw key_error(Stage::get_stage_name(stage_type));
 }
 
 string Compiler::get_diagnostics() const
 {
        string combined;
-       for(list<Stage>::const_iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               for(vector<Diagnostic>::const_iterator j=i->diagnostics.begin(); j!=i->diagnostics.end(); ++j)
-                       if(j->source!=INTERNAL_SOURCE)
-                               append(combined, "\n", format("%s:%d: %s", module->source_map.get_name(j->source), j->line, j->message));
+       for(const Stage &s: module->stages)
+               for(const Diagnostic &d: s.diagnostics)
+                       if(d.source!=INTERNAL_SOURCE)
+                               append(combined, "\n", format("%s:%d: %s", module->source_map.get_name(d.source), d.line, d.message));
        return combined;
 }
 
@@ -228,15 +228,15 @@ void Compiler::append_module(const Module &mod, ModuleCache &mod_cache)
        module->source_map.merge_from(mod.source_map);
 
        vector<Import *> imports;
-       for(NodeList<Statement>::const_iterator i=mod.shared.content.body.begin(); i!=mod.shared.content.body.end(); ++i)
-               if(Import *imp = dynamic_cast<Import *>(i->get()))
+       for(const RefPtr<Statement> &s: mod.shared.content.body)
+               if(Import *imp = dynamic_cast<Import *>(s.get()))
                        imports.push_back(imp);
-       for(vector<Import *>::iterator i=imports.begin(); i!=imports.end(); ++i)
-               import(mod_cache, (*i)->module);
+       for(Import *i: imports)
+               import(mod_cache, i->module);
 
        append_stage(mod.shared);
-       for(list<Stage>::const_iterator i=mod.stages.begin(); i!=mod.stages.end(); ++i)
-               append_stage(*i);
+       for(const Stage &s: mod.stages)
+               append_stage(s);
 }
 
 void Compiler::append_stage(const Stage &stage)
@@ -246,11 +246,10 @@ void Compiler::append_stage(const Stage &stage)
                target = &module->shared;
        else
        {
-               list<Stage>::iterator i;
-               for(i=module->stages.begin(); (i!=module->stages.end() && i->type<stage.type); ++i) ;
+               auto i = find_if(module->stages, [&stage](const Stage &s){ return s.type>=stage.type; });
                if(i==module->stages.end() || i->type>stage.type)
                {
-                       list<Stage>::iterator j = module->stages.insert(i, stage.type);
+                       auto j = module->stages.insert(i, stage.type);
                        if(i!=module->stages.end())
                                i->previous = &*j;
                        i = j;
@@ -263,9 +262,9 @@ void Compiler::append_stage(const Stage &stage)
 
        if(stage.required_features.glsl_version>target->required_features.glsl_version)
                target->required_features.glsl_version = stage.required_features.glsl_version;
-       for(NodeList<Statement>::const_iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
-               if(!dynamic_cast<Import *>(i->get()))
-                       target->content.body.push_back(*i);
+       for(const RefPtr<Statement> &s: stage.content.body)
+               if(!dynamic_cast<Import *>(s.get()))
+                       target->content.body.push_back(s);
 }
 
 void Compiler::import(ModuleCache &mod_cache, const string &name)
@@ -338,12 +337,8 @@ void Compiler::validate(Stage &stage)
 bool Compiler::check_errors(Stage &stage)
 {
        stable_sort(stage.diagnostics, &diagnostic_line_order);
-
-       for(vector<Diagnostic>::const_iterator i=stage.diagnostics.begin(); i!=stage.diagnostics.end(); ++i)
-               if(i->severity==Diagnostic::ERR)
-                       return false;
-
-       return true;
+       return !any_of(stage.diagnostics.begin(), stage.diagnostics.end(),
+               [](const Diagnostic &d){ return d.severity==Diagnostic::ERR; });
 }
 
 bool Compiler::diagnostic_line_order(const Diagnostic &diag1, const Diagnostic &diag2)
@@ -407,9 +402,9 @@ void Compiler::finalize(Stage &stage, Mode mode)
 
 void Compiler::inject_block(Block &target, const Block &source)
 {
-       NodeList<Statement>::iterator insert_point = target.body.begin();
-       for(NodeList<Statement>::const_iterator i=source.body.begin(); i!=source.body.end(); ++i)
-               target.body.insert(insert_point, (*i)->clone());
+       auto insert_point = target.body.begin();
+       for(const RefPtr<Statement> &s: source.body)
+               target.body.insert(insert_point, s->clone());
 }
 
 } // namespace SL
index beafaddf47605454f177e4f529235aa01c4fefaf..2543450212c4d4442005770cf7eb8ca5f8e34da3 100644 (file)
@@ -14,14 +14,14 @@ string DumpTree::apply(Stage &stage)
        begin_sub();
        append(format("Version: %d.%02d", stage.required_features.glsl_version.major, stage.required_features.glsl_version.minor));
 
-       for(map<string, TypeDeclaration *>::const_iterator i=stage.types.begin(); i!=stage.types.end(); ++i)
-               append(format("Type: %%%d %s", get_label(*i->second), i->first));
+       for(const auto &kvp: stage.types)
+               append(format("Type: %%%d %s", get_label(*kvp.second), kvp.first));
 
-       for(map<string, InterfaceBlock *>::const_iterator i=stage.interface_blocks.begin(); i!=stage.interface_blocks.end(); ++i)
-               append(format("Interface block: %%%d %s", get_label(*i->second), i->first));
+       for(const auto &kvp: stage.interface_blocks)
+               append(format("Interface block: %%%d %s", get_label(*kvp.second), kvp.first));
 
-       for(map<string, FunctionDeclaration *>::const_iterator i=stage.functions.begin(); i!=stage.functions.end(); ++i)
-               append(format("Function: %%%d %s", get_label(*i->second), i->first));
+       for(const auto &kvp: stage.functions)
+               append(format("Function: %%%d %s", get_label(*kvp.second), kvp.first));
 
        last_branch();
        stage.content.visit(*this);
@@ -31,7 +31,7 @@ string DumpTree::apply(Stage &stage)
 void DumpTree::append(const string &line)
 {
        StringCodec::Utf8::Encoder enc;
-       for(vector<TreeChars>::const_iterator i=tree.begin(); i!=tree.end(); )
+       for(auto i=tree.begin(); i!=tree.end(); )
        {
                enc.encode_char(*i++, formatted);
                enc.encode_char((i==tree.end() ? REACH : EMPTY), formatted);
@@ -48,9 +48,9 @@ void DumpTree::append(const Node &node, const string &line)
 void DumpTree::append_subtree(const vector<Branch> &branches)
 {
        begin_sub();
-       for(vector<Branch>::const_iterator i=branches.begin(); i!=branches.end(); )
+       for(auto i=branches.begin(); i!=branches.end(); )
        {
-               vector<Branch>::const_iterator j = increment(i, branches);
+               auto j = increment(i, branches);
                if(!j->text.empty())
                {
                        append(j->text);
@@ -111,7 +111,7 @@ string DumpTree::format_type(TypeDeclaration *type)
 template<typename T>
 typename T::const_iterator DumpTree::increment(typename T::const_iterator &iter, const T &container)
 {
-       typename T::const_iterator ret = iter++;
+       auto ret = iter++;
        if(iter==container.end())
                last_branch();
        return ret;
@@ -122,12 +122,12 @@ void DumpTree::visit(Block &block)
        append(block, format("Block %s", (block.use_braces ? "{}" : "(inline)")));
        begin_sub();
 
-       for(map<string, VariableDeclaration *>::const_iterator i=block.variables.begin(); i!=block.variables.end(); ++i)
-               append(format("Variable: %%%d %s %s", get_label(*i->second), i->second->type, i->first));
+       for(const auto &kvp: block.variables)
+               append(format("Variable: %%%d %s %s", get_label(*kvp.second), kvp.second->type, kvp.first));
 
-       for(NodeList<Statement>::const_iterator i=block.body.begin(); i!=block.body.end(); )
+       for(auto i=block.body.cbegin(); i!=block.body.cend(); )
        {
-               NodeList<Statement>::const_iterator j = increment(i, block.body);
+               auto j = increment(i, block.body);
                (*j)->visit(*this);
        }
 
@@ -254,9 +254,9 @@ void DumpTree::visit(FunctionCall &call)
        append(call, head);
 
        begin_sub();
-       for(NodeArray<Expression>::const_iterator i=call.arguments.begin(); i!=call.arguments.end(); )
+       for(auto i=call.arguments.cbegin(); i!=call.arguments.cend(); )
        {
-               NodeArray<Expression>::const_iterator j = increment(i, call.arguments);
+               auto j = increment(i, call.arguments);
                (*j)->visit(*this);
        }
        end_sub();
@@ -282,9 +282,9 @@ void DumpTree::visit(Layout &layout)
 {
        append(layout, "Layout");
        begin_sub();
-       for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); )
+       for(auto i=layout.qualifiers.cbegin(); i!=layout.qualifiers.cend(); )
        {
-               vector<Layout::Qualifier>::const_iterator j = increment(i, layout.qualifiers);
+               auto j = increment(i, layout.qualifiers);
                string qualifier = j->name;
                if(j->has_value)
                        qualifier += format("=%d", j->value);
@@ -406,8 +406,8 @@ void DumpTree::visit(FunctionDeclaration &func)
        begin_sub();
        if(func.return_type_declaration)
                append(format("Return type: %%%d %s", get_label(*func.return_type_declaration), func.return_type_declaration->name));
-       for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
-               (*i)->visit(*this);
+       for(const RefPtr<VariableDeclaration> &p: func.parameters)
+               p->visit(*this);
        last_branch();
        if(func.definition==&func)
                func.body.visit(*this);
index 192baec550e111313c76a5cde659e37c6604fba8..eee8a5198efa8b2037848bcc7a34bd8cd0d333ff 100644 (file)
@@ -30,16 +30,15 @@ void StructOrganizer::visit(VariableDeclaration &var)
                bool has_matrix_order = false;
                if(var.layout)
                {
-                       vector<Layout::Qualifier> &qualifiers = var.layout->qualifiers;
-                       for(vector<Layout::Qualifier>::iterator i=qualifiers.begin(); i!=qualifiers.end(); ++i)
+                       for(Layout::Qualifier &q: var.layout->qualifiers)
                        {
-                               if(i->name=="offset" && i->has_value)
+                               if(q.name=="offset" && q.has_value)
                                {
-                                       layout_offset = &i->value;
-                                       if(i->value>=offset)
-                                               offset = i->value;
+                                       layout_offset = &q.value;
+                                       if(q.value>=offset)
+                                               offset = q.value;
                                }
-                               else if(i->name=="column_major" || i->name=="row_major")
+                               else if(q.name=="column_major" || q.name=="row_major")
                                        has_matrix_order = true;
                        }
                }
@@ -74,14 +73,14 @@ void StructOrganizer::visit(VariableDeclaration &var)
 
 void LocationAllocator::apply(Module &module, const Features &features)
 {
-       for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
-               apply(*i);
+       for(Stage &s: module.stages)
+               apply(s);
        allocate_locations("uniform");
 
-       for(vector<InterfaceBlock *>::const_iterator i=unbound_blocks.begin(); i!=unbound_blocks.end(); ++i)
-               bind_uniform((*i)->layout, (*i)->block_name, features.uniform_binding_range);
-       for(vector<VariableDeclaration *>::const_iterator i=unbound_textures.begin(); i!=unbound_textures.end(); ++i)
-               bind_uniform((*i)->layout, (*i)->name, features.texture_binding_range);
+       for(InterfaceBlock *b: unbound_blocks)
+               bind_uniform(b->layout, b->block_name, features.uniform_binding_range);
+       for(VariableDeclaration *t: unbound_textures)
+               bind_uniform(t->layout, t->name, features.texture_binding_range);
 }
 
 void LocationAllocator::apply(Stage &stage)
@@ -97,9 +96,9 @@ void LocationAllocator::apply(Stage &stage)
 
 void LocationAllocator::allocate_locations(const string &iface)
 {
-       vector<VariableDeclaration *>::iterator write = unplaced_variables.begin();
+       auto write = unplaced_variables.begin();
        unsigned next = 0;
-       for(vector<VariableDeclaration *>::const_iterator i=unplaced_variables.begin(); i!=unplaced_variables.end(); ++i)
+       for(auto i=unplaced_variables.begin(); i!=unplaced_variables.end(); ++i)
        {
                if((*i)->interface!=iface)
                {
@@ -111,7 +110,7 @@ void LocationAllocator::allocate_locations(const string &iface)
 
                if((*i)->interface=="uniform")
                {
-                       map<string, Uniform>::const_iterator j = uniforms.find((*i)->name);
+                       auto j = uniforms.find((*i)->name);
                        if(j!=uniforms.end() && j->second.location>=0)
                        {
                                add_layout_value((*i)->layout, "location", j->second.location);
@@ -147,7 +146,7 @@ void LocationAllocator::allocate_locations(const string &iface)
 
 void LocationAllocator::bind_uniform(RefPtr<Layout> &layout, const string &name, unsigned range)
 {
-       map<string, Uniform>::const_iterator i = uniforms.find(name);
+       auto i = uniforms.find(name);
        if(i!=uniforms.end() && i->second.bind_point>=0)
                add_layout_value(layout, "binding", i->second.bind_point);
        else
@@ -252,7 +251,7 @@ void PrecisionConverter::apply(Stage &s)
 
 void PrecisionConverter::visit(Block &block)
 {
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
        {
                if(&block==&stage->content)
                        insert_point = i;
@@ -341,7 +340,7 @@ void LegacyConverter::unsupported(const string &reason)
 
 void LegacyConverter::visit(Block &block)
 {
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
        {
                if(&block==&stage->content)
                        uniform_insert_point = i;
@@ -515,7 +514,7 @@ void LegacyConverter::visit(VariableDeclaration &var)
 {
        if(var.layout)
        {
-               for(vector<Layout::Qualifier>::const_iterator i=var.layout->qualifiers.begin(); i!=var.layout->qualifiers.end(); )
+               for(auto i=var.layout->qualifiers.begin(); i!=var.layout->qualifiers.end(); )
                {
                        if(i->name=="location")
                        {
@@ -621,7 +620,7 @@ void LegacyConverter::visit(InterfaceBlock &iface)
 {
        if(iface.layout)
        {
-               for(vector<Layout::Qualifier>::const_iterator i=iface.layout->qualifiers.begin(); i!=iface.layout->qualifiers.end(); )
+               for(auto i=iface.layout->qualifiers.begin(); i!=iface.layout->qualifiers.end(); )
                {
                        if(i->name=="location" && !supports_interface_block_location())
                                i = iface.layout->qualifiers.erase(i);
index 4550b51c29360997e12c728208cb7c1decca0ba5..a17f7fb502a9e751eb17fe92f4b5d8c2ea383add 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/hash.h>
 #include <msp/core/raii.h>
 #include "generate.h"
@@ -10,22 +11,18 @@ namespace SL {
 
 void ConstantIdAssigner::apply(Module &module, const Features &features)
 {
-       for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
-               i->content.visit(*this);
+       for(Stage &s: module.stages)
+               s.content.visit(*this);
 
-       for(vector<VariableDeclaration *>::iterator i=auto_constants.begin(); i!=auto_constants.end(); ++i)
+       for(VariableDeclaration *v: auto_constants)
        {
-               unsigned id = hash32((*i)->name)%features.constant_id_range;
+               unsigned id = hash32(v->name)%features.constant_id_range;
                while(used_ids.count(id))
                        id = (id+1)%features.constant_id_range;
 
-               vector<Layout::Qualifier> &qualifiers = (*i)->layout->qualifiers;
-               for(vector<Layout::Qualifier>::iterator j=qualifiers.begin(); j!=qualifiers.end(); ++j)
-                       if(j->name=="constant_id")
-                       {
-                               j->value = id;
-                               break;
-                       }
+               auto i = find_member(v->layout->qualifiers, string("constant_id"), &Layout::Qualifier::name);
+               if(i!=v->layout->qualifiers.end())
+                       i->value = id;
 
                used_ids.insert(id);
        }
@@ -35,16 +32,14 @@ void ConstantIdAssigner::visit(VariableDeclaration &var)
 {
        if(var.layout)
        {
-               vector<Layout::Qualifier> &qualifiers = var.layout->qualifiers;
-               for(vector<Layout::Qualifier>::iterator i=qualifiers.begin(); i!=qualifiers.end(); ++i)
-                       if(i->name=="constant_id" && i->has_value)
-                       {
-                               if(i->value==-1)
-                                       auto_constants.push_back(&var);
-                               else
-                                       used_ids.insert(i->value);
-                               break;
-                       }
+               auto i = find_member(var.layout->qualifiers, string("constant_id"), &Layout::Qualifier::name);
+               if(i!=var.layout->qualifiers.end() && i->has_value)
+               {
+                       if(i->value==-1)
+                               auto_constants.push_back(&var);
+                       else
+                               used_ids.insert(i->value);
+               }
        }
 }
 
@@ -80,7 +75,7 @@ void InterfaceGenerator::apply(Stage &s)
 void InterfaceGenerator::visit(Block &block)
 {
        SetForScope<Block *> set_block(current_block, &block);
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
        {
                assignment_insert_point = i;
                if(&block==&stage->content)
@@ -198,7 +193,7 @@ void InterfaceGenerator::visit(VariableReference &var)
                return;
 
        const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
-       map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
+       auto i = prev_vars.find(var.name);
        if(i==prev_vars.end() || i->second->interface!="out")
                i = prev_vars.find(in_prefix+var.name);
        if(i!=prev_vars.end() && i->second->interface=="out")
@@ -215,7 +210,7 @@ void InterfaceGenerator::visit(VariableReference &var)
        }
 
        const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
-       map<string, InterfaceBlock *>::const_iterator j = prev_blocks.find(var.name);
+       auto j = prev_blocks.find(var.name);
        if(j!=prev_blocks.end() && j->second->interface=="out")
        {
                generate_interface(*j->second);
@@ -224,14 +219,14 @@ void InterfaceGenerator::visit(VariableReference &var)
                return;
        }
 
-       for(j=prev_blocks.begin(); j!=prev_blocks.end(); ++j)
-               if(j->second->instance_name.empty() && j->second->struct_declaration)
+       for(const auto &kvp: prev_blocks)
+               if(kvp.second->instance_name.empty() && kvp.second->struct_declaration)
                {
-                       const map<string, VariableDeclaration *> &iface_vars = j->second->struct_declaration->members.variables;
+                       const map<string, VariableDeclaration *> &iface_vars = kvp.second->struct_declaration->members.variables;
                        i = iface_vars.find(var.name);
                        if(i!=iface_vars.end())
                        {
-                               generate_interface(*j->second);
+                               generate_interface(*kvp.second);
                                return;
                        }
                }
@@ -270,7 +265,7 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
                if(!var.linked_declaration && stage->previous)
                {
                        const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
-                       map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
+                       auto i = prev_vars.find(var.name);
                        if(i!=prev_vars.end() && i->second->interface=="out")
                        {
                                var.linked_declaration = i->second;
@@ -291,7 +286,7 @@ void InterfaceGenerator::visit(InterfaceBlock &iface)
                if(!iface.linked_block && stage->previous)
                {
                        const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
-                       map<string, InterfaceBlock *>::const_iterator i = prev_blocks.find("out "+iface.block_name);
+                       auto i = prev_blocks.find("out "+iface.block_name);
                        if(i!=prev_blocks.end())
                        {
                                iface.linked_block = i->second;
@@ -317,16 +312,15 @@ void InterfaceGenerator::visit(Passthrough &pass)
 
        if(stage->previous)
        {
-               const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
-               for(map<string, VariableDeclaration *>::const_iterator i=prev_vars.begin(); i!=prev_vars.end(); ++i)
+               for(const auto &kvp: stage->previous->content.variables)
                {
-                       if(i->second->interface!="out")
+                       if(kvp.second->interface!="out")
                                continue;
 
                        /* Pass through output variables from the previous stage, but only
                        those which are not already linked to an input here. */
-                       if(!i->second->linked_declaration && generate_interface(*i->second, "in", i->second->name))
-                               pass_vars.push_back(i->second);
+                       if(!kvp.second->linked_declaration && generate_interface(*kvp.second, "in", kvp.second->name))
+                               pass_vars.push_back(kvp.second);
                }
        }
 
@@ -349,13 +343,13 @@ void InterfaceGenerator::visit(Passthrough &pass)
                insert_assignment("gl_Position", memacc);
        }
 
-       for(vector<VariableDeclaration *>::const_iterator i=pass_vars.begin(); i!=pass_vars.end(); ++i)
+       for(VariableDeclaration *v: pass_vars)
        {
-               string out_name = change_prefix((*i)->name, out_prefix);
-               generate_interface(**i, "out", out_name);
+               string out_name = change_prefix(v->name, out_prefix);
+               generate_interface(*v, "out", out_name);
 
                VariableReference *ref = new VariableReference;
-               ref->name = (*i)->name;
+               ref->name = v->name;
                if(pass.subscript)
                {
                        BinaryExpression *subscript = new BinaryExpression;
index 116eb20a288e977b1a5353576a5ed71f4fd6a023..a0686902a8b1183d80f85835515bf7c496dd4bb8 100644 (file)
@@ -16,24 +16,24 @@ ModuleCache::ModuleCache(DataFile::Collection *r):
 
 ModuleCache::ModuleCache(const ModuleCache &other)
 {
-       for(map<string, Module *>::const_iterator i=other.modules.begin(); i!=other.modules.end(); ++i)
-               modules[i->first] = new Module(*i->second);
+       for(const auto &kvp: other.modules)
+               modules[kvp.first] = new Module(*kvp.second);
 }
 
 ModuleCache &ModuleCache::operator=(const ModuleCache &other)
 {
-       for(map<string, Module *>::iterator i=modules.begin(); i!=modules.end(); ++i)
-               delete i->second;
+       for(auto &kvp: modules)
+               delete kvp.second;
        modules.clear();
-       for(map<string, Module *>::const_iterator i=other.modules.begin(); i!=other.modules.end(); ++i)
-               modules[i->first] = new Module(*i->second);
+       for(const auto &kvp: other.modules)
+               modules[kvp.first] = new Module(*kvp.second);
        return *this;
 }
 
 ModuleCache::~ModuleCache()
 {
-       for(map<string, Module *>::iterator i=modules.begin(); i!=modules.end(); ++i)
-               delete i->second;
+       for(auto &kvp: modules)
+               delete kvp.second;
 }
 
 const Module &ModuleCache::add_module(const string &source, const string &src_name)
@@ -57,7 +57,7 @@ const Module &ModuleCache::add_module(IO::Base &io, const string &src_name)
 const Module &ModuleCache::get_module(const string &name)
 {
        string fn = name+".glsl";
-       map<string, Module *>::const_iterator i = modules.find(fn);
+       auto i = modules.find(fn);
        if(i!=modules.end())
                return *i->second;
 
index 593a3222533874b6d8fde6265608efd9642e46e1..9388c04129cfc1b03020ef0f00da650bf2b46f1a 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/raii.h>
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
@@ -26,20 +27,19 @@ void ConstantSpecializer::visit(VariableDeclaration &var)
        if(var.layout)
        {
                vector<Layout::Qualifier> &qualifiers = var.layout->qualifiers;
-               for(vector<Layout::Qualifier>::iterator i=qualifiers.begin(); (!specializable && i!=qualifiers.end()); ++i)
-                       if(i->name=="constant_id")
-                       {
-                               specializable = true;
-                               qualifiers.erase(i);
-                       }
-
-               if(qualifiers.empty())
-                       var.layout = 0;
+               auto i = find_member(qualifiers, string("constant_id"), &Layout::Qualifier::name);
+               if(i!=qualifiers.end())
+               {
+                       specializable = true;
+                       qualifiers.erase(i);
+                       if(qualifiers.empty())
+                               var.layout = 0;
+               }
        }
 
        if(specializable)
        {
-               map<string, int>::const_iterator i = values->find(var.name);
+               auto i = values->find(var.name);
                if(i!=values->end())
                {
                        RefPtr<Literal> literal = new Literal;
@@ -85,9 +85,8 @@ void InlineableFunctionLocator::visit(FunctionCall &call)
 
 void InlineableFunctionLocator::visit(FunctionDeclaration &func)
 {
-       bool has_out_params = false;
-       for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); (!has_out_params && i!=func.parameters.end()); ++i)
-               has_out_params = ((*i)->interface=="out");
+       bool has_out_params = any_of(func.parameters.begin(), func.parameters.end(),
+               [](const RefPtr<VariableDeclaration> &p){ return p->interface=="out"; });
 
        unsigned &count = refcounts[func.definition];
        if((count<=1 || func.source==BUILTIN_SOURCE) && !has_out_params)
@@ -141,9 +140,9 @@ string InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_fu
 
        vector<RefPtr<VariableDeclaration> > params;
        params.reserve(source_func->parameters.size());
-       for(NodeArray<VariableDeclaration>::iterator i=source_func->parameters.begin(); i!=source_func->parameters.end(); ++i)
+       for(const RefPtr<VariableDeclaration> &p: source_func->parameters)
        {
-               RefPtr<VariableDeclaration> var = (*i)->clone();
+               RefPtr<VariableDeclaration> var = p->clone();
                var->interface.clear();
 
                SetForScope<Pass> set_pass(pass, RENAME);
@@ -153,12 +152,12 @@ string InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_fu
                params.push_back(var);
        }
 
-       for(NodeList<Statement>::iterator i=source_func->body.body.begin(); i!=source_func->body.body.end(); ++i)
+       for(const RefPtr<Statement> &s: source_func->body.body)
        {
                r_inlined_statement = 0;
-               (*i)->visit(*this);
+               s->visit(*this);
                if(!r_inlined_statement)
-                       r_inlined_statement = (*i)->clone();
+                       r_inlined_statement = s->clone();
 
                SetForScope<Pass> set_pass(pass, RENAME);
                r_inlined_statement->visit(*this);
@@ -194,7 +193,7 @@ void InlineContentInjector::visit(VariableReference &var)
 {
        if(pass==RENAME)
        {
-               map<string, VariableDeclaration *>::const_iterator i = staging_block.variables.find(var.name);
+               auto i = staging_block.variables.find(var.name);
                if(i!=staging_block.variables.end())
                        var.name = i->second->name;
        }
@@ -289,7 +288,7 @@ void FunctionInliner::visit(Block &block)
 {
        SetForScope<Block *> set_block(current_block, &block);
        SetForScope<NodeList<Statement>::iterator> save_insert_point(insert_point, block.body.begin());
-       for(NodeList<Statement>::iterator i=block.body.begin(); (!r_inlined_here && i!=block.body.end()); ++i)
+       for(auto i=block.body.begin(); (!r_inlined_here && i!=block.body.end()); ++i)
        {
                insert_point = i;
                (*i)->visit(*this);
@@ -298,7 +297,7 @@ void FunctionInliner::visit(Block &block)
 
 void FunctionInliner::visit(FunctionCall &call)
 {
-       for(NodeArray<Expression>::iterator i=call.arguments.begin(); (!r_inlined_here && i!=call.arguments.end()); ++i)
+       for(auto i=call.arguments.begin(); (!r_inlined_here && i!=call.arguments.end()); ++i)
                visit(*i);
 
        if(r_inlined_here)
@@ -364,13 +363,13 @@ bool ExpressionInliner::apply(Stage &s)
        s.content.visit(*this);
 
        bool any_inlined = false;
-       for(list<ExpressionInfo>::iterator i=expressions.begin(); i!=expressions.end(); ++i)
-               if(i->expression && (i->trivial || i->uses.size()==1))
+       for(ExpressionInfo &e: expressions)
+               if(e.expression && (e.trivial || e.uses.size()==1))
                {
-                       for(vector<ExpressionUse>::iterator j=i->uses.begin(); j!=i->uses.end(); ++j)
-                               if(!j->blocked)
+                       for(ExpressionUse &u: e.uses)
+                               if(!u.blocked)
                                {
-                                       *j->reference = i->expression->clone();
+                                       *u.reference = e.expression->clone();
                                        any_inlined = true;
                                }
                }
@@ -413,7 +412,7 @@ void ExpressionInliner::visit(VariableReference &var)
 {
        if(var.declaration && access_read)
        {
-               map<Assignment::Target, ExpressionInfo *>::iterator i = assignments.find(var.declaration);
+               auto i = assignments.find(var.declaration);
                if(i!=assignments.end())
                        r_ref_info = i->second;
        }
@@ -459,7 +458,7 @@ void ExpressionInliner::visit(Assignment &assign)
        r_trivial = true;
        visit(assign.right);
 
-       map<Assignment::Target, ExpressionInfo *>::iterator i = assignments.find(assign.target);
+       auto i = assignments.find(assign.target);
        if(i!=assignments.end())
        {
                if(iteration_body && i->second->expression)
@@ -467,9 +466,9 @@ void ExpressionInliner::visit(Assignment &assign)
                        /* Block inlining into previous references within the iteration
                        statement.  On iterations after the first they would refer to the
                        assignment within the iteration. */
-                       for(vector<ExpressionUse>::iterator j=i->second->uses.begin(); j!=i->second->uses.end(); ++j)
-                               for(Block *k=j->ref_scope; (!j->blocked && k); k=k->parent)
-                                       j->blocked = (k==iteration_body);
+                       for(ExpressionUse &u: i->second->uses)
+                               for(Block *k=u.ref_scope; (!u.blocked && k); k=k->parent)
+                                       u.blocked = (k==iteration_body);
                }
 
                expressions.push_back(ExpressionInfo());
@@ -510,8 +509,8 @@ void ExpressionInliner::visit(VariableDeclaration &var)
        bool constant = var.constant;
        if(constant && var.layout)
        {
-               for(vector<Layout::Qualifier>::const_iterator i=var.layout->qualifiers.begin(); (constant && i!=var.layout->qualifiers.end()); ++i)
-                       constant = (i->name!="constant_id");
+               constant = !any_of(var.layout->qualifiers.begin(), var.layout->qualifiers.end(),
+                       [](const Layout::Qualifier &q){ return q.name=="constant_id"; });
        }
 
        /* Only inline global variables if they're constant and have trivial
@@ -894,7 +893,7 @@ ConstantConditionEliminator::ConstantStatus ConstantConditionEliminator::check_c
 void ConstantConditionEliminator::visit(Block &block)
 {
        SetForScope<Block *> set_block(current_block, &block);
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
        {
                insert_point = i;
                (*i)->visit(*this);
@@ -963,7 +962,7 @@ bool UnreachableCodeRemover::apply(Stage &stage)
 
 void UnreachableCodeRemover::visit(Block &block)
 {
-       NodeList<Statement>::iterator i = block.body.begin();
+       auto i = block.body.begin();
        for(; (reachable && i!=block.body.end()); ++i)
                (*i)->visit(*this);
        for(; i!=block.body.end(); ++i)
@@ -1063,29 +1062,29 @@ bool UnusedVariableRemover::apply(Stage &s)
        stage = &s;
        s.content.visit(*this);
 
-       for(list<AssignmentInfo>::const_iterator i=assignments.begin(); i!=assignments.end(); ++i)
-               if(i->used_by.empty())
-                       unused_nodes.insert(i->node);
+       for(const AssignmentInfo &a: assignments)
+               if(a.used_by.empty())
+                       unused_nodes.insert(a.node);
 
-       for(BlockVariableMap::const_iterator i=variables.begin(); i!=variables.end(); ++i)
+       for(const auto &kvp: variables)
        {
-               if(i->second.output)
+               if(kvp.second.output)
                {
                        /* The last visible assignments of output variables are used by the
                        next stage or the API. */
-                       for(vector<AssignmentInfo *>::const_iterator j=i->second.assignments.begin(); j!=i->second.assignments.end(); ++j)
-                               unused_nodes.erase((*j)->node);
+                       for(AssignmentInfo *a: kvp.second.assignments)
+                               unused_nodes.erase(a->node);
                }
 
-               if(!i->second.output && !i->second.referenced)
+               if(!kvp.second.output && !kvp.second.referenced)
                {
                        // Don't remove variables from inside interface blocks.
-                       if(!i->second.interface_block)
-                               unused_nodes.insert(i->first);
+                       if(!kvp.second.interface_block)
+                               unused_nodes.insert(kvp.first);
                }
-               else if(i->second.interface_block)
+               else if(kvp.second.interface_block)
                        // Interface blocks are kept if even one member is used.
-                       unused_nodes.erase(i->second.interface_block);
+                       unused_nodes.erase(kvp.second.interface_block);
        }
 
        NodeRemover().apply(s, unused_nodes);
@@ -1100,16 +1099,16 @@ void UnusedVariableRemover::referenced(const Assignment::Target &target, Node &n
        if(!assignment_target)
        {
                bool loop_external = false;
-               for(vector<AssignmentInfo *>::const_iterator i=var_info.assignments.begin(); i!=var_info.assignments.end(); ++i)
+               for(AssignmentInfo *a: var_info.assignments)
                {
                        bool covered = true;
-                       for(unsigned j=0; (covered && j<(*i)->target.chain_len && j<target.chain_len); ++j)
+                       for(unsigned j=0; (covered && j<a->target.chain_len && j<target.chain_len); ++j)
                        {
-                               Assignment::Target::ChainType type1 = static_cast<Assignment::Target::ChainType>((*i)->target.chain[j]&0xC0);
+                               Assignment::Target::ChainType type1 = static_cast<Assignment::Target::ChainType>(a->target.chain[j]&0xC0);
                                Assignment::Target::ChainType type2 = static_cast<Assignment::Target::ChainType>(target.chain[j]&0xC0);
                                if(type1==Assignment::Target::SWIZZLE || type2==Assignment::Target::SWIZZLE)
                                {
-                                       unsigned index1 = (*i)->target.chain[j]&0x3F;
+                                       unsigned index1 = a->target.chain[j]&0x3F;
                                        unsigned index2 = target.chain[j]&0x3F;
                                        if(type1==Assignment::Target::SWIZZLE && type2==Assignment::Target::SWIZZLE)
                                                covered = index1&index2;
@@ -1121,13 +1120,13 @@ void UnusedVariableRemover::referenced(const Assignment::Target &target, Node &n
                                        covered as true */
                                }
                                else
-                                       covered = ((*i)->target.chain[j]==target.chain[j]);
+                                       covered = (a->target.chain[j]==target.chain[j]);
                        }
 
                        if(covered)
                        {
-                               (*i)->used_by.push_back(&node);
-                               if((*i)->in_loop<in_loop)
+                               a->used_by.push_back(&node);
+                               if(a->in_loop<in_loop)
                                        loop_external = true;
                        }
                }
@@ -1243,9 +1242,9 @@ void UnusedVariableRemover::visit(FunctionCall &call)
 
        if(stage->type==Stage::GEOMETRY && call.name=="EmitVertex")
        {
-               for(map<Statement *, VariableInfo>::const_iterator i=variables.begin(); i!=variables.end(); ++i)
-                       if(i->second.output)
-                               referenced(i->first, call);
+               for(const auto &kvp: variables)
+                       if(kvp.second.output)
+                               referenced(kvp.first, call);
        }
 }
 
@@ -1326,24 +1325,24 @@ void UnusedVariableRemover::visit(InterfaceBlock &iface)
 
 void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars)
 {
-       for(BlockVariableMap::const_iterator i=other_vars.begin(); i!=other_vars.end(); ++i)
+       for(const auto &kvp: other_vars)
        {
-               BlockVariableMap::iterator j = variables.find(i->first);
+               auto j = variables.find(kvp.first);
                if(j!=variables.end())
                {
                        /* The merged blocks started as copies of each other so any common
                        assignments must be in the beginning. */
                        unsigned k = 0;
-                       for(; (k<i->second.assignments.size() && k<j->second.assignments.size()); ++k)
-                               if(i->second.assignments[k]!=j->second.assignments[k])
+                       for(; (k<kvp.second.assignments.size() && k<j->second.assignments.size()); ++k)
+                               if(kvp.second.assignments[k]!=j->second.assignments[k])
                                        break;
 
                        // Remaining assignments are unique to each block; merge them.
-                       j->second.assignments.insert(j->second.assignments.end(), i->second.assignments.begin()+k, i->second.assignments.end());
-                       j->second.referenced |= i->second.referenced;
+                       j->second.assignments.insert(j->second.assignments.end(), kvp.second.assignments.begin()+k, kvp.second.assignments.end());
+                       j->second.referenced |= kvp.second.referenced;
                }
                else
-                       variables.insert(*i);
+                       variables.insert(kvp);
        }
 }
 
@@ -1354,17 +1353,17 @@ void UnusedVariableRemover::visit(FunctionDeclaration &func)
 
        BlockVariableMap saved_vars = variables;
        // Assignments from other functions should not be visible.
-       for(BlockVariableMap::iterator i=variables.begin(); i!=variables.end(); ++i)
-               i->second.assignments.resize(i->second.initialized);
+       for(auto &kvp: variables)
+               kvp.second.assignments.resize(kvp.second.initialized);
        TraversingVisitor::visit(func);
        swap(variables, saved_vars);
        merge_variables(saved_vars);
 
        /* Always treat function parameters as referenced.  Removing unused
        parameters is not currently supported. */
-       for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
+       for(const RefPtr<VariableDeclaration> &p: func.parameters)
        {
-               BlockVariableMap::iterator j = variables.find(i->get());
+               auto j = variables.find(p.get());
                if(j!=variables.end())
                        j->second.referenced = true;
        }
@@ -1397,8 +1396,8 @@ void UnusedVariableRemover::visit(Iteration &iter)
 
        /* Visit the external references of the loop again to record assignments
        done in the loop as used. */
-       for(vector<Node *>::const_iterator i=saved_refs.begin(); i!=saved_refs.end(); ++i)
-               (*i)->visit(*this);
+       for(Node *n: saved_refs)
+               n->visit(*this);
 
        /* Merge assignments from the iteration, without clearing previous state.
        Further analysis is needed to determine which parts of the iteration body
index 50b60c1411d34a67ec5aae4d20a7b5dab233a881..6ba06447a3b02e6254b128884c72a206813ee22b 100644 (file)
@@ -59,8 +59,8 @@ string Formatter::apply(Stage &s)
 void Formatter::append(const string &text)
 {
        formatted += text;
-       for(string::const_iterator i=text.begin(); i!=text.end(); ++i)
-               if(*i=='\n')
+       for(char c: text)
+               if(c=='\n')
                        ++source_line;
 }
 
@@ -99,16 +99,16 @@ void Formatter::visit(Block &block)
        SetForScope<unsigned> set(indent, indent+(indent>0 || use_braces));
        string spaces(indent*2, ' ');
        bool first = true;
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(const RefPtr<Statement> &s: block.body)
        {
-               if(omit_builtin && (*i)->source<=BUILTIN_SOURCE)
+               if(omit_builtin && s->source<=BUILTIN_SOURCE)
                        continue;
                if(!first)
                        append('\n');
                first = false;
-               set_source((*i)->source, (*i)->line);
+               set_source(s->source, s->line);
                append(spaces);
-               (*i)->visit(*this);
+               s->visit(*this);
        }
 
        if(use_braces)
@@ -218,7 +218,7 @@ void Formatter::visit(TernaryExpression &ternary)
 void Formatter::visit(FunctionCall &call)
 {
        append(format("%s(", call.name));
-       for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
+       for(auto i=call.arguments.begin(); i!=call.arguments.end(); ++i)
        {
                if(i!=call.arguments.begin())
                        append(", ");
@@ -246,7 +246,7 @@ void Formatter::visit(Precision &prec)
 void Formatter::visit(Layout &layout)
 {
        append("layout(");
-       for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
+       for(auto i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
        {
                if(i!=layout.qualifiers.begin())
                        append(", ");
@@ -340,7 +340,7 @@ void Formatter::visit(InterfaceBlock &iface)
 void Formatter::visit(FunctionDeclaration &func)
 {
        append(format("%s %s(", func.return_type_declaration->name, func.name));
-       for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
+       for(auto i=func.parameters.begin(); i!=func.parameters.end(); ++i)
        {
                if(i!=func.parameters.begin())
                        append(", ");
index 626a65424532e189aa30e6b376f5ca041425ef24..cc0233eab702b468704cc2b9b8703e383aeee813 100644 (file)
@@ -58,8 +58,8 @@ void Parser::parse_source(const string &name, int index)
 
        if(const Stage *builtin = get_builtins(Stage::SHARED))
        {
-               for(map<string, TypeDeclaration *>::const_iterator i=builtin->types.begin(); i!=builtin->types.end(); ++i)
-                       global_types.insert(i->first);
+               for(const auto &kvp: builtin->types)
+                       global_types.insert(kvp.first);
        }
 
        tokenizer.begin(source, name);
@@ -99,13 +99,13 @@ void Parser::stage_change(Stage::Type stage)
        cur_stage = &module->stages.back();
 
        stage_types.clear();
-       for(vector<const Module *>::const_iterator i=imported_modules.begin(); i!=imported_modules.end(); ++i)
+       for(const Module *m: imported_modules)
        {
-               list<Stage>::const_iterator j = find_member((*i)->stages, stage, &Stage::type);
-               if(j!=(*i)->stages.end())
+               auto j = find_member(m->stages, stage, &Stage::type);
+               if(j!=m->stages.end())
                {
-                       for(map<string, TypeDeclaration *>::const_iterator k=j->types.begin(); k!=j->types.end(); ++k)
-                               stage_types.insert(k->first);
+                       for(const auto &kvp: j->types)
+                               stage_types.insert(kvp.first);
                }
        }
 }
@@ -369,8 +369,8 @@ RefPtr<Import> Parser::parse_import()
        {
                const Module &imported_mod = mod_cache->get_module(import->module);
                imported_modules.push_back(&imported_mod);
-               for(map<string, TypeDeclaration *>::const_iterator i=imported_mod.shared.types.begin(); i!=imported_mod.shared.types.end(); ++i)
-                       global_types.insert(i->first);
+               for(const auto &kvp: imported_mod.shared.types)
+                       global_types.insert(kvp.first);
        }
 
        return import;
index 91e8fa55dde940020c5255e97e48eb69abbf7afb..82ad244c1d7083c1ad8b61e4c22fee69e25e7f2f 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include "reflect.h"
 
 using namespace std;
@@ -158,8 +159,8 @@ void TypeComparer::visit(StructDeclaration &strct)
                else
                {
                        r_result = true;
-                       NodeList<Statement>::const_iterator i = strct1->members.body.begin();
-                       NodeList<Statement>::const_iterator j = strct.members.body.begin();
+                       auto i = strct1->members.body.begin();
+                       auto j = strct.members.body.begin();
                        for(; (r_result && i!=strct1->members.body.end()); ++i, ++j)
                                compare(**i, **j);
                }
@@ -207,10 +208,10 @@ void LocationCounter::visit(ImageTypeDeclaration &)
 void LocationCounter::visit(StructDeclaration &strct)
 {
        unsigned total = 0;
-       for(NodeList<Statement>::const_iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i)
+       for(const RefPtr<Statement> &s: strct.members.body)
        {
                r_count = 1;
-               (*i)->visit(*this);
+               s->visit(*this);
                total += r_count;
        }
        r_count = total;
@@ -256,12 +257,12 @@ void MemoryRequirementsCalculator::visit(StructDeclaration &strct)
 {
        unsigned total = 0;
        unsigned max_align = 1;
-       for(NodeList<Statement>::iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i)
+       for(const RefPtr<Statement> &s: strct.members.body)
        {
                r_size = 0;
                r_alignment = 1;
                r_offset = -1;
-               (*i)->visit(*this);
+               s->visit(*this);
                if(r_offset)
                        total = r_offset;
                total += r_alignment-1;
@@ -277,10 +278,9 @@ void MemoryRequirementsCalculator::visit(VariableDeclaration &var)
 {
        if(var.layout)
        {
-               const vector<Layout::Qualifier> qualifiers = var.layout->qualifiers;
-               for(vector<Layout::Qualifier>::const_iterator i=qualifiers.begin(); (r_offset<0 && i!=qualifiers.end()); ++i)
-                       if(i->name=="offset")
-                               r_offset = i->value;
+               auto i = find_member(var.layout->qualifiers, string("offset"), &Layout::Qualifier::name);
+               if(i!=var.layout->qualifiers.end())
+                       r_offset = i->value;
        }
 
        if(var.type_declaration)
index f2670b53e6805a78f7a2ce6627882299904ff254..c12a0f48cd389997a95da283b0bd583b6867729f 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include <msp/core/raii.h>
 #include <msp/strings/utils.h>
 #include "reflect.h"
@@ -34,7 +34,7 @@ bool TypeResolver::apply(Stage &s)
 
 TypeDeclaration *TypeResolver::get_or_create_array_type(TypeDeclaration &type)
 {
-       map<TypeDeclaration *, TypeDeclaration *>::iterator i = array_types.find(&type);
+       auto i = array_types.find(&type);
        if(i!=array_types.end())
                return i->second;
 
@@ -52,10 +52,10 @@ TypeDeclaration *TypeResolver::get_or_create_array_type(TypeDeclaration &type)
 void TypeResolver::resolve_type(TypeDeclaration *&type, const string &name, bool array)
 {
        TypeDeclaration *resolved = 0;
-       map<string, TypeDeclaration *>::iterator i = stage->types.find(name);
+       auto i = stage->types.find(name);
        if(i!=stage->types.end())
        {
-               map<TypeDeclaration *, TypeDeclaration *>::iterator j = alias_map.find(i->second);
+               auto j = alias_map.find(i->second);
                resolved = (j!=alias_map.end() ? j->second : i->second);
        }
 
@@ -68,7 +68,7 @@ void TypeResolver::resolve_type(TypeDeclaration *&type, const string &name, bool
 
 void TypeResolver::visit(Block &block)
 {
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
        {
                if(!block.parent)
                        type_insert_point = i;
@@ -164,8 +164,8 @@ bool VariableResolver::apply(Stage &s)
        s.interface_blocks.clear();
        r_any_resolved = false;
        s.content.visit(*this);
-       for(vector<VariableDeclaration *>::const_iterator i=redeclared_builtins.begin(); i!=redeclared_builtins.end(); ++i)
-               (*i)->source = GENERATED_SOURCE;
+       for(VariableDeclaration *v: redeclared_builtins)
+               v->source = GENERATED_SOURCE;
        NodeRemover().apply(s, nodes_to_remove);
        return r_any_resolved;
 }
@@ -218,7 +218,7 @@ void VariableResolver::visit(VariableReference &var)
        one. */
        for(Block *block=current_block; (!declaration && block); block=block->parent)
        {
-               map<string, VariableDeclaration *>::iterator i = block->variables.find(var.name);
+               auto i = block->variables.find(var.name);
                if(i!=block->variables.end())
                        declaration = i->second;
        }
@@ -226,7 +226,7 @@ void VariableResolver::visit(VariableReference &var)
        if(!declaration)
        {
                const map<string, InterfaceBlock *> &blocks = stage->interface_blocks;
-               map<string, InterfaceBlock *>::const_iterator i = blocks.find(var.name);
+               auto i = blocks.find(var.name);
                if(i==blocks.end())
                {
                        // Look for the variable in anonymous interface blocks.
@@ -274,7 +274,7 @@ void VariableResolver::visit(VariableReference &var)
 
 void VariableResolver::visit(InterfaceBlockReference &iface)
 {
-       map<string, InterfaceBlock *>::iterator i = stage->interface_blocks.find(iface.name);
+       auto i = stage->interface_blocks.find(iface.name);
        InterfaceBlock *declaration = (i!=stage->interface_blocks.end() ? i->second : 0);
        r_any_resolved |= (declaration!=iface.declaration);
        iface.declaration = declaration;
@@ -290,12 +290,12 @@ void VariableResolver::visit(MemberAccess &memacc)
        int index = -1;
        if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(memacc.left->type))
        {
-               map<string, VariableDeclaration *>::iterator i = strct->members.variables.find(memacc.member);
+               auto i = strct->members.variables.find(memacc.member);
                if(i!=strct->members.variables.end())
                {
                        declaration = i->second;
                        index = 0;
-                       for(NodeList<Statement>::const_iterator j=strct->members.body.begin(); (j!=strct->members.body.end() && j->get()!=i->second); ++j)
+                       for(auto j=strct->members.body.begin(); (j!=strct->members.body.end() && j->get()!=i->second); ++j)
                                ++index;
 
                        if(record_target)
@@ -313,7 +313,7 @@ void VariableResolver::visit(MemberAccess &memacc)
                        bool ok = true;
                        UInt8 components[4] = { };
                        for(unsigned i=0; (ok && i<memacc.member.size()); ++i)
-                               ok = ((components[i] = (find(component_names, component_names+12, memacc.member[i])-component_names)/3) < 4);
+                               ok = ((components[i] = (std::find(component_names, component_names+12, memacc.member[i])-component_names)/3) < 4);
 
                        if(ok)
                        {
@@ -390,19 +390,16 @@ void VariableResolver::visit(Assignment &assign)
 
 void VariableResolver::merge_layouts(Layout &to_layout, const Layout &from_layout)
 {
-       for(vector<Layout::Qualifier>::const_iterator i=from_layout.qualifiers.begin(); i!=from_layout.qualifiers.end(); ++i)
+       for(const Layout::Qualifier &q: from_layout.qualifiers)
        {
-               bool found = false;
-               for(vector<Layout::Qualifier>::iterator j=to_layout.qualifiers.begin(); (!found && j!=to_layout.qualifiers.end()); ++j)
-                       if(j->name==i->name)
-                       {
-                               j->has_value = i->value;
-                               j->value = i->value;
-                               found = true;
-                       }
-
-               if(!found)
-                       to_layout.qualifiers.push_back(*i);
+               auto i = find_member(to_layout.qualifiers, q.name, &Layout::Qualifier::name);
+               if(i!=to_layout.qualifiers.end())
+               {
+                       i->has_value = q.value;
+                       i->value = q.value;
+               }
+               else
+                       to_layout.qualifiers.push_back(q);
        }
 }
 
@@ -474,18 +471,16 @@ ExpressionResolver::Compatibility ExpressionResolver::get_compatibility(BasicTyp
 
 BasicTypeDeclaration *ExpressionResolver::find_type(BasicTypeDeclaration::Kind kind, unsigned size, bool sign)
 {
-       for(vector<BasicTypeDeclaration *>::const_iterator i=basic_types.begin(); i!=basic_types.end(); ++i)
-               if((*i)->kind==kind && (*i)->size==size && (*i)->sign==sign)
-                       return *i;
-       return 0;
+       auto i = find_if(basic_types,
+               [kind, size, sign](const BasicTypeDeclaration *t){ return t->kind==kind && t->size==size && t->sign==sign; });
+       return (i!=basic_types.end() ? *i : 0);
 }
 
 BasicTypeDeclaration *ExpressionResolver::find_type(BasicTypeDeclaration &elem_type, BasicTypeDeclaration::Kind kind, unsigned size)
 {
-       for(vector<BasicTypeDeclaration *>::const_iterator i=basic_types.begin(); i!=basic_types.end(); ++i)
-               if(get_element_type(**i)==&elem_type && (*i)->kind==kind && (*i)->size==size)
-                       return *i;
-       return 0;
+       auto i = find_if(basic_types,
+               [&elem_type, kind, size](BasicTypeDeclaration *t){ return get_element_type(*t)==&elem_type && t->kind==kind && t->size==size; });
+       return (i!=basic_types.end() ? *i : 0);
 }
 
 void ExpressionResolver::convert_to(RefPtr<Expression> &expr, BasicTypeDeclaration &type)
@@ -549,7 +544,7 @@ void ExpressionResolver::resolve(Expression &expr, TypeDeclaration *type, bool l
 void ExpressionResolver::visit(Block &block)
 {
        SetForScope<Block *> set_block(current_block, &block);
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
        {
                insert_point = i;
                (*i)->visit(*this);
@@ -857,7 +852,7 @@ void ExpressionResolver::visit_constructor(FunctionCall &call)
        if(call.arguments.empty())
                return;
 
-       map<string, TypeDeclaration *>::const_iterator i = stage->types.find(call.name);
+       auto i = stage->types.find(call.name);
        if(i==stage->types.end())
                return;
        else if(call.arguments.size()==1 && i->second==call.arguments[0]->type)
@@ -872,10 +867,10 @@ void ExpressionResolver::visit_constructor(FunctionCall &call)
                args.reserve(call.arguments.size());
                unsigned arg_component_total = 0;
                bool has_matrices = false;
-               for(NodeArray<Expression>::const_iterator j=call.arguments.begin(); j!=call.arguments.end(); ++j)
+               for(const RefPtr<Expression> &a: call.arguments)
                {
                        ArgumentInfo info;
-                       if(!(info.type=dynamic_cast<BasicTypeDeclaration *>((*j)->type)))
+                       if(!(info.type=dynamic_cast<BasicTypeDeclaration *>(a->type)))
                                return;
                        if(is_scalar(*info.type) || info.type->kind==BasicTypeDeclaration::BOOL)
                                info.component_count = 1;
@@ -1033,12 +1028,12 @@ void ExpressionResolver::visit_constructor(FunctionCall &call)
                if(convert_args)
                {
                        // The argument list may have changed so can't rely on args.
-                       for(NodeArray<Expression>::iterator j=call.arguments.begin(); j!=call.arguments.end(); ++j)
-                               if(BasicTypeDeclaration *basic_arg = dynamic_cast<BasicTypeDeclaration *>((*j)->type))
+                       for(RefPtr<Expression> &a: call.arguments)
+                               if(BasicTypeDeclaration *basic_arg = dynamic_cast<BasicTypeDeclaration *>(a->type))
                                {
                                        BasicTypeDeclaration *elem_arg = get_element_type(*basic_arg);
                                        if(elem_arg!=elem)
-                                               convert_to_element(*j, *elem);
+                                               convert_to_element(a, *elem);
                                }
                }
        }
@@ -1047,16 +1042,17 @@ void ExpressionResolver::visit_constructor(FunctionCall &call)
                if(call.arguments.size()!=strct->members.body.size())
                        return;
 
-               unsigned k = 0;
-               for(NodeList<Statement>::const_iterator j=strct->members.body.begin(); j!=strct->members.body.end(); ++j, ++k)
+               auto j = call.arguments.begin();
+               for(const RefPtr<Statement> &s: strct->members.body)
                {
-                       if(VariableDeclaration *var = dynamic_cast<VariableDeclaration *>(j->get()))
+                       if(VariableDeclaration *var = dynamic_cast<VariableDeclaration *>(s.get()))
                        {
-                               if(!call.arguments[k]->type || call.arguments[k]->type!=var->type_declaration)
+                               if(!(*j)->type || (*j)->type!=var->type_declaration)
                                        return;
                        }
                        else
                                return;
+                       ++j;
                }
        }
 
@@ -1136,7 +1132,7 @@ void FunctionResolver::visit(FunctionCall &call)
        {
                string arg_types;
                bool has_signature = true;
-               for(NodeArray<Expression>::const_iterator i=call.arguments.begin(); (has_signature && i!=call.arguments.end()); ++i)
+               for(auto i=call.arguments.begin(); (has_signature && i!=call.arguments.end()); ++i)
                {
                        if((*i)->type)
                                append(arg_types, ",", (*i)->type->name);
@@ -1146,7 +1142,7 @@ void FunctionResolver::visit(FunctionCall &call)
 
                if(has_signature)
                {
-                       map<string, FunctionDeclaration *>::iterator i = stage->functions.find(format("%s(%s)", call.name, arg_types));
+                       auto i = stage->functions.find(format("%s(%s)", call.name, arg_types));
                        declaration = (i!=stage->functions.end() ? i->second : 0);
 
                        if(!declaration)
@@ -1177,10 +1173,10 @@ void FunctionResolver::visit(FunctionDeclaration &func)
        if(func.signature.empty())
        {
                string param_types;
-               for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
+               for(const RefPtr<VariableDeclaration> &p: func.parameters)
                {
-                       if((*i)->type_declaration)
-                               append(param_types, ",", (*i)->type_declaration->name);
+                       if(p->type_declaration)
+                               append(param_types, ",", p->type_declaration->name);
                        else
                                return;
                }
@@ -1205,11 +1201,11 @@ void FunctionResolver::visit(FunctionDeclaration &func)
                stage_decl = &func;
 
                // Set all previous declarations to use this definition.
-               for(vector<FunctionDeclaration *>::iterator i=decls.begin(); i!=decls.end(); ++i)
+               for(FunctionDeclaration *f: decls)
                {
-                       r_any_resolved |= (func.definition!=(*i)->definition);
-                       (*i)->definition = func.definition;
-                       (*i)->body.body.clear();
+                       r_any_resolved |= (func.definition!=f->definition);
+                       f->definition = func.definition;
+                       f->body.body.clear();
                }
        }
        else
index 9eb33b05733a9ce3c0659cad2272aedcd37b2d1e..b81931e1143dfe24719833444257e7d235adedd5 100644 (file)
@@ -59,9 +59,9 @@ string SourceMap::translate_errors(const string &errors) const
        static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$");
        vector<string> lines = split(errors, '\n');
        string translated;
-       for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
+       for(const string &l: lines)
        {
-               RegMatch m = r_message.match(*i);
+               RegMatch m = r_message.match(l);
                if(m)
                {
                        unsigned index = 0;
@@ -82,7 +82,7 @@ string SourceMap::translate_errors(const string &errors) const
                        translated += format("%s:%d: %s", src, line, m[6].str);
                }
                else
-                       translated += *i;
+                       translated += l;
                translated += '\n';
        }
 
index 72f73bd56bdf9c4ff1d3738342986b6fbf7a315f..1da748a64eb297f23f5f135aa3743af92eabbaea 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/core/raii.h>
 #include "reflect.h"
@@ -151,11 +152,11 @@ void SpirVGenerator::apply(Module &module)
 {
        use_capability(CAP_SHADER);
 
-       for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
+       for(Stage &s: module.stages)
        {
-               stage = &*i;
+               stage = &s;
                interface_layouts.clear();
-               i->content.visit(*this);
+               s.content.visit(*this);
        }
 
        writer.finalize(SPIRV_GENERATOR_MSP, next_id);
@@ -239,7 +240,7 @@ SpirVGenerator::Id SpirVGenerator::get_id(Node &node) const
 
 SpirVGenerator::Id SpirVGenerator::allocate_id(Node &node, Id type_id)
 {
-       map<Node *, Declaration>::iterator i = declared_ids.find(&node);
+       auto i = declared_ids.find(&node);
        if(i!=declared_ids.end())
        {
                if(i->second.type_id)
@@ -255,7 +256,7 @@ SpirVGenerator::Id SpirVGenerator::allocate_id(Node &node, Id type_id)
 
 SpirVGenerator::Id SpirVGenerator::allocate_forward_id(Node &node)
 {
-       map<Node *, Declaration>::iterator i = declared_ids.find(&node);
+       auto i = declared_ids.find(&node);
        if(i!=declared_ids.end())
                return i->second.id;
 
@@ -345,7 +346,7 @@ SpirVGenerator::Id SpirVGenerator::get_standard_type_id(BasicTypeDeclaration::Ki
 
 bool SpirVGenerator::is_scalar_type(Id type_id, BasicTypeDeclaration::Kind kind) const
 {
-       map<TypeKey, Id>::const_iterator i = standard_type_ids.find(TypeKey(kind, true));
+       auto i = standard_type_ids.find(TypeKey(kind, true));
        return (i!=standard_type_ids.end() && i->second==type_id);
 }
 
@@ -413,7 +414,7 @@ SpirVGenerator::Id SpirVGenerator::get_load_id(VariableDeclaration &var)
 
 void SpirVGenerator::prune_loads(Id min_id)
 {
-       for(map<const VariableDeclaration *, Id>::iterator i=variable_load_ids.begin(); i!=variable_load_ids.end(); )
+       for(auto i=variable_load_ids.begin(); i!=variable_load_ids.end(); )
        {
                if(i->second>=min_id)
                        variable_load_ids.erase(i++);
@@ -499,8 +500,8 @@ SpirVGenerator::Id SpirVGenerator::write_construct(Id type_id, const Id *elem_id
 
 void SpirVGenerator::visit(Block &block)
 {
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
-               (*i)->visit(*this);
+       for(const RefPtr<Statement> &s: block.body)
+               s->visit(*this);
 }
 
 void SpirVGenerator::visit(Literal &literal)
@@ -564,13 +565,13 @@ void SpirVGenerator::generate_composite_access(TypeDeclaration &result_type)
                        throw internal_error("composite access through pointer in constant context");
 
                Id int32_type_id = get_standard_type_id(BasicTypeDeclaration::INT, 1);
-               for(vector<unsigned>::iterator i=r_composite_chain.begin(); i!=r_composite_chain.end(); ++i)
-                       *i = (*i<0x400000 ? get_constant_id(int32_type_id, static_cast<int>(*i)) : *i&0x3FFFFF);
+               for(unsigned &i: r_composite_chain)
+                       i = (i<0x400000 ? get_constant_id(int32_type_id, static_cast<int>(i)) : i&0x3FFFFF);
 
                /* Find the storage class of the base and obtain appropriate pointer type
                for the result. */
                const Declaration &base_decl = get_item(declared_ids, r_composite_base);
-               map<TypeKey, Id>::const_iterator i = pointer_type_ids.begin();
+               auto i = pointer_type_ids.begin();
                for(; (i!=pointer_type_ids.end() && i->second!=base_decl.type_id); ++i) ;
                if(i==pointer_type_ids.end())
                        throw internal_error("could not find storage class");
@@ -582,18 +583,18 @@ void SpirVGenerator::generate_composite_access(TypeDeclaration &result_type)
                throw internal_error("assignment to temporary composite");
        else
        {
-               for(vector<unsigned>::iterator i=r_composite_chain.begin(); i!=r_composite_chain.end(); ++i)
-                       for(map<ConstantKey, Id>::iterator j=constant_ids.begin(); (*i>=0x400000 && j!=constant_ids.end()); ++j)
-                               if(j->second==(*i&0x3FFFFF))
-                                       *i = j->first.int_value;
+               for(unsigned i: r_composite_chain)
+                       for(auto j=constant_ids.begin(); (i>=0x400000 && j!=constant_ids.end()); ++j)
+                               if(j->second==(i&0x3FFFFF))
+                                       i = j->first.int_value;
 
                opcode = OP_COMPOSITE_EXTRACT;
        }
 
        Id access_id = begin_expression(opcode, access_type_id, 1+r_composite_chain.size());
        writer.write(r_composite_base_id);
-       for(vector<unsigned>::const_iterator i=r_composite_chain.begin(); i!=r_composite_chain.end(); ++i)
-               writer.write(*i);
+       for(unsigned i: r_composite_chain)
+               writer.write(i);
        end_expression(opcode);
 
        r_constant_result = false;
@@ -1062,9 +1063,9 @@ void SpirVGenerator::visit(FunctionCall &call)
        vector<Id> argument_ids;
        argument_ids.reserve(call.arguments.size());
        bool all_args_const = true;
-       for(NodeArray<Expression>::const_iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
+       for(const RefPtr<Expression> &a: call.arguments)
        {
-               (*i)->visit(*this);
+               a->visit(*this);
                argument_ids.push_back(r_expression_result_id);
                all_args_const &= r_constant_result;
        }
@@ -1080,8 +1081,8 @@ void SpirVGenerator::visit(FunctionCall &call)
        else if(call.declaration->source==BUILTIN_SOURCE)
        {
                string arg_types;
-               for(NodeArray<Expression>::const_iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
-                       if(BasicTypeDeclaration *basic_arg = dynamic_cast<BasicTypeDeclaration *>((*i)->type))
+               for(const RefPtr<Expression> &a: call.arguments)
+                       if(BasicTypeDeclaration *basic_arg = dynamic_cast<BasicTypeDeclaration *>(a->type))
                        {
                                BasicTypeDeclaration &elem_arg = *get_element_type(*basic_arg);
                                switch(elem_arg.kind)
@@ -1137,14 +1138,14 @@ void SpirVGenerator::visit(FunctionCall &call)
        {
                r_expression_result_id = begin_expression(OP_FUNCTION_CALL, result_type_id, 1+call.arguments.size());
                writer.write(get_id(*call.declaration->definition));
-               for(vector<Id>::const_iterator i=argument_ids.begin(); i!=argument_ids.end(); ++i)
-                       writer.write(*i);
+               for(Id i: argument_ids)
+                       writer.write(i);
                end_expression(OP_FUNCTION_CALL);
 
                // Any global variables the called function uses might have changed value
                set<Node *> dependencies = DependencyCollector().apply(*call.declaration->definition);
-               for(set<Node *>::const_iterator i=dependencies.begin(); i!=dependencies.end(); ++i)
-                       if(const VariableDeclaration *var = dynamic_cast<const VariableDeclaration *>(*i))
+               for(Node *n: dependencies)
+                       if(const VariableDeclaration *var = dynamic_cast<const VariableDeclaration *>(n))
                                variable_load_ids.erase(var);
        }
 }
@@ -1405,7 +1406,7 @@ void SpirVGenerator::visit_builtin_interpolate(FunctionCall &call, const vector<
        writer.write(ext_id);
        writer.write(opcode);
        writer.write(get_id(*var->declaration));
-       for(vector<Id>::const_iterator i=argument_ids.begin(); ++i!=argument_ids.end(); )
+       for(auto i=argument_ids.begin(); ++i!=argument_ids.end(); )
                writer.write(*i);
        end_expression(OP_EXT_INST);
 }
@@ -1422,11 +1423,11 @@ void SpirVGenerator::visit(InterfaceLayout &layout)
 
 bool SpirVGenerator::check_duplicate_type(TypeDeclaration &type)
 {
-       for(map<Node *, Declaration>::const_iterator i=declared_ids.begin(); i!=declared_ids.end(); ++i)
-               if(TypeDeclaration *type2 = dynamic_cast<TypeDeclaration *>(i->first))
+       for(const auto &kvp: declared_ids)
+               if(TypeDeclaration *type2 = dynamic_cast<TypeDeclaration *>(kvp.first))
                        if(TypeComparer().apply(type, *type2))
                        {
-                               insert_unique(declared_ids, &type, i->second);
+                               insert_unique(declared_ids, &type, kvp.second);
                                return true;
                        }
 
@@ -1527,9 +1528,9 @@ void SpirVGenerator::visit(StructDeclaration &strct)
        bool builtin = (strct.interface_block && !strct.interface_block->block_name.compare(0, 3, "gl_"));
        vector<Id> member_type_ids;
        member_type_ids.reserve(strct.members.body.size());
-       for(NodeList<Statement>::const_iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i)
+       for(const RefPtr<Statement> &s: strct.members.body)
        {
-               const VariableDeclaration *var = dynamic_cast<const VariableDeclaration *>(i->get());
+               const VariableDeclaration *var = dynamic_cast<const VariableDeclaration *>(s.get());
                if(!var)
                        continue;
 
@@ -1547,14 +1548,13 @@ void SpirVGenerator::visit(StructDeclaration &strct)
                {
                        if(var->layout)
                        {
-                               const vector<Layout::Qualifier> &qualifiers = var->layout->qualifiers;
-                               for(vector<Layout::Qualifier>::const_iterator j=qualifiers.begin(); j!=qualifiers.end(); ++j)
+                               for(const Layout::Qualifier &q: var->layout->qualifiers)
                                {
-                                       if(j->name=="offset")
-                                               writer.write_op_member_decorate(type_id, index, DECO_OFFSET, j->value);
-                                       else if(j->name=="column_major")
+                                       if(q.name=="offset")
+                                               writer.write_op_member_decorate(type_id, index, DECO_OFFSET, q.value);
+                                       else if(q.name=="column_major")
                                                writer.write_op_member_decorate(type_id, index, DECO_COL_MAJOR);
-                                       else if(j->name=="row_major")
+                                       else if(q.name=="row_major")
                                                writer.write_op_member_decorate(type_id, index, DECO_ROW_MAJOR);
                                }
                        }
@@ -1572,8 +1572,8 @@ void SpirVGenerator::visit(StructDeclaration &strct)
 
        writer.begin_op(content.globals, OP_TYPE_STRUCT);
        writer.write(type_id);
-       for(vector<Id>::const_iterator i=member_type_ids.begin(); i!=member_type_ids.end(); ++i)
-               writer.write(*i);
+       for(Id i: member_type_ids)
+               writer.write(i);
        writer.end_op(OP_TYPE_STRUCT);
 }
 
@@ -1584,9 +1584,9 @@ void SpirVGenerator::visit(VariableDeclaration &var)
        int spec_id = -1;
        if(layout_ql)
        {
-               for(vector<Layout::Qualifier>::const_iterator i=layout_ql->begin(); (spec_id<0 && i!=layout_ql->end()); ++i)
-                       if(i->name=="constant_id")
-                               spec_id = i->value;
+               auto i = find_member(*layout_ql, string("constant_id"), &Layout::Qualifier::name);
+               if(i!=layout_ql->end())
+                       spec_id = i->value;
        }
 
        Id type_id = get_variable_type_id(var);
@@ -1649,14 +1649,14 @@ void SpirVGenerator::visit(VariableDeclaration &var)
 
                if(layout_ql)
                {
-                       for(vector<Layout::Qualifier>::const_iterator i=layout_ql->begin(); i!=layout_ql->end(); ++i)
+                       for(const Layout::Qualifier &q: *layout_ql)
                        {
-                               if(i->name=="location")
-                                       writer.write_op_decorate(var_id, DECO_LOCATION, i->value);
-                               else if(i->name=="set")
-                                       writer.write_op_decorate(var_id, DECO_DESCRIPTOR_SET, i->value);
-                               else if(i->name=="binding")
-                                       writer.write_op_decorate(var_id, DECO_BINDING, i->value);
+                               if(q.name=="location")
+                                       writer.write_op_decorate(var_id, DECO_LOCATION, q.value);
+                               else if(q.name=="set")
+                                       writer.write_op_decorate(var_id, DECO_DESCRIPTOR_SET, q.value);
+                               else if(q.name=="binding")
+                                       writer.write_op_decorate(var_id, DECO_BINDING, q.value);
                        }
                }
 
@@ -1700,10 +1700,9 @@ void SpirVGenerator::visit(InterfaceBlock &iface)
 
        if(iface.layout)
        {
-               const vector<Layout::Qualifier> &qualifiers = iface.layout->qualifiers;
-               for(vector<Layout::Qualifier>::const_iterator i=qualifiers.begin(); i!=qualifiers.end(); ++i)
-                       if(i->name=="binding")
-                               writer.write_op_decorate(block_id, DECO_BINDING, i->value);
+               auto i = find_member(iface.layout->qualifiers, string("binding"), &Layout::Qualifier::name);
+               if(i!=iface.layout->qualifiers.end())
+                       writer.write_op_decorate(block_id, DECO_BINDING, i->value);
        }
 }
 
@@ -1721,15 +1720,15 @@ void SpirVGenerator::visit_entry_point(FunctionDeclaration &func, Id func_id)
        writer.write_string(func.name);
 
        set<Node *> dependencies = DependencyCollector().apply(func);
-       for(set<Node *>::const_iterator i=dependencies.begin(); i!=dependencies.end(); ++i)
+       for(Node *n: dependencies)
        {
-               if(const VariableDeclaration *var = dynamic_cast<const VariableDeclaration *>(*i))
+               if(const VariableDeclaration *var = dynamic_cast<const VariableDeclaration *>(n))
                {
                        if(!var->interface.empty())
-                               writer.write(get_id(**i));
+                               writer.write(get_id(*n));
                }
-               else if(dynamic_cast<InterfaceBlock *>(*i))
-                       writer.write(get_id(**i));
+               else if(dynamic_cast<InterfaceBlock *>(n))
+                       writer.write(get_id(*n));
        }
 
        writer.end_op(OP_ENTRY_POINT);
@@ -1739,28 +1738,27 @@ void SpirVGenerator::visit_entry_point(FunctionDeclaration &func, Id func_id)
        else if(stage->type==Stage::GEOMETRY)
                use_capability(CAP_GEOMETRY);
 
-       for(vector<const InterfaceLayout *>::const_iterator i=interface_layouts.begin(); i!=interface_layouts.end(); ++i)
+       for(const InterfaceLayout *i: interface_layouts)
        {
-               const vector<Layout::Qualifier> &qualifiers = (*i)->layout.qualifiers;
-               for(vector<Layout::Qualifier>::const_iterator j=qualifiers.begin(); j!=qualifiers.end(); ++j)
+               for(const Layout::Qualifier &q: i->layout.qualifiers)
                {
-                       if(j->name=="point")
+                       if(q.name=="point")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id,
-                                       ((*i)->interface=="in" ? EXEC_INPUT_POINTS : EXEC_OUTPUT_POINTS));
-                       else if(j->name=="lines")
+                                       (i->interface=="in" ? EXEC_INPUT_POINTS : EXEC_OUTPUT_POINTS));
+                       else if(q.name=="lines")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_INPUT_LINES);
-                       else if(j->name=="lines_adjacency")
+                       else if(q.name=="lines_adjacency")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_INPUT_LINES_ADJACENCY);
-                       else if(j->name=="triangles")
+                       else if(q.name=="triangles")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_TRIANGLES);
-                       else if(j->name=="triangles_adjacency")
+                       else if(q.name=="triangles_adjacency")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_INPUT_TRIANGLES_ADJACENCY);
-                       else if(j->name=="line_strip")
+                       else if(q.name=="line_strip")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_OUTPUT_LINE_STRIP);
-                       else if(j->name=="triangle_strip")
+                       else if(q.name=="triangle_strip")
                                writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_OUTPUT_TRIANGLE_STRIP);
-                       else if(j->name=="max_vertices")
-                               writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_OUTPUT_VERTICES, j->value);
+                       else if(q.name=="max_vertices")
+                               writer.write_op(content.exec_modes, OP_EXECUTION_MODE, func_id, EXEC_OUTPUT_VERTICES, q.value);
                }
        }
 }
@@ -1779,8 +1777,8 @@ void SpirVGenerator::visit(FunctionDeclaration &func)
        Id return_type_id = get_id(*func.return_type_declaration);
        vector<unsigned> param_type_ids;
        param_type_ids.reserve(func.parameters.size());
-       for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
-               param_type_ids.push_back(get_variable_type_id(**i));
+       for(const RefPtr<VariableDeclaration> &p: func.parameters)
+               param_type_ids.push_back(get_variable_type_id(*p));
 
        string sig_with_return = func.return_type+func.signature;
        Id &type_id = function_type_ids[sig_with_return];
@@ -1790,8 +1788,8 @@ void SpirVGenerator::visit(FunctionDeclaration &func)
                writer.begin_op(content.globals, OP_TYPE_FUNCTION);
                writer.write(type_id);
                writer.write(return_type_id);
-               for(vector<unsigned>::const_iterator i=param_type_ids.begin(); i!=param_type_ids.end(); ++i)
-                       writer.write(*i);
+               for(unsigned i: param_type_ids)
+                       writer.write(i);
                writer.end_op(OP_TYPE_FUNCTION);
 
                writer.write_op_name(type_id, sig_with_return);
index 4526bf2bd986075f6bfe50e50dae1eabf2ebd204..502c274810074c00b488711e55cae6e15ae29c7c 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include "syntax.h"
 #include "visitor.h"
@@ -69,8 +70,8 @@ template<typename C>
 NodeContainer<C>::NodeContainer(const NodeContainer &c):
        C(c)
 {
-       for(typename C::iterator i=this->begin(); i!=this->end(); ++i)
-               *i = (*i)->clone();
+       for(auto &i: *this)
+               i = i->clone();
 }
 
 
@@ -491,10 +492,8 @@ string get_unused_variable_name(const Block &block, const string &base)
 
 int get_layout_value(const Layout &layout, const string &name, int def_value)
 {
-       for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
-               if(i->name==name)
-                       return i->value;
-       return def_value;
+       auto i = find_member(layout.qualifiers, name, &Layout::Qualifier::name);
+       return (i!=layout.qualifiers.end() ? i->value : def_value);
 }
 
 void add_to_chain(Assignment::Target &target, Assignment::Target::ChainType type, unsigned index)
index bd455e3cb200408128534b6e9a235198e6d08807..595a97abc71e28402fef288be5f7c9636bc87e28 100644 (file)
@@ -95,7 +95,7 @@ void Tokenizer::preprocess()
 {
        SetForScope<deque<string> > clear_tokens(next_tokens, deque<string>());
 
-       string::const_iterator line_end = iter;
+       auto line_end = iter;
        for(; (line_end!=source_end && *line_end!='\n'); ++line_end) ;
        SetForScope<string::const_iterator> stop_at_line_end(source_end, line_end);
 
index fdff3fe657aa56972690304c587e5bf61e8b3816..ce30c2abdf44fe9156476e9eba145063c90fde43 100644 (file)
@@ -61,16 +61,16 @@ const char *DeclarationValidator::describe_variable(ScopeType scope)
 
 void DeclarationValidator::visit(Layout &layout)
 {
-       for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
+       for(const Layout::Qualifier &q: layout.qualifiers)
        {
                bool allowed = false;
                string err_descr;
                bool value = true;
-               if(i->name=="location")
+               if(q.name=="location")
                        allowed = (variable && scope==GLOBAL);
-               else if(i->name=="binding" || i->name=="set")
+               else if(q.name=="binding" || q.name=="set")
                {
-                       if(i->name=="set")
+                       if(q.name=="set")
                        {
                                error(layout, "Layout qualifier 'set' not allowed when targeting OpenGL");
                                continue;
@@ -91,7 +91,7 @@ void DeclarationValidator::visit(Layout &layout)
                                err_descr = "non-uniform interface block";
                        }
                }
-               else if(i->name=="constant_id")
+               else if(q.name=="constant_id")
                {
                        allowed = (variable && scope==GLOBAL);
                        if(allowed)
@@ -113,35 +113,35 @@ void DeclarationValidator::visit(Layout &layout)
                                }
                        }
                }
-               else if(i->name=="offset")
+               else if(q.name=="offset")
                        allowed = (variable && scope==INTERFACE_BLOCK && iface_block->interface=="uniform");
-               else if(i->name=="align")
+               else if(q.name=="align")
                        allowed = (scope==INTERFACE_BLOCK && iface_block->interface=="uniform");
-               else if(i->name=="points")
+               else if(q.name=="points")
                {
                        allowed = (stage->type==Stage::GEOMETRY && iface_layout && (iface_layout->interface=="in" || iface_layout->interface=="out"));
                        value = false;
                }
-               else if(i->name=="lines" || i->name=="lines_adjacency" || i->name=="triangles" || i->name=="triangles_adjacency")
+               else if(q.name=="lines" || q.name=="lines_adjacency" || q.name=="triangles" || q.name=="triangles_adjacency")
                {
                        allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
                        value = false;
                }
-               else if(i->name=="line_strip" || i->name=="triangle_strip")
+               else if(q.name=="line_strip" || q.name=="triangle_strip")
                {
                        allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
                        value = false;
                }
-               else if(i->name=="invocations")
+               else if(q.name=="invocations")
                        allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
-               else if(i->name=="max_vertices")
+               else if(q.name=="max_vertices")
                        allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
-               else if(i->name=="std140" || i->name=="std430")
+               else if(q.name=="std140" || q.name=="std430")
                {
                        allowed = (iface_block && !variable && iface_block->interface=="uniform");
                        value = false;
                }
-               else if(i->name=="column_major" || i->name=="row_major")
+               else if(q.name=="column_major" || q.name=="row_major")
                {
                        allowed = (variable && scope==INTERFACE_BLOCK);
                        if(allowed)
@@ -167,12 +167,12 @@ void DeclarationValidator::visit(Layout &layout)
                                else
                                        err_descr = "unknown declaration";
                        }
-                       error(layout, format("Layout qualifier '%s' not allowed on %s", i->name, err_descr));
+                       error(layout, format("Layout qualifier '%s' not allowed on %s", q.name, err_descr));
                }
-               else if(value && !i->has_value)
-                       error(layout, format("Layout qualifier '%s' requires a value", i->name));
-               else if(!value && i->has_value)
-                       error(layout, format("Layout qualifier '%s' does not allow a value", i->name));
+               else if(value && !q.has_value)
+                       error(layout, format("Layout qualifier '%s' requires a value", q.name));
+               else if(!value && q.has_value)
+                       error(layout, format("Layout qualifier '%s' does not allow a value", q.name));
        }
 }
 
@@ -298,8 +298,8 @@ void DeclarationValidator::visit(InterfaceBlock &iface)
 void DeclarationValidator::visit(FunctionDeclaration &func)
 {
        SetForScope<ScopeType> set_scope(scope, FUNCTION_PARAM);
-       for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
-               (*i)->visit(*this);
+       for(const RefPtr<VariableDeclaration> &p: func.parameters)
+               p->visit(*this);
        scope = FUNCTION;
        func.body.visit(*this);
 }
@@ -318,7 +318,7 @@ void IdentifierValidator::multiple_definition(const string &name, Statement &sta
 Statement *IdentifierValidator::find_definition(const string &name)
 {
        BlockDeclarationMap *decls = &declarations[current_block];
-       BlockDeclarationMap::const_iterator i = decls->find(name);
+       auto i = decls->find(name);
        if(i==decls->end() && anonymous_block)
        {
                decls = &declarations[current_block->parent];
@@ -362,7 +362,7 @@ void IdentifierValidator::visit(VariableDeclaration &var)
 void IdentifierValidator::visit(InterfaceBlock &iface)
 {
        string key = format("%s %s", iface.interface, iface.block_name);
-       map<string, InterfaceBlock *>::const_iterator i = interface_blocks.find(key);
+       auto i = interface_blocks.find(key);
        if(i!=interface_blocks.end())
                multiple_definition(format("interface block '%s %s'", iface.interface, iface.block_name), iface, *i->second);
        else
@@ -382,16 +382,15 @@ void IdentifierValidator::visit(InterfaceBlock &iface)
        if(iface.instance_name.empty() && iface.struct_declaration)
        {
                // Inject anonymous interface block members into the global scope
-               const map<string, VariableDeclaration *> &iface_vars = iface.struct_declaration->members.variables;
-               for(map<string, VariableDeclaration *>::const_iterator j=iface_vars.begin(); j!=iface_vars.end(); ++j)
-                       check_definition(j->first, *j->second);
+               for(const auto &kvp: iface.struct_declaration->members.variables)
+                       check_definition(kvp.first, *kvp.second);
        }
 }
 
 void IdentifierValidator::visit(FunctionDeclaration &func)
 {
        string key = func.name+func.signature;
-       map<string, FunctionDeclaration *>::const_iterator i = overloaded_functions.find(key);
+       auto i = overloaded_functions.find(key);
        if(i==overloaded_functions.end())
                overloaded_functions.insert(make_pair(key, &func));
        else if(func.return_type_declaration && i->second->return_type_declaration!=func.return_type_declaration)
@@ -460,7 +459,7 @@ void ReferenceValidator::visit(FunctionCall &call)
                bool have_declaration = call.constructor;
                if(!call.constructor)
                {
-                       map<string, FunctionDeclaration *>::iterator i = stage->functions.lower_bound(call.name);
+                       auto i = stage->functions.lower_bound(call.name);
                        have_declaration = (i!=stage->functions.end() && i->second->name==call.name);
                }
 
@@ -468,7 +467,7 @@ void ReferenceValidator::visit(FunctionCall &call)
                {
                        bool valid_types = true;
                        string signature;
-                       for(NodeArray<Expression>::const_iterator j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j)
+                       for(auto j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j)
                        {
                                if((*j)->type)
                                        append(signature, ", ", (*j)->type->name);
@@ -705,14 +704,14 @@ FlowControlValidator::FlowControlValidator():
 
 void FlowControlValidator::visit(Block &block)
 {
-       for(NodeList<Statement>::const_iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(const RefPtr<Statement> &s: block.body)
        {
                if(!reachable)
                {
-                       diagnose(**i, Diagnostic::WARN, "Unreachable code detected");
+                       diagnose(*s, Diagnostic::WARN, "Unreachable code detected");
                        break;
                }
-               (*i)->visit(*this);
+               s->visit(*this);
        }
 }
 
@@ -747,10 +746,7 @@ void FlowControlValidator::visit(Iteration &iter)
 
 int StageInterfaceValidator::get_location(const Layout &layout)
 {
-       for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
-               if(i->name=="location")
-                       return i->value;
-       return -1;
+       return get_layout_value(layout, "location", -1);
 }
 
 void StageInterfaceValidator::visit(VariableDeclaration &var)
@@ -791,7 +787,7 @@ void StageInterfaceValidator::visit(VariableDeclaration &var)
                unsigned loc_count = LocationCounter().apply(var);
                for(unsigned i=0; i<loc_count; ++i)
                {
-                       map<unsigned, VariableDeclaration *>::const_iterator j = used.find(location+i);
+                       auto j = used.find(location+i);
                        if(j!=used.end())
                        {
                                error(var, format("Overlapping location %d for '%s %s'", location+i, var.interface, var.name));
@@ -806,16 +802,16 @@ void StageInterfaceValidator::visit(VariableDeclaration &var)
 
 void GlobalInterfaceValidator::apply(Module &module)
 {
-       for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
+       for(Stage &s: module.stages)
        {
-               stage = &*i;
-               i->content.visit(*this);
+               stage = &s;
+               s.content.visit(*this);
        }
 }
 
 void GlobalInterfaceValidator::check_uniform(const Uniform &uni)
 {
-       map<string, const Uniform *>::const_iterator i = used_names.find(uni.name);
+       auto i = used_names.find(uni.name);
        if(i!=used_names.end())
        {
                if(uni.location>=0 && i->second->location>=0 && i->second->location!=uni.location)
@@ -845,7 +841,7 @@ void GlobalInterfaceValidator::check_uniform(const Uniform &uni)
 
        if(uni.location>=0)
        {
-               map<unsigned, const Uniform *>::const_iterator j = used_locations.find(uni.location);
+               auto j = used_locations.find(uni.location);
                if(j!=used_locations.end())
                {
                        if(j->second->name!=uni.name)
@@ -864,7 +860,7 @@ void GlobalInterfaceValidator::check_uniform(const Uniform &uni)
        if(uni.bind_point>=0)
        {
                map<unsigned, const Uniform *> &used = used_bindings[uni.desc_set];
-               map<unsigned, const Uniform *>::const_iterator j = used.find(uni.bind_point);
+               auto j = used.find(uni.bind_point);
                if(j!=used.end())
                {
                        if(j->second->name!=uni.name)
index 3e480484c33dd6e12ad1ac8bad61801ba01b94c4..5e56d91945f057a3a1013a9fe8c233d475926dc7 100644 (file)
@@ -12,8 +12,8 @@ void TraversingVisitor::visit(Block &block)
        if(&block!=current_block)
                enter(block);
        SetForScope<Block *> set_block(current_block, &block);
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
-               (*i)->visit(*this);
+       for(const RefPtr<Statement> &s: block.body)
+               s->visit(*this);
 }
 
 void TraversingVisitor::visit(RefPtr<Expression> &expr)
@@ -57,8 +57,8 @@ void TraversingVisitor::visit(TernaryExpression &ternary)
 
 void TraversingVisitor::visit(FunctionCall &call)
 {
-       for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
-               visit(*i);
+       for(RefPtr<Expression> &a: call.arguments)
+               visit(a);
 }
 
 void TraversingVisitor::visit(ExpressionStatement &expr)
@@ -98,8 +98,8 @@ void TraversingVisitor::visit(FunctionDeclaration &func)
 {
        enter(func.body);
        SetForScope<Block *> set_block(current_block, &func.body);
-       for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
-               (*i)->visit(*this);
+       for(const RefPtr<VariableDeclaration> &p: func.parameters)
+               p->visit(*this);
        func.body.visit(*this);
 }
 
@@ -152,7 +152,7 @@ void NodeRemover::apply(Stage &s, const set<Node *> &tr)
 template<typename T>
 void NodeRemover::remove_from_map(map<string, T *> &vars, const string &key, T &node)
 {
-       typename map<string, T *>::iterator i = vars.find(key);
+       auto i = vars.find(key);
        if(i!=vars.end() && i->second==&node)
                vars.erase(i);
 }
@@ -160,7 +160,7 @@ void NodeRemover::remove_from_map(map<string, T *> &vars, const string &key, T &
 void NodeRemover::visit(Block &block)
 {
        SetForScope<Block *> set_block(current_block, &block);
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); )
+       for(auto i=block.body.begin(); i!=block.body.end(); )
        {
                (*i)->visit(*this);
                if(to_remove->count(i->get()))
@@ -234,15 +234,12 @@ void NodeReorderer::apply(Stage &stage, Node &before, const set<Node *> &tr)
 
 void NodeReorderer::visit(Block &block)
 {
-       NodeList<Statement>::iterator insert_point = block.body.end();
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); )
+       auto insert_point = block.body.end();
+       for(auto i=block.body.begin(); i!=block.body.end(); )
        {
                (*i)->visit(*this);
                if(insert_point!=block.body.end() && to_reorder->count(i->get()))
-               {
-                       NodeList<Statement>::iterator j = i++;
-                       block.body.splice(insert_point, block.body, j);
-               }
+                       block.body.splice(insert_point, block.body, i++);
                else
                {
                        if(i->get()==reorder_before)
index 699aabc02c7daa8679d60b2ab6fd8eaf8d99723b..91bc4d064b5afaef528057a2a654f2e8a11f7197 100644 (file)
@@ -74,7 +74,7 @@ void Lighting::attach(const Light &l)
 
 void Lighting::detach(const Light &l)
 {
-       vector<AttachedLight>::iterator i = find_member(lights, &l, &AttachedLight::light);
+       auto i = find_member(lights, &l, &AttachedLight::light);
        if(i!=lights.end())
                lights.erase(i);
 }
index 2d7e448788e0d81612bb191c7b4733b793e2c6c1..d03a72a53eaca89a5debb1ccace6a6054c80e504 100644 (file)
@@ -18,12 +18,12 @@ const Program *Material::create_compatible_shader(const map<string, int> &extra_
        map<string, int> spec_values;
        fill_program_info(module_name, spec_values);
 
-       for(map<string, int>::const_iterator i=extra_spec.begin(); i!=extra_spec.end(); ++i)
-               spec_values[i->first] = i->second;
+       for(const auto &kvp: extra_spec)
+               spec_values[kvp.first] = kvp.second;
 
        string info = module_name;
-       for(map<string, int>::const_iterator i=spec_values.begin(); i!=spec_values.end(); ++i)
-               info += format(",%s:%d", i->first, i->second);
+       for(const auto &kvp: spec_values)
+               info += format(",%s:%d", kvp.first, kvp.second);
 
        Resources &res = Resources::get_global();
        string name = format("_material_%016x.shader", hash64(info));
index 9a7ceef782075ee38821aa5ae9b45f1b6e13c425..f144a5dd5230927f683d3c0e781d8fb0a0fe799f 100644 (file)
@@ -61,7 +61,7 @@ void RenderPass::set_shader_program(const Program *prog, const ProgramData *data
 
 Tag RenderPass::get_slotted_uniform_tag(Tag slot) const
 {
-       map<Tag, Tag>::const_iterator i = uniform_slots.find(slot);
+       auto i = uniform_slots.find(slot);
        if(i==uniform_slots.end())
                return Tag();
        return i->second;
@@ -76,7 +76,7 @@ void RenderPass::set_material(const Material *mat)
 
 void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
 {
-       vector<TextureSlot>::iterator i = find_member(textures, tag, &TextureSlot::tag);
+       auto i = find_member(textures, tag, &TextureSlot::tag);
        if(i==textures.end())
        {
                textures.push_back(TextureSlot(tag));
@@ -89,7 +89,7 @@ void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
 
 Tag RenderPass::get_texture_tag(const string &slot) const
 {
-       vector<TextureSlot>::const_iterator i = find_member(textures, slot, &TextureSlot::slot_name);
+       auto i = find_member(textures, slot, &TextureSlot::slot_name);
        return (i!=textures.end() ? i->tag : Tag());
 }
 
@@ -99,28 +99,27 @@ void RenderPass::set_texture(unsigned index, const Texture *tex, const Sampler *
                throw invalid_operation("RenderPass::set_texture");
 
        const vector<Program::UniformInfo> &uniforms = shprog->get_uniforms();
-       for(vector<Program::UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               if(is_image(i->type) && i->binding==static_cast<int>(index))
-                       return set_texture(i->tag, tex, samp);
+       for(const Program::UniformInfo &u: uniforms)
+               if(is_image(u.type) && u.binding==static_cast<int>(index))
+                       return set_texture(u.tag, tex, samp);
 
        if(shdata)
        {
-               const vector<Tag> &tags = shdata->get_uniform_tags();
-               for(vector<Tag>::const_iterator i=tags.begin(); i!=tags.end(); ++i)
+               for(Tag t: shdata->get_uniform_tags())
                {
-                       vector<Program::UniformInfo>::const_iterator j = find_member(uniforms, *i, &Program::UniformInfo::tag);
+                       auto j = find_member(uniforms, t, &Program::UniformInfo::tag);
                        if(j==uniforms.end() || !is_image(j->type))
                                continue;
-                       if(const Uniform1i *uni1i = dynamic_cast<const Uniform1i *>(shdata->find_uniform(*i)))
+                       if(const Uniform1i *uni1i = dynamic_cast<const Uniform1i *>(shdata->find_uniform(t)))
                                if(uni1i->get()==static_cast<int>(index))
-                                       return set_texture(*i, tex, samp);
+                                       return set_texture(t, tex, samp);
                }
        }
 }
 
 int RenderPass::get_texture_index(const string &n) const
 {
-       vector<TextureSlot>::const_iterator i = find_member(textures, n, &TextureSlot::slot_name);
+       auto i = find_member(textures, n, &TextureSlot::slot_name);
        return (shprog && i!=textures.end() ? shprog->get_uniform_binding(i->tag) : -1);
 }
 
@@ -136,8 +135,8 @@ void RenderPass::set_receive_shadows(bool rs)
 
 void RenderPass::apply(Renderer &renderer) const
 {
-       for(vector<TextureSlot>::const_iterator i=textures.begin(); i!=textures.end(); ++i)
-               renderer.set_texture(i->tag, i->texture, i->sampler);
+       for(const TextureSlot &t: textures)
+               renderer.set_texture(t.tag, t.texture, t.sampler);
        renderer.set_shader_program(shprog, shdata.get());
        if(material)
                renderer.add_shader_data(material->get_shader_data());
@@ -237,7 +236,7 @@ void RenderPass::Loader::shader(const string &n)
 
 void RenderPass::Loader::texture(const string &n)
 {
-       vector<TextureSlot>::iterator i = find_member(obj.textures, Tag(n), &TextureSlot::tag);
+       auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag);
        if(i==obj.textures.end())
        {
                obj.textures.push_back(TextureSlot(n));
@@ -253,16 +252,15 @@ void RenderPass::Loader::texunit(unsigned)
        string name;
        if(obj.shprog)
        {
-               const vector<Program::UniformInfo> &uniforms = obj.shprog->get_uniforms();
-               for(vector<Program::UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-                       if(is_image(i->type) && i->binding>=0)
+               for(const Program::UniformInfo &u: obj.shprog->get_uniforms())
+                       if(is_image(u.type) && u.binding>=0)
                        {
                                if(!name.empty())
                                {
                                        name.clear();
                                        break;
                                }
-                               name = i->name;
+                               name = u.name;
                        }
        }
 
index 26a70a018dde6042ce7ddc5f8b21a2e942257ad5..ef1764112c4f3de6b98a2310ce67b84267e34e9d 100644 (file)
@@ -31,19 +31,19 @@ const RenderPass &Technique::get_pass(Tag tag) const
 
 const RenderPass *Technique::find_pass(Tag tag) const
 {
-       PassMap::const_iterator i = passes.find(tag);
+       auto i = passes.find(tag);
        return (i!=passes.end() ? &i->second : 0);
 }
 
 bool Technique::replace_texture(const string &slot, const Texture &tex)
 {
        bool replaced = false;
-       for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
+       for(auto &kvp: passes)
        {
-               Tag tag = i->second.get_texture_tag(slot);
+               Tag tag = kvp.second.get_texture_tag(slot);
                if(tag.id)
                {
-                       i->second.set_texture(tag, &tex);
+                       kvp.second.set_texture(tag, &tex);
                        replaced = true;
                }
        }
@@ -54,12 +54,12 @@ bool Technique::replace_texture(const string &slot, const Texture &tex)
 bool Technique::replace_material(const string &slot, const Material &mat)
 {
        bool replaced = false;
-       for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
+       for(auto &kvp: passes)
        {
-               const string &pass_slot = i->second.get_material_slot_name();
+               const string &pass_slot = kvp.second.get_material_slot_name();
                if(!pass_slot.empty() && pass_slot==slot)
                {
-                       i->second.set_material(&mat);
+                       kvp.second.set_material(&mat);
                        replaced = true;
                }
        }
@@ -71,24 +71,24 @@ bool Technique::replace_uniforms(const ProgramData &shdata)
 {
        bool replaced = false;
        const vector<Tag> &uniform_tags = shdata.get_uniform_tags();
-       for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
+       for(auto &kvp: passes)
        {
                RefPtr<ProgramData> new_shdata;
-               for(vector<Tag>::const_iterator j=uniform_tags.begin(); j!=uniform_tags.end(); ++j)
+               for(Tag t: uniform_tags)
                {
-                       Tag tag = i->second.get_slotted_uniform_tag(*j);
+                       Tag tag = kvp.second.get_slotted_uniform_tag(t);
                        if(!tag.id)
                                continue;
 
                        if(!new_shdata)
-                               new_shdata = new ProgramData(*i->second.get_shader_data());
+                               new_shdata = new ProgramData(*kvp.second.get_shader_data());
 
-                       new_shdata->uniform(tag, shdata.get_uniform(*j));
+                       new_shdata->uniform(tag, shdata.get_uniform(t));
                        replaced = true;
                }
 
                if(new_shdata)
-                       i->second.set_shader_program(i->second.get_shader_program(), new_shdata.get());
+                       kvp.second.set_shader_program(kvp.second.get_shader_program(), new_shdata.get());
        }
 
        return replaced;
@@ -96,8 +96,8 @@ bool Technique::replace_uniforms(const ProgramData &shdata)
 
 bool Technique::has_shaders() const
 {
-       for(PassMap::const_iterator i=passes.begin(); i!=passes.end(); ++i)
-               if(i->second.get_shader_program())
+       for(const auto &kvp: passes)
+               if(kvp.second.get_shader_program())
                        return true;
        return false;
 }
@@ -105,8 +105,8 @@ bool Technique::has_shaders() const
 void Technique::set_debug_name(const std::string &name)
 {
 #ifdef DEBUG
-       for(map<Tag, RenderPass>::iterator i=passes.begin(); i!=passes.end(); ++i)
-               i->second.set_debug_name(format("%s [pass:%s]", name, i->first.str()));
+       for(auto &kvp: passes)
+               kvp.second.set_debug_name(format("%s [pass:%s]", name, kvp.first.str()));
 #else
        (void)name;
 #endif
@@ -182,9 +182,9 @@ void Technique::InheritLoader::material(const string &slot, const string &name)
        RenderPass &pass = get_item(obj.passes, slot);
        if(const Material *base_mat = pass.get_material())
        {
-               for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
-                       if(i->second.get_material()==base_mat)
-                               i->second.set_material(&mat);
+               for(auto &kvp: obj.passes)
+                       if(kvp.second.get_material()==base_mat)
+                               kvp.second.set_material(&mat);
        }
        else
                pass.set_material(&mat);
index bfd979aae573c26f5a29330ff2a5a1c86981d1d0..74c37fc8e2ca0e03c24fdd4f691a60f96abeb640 100644 (file)
@@ -49,18 +49,14 @@ private:
                void uniforms();
        };
 
-public:
-       typedef std::map<Tag, RenderPass> PassMap;
-
-private:
-       PassMap passes;
+       std::map<Tag, RenderPass> passes;
 
 public:
        RenderPass &add_pass(Tag);
        bool has_pass(Tag) const;
        const RenderPass &get_pass(Tag) const;
        const RenderPass *find_pass(Tag) const;
-       const PassMap &get_passes() const { return passes; }
+       const std::map<Tag, RenderPass> &get_passes() const { return passes; }
        bool replace_texture(const std::string &, const Texture &);
        bool replace_material(const std::string &, const Material &);
        bool replace_uniforms(const ProgramData &);
index 293fa6cdad8e1ee55384df261a50f22b58997a25..a53a988105d410a3fd3d58be119876b43a58f040 100644 (file)
@@ -28,10 +28,9 @@ InstanceArray::InstanceArray(const Object &o):
        matrix_offset(0)
 {
        const Technique *tech = object.get_technique();
-       const Technique::PassMap &passes = tech->get_passes();
-       for(Technique::PassMap::const_iterator i=passes.begin(); i!=passes.end(); ++i)
+       for(const auto &kvp: tech->get_passes())
        {
-               const Program *shprog = i->second.get_shader_program();
+               const Program *shprog = kvp.second.get_shader_program();
                if(!shprog)
                        throw invalid_argument("InstanceArray::InstanceArray");
 
@@ -65,8 +64,8 @@ InstanceArray::InstanceArray(const Object &o):
 
 InstanceArray::~InstanceArray()
 {
-       for(vector<ObjectInstance *>::iterator i=instances.begin(); i!=instances.end(); ++i)
-               delete *i;
+       for(ObjectInstance *i: instances)
+               delete i;
        delete vtx_setup;
        delete instance_data;
        delete instance_buffer;
@@ -94,7 +93,7 @@ void InstanceArray::append(ObjectInstance *inst)
 
 void InstanceArray::remove(ObjectInstance &inst)
 {
-       vector<ObjectInstance *>::iterator i = find(instances, &inst);
+       auto i = find(instances, &inst);
        if(i==instances.end())
                throw key_error(&inst);
 
@@ -141,12 +140,12 @@ void InstanceArray::render(Renderer &renderer, Tag tag) const
        }
        else
        {
-               for(vector<ObjectInstance *>::const_iterator i=instances.begin(); i!=instances.end(); ++i)
+               for(ObjectInstance *i: instances)
                {
-                       const Matrix &m = *(*i)->get_matrix();
+                       const Matrix &m = *i->get_matrix();
                        for(unsigned j=0; j<3; ++j)
                                glVertexAttrib4f(matrix_location+j, m(j, 0), m(j, 1), m(j, 2), m(j, 3));
-                       (*i)->render(renderer, tag);
+                       i->render(renderer, tag);
                }
        }
 }
index 067686d205cee62f8b117ce429c75f58c2e1b21a..8a3963eebe992f9db802184b5f20b9d86b461ab7 100644 (file)
@@ -76,12 +76,12 @@ void Object::set_mesh(unsigned i, const Mesh *m)
 void Object::update_bounding_sphere()
 {
        vector<Vector3> points;
-       for(vector<LevelOfDetail>::const_iterator i=lods.begin(); i!=lods.end(); ++i)
+       for(const LevelOfDetail &l: lods)
        {
-               if(!i->mesh || !i->mesh->is_loaded())
+               if(!l.mesh || !l.mesh->is_loaded())
                        continue;
 
-               const VertexArray &vertices = i->mesh->get_vertices();
+               const VertexArray &vertices = l.mesh->get_vertices();
 
                int offset = vertices.get_format().offset(VERTEX3);
                bool three = true;
index 7c043fa691c5ab578fc7da430244db471632bdc0..23d79df2ab71a8185bd79318cc3194f692a38bbb 100644 (file)
@@ -26,8 +26,8 @@ OccludedScene::~OccludedScene()
 {
        vector<unsigned> queries;
        queries.reserve(occluded_cache.size());
-       for(OccludedArray::iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
-               queries.push_back(i->query);
+       for(OccludedRenderable &o: occluded_cache)
+               queries.push_back(o.query);
        glDeleteQueries(queries.size(), &queries[0]);
 }
 
@@ -58,9 +58,9 @@ void OccludedScene::populate_cache() const
                        occluded_cache[old_size+i].query = new_queries[i];
        }
 
-       OccludedArray::iterator j = occluded_cache.begin();
-       for(RenderableSet::iterator i=renderables.begin(); i!=renderables.end(); ++i, ++j)
-               j->renderable = *i;
+       auto j = occluded_cache.begin();
+       for(Renderable *r: renderables)
+               j++->renderable = r;
        for(; j!=occluded_cache.end(); ++j)
        {
                j->renderable = 0;
@@ -73,14 +73,14 @@ void OccludedScene::populate_cache() const
 void OccludedScene::setup_frame(Renderer &renderer)
 {
        populate_cache();
-       for(OccludedArray::const_iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
-               i->renderable->setup_frame(renderer);
+       for(const OccludedRenderable &o: occluded_cache)
+               o.renderable->setup_frame(renderer);
 }
 
 void OccludedScene::finish_frame()
 {
-       for(OccludedArray::const_iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
-               i->renderable->finish_frame();
+       for(const OccludedRenderable &o: occluded_cache)
+               o.renderable->finish_frame();
 }
 
 void OccludedScene::render(Renderer &renderer, Tag tag) const
@@ -93,8 +93,8 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
        const Camera *camera = renderer.get_camera();
        if(!camera)
        {
-               for(OccludedArray::const_iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
-                       renderer.render(*i->renderable, tag);
+               for(const OccludedRenderable &o: occluded_cache)
+                       renderer.render(*o.renderable, tag);
                return;
        }
 
@@ -105,7 +105,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
 
        // Perform frustum culling and render any major occluders
        bool use_frustum = setup_frustum(renderer);
-       for(OccludedArray::iterator i=occluded_cache.begin(); (i!=occluded_cache.end() && i->renderable); ++i)
+       for(auto i=occluded_cache.begin(); (i!=occluded_cache.end() && i->renderable); ++i)
        {
                i->in_frustum = (!use_frustum || !frustum_cull(*i->renderable));
                if(!i->in_frustum)
@@ -128,7 +128,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
        }
 
        // Move all objects within the frustum to the beginning of the array
-       for(OccludedArray::iterator i=occluded_cache.begin(), j=i+renderables.size()-1; i!=j; )
+       for(auto i=occluded_cache.begin(), j=i+renderables.size()-1; i!=j; )
        {
                if(i->in_frustum)
                        ++i;
@@ -146,7 +146,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
                glDepthMask(false);
 
                // Fire off the occlusion queries
-               for(OccludedArray::const_iterator i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i)
+               for(auto i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i)
                        if(!i->occluder)
                        {
                                glBeginQuery(GL_ANY_SAMPLES_PASSED, i->query);
@@ -163,7 +163,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
        }
 
        // Render anything that has a chance of being visible
-       for(OccludedArray::const_iterator i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i)
+       for(auto i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i)
                if(!i->occluder)
                {
                        unsigned any_passed = 0;
index 9140d13b62624b56ab1ce7e5f022f691df4a2302..056acb2e0d12b2e14f74fcbffcde37cee09f7674 100644 (file)
@@ -31,14 +31,11 @@ private:
                OccludedRenderable();
        };
 
-       typedef std::set<Renderable *> RenderableSet;
-       typedef std::vector<OccludedRenderable> OccludedArray;
-
        const Mesh &bounding_mesh;
        const Program &bounding_shader;
-       RenderableSet renderables;
+       std::set<Renderable *> renderables;
        float occluder_min_size;
-       mutable OccludedArray occluded_cache;
+       mutable std::vector<OccludedRenderable> occluded_cache;
        mutable bool cache_dirty;
 
 public:
index 4386d3e79058f2ac7559f2f30ee1bcc92bce60d4..5912e747df787295bfbf91f83bf86756408f10db 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include "orderedscene.h"
 #include "renderer.h"
 
@@ -12,7 +12,7 @@ void OrderedScene::add(Renderable &r)
 
 void OrderedScene::remove(Renderable &r)
 {
-       RenderableList::iterator end = std::remove(renderables.begin(), renderables.end(), &r);
+       auto end = std::remove(renderables.begin(), renderables.end(), &r);
        renderables.erase(end, renderables.end());
 }
 
@@ -23,42 +23,41 @@ void OrderedScene::prepend(Renderable &r)
 
 void OrderedScene::insert(unsigned index, Renderable &r)
 {
-       RenderableList::iterator i = renderables.begin();
+       auto i = renderables.begin();
        for(; (i!=renderables.end() && index); ++i, --index) ;
        renderables.insert(i, &r);
 }
 
 void OrderedScene::insert_after(Renderable &after, Renderable &r)
 {
-       RenderableList::iterator i = renderables.begin();
-       for(; (i!=renderables.end() && *i!=&after); ++i) ;
+       auto i = find(renderables, &after);
        renderables.insert(i, &r);
 }
 
 void OrderedScene::setup_frame(Renderer &renderer)
 {
-       for(RenderableList::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               (*i)->setup_frame(renderer);
+       for(Renderable *r: renderables)
+               r->setup_frame(renderer);
 }
 
 void OrderedScene::finish_frame()
 {
-       for(RenderableList::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               (*i)->finish_frame();
+       for(Renderable *r: renderables)
+               r->finish_frame();
 }
 
 void OrderedScene::render(Renderer &renderer, Tag tag) const
 {
        if(setup_frustum(renderer))
        {
-               for(RenderableList::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-                       if(!frustum_cull(**i))
-                               renderer.render(**i, tag);
+               for(Renderable *r: renderables)
+                       if(!frustum_cull(*r))
+                               renderer.render(*r, tag);
        }
        else
        {
-               for(RenderableList::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-                       renderer.render(**i, tag);
+               for(Renderable *r: renderables)
+                       renderer.render(*r, tag);
        }
 }
 
index 0ca1c4650697e7a845a7f54e09ebf9648f352ddd..aa43eb73ea83e4dd90595550ab6d7683ffb6e113 100644 (file)
@@ -17,9 +17,7 @@ public:
        using Scene::Loader;
 
 private:
-       typedef std::list<Renderable *> RenderableList;
-
-       RenderableList renderables;
+       std::list<Renderable *> renderables;
 
 public:
        virtual void add(Renderable &);
index 79b559019d116b196502267222e5c37e6985642d..e8e30e6344c8d4ca6c982027bab6f73195376bfd 100644 (file)
@@ -36,8 +36,8 @@ ProgramData::ProgramData(const ProgramData &other):
        buffer(0),
        dirty(0)
 {
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->value = i->value->clone();
+       for(TaggedUniform &u: uniforms)
+               u.value = u.value->clone();
 }
 
 ProgramData::ProgramData(const ProgramData &other, const Program *p):
@@ -48,13 +48,13 @@ ProgramData::ProgramData(const ProgramData &other, const Program *p):
 {
        if(tied_program)
        {
-               for(vector<TaggedUniform>::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i)
-                       validate_tag(i->tag);
+               for(const TaggedUniform &u: other.uniforms)
+                       validate_tag(u.tag);
        }
 
        uniforms = other.uniforms;
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->value = i->value->clone();
+       for(TaggedUniform &u: uniforms)
+               u.value = u.value->clone();
 }
 
 ProgramData &ProgramData::operator=(const ProgramData &other)
@@ -62,11 +62,11 @@ ProgramData &ProgramData::operator=(const ProgramData &other)
        tied_program = other.tied_program;
 
        uniforms = other.uniforms;
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->value = i->value->clone();
+       for(TaggedUniform &u: uniforms)
+               u.value = u.value->clone();
 
-       for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
-               delete i->block;
+       for(SharedBlock &b: blocks)
+               delete b.block;
        programs.clear();
 
        last_buffer_block = 0;
@@ -78,13 +78,13 @@ ProgramData &ProgramData::operator=(const ProgramData &other)
 
 ProgramData::~ProgramData()
 {
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               delete i->value;
-       for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
+       for(TaggedUniform &u: uniforms)
+               delete u.value;
+       for(SharedBlock &b: blocks)
        {
-               if(i->indices.type_flag==0xFE)
-                       delete[] i->indices.dynamic.values;
-               delete i->block;
+               if(b.indices.type_flag==0xFE)
+                       delete[] b.indices.dynamic.values;
+               delete b.block;
        }
        delete buffer;
 }
@@ -181,7 +181,7 @@ void ProgramData::add_uniform(Tag tag, Uniform *uni)
                throw too_many_uniforms(tag.str());
        }
 
-       vector<TaggedUniform>::iterator j = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
+       auto j = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
 
        TaggedUniform nu;
        nu.tag = tag;
@@ -431,7 +431,7 @@ void ProgramData::uniform_matrix4_array(Tag tag, unsigned n, const float *v)
 
 void ProgramData::remove_uniform(Tag tag)
 {
-       vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
+       auto i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
        if(i==uniforms.end() || i->tag!=tag)
                return;
 
@@ -445,8 +445,8 @@ vector<Tag> ProgramData::get_uniform_tags() const
 {
        vector<Tag> tags;
        tags.reserve(uniforms.size());
-       for(vector<TaggedUniform>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               tags.push_back(i->tag);
+       for(const TaggedUniform &u: uniforms)
+               tags.push_back(u.tag);
        return tags;
 }
 
@@ -466,14 +466,14 @@ const Uniform *ProgramData::find_uniform(Tag tag) const
 
 int ProgramData::find_uniform_index(Tag tag) const
 {
-       vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
+       auto i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
        return ((i!=uniforms.end() && i->tag==tag) ? i-uniforms.begin() : -1);
 }
 
 vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Program &prog) const
 {
        Program::LayoutHash prog_hash = prog.get_uniform_layout_hash();
-       vector<ProgramBlock>::iterator i = lower_bound_member(programs, prog_hash, &ProgramBlock::prog_hash);
+       auto i = lower_bound_member(programs, prog_hash, &ProgramBlock::prog_hash);
        if(i!=programs.end() && i->prog_hash==prog_hash)
                return i;
 
@@ -485,8 +485,8 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
        the hashes so they can be matched up later. */
        vector<Program::LayoutHash> block_hashes;
        block_hashes.reserve(programs.size());
-       for(vector<ProgramBlock>::iterator j=programs.begin(); j!=programs.end(); ++j)
-               block_hashes.push_back(j->block_index>=0 ? blocks[j->block_index].block_hash : 0);
+       for(const ProgramBlock &b: programs)
+               block_hashes.push_back(b.block_index>=0 ? blocks[b.block_index].block_hash : 0);
 
        for(unsigned j=0; j<block_infos.size(); ++j)
        {
@@ -494,7 +494,7 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
                block_hashes[index+1+j] = info.layout_hash;
                programs[index+1+j].bind_point = info.bind_point;
 
-               vector<SharedBlock>::iterator k = lower_bound_member(blocks, info.layout_hash, &SharedBlock::block_hash);
+               auto k = lower_bound_member(blocks, info.layout_hash, &SharedBlock::block_hash);
                if(k==blocks.end() || k->block_hash!=info.layout_hash)
                {
                        k = blocks.insert(k, SharedBlock(info.layout_hash));
@@ -508,7 +508,7 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
                unsigned hash = block_hashes[j];
                if(hash)
                {
-                       vector<SharedBlock>::const_iterator k = lower_bound_member(blocks, hash, &SharedBlock::block_hash);
+                       auto k = lower_bound_member(blocks, hash, &SharedBlock::block_hash);
                        programs[j].block_index = k-blocks.begin();
                }
                else
@@ -600,7 +600,7 @@ void ProgramData::update_block(SharedBlock &block, const Program::UniformBlockIn
 vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(const Program &prog) const
 {
        BufferBackedUniformBlock *old_last_block = last_buffer_block;
-       vector<ProgramBlock>::iterator prog_begin = get_program(prog);
+       auto prog_begin = get_program(prog);
 
        Mask force_dirty = (dirty==ALL_ONES ? ALL_ONES : 0U);
        Mask affected = (dirty&prog_begin->masks.used) | force_dirty;
@@ -611,11 +611,11 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
                program will cause this to happen if there's any dirty uniforms. */
                if(affected)
                {
-                       for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
-                               i->dirty |= (dirty&i->used) | force_dirty;
-                       for(vector<ProgramBlock>::iterator i=programs.begin(); i!=programs.end(); ++i)
-                               if(i->block_index<0)
-                                       i->masks.dirty |= (dirty&i->masks.used) | force_dirty;
+                       for(SharedBlock &b: blocks)
+                               b.dirty |= (dirty&b.used) | force_dirty;
+                       for(ProgramBlock &b: programs)
+                               if(b.block_index<0)
+                                       b.masks.dirty |= (dirty&b.masks.used) | force_dirty;
                        dirty = 0;
                }
 
@@ -626,29 +626,31 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
                        /* The set of uniforms has changed since this program was last used.
                        Refresh uniform indices within the program's blocks. */
                        prog_begin->masks.used = 0;
-                       vector<ProgramBlock>::iterator j = prog_begin+1;
-                       for(vector<Program::UniformBlockInfo>::const_iterator i=block_infos.begin(); i!=block_infos.end(); ++i, ++j)
+                       auto j = prog_begin+1;
+                       for(const Program::UniformBlockInfo &b: block_infos)
                        {
                                SharedBlock &shared = blocks[j->block_index];
                                if(shared.dirty==ALL_ONES)
-                                       update_block_uniform_indices(shared, *i);
+                                       update_block_uniform_indices(shared, b);
                                prog_begin->masks.used |= shared.used;
                                j->block = (shared.used ? shared.block : 0);
+                               ++j;
                        }
                }
 
                // Update the contents of all dirty blocks.
                bool buffered_blocks_updated = false;
-               vector<ProgramBlock>::iterator j = prog_begin+1;
-               for(vector<Program::UniformBlockInfo>::const_iterator i=block_infos.begin(); i!=block_infos.end(); ++i, ++j)
+               auto j = prog_begin+1;
+               for(const Program::UniformBlockInfo &b: block_infos)
                {
                        SharedBlock &shared = blocks[j->block_index];
                        if(shared.dirty)
                        {
-                               update_block(shared, *i);
+                               update_block(shared, b);
                                shared.dirty = 0;
                                buffered_blocks_updated |= (j->bind_point>=0);
                        }
+                       ++j;
                }
 
                prog_begin->masks.dirty = 0;
@@ -680,9 +682,9 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
 
 void ProgramData::apply(const Program &prog, PipelineState &state) const
 {
-       vector<ProgramBlock>::const_iterator prog_begin = prepare_program(prog);
+       auto prog_begin = prepare_program(prog);
        Program::LayoutHash prog_hash = prog_begin->prog_hash;
-       for(vector<ProgramBlock>::const_iterator i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i)
+       for(auto i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i)
                if(i->block)
                {
                        if(i->bind_point<0)
index 5610f30a7e4a863c1afb11f043903e0e0314c6d8..6f7e9cba34d3c156a50e255372d0c59d078e8da9 100644 (file)
@@ -89,7 +89,7 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
                        flush_textures();
        }
 
-       for(vector<BoundTexture>::iterator i=texture_stack.end(); i!=texture_stack.begin(); )
+       for(auto i=texture_stack.end(); i!=texture_stack.begin(); )
                if((--i)->tag==tag)
                {
                        i->replaced = texture_stack.size();
@@ -319,15 +319,15 @@ void Renderer::apply_state()
        if(state->texture_count<texture_stack.size())
                flush_textures();
 
-       for(vector<BoundTexture>::const_iterator i=texture_stack.begin(); i!=texture_stack.end(); ++i)
+       for(const BoundTexture &t: texture_stack)
        {
-               int unit = (i->tag.id ? state->shprog->get_uniform_binding(i->tag) : i->unit);
+               int unit = (t.tag.id ? state->shprog->get_uniform_binding(t.tag) : t.unit);
                if(unit>=0)
-                       pipeline_state.set_texture(unit, i->texture, i->sampler);
+                       pipeline_state.set_texture(unit, t.texture, t.sampler);
        }
 
        bool shdata_changed = changed&SHADER_DATA;
-       for(vector<BoundProgramData>::const_iterator i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
+       for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
                shdata_changed = (i->shdata->get_generation()!=i->generation);
        bool extra_shdata = (shdata_stack.size()>state->shdata_count);
 
@@ -335,10 +335,10 @@ void Renderer::apply_state()
        {
                if(extra_shdata)
                        shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end());
-               for(vector<BoundProgramData>::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i)
+               for(const BoundProgramData &d: shdata_stack)
                {
-                       i->shdata->apply(*state->shprog, pipeline_state);
-                       i->generation = i->shdata->get_generation();
+                       d.shdata->apply(*state->shprog, pipeline_state);
+                       d.generation = d.shdata->get_generation();
                }
                changed &= ~SHADER_DATA;
        }
index 6a1142857492dce2fc1558f43c017eed6b003015..b144580ca50a5aa04c35b35e266c958e63d69ae1 100644 (file)
@@ -41,8 +41,8 @@ RenderTarget::RenderTarget(unsigned w, unsigned h, const FrameFormat &f):
 
 RenderTarget::~RenderTarget()
 {
-       for(vector<Texture *>::iterator i=textures.begin(); i!=textures.end(); ++i)
-               delete *i;
+       for(Texture *t: textures)
+               delete t;
 }
 
 const Texture2D &RenderTarget::get_target_texture(unsigned i) const
index 3460bc724c30905a05759a3f51046bac720eb306..e953b4d6925944b10d872301ef35667a7904f857 100644 (file)
@@ -57,9 +57,9 @@ void Sequence::init(unsigned w, unsigned h, const FrameFormat &f)
 
 Sequence::~Sequence()
 {
-       for(vector<PostProcStep>::iterator i=postproc.begin(); i!=postproc.end(); ++i)
-               if(i->owned)
-                       delete i->postproc;
+       for(PostProcStep &p: postproc)
+               if(p.owned)
+                       delete p.postproc;
        delete target[0];
        delete target[1];
        delete target_ms;
@@ -94,15 +94,15 @@ void Sequence::add_postprocessor(PostProcessor *pp, bool owned)
 
 void Sequence::setup_frame(Renderer &renderer)
 {
-       for(vector<Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
-               if(Renderable *renderable = i->get_renderable())
+       for(const Step &s: steps)
+               if(Renderable *renderable = s.get_renderable())
                        renderable->setup_frame(renderer);
 }
 
 void Sequence::finish_frame()
 {
-       for(vector<Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
-               if(Renderable *renderable = i->get_renderable())
+       for(const Step &s: steps)
+               if(Renderable *renderable = s.get_renderable())
                        renderable->finish_frame();
 }
 
@@ -121,20 +121,20 @@ void Sequence::render(Renderer &renderer, Tag tag) const
                renderer.clear();
        }
 
-       for(vector<Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
+       for(const Step &s: steps)
        {
                Renderer::Push _push2(renderer);
 
-               renderer.set_depth_test(&i->get_depth_test());
-               renderer.set_stencil_test(&i->get_stencil_test());
-               renderer.set_blend(&i->get_blend());
+               renderer.set_depth_test(&s.get_depth_test());
+               renderer.set_stencil_test(&s.get_stencil_test());
+               renderer.set_blend(&s.get_blend());
 
-               if (const Lighting *lighting = i->get_lighting())
+               if (const Lighting *lighting = s.get_lighting())
                        renderer.add_shader_data(lighting->get_shader_data());
-               renderer.set_clipping(i->get_clipping());
+               renderer.set_clipping(s.get_clipping());
 
-               if(const Renderable *renderable = i->get_renderable())
-                       renderer.render(*renderable, i->get_tag());
+               if(const Renderable *renderable = s.get_renderable())
+                       renderer.render(*renderable, s.get_tag());
        }
 
        if(target[0])
index af2b366fa61c55c2bcb0852f2185f8441a4d6ddc..bcc4af21dc1779f086348c1b054883733cf01425 100644 (file)
@@ -29,14 +29,14 @@ void SimpleScene::populate_cache() const
 void SimpleScene::setup_frame(Renderer &renderer)
 {
        populate_cache();
-       for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
-               (*i)->setup_frame(renderer);
+       for(Renderable *r: cache)
+               r->setup_frame(renderer);
 }
 
 void SimpleScene::finish_frame()
 {
-       for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
-               (*i)->finish_frame();
+       for(Renderable *r: cache)
+               r->finish_frame();
 }
 
 void SimpleScene::render(Renderer &renderer, Tag tag) const
@@ -44,14 +44,14 @@ void SimpleScene::render(Renderer &renderer, Tag tag) const
        populate_cache();
        if(setup_frustum(renderer))
        {
-               for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
-                       if(!frustum_cull(**i))
-                               renderer.render(**i, tag);
+               for(Renderable *r: cache)
+                       if(!frustum_cull(*r))
+                               renderer.render(*r, tag);
        }
        else
        {
-               for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
-                       renderer.render(**i, tag);
+               for(Renderable *r: cache)
+                       renderer.render(*r, tag);
        }
 }
 
index 2fb89a315113198160340b66139481f9d555aa28..1e90874b9e1ab6fa682ab385a48e4a37e629e9b1 100644 (file)
@@ -16,11 +16,8 @@ public:
        using Scene::Loader;
 
 private:
-       typedef std::set<Renderable *> RenderableSet;
-       typedef std::vector<Renderable *> RenderableArray;
-
-       RenderableSet renderables;
-       mutable RenderableArray cache;
+       std::set<Renderable *> renderables;
+       mutable std::vector<Renderable *> cache;
 
 public:
        virtual void add(Renderable &);
index 2e57afd57cb04dd36b9fa2e9b466993d571546a5..7b64fb2b478387b448eac09acd32e9e418af31f2 100644 (file)
@@ -46,14 +46,14 @@ void ZSortedScene::populate_cache() const
 void ZSortedScene::setup_frame(Renderer &renderer)
 {
        populate_cache();
-       for(SortedArray::const_iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
-               i->renderable->setup_frame(renderer);
+       for(const SortedRenderable &r: sorted_cache)
+               r.renderable->setup_frame(renderer);
 }
 
 void ZSortedScene::finish_frame()
 {
-       for(SortedArray::const_iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
-               i->renderable->finish_frame();
+       for(const SortedRenderable &r: sorted_cache)
+               r.renderable->finish_frame();
 }
 
 void ZSortedScene::render(Renderer &renderer, Tag tag) const
@@ -66,8 +66,8 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const
        const Camera *camera = renderer.get_camera();
        if(!camera)
        {
-               for(SortedArray::const_iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
-                       renderer.render(*i->renderable, tag);
+               for(const SortedRenderable &r: sorted_cache)
+                       renderer.render(*r.renderable, tag);
                return;
        }
 
@@ -77,25 +77,25 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const
        float sign = 1.0f-order*2.0f;
 
        bool use_frustum = setup_frustum(renderer);
-       for(SortedArray::iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
+       for(SortedRenderable &r: sorted_cache)
        {
-               i->in_frustum = (!use_frustum || !frustum_cull(*i->renderable));
-               if(!i->in_frustum)
+               r.in_frustum = (!use_frustum || !frustum_cull(*r.renderable));
+               if(!r.in_frustum)
                        continue;
 
-               if(const Matrix *matrix = i->renderable->get_matrix())
+               if(const Matrix *matrix = r.renderable->get_matrix())
                {
-                       if(const Geometry::BoundingSphere<float, 3> *bsphere = i->renderable->get_bounding_sphere())
-                               i->depth = dot(*matrix*bsphere->get_center()-camera_pos, look_dir)+bsphere->get_radius()*radius_factor;
+                       if(const Geometry::BoundingSphere<float, 3> *bsphere = r.renderable->get_bounding_sphere())
+                               r.depth = dot(*matrix*bsphere->get_center()-camera_pos, look_dir)+bsphere->get_radius()*radius_factor;
                        else
-                               i->depth = dot(*matrix*Vector3()-camera_pos, look_dir);
-                       i->depth *= sign;
+                               r.depth = dot(*matrix*Vector3()-camera_pos, look_dir);
+                       r.depth *= sign;
                }
                else
-                       i->depth = 0;
+                       r.depth = 0;
        }
 
-       for(SortedArray::iterator i=sorted_cache.begin(), j=i; i!=sorted_cache.end(); ++i)
+       for(auto i=sorted_cache.begin(), j=i; i!=sorted_cache.end(); ++i)
                if(i->in_frustum)
                {
                        if(i!=j)
@@ -104,7 +104,7 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const
                        if(j!=sorted_cache.begin() && *j<*(j-1))
                        {
                                SortedRenderable sr = *j;
-                               SortedArray::iterator k = j-1;
+                               auto k = j-1;
                                *j = *k;
                                while(k!=sorted_cache.begin() && sr<*(k-1))
                                {
@@ -117,7 +117,7 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const
                        ++j;
                }
 
-       for(SortedArray::const_iterator i=sorted_cache.begin(); (i!=sorted_cache.end() && i->in_frustum); ++i)
+       for(auto i=sorted_cache.begin(); (i!=sorted_cache.end() && i->in_frustum); ++i)
                renderer.render(*i->renderable, tag);
 }
 
index 319cd8c35dfe2b17e93a84b836def3a23427409b..9653567c107be6d88b50a096d5a7b825b1b739fc 100644 (file)
@@ -42,13 +42,10 @@ private:
                bool operator<(const SortedRenderable &o) const { return depth<o.depth; }
        };
 
-       typedef std::set<Renderable *> RenderableSet;
-       typedef std::vector<SortedRenderable> SortedArray;
-
-       RenderableSet renderables;
+       std::set<Renderable *> renderables;
        SortOrder order;
        DepthReference reference;
-       mutable SortedArray sorted_cache;
+       mutable std::vector<SortedRenderable> sorted_cache;
 
 public:
        ZSortedScene();
index 30f75013252fe2397819cb5cb5a49330e54347de..4bac0aec841aa1552f3062a42a93f57ea2b7fb31 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include <typeinfo>
 #include <msp/debug/demangle.h>
 #include <msp/strings/format.h>
@@ -118,8 +118,7 @@ void ResourceManager::load_resource(Resource &r)
        if(async_loads)
        {
                managed.state = ManagedResource::LOAD_QUEUED;
-               LoadQueue::iterator i;
-               for(i=queue.begin(); (i!=queue.end() && (*i)->load_priority>=managed.load_priority); ++i) ;
+               auto i = find_if(queue, [&managed](ManagedResource *q){ return q->load_priority>managed.load_priority; });
                queue.insert(i, &managed);
        }
        else
@@ -156,15 +155,15 @@ void ResourceManager::remove_resource(Resource &r)
        ManagedResource::State state = managed.state;
        if(state==ManagedResource::LOAD_QUEUED)
        {
-               LoadQueue::iterator i = find(queue.begin(), queue.end(), &managed);
+               auto i = find(queue, &managed);
                if(i!=queue.end())
                        queue.erase(i);
        }
        else if(state>ManagedResource::LOAD_QUEUED && state<ManagedResource::LOADED)
                thread.remove_resource(managed);
 
-       for(vector<ResourceObserver *>::const_iterator i=managed.observers.begin(); i!=managed.observers.end(); ++i)
-               (*i)->resource_removed(r);
+       for(ResourceObserver *o: managed.observers)
+               o->resource_removed(r);
 
        MutexLock lock(map_mutex);
        remove_existing(resources, &r);
@@ -202,9 +201,9 @@ void ResourceManager::tick()
                        unload_by_age();
 
                        next_unload = frame;
-                       for(ResourceMap::iterator i=resources.begin(); i!=resources.end(); ++i)
-                               if(i->second.state==ManagedResource::LOADED)
-                                       next_unload = min(next_unload, i->second.last_used);
+                       for(const auto &kvp: resources)
+                               if(kvp.second.state==ManagedResource::LOADED)
+                                       next_unload = min(next_unload, kvp.second.last_used);
                        next_unload = (next_unload<frame ? next_unload+max_retain_frames : 0);
                }
 
@@ -219,8 +218,8 @@ void ResourceManager::dispatch_work()
 
        if(queue.front()->last_used+min_retain_frames<frame)
        {
-               for(LoadQueue::iterator i=queue.begin(); i!=queue.end(); ++i)
-                       (*i)->state = ManagedResource::NOT_LOADED;
+               for(ManagedResource *r: queue)
+                       r->state = ManagedResource::NOT_LOADED;
                queue.clear();
                return;
        }
@@ -237,11 +236,11 @@ void ResourceManager::unload_by_age()
 {
        unsigned unload_limit = frame-max_retain_frames;
 
-       for(ResourceMap::iterator i=resources.begin(); i!=resources.end(); ++i)
-               if(i->second.state==ManagedResource::LOADED && i->second.last_used<unload_limit)
+       for(auto &kvp: resources)
+               if(kvp.second.state==ManagedResource::LOADED && kvp.second.last_used<unload_limit)
                {
-                       i->second.unload();
-                       total_data_size -= i->second.data_size;
+                       kvp.second.unload();
+                       total_data_size -= kvp.second.data_size;
                }
 }
 
@@ -253,13 +252,13 @@ void ResourceManager::unload_by_size()
        {
                ManagedResource *best = 0;
                UInt64 best_impact = 0;
-               for(ResourceMap::iterator i=resources.begin(); i!=resources.end(); ++i)
-                       if(i->second.state==ManagedResource::LOADED && i->second.last_used<unload_limit)
+               for(auto &kvp: resources)
+                       if(kvp.second.state==ManagedResource::LOADED && kvp.second.last_used<unload_limit)
                        {
-                               UInt64 impact = i->second.data_size*(frame-i->second.last_used);
+                               UInt64 impact = kvp.second.data_size*(frame-kvp.second.last_used);
                                if(!best || impact>best_impact)
                                {
-                                       best = &i->second;
+                                       best = &kvp.second;
                                        best_impact = impact;
                                }
                        }
@@ -336,8 +335,8 @@ void ResourceManager::ManagedResource::finish_loading(bool successful)
                state = LOADED;
                data_size = resource->get_data_size();
 
-               for(vector<ResourceObserver *>::const_iterator i=observers.begin(); i!=observers.end(); ++i)
-                       (*i)->resource_loaded(*resource);
+               for(ResourceObserver *o: observers)
+                       o->resource_loaded(*resource);
        }
        else
        {
@@ -356,8 +355,8 @@ void ResourceManager::ManagedResource::unload()
        resource->unload();
        state = NOT_LOADED;
 
-       for(vector<ResourceObserver *>::const_iterator i=observers.begin(); i!=observers.end(); ++i)
-               (*i)->resource_unloaded(*resource);
+       for(ResourceObserver *o: observers)
+               o->resource_unloaded(*resource);
 }
 
 void ResourceManager::ManagedResource::add_observer(ResourceObserver &w)
@@ -368,7 +367,7 @@ void ResourceManager::ManagedResource::add_observer(ResourceObserver &w)
 
 void ResourceManager::ManagedResource::remove_observer(ResourceObserver &w)
 {
-       vector<ResourceObserver *>::iterator end = remove(observers.begin(), observers.end(), &w);
+       auto end = remove(observers.begin(), observers.end(), &w);
        if(end!=observers.end())
                observers.erase(end, observers.end());
 }
@@ -415,7 +414,7 @@ void ResourceManager::LoadingThread::main()
        }
 }
 
-ResourceManager::ManagedResource *ResourceManager::LoadingThread::front(LoadQueue &que)
+ResourceManager::ManagedResource *ResourceManager::LoadingThread::front(list<ManagedResource *> &que)
 {
        MutexLock lock(queue_mutex);
        if(que.empty())
@@ -459,10 +458,10 @@ bool ResourceManager::LoadingThread::try_remove_resource(ManagedResource &r)
 {
        MutexLock lock(queue_mutex);
 
-       LoadQueue::iterator i = find(async_queue.begin(), async_queue.end(), &r);
+       auto i = find(async_queue, &r);
        if(i==async_queue.end())
        {
-               i = find(sync_queue.begin(), sync_queue.end(), &r);
+               i = find(sync_queue, &r);
                if(i!=sync_queue.end())
                {
                        sync_queue.erase(i);
index ba4f39a9461668cbe4912a9f2d8afe5a8ee38e97..2596999750724f32c239da69c4f261bc6ae324a3 100644 (file)
@@ -76,15 +76,13 @@ private:
                void remove_observer(ResourceObserver &);
        };
 
-       typedef std::list<ManagedResource *> LoadQueue;
-
        class LoadingThread: public Thread
        {
        private:
                Semaphore sem;
                Mutex queue_mutex;
-               LoadQueue async_queue;
-               LoadQueue sync_queue;
+               std::list<ManagedResource *> async_queue;
+               std::list<ManagedResource *> sync_queue;
                unsigned capacity;
                unsigned size;
                std::list<resource_load_error> error_queue;
@@ -98,7 +96,7 @@ private:
        private:
                virtual void main();
 
-               ManagedResource *front(LoadQueue &);
+               ManagedResource *front(std::list<ManagedResource *> &);
 
        public:
                void add_resource(ManagedResource &);
@@ -113,13 +111,11 @@ private:
                void terminate();
        };
 
-       typedef std::map<const Resource *, ManagedResource> ResourceMap;
-
        LoadingPolicy policy;
        bool async_loads;
        mutable Mutex map_mutex;
-       ResourceMap resources;
-       LoadQueue queue;
+       std::map<const Resource *, ManagedResource> resources;
+       std::list<ManagedResource *> queue;
        UInt64 total_data_size;
        UInt64 size_limit;
        unsigned frame;
index 35bbc8bcfb82449e1261d8d1ce542df069b86833..dbac0f516a02d7334feb37fb0dc03d97bd734947 100644 (file)
@@ -80,8 +80,8 @@ using namespace Msp;
 
 void GlslCompilerHelper::load_all_test_cases(const FS::Path &tests_dir)
 {
-       list<string> test_files = FS::list_filtered(tests_dir, "\\.glsl$");
-       test_files.sort();
+       vector<string> test_files = FS::list_filtered(tests_dir, "\\.glsl$");
+       sort(test_files);
        for(const auto &fn: test_files)
                load_test_case((tests_dir/fn).str());
 }