Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / XML_Utils / XSCRT / Traversal.hpp
bloba40cf5f59071f4fc1055d4804a5510aca923f40a
1 // file : XSCRT/Traversal.hpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #ifndef XSCRT_TRAVERSAL_HPP
4 #define XSCRT_TRAVERSAL_HPP
6 #include <map>
7 #include <set>
8 #include <vector>
10 #include "ace/XML_Utils/XSCRT/ExtendedTypeInfo.hpp"
12 namespace XSCRT
14 namespace Traversal
16 template<typename B>
17 class TraverserBase
19 protected:
20 virtual ~TraverserBase () = default;
22 //@@ VC6
23 public:
24 virtual void trampoline (B& n) = 0;
26 virtual void trampoline (B const& n) = 0;
29 template <typename B>
30 class DispatcherBase
32 public:
33 virtual ~DispatcherBase () = default;
35 virtual void dispatch (B& n);
37 virtual void dispatch (B const& n);
39 void
40 map (TypeId id, TraverserBase<B>& t)
42 //@@ VC6
43 Traversers& traversers = traversal_map_[id];
44 traversers.push_back (&t);
47 public:
48 typedef std::vector<TraverserBase<B>*> Traversers;
49 typedef std::map<TypeId, Traversers> TraversalMap;
50 typedef typename TraversalMap::const_iterator Iterator;
52 Iterator
53 begin () const
55 return traversal_map_.begin ();
58 Iterator
59 end () const
61 return traversal_map_.end ();
64 private:
65 struct TypeInfoComparator
67 bool
68 operator () (ExtendedTypeInfo const& x,
69 ExtendedTypeInfo const& y) const
71 return x.type_id () < y.type_id ();
75 typedef std::map<ExtendedTypeInfo, unsigned long, TypeInfoComparator> LevelMap;
76 typedef std::set<ExtendedTypeInfo, TypeInfoComparator> TypeInfoSet;
78 static unsigned long
79 compute_levels (ExtendedTypeInfo const& ti,
80 unsigned long cur,
81 LevelMap& map);
83 static void
84 flatten_tree (ExtendedTypeInfo const& ti, TypeInfoSet& set);
86 private:
87 TraversalMap traversal_map_;
90 template <typename B>
91 class Dispatcher : public virtual DispatcherBase<B>
93 public:
94 Dispatcher ()
95 : merge_ (true)
99 void
100 traverser (DispatcherBase<B>& d)
102 for (typename DispatcherBase<B>::Iterator
103 i (d.begin ()), end (d.end ());
104 i != end; ++i)
106 for (typename DispatcherBase<B>::Traversers::const_iterator
107 t (i->second.begin ()), end (i->second.end ());
108 t != end; ++t)
110 dispatcher_.map (i->first, **t);
115 public:
116 virtual void
117 dispatch (B& n)
119 merge ();
120 dispatcher_.dispatch (n);
123 virtual void
124 dispatch (B const& n)
126 merge ();
127 dispatcher_.dispatch (n);
130 using DispatcherBase<B>::begin;
131 using DispatcherBase<B>::end;
133 private:
134 void
135 merge ()
137 if (merge_)
139 for (typename DispatcherBase<B>::Iterator
140 i (begin ()), e (end ()); i != e; ++i)
142 for (typename DispatcherBase<B>::Traversers::const_iterator
143 t (i->second.begin ()), e (i->second.end ()); t != e; ++t)
145 dispatcher_.map (i->first, **t);
149 merge_ = false;
153 protected:
154 template <typename X, typename A, typename I>
155 void
156 iterate_and_dispatch (I begin, I end, X& x, void (X::*next)(A&), A& a)
158 for (; begin != end;)
160 dispatch (*begin);
162 if (++begin != end) (x.*next) (a);
166 private:
167 bool merge_;
168 DispatcherBase<B> dispatcher_;
171 template <typename T, typename B>
172 struct Traverser : TraverserBase<B>, virtual Dispatcher<B>
174 typedef T Type;
176 Traverser ()
178 DispatcherBase<B>::map (typeid (Type), *this);
181 virtual void
182 traverse (Type&)
184 abort ();
187 virtual void
188 traverse (Type const&)
190 abort ();
193 protected:
194 virtual void
195 trampoline (B& n)
197 traverse (dynamic_cast<Type&> (n));
200 virtual void
201 trampoline (B const& n)
203 traverse (dynamic_cast<Type const&> (n));
209 #include <ace/XML_Utils/XSCRT/Traversal.tpp>
211 #endif // XSCRT_TRAVERSAL_HPP