Small reoraganization, cleaning 'use namespace' usages
diff --git a/examples/trie.cc b/examples/trie.cc
index fb10fc4..bdbc328 100644
--- a/examples/trie.cc
+++ b/examples/trie.cc
@@ -24,20 +24,11 @@
#include "../utils/lru-policy.h"
#include "../utils/random-policy.h"
#include "../utils/fifo-policy.h"
-#include <boost/intrusive/parent_from_member.hpp>
-#include <boost/mpl/vector.hpp>
-#include <boost/mpl/inherit.hpp>
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits.hpp>
-#include <boost/mpl/inherit_linearly.hpp>
-#include <boost/mpl/range_c.hpp>
-#include <boost/mpl/copy.hpp>
-#include <boost/mpl/vector_c.hpp>
-#include <boost/mpl/clear.hpp>
-#include <boost/mpl/sequence_tag.hpp>
+#include "../utils/multi-policy.h"
using namespace ns3;
-namespace mpl = boost::mpl;
+using namespace ndnSIM;
+using namespace boost;
NS_LOG_COMPONENT_DEFINE ("Trie");
@@ -58,366 +49,22 @@
return os;
}
-template <class T>
-struct wrap
-{
- T value_;
-};
-
-template< class Vector >
-struct multi_type_container
- : public mpl::inherit_linearly< Vector, mpl::inherit<wrap<mpl::_2>, mpl::_1 >
- >::type
-{
- template<int N>
- struct index
- {
- typedef typename mpl::at_c<Vector, N>::type type;
- };
-
- template<class T>
- T &
- get ()
- {
- return static_cast< wrap<T> &> (*this).value_;
- }
-
- template<class T>
- const T &
- get () const
- {
- return static_cast< const wrap<T> &> (*this).value_;
- }
-
- template<int N>
- typename mpl::at_c<Vector, N>::type &
- get ()
- {
- typedef typename mpl::at_c<Vector, N>::type T;
- return static_cast< wrap<T> &> (*this).value_;
- }
-
- template<int N>
- const typename mpl::at_c<Vector, N>::type &
- get () const
- {
- typedef typename mpl::at_c<Vector, N>::type T;
- return static_cast< const wrap<T> &> (*this).value_;
- }
-};
-
-///////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////
-
-template< class Base, class Value >
-struct policy_wrap
-{
- typedef Value value_type;
-
- policy_wrap (Base &base)
- : value_ (base)
- { }
-
- Value value_;
-};
-
-template< class Base, class Super/*empy_wrap/previous level*/, class Value/*policy_wrap< element in vector >*/ >
-struct inherit_with_base : Super, Value
-{
- inherit_with_base (Base &base)
- : Super (base), Value (base)
- { }
-
- void
- update (typename Base::iterator item)
- {
- Value::value_.update (item);
- Super::update (item);
- }
-
- bool
- insert (typename Base::iterator item)
- {
- // BOOST_MPL_ASSERT ((boost::is_same<Item,typename Base::iterator>));
- bool ok = Value::value_.insert (item);
- if (!ok)
- return false;
-
- ok = Super::insert (item);
- if (!ok)
- {
- Value::value_.erase (item);
- return false;
- }
- return true;
- }
-
- void
- lookup (typename Base::iterator item)
- {
- Value::value_.lookup (item);
- Super::lookup (item);
- }
-
- void
- erase (typename Base::iterator item)
- {
- Value::value_.erase (item);
- Super::erase (item);
- }
-};
-
-template< class Base >
-struct empty_policy_wrap
-{
- empty_policy_wrap (Base &base) { }
-
- void update (typename Base::iterator item) {}
- bool insert (typename Base::iterator item) { return true; }
- void lookup (typename Base::iterator item) {}
- void erase (typename Base::iterator item) {}
-};
-
-template< class Base, class Vector >
-struct multi_policy_container
- : public mpl::fold< Vector,
- empty_policy_wrap<Base>,
- inherit_with_base<Base,
- mpl::_1/*empty/previous*/,
- policy_wrap<Base, mpl::_2>/*element in vector*/>
- >::type
-{
- typedef typename mpl::fold< Vector,
- empty_policy_wrap<Base>,
- inherit_with_base<Base,
- mpl::_1/*empty/previous*/,
- policy_wrap<Base, mpl::_2>/*element in vector*/>
- >::type super;
-
- multi_policy_container (Base &base)
- : super (base)
- { }
-
- template<int N>
- struct index
- {
- typedef typename mpl::at_c<Vector, N>::type type;
- };
-
- template<class T>
- T &
- get ()
- {
- return static_cast< policy_wrap<Base, T> &> (*this).value_;
- }
-
- template<class T>
- const T &
- get () const
- {
- return static_cast< const policy_wrap<Base, T> &> (*this).value_;
- }
-
- template<int N>
- typename mpl::at_c<Vector, N>::type &
- get ()
- {
- typedef typename mpl::at_c<Vector, N>::type T;
- return static_cast< policy_wrap<Base, T> &> (*this).value_;
- }
-
- template<int N>
- const typename mpl::at_c<Vector, N>::type &
- get () const
- {
- typedef typename mpl::at_c<Vector, N>::type T;
- return static_cast< const policy_wrap<Base, T> &> (*this).value_;
- }
-};
-
-
-template<class BaseHook, class ValueType, int N>
-struct FunctorHook
-{
- typedef typename BaseHook::template index<N>::type hook_type;
- typedef hook_type* hook_ptr;
- typedef const hook_type* const_hook_ptr;
-
- typedef ValueType value_type;
- typedef value_type* pointer;
- typedef const value_type* const_pointer;
-
- //Required static functions
- static hook_ptr to_hook_ptr (value_type &value)
- { return &value.policy_hook_.template get<N> (); }
-
- static const_hook_ptr to_hook_ptr(const value_type &value)
- { return &value.policy_hook_.template get<N> (); }
-
- static pointer to_value_ptr(hook_ptr n)
- {
- return
- bi::get_parent_from_member<value_type>
- (static_cast<BaseHook*> (bi::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
- &value_type::policy_hook_);
- }
- static const_pointer to_value_ptr(const_hook_ptr n)
- {
- return
- bi::get_parent_from_member<value_type>
- (static_cast<const BaseHook*> (bi::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
- &value_type::policy_hook_);
- }
-};
-
-template<typename Policies> // e.g., mpl::vector1< lru_policy_traits >
-struct multi_policy_traits
-{
- typedef Policies policy_traits;
-
- struct getHook
- {
- template<class Item>
- struct apply
- {
- typedef typename Item::policy_hook_type type;
- };
- };
-
- typedef multi_type_container< typename mpl::transform1<policy_traits, getHook>::type > policy_hook_type;
- typedef mpl::range_c<int, 0, mpl::size<policy_traits>::type::value> policies_range;
-
- template<class Container>
- struct container_hook
- {
- typedef void type;
- // struct getFunctionHook
- // {
- // template<class Number>
- // struct apply
- // {
- // // typedef void type;
- // typedef bi::function_hook< FunctorHook <policy_hook_type,
- // Container,
- // Number::value> > type;
- // };
- // };
-
- // struct type
- // {
- // typedef
- // typename mpl::transform1<policies_range,
- // getFunctionHook,
- // mpl::back_inserter< mpl::vector0<> > >::type hooks;
- // };
- };
-
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- // 1 hooks
- // 2 actual policies
-
- // struct getPolicy
- // {
- // template<class Item>
- // struct apply
- // {
- // typedef typename Item::template policy<Base,
- // Container,
- // typename mpl::at_c<typename Hook::hooks,0>::type >::type type;
- // };
- // };
-
- // typedef typename mpl::transform1<policy_traits, getPolicy>::type policies;
-
- struct getPolicy
- {
- template<class Number>
- struct apply
- {
- typedef
- typename mpl::at_c<policy_traits, Number::value>::type::
- template policy<Base,
- Container,
- bi::function_hook< FunctorHook <policy_hook_type,
- Container,
- Number::value> > >::type
- type;
- };
- };
-
- typedef
- typename mpl::transform1<policies_range,
- getPolicy,
- mpl::back_inserter< mpl::vector0<> > >::type policies;
-
-
- typedef multi_policy_container< Base, policies > policy_container;
-
- class type : public policy_container
- {
- public:
- typedef Container parent_trie;
-
- type (Base &base)
- : policy_container (base)
- {
- }
-
- inline void
- update (typename parent_trie::iterator item)
- {
- policy_container::update (item);
- }
-
- inline bool
- insert (typename parent_trie::iterator item)
- {
- return policy_container::insert (item);
- }
-
- inline void
- lookup (typename parent_trie::iterator item)
- {
- policy_container::lookup (item);
- }
-
- inline void
- erase (typename parent_trie::iterator item)
- {
- policy_container::erase (item);
- }
- };
- };
-};
-
-
int
main (int argc, char *argv[])
{
CommandLine args;
args.Parse (argc, argv);
- // typedef multi_policy_traits<lru_policy_traits> traits;
- // // traits::policy<traits::hook>
- // traits::policy<Bla1,Bla2, traits::container_hook<Bla2>::type> x;
-
typedef trie_with_policy<
ns3::CcnxNameComponents,
smart_pointer_payload_traits<Integer>,
multi_policy_traits<
- mpl::vector2<lru_policy_traits,fifo_policy_traits>
- // mpl::vector1<lru_policy_traits>
+ mpl::vector2<lru_policy_traits,random_policy_traits>
> > trie;
- // // multi_policy_traits<lru_policy_traits, random_policy_traits> > trie;
trie x;
- x.getPolicy ().get<0> ().set_max_size (3);
- x.getPolicy ().get<1> ().set_max_size (100);
+ x.getPolicy ().get<0> ().set_max_size (100);
+ x.getPolicy ().get<1> ().set_max_size (3);
// // x.getPolicy ().get<1> ().set_max_size (3);
// // // x.getPolicy ().get1 ().set_max_size (10);
// // // x.getPolicy ().get2 ().set_max_size (3);