Small reoraganization, cleaning 'use namespace' usages
diff --git a/utils/detail/functor-hook.h b/utils/detail/functor-hook.h
new file mode 100644
index 0000000..94b8b8f
--- /dev/null
+++ b/utils/detail/functor-hook.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef FUNCTOR_HOOK_H_
+#define FUNCTOR_HOOK_H_
+
+#include <boost/intrusive/parent_from_member.hpp>
+
+namespace ndnSIM
+{
+namespace detail
+{
+
+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
+ boost::intrusive::get_parent_from_member<value_type>
+ (static_cast<BaseHook*> (boost::intrusive::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
+ boost::intrusive::get_parent_from_member<value_type>
+ (static_cast<const BaseHook*> (boost::intrusive::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
+ &value_type::policy_hook_);
+ }
+};
+
+} // detail
+} // ndnSIM
+
+#endif // FUNCTOR_HOOK_H_
diff --git a/utils/detail/multi-policy-container.h b/utils/detail/multi-policy-container.h
new file mode 100644
index 0000000..9fcc061
--- /dev/null
+++ b/utils/detail/multi-policy-container.h
@@ -0,0 +1,154 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef MULTI_POLICY_CONTAINER_H_
+#define MULTI_POLICY_CONTAINER_H_
+
+#include <boost/mpl/inherit_linearly.hpp>
+#include <boost/mpl/at.hpp>
+
+namespace ndnSIM
+{
+namespace detail
+{
+
+template< class Base, class Value >
+struct policy_wrap
+{
+ 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)
+ {
+ 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 boost::mpl::fold< Vector,
+ empty_policy_wrap<Base>,
+ inherit_with_base<Base,
+ boost::mpl::_1/*empty/previous*/,
+ policy_wrap<Base, boost::mpl::_2>/*element in vector*/>
+ >::type
+{
+ typedef typename boost::mpl::fold< Vector,
+ empty_policy_wrap<Base>,
+ inherit_with_base<Base,
+ boost::mpl::_1/*empty/previous*/,
+ policy_wrap<Base, boost::mpl::_2>/*element in vector*/>
+ >::type super;
+
+ multi_policy_container (Base &base)
+ : super (base)
+ { }
+
+ template<int N>
+ struct index
+ {
+ typedef typename boost::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 boost::mpl::at_c<Vector, N>::type &
+ get ()
+ {
+ typedef typename boost::mpl::at_c<Vector, N>::type T;
+ return static_cast< policy_wrap<Base, T> &> (*this).value_;
+ }
+
+ template<int N>
+ const typename boost::mpl::at_c<Vector, N>::type &
+ get () const
+ {
+ typedef typename boost::mpl::at_c<Vector, N>::type T;
+ return static_cast< const policy_wrap<Base, T> &> (*this).value_;
+ }
+};
+
+
+} // detail
+} // ndnSIM
+
+#endif // MULTI_POLICY_CONTAINER_H_
diff --git a/utils/detail/multi-type-container.h b/utils/detail/multi-type-container.h
new file mode 100644
index 0000000..43a25da
--- /dev/null
+++ b/utils/detail/multi-type-container.h
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef MULTI_TYPE_CONTAINER_H_
+#define MULTI_TYPE_CONTAINER_H_
+
+#include <boost/mpl/inherit_linearly.hpp>
+#include <boost/mpl/inherit.hpp>
+#include <boost/mpl/at.hpp>
+
+namespace ndnSIM
+{
+namespace detail
+{
+
+template <class T>
+struct wrap
+{
+ T value_;
+};
+
+template< class Vector >
+struct multi_type_container
+ : public boost::mpl::inherit_linearly< Vector, boost::mpl::inherit<wrap<boost::mpl::_2>, boost::mpl::_1 >
+ >::type
+{
+ template<int N>
+ struct index
+ {
+ typedef typename boost::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 boost::mpl::at_c<Vector, N>::type &
+ get ()
+ {
+ typedef typename boost::mpl::at_c<Vector, N>::type T;
+ return static_cast< wrap<T> &> (*this).value_;
+ }
+
+ template<int N>
+ const typename boost::mpl::at_c<Vector, N>::type &
+ get () const
+ {
+ typedef typename boost::mpl::at_c<Vector, N>::type T;
+ return static_cast< const wrap<T> &> (*this).value_;
+ }
+};
+
+} // detail
+} // ndnSIM
+
+#endif // MULTI_TYPE_CONTAINER_H_
diff --git a/utils/fifo-policy.h b/utils/fifo-policy.h
index e8139ae..9f215fc 100644
--- a/utils/fifo-policy.h
+++ b/utils/fifo-policy.h
@@ -21,15 +21,21 @@
#ifndef FIFO_POLICY_H_
#define FIFO_POLICY_H_
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/list.hpp>
+
+namespace ndnSIM
+{
+
struct fifo_policy_traits
{
- struct policy_hook_type : public bi::list_member_hook<> {};
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
template<class Container>
struct container_hook
{
// could be class/struct implementation
- typedef bi::member_hook< Container,
+ typedef boost::intrusive::member_hook< Container,
policy_hook_type,
&Container::policy_hook_ > type;
};
@@ -39,7 +45,7 @@
class Hook>
struct policy
{
- typedef typename bi::list< Container, Hook > policy_container;
+ typedef typename boost::intrusive::list< Container, Hook > policy_container;
// could be just typedef
class type : public policy_container
@@ -105,4 +111,6 @@
};
};
+} // ndnSIM
+
#endif
diff --git a/utils/lru-policy.h b/utils/lru-policy.h
index cd091ce..bf03fa8 100644
--- a/utils/lru-policy.h
+++ b/utils/lru-policy.h
@@ -21,16 +21,22 @@
#ifndef LRU_POLICY_H_
#define LRU_POLICY_H_
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/list.hpp>
+
+namespace ndnSIM
+{
+
struct lru_policy_traits
{
- struct policy_hook_type : public bi::list_member_hook<> {};
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
template<class Container>
struct container_hook
{
- typedef bi::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ typedef boost::intrusive::member_hook< Container,
+ policy_hook_type,
+ &Container::policy_hook_ > type;
};
template<class Base,
@@ -38,7 +44,7 @@
class Hook>
struct policy
{
- typedef typename bi::list< Container, Hook > policy_container;
+ typedef typename boost::intrusive::list< Container, Hook > policy_container;
// could be just typedef
class type : public policy_container
@@ -110,4 +116,6 @@
};
};
+} // ndnSIM
+
#endif
diff --git a/utils/multi-policy.h b/utils/multi-policy.h
new file mode 100644
index 0000000..fd126ae
--- /dev/null
+++ b/utils/multi-policy.h
@@ -0,0 +1,124 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef MULTI_POLICY_H_
+#define MULTI_POLICY_H_
+
+#include "detail/multi-type-container.h"
+#include "detail/multi-policy-container.h"
+#include "detail/functor-hook.h"
+
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/back_inserter.hpp>
+#include <boost/mpl/vector.hpp>
+
+#include <boost/intrusive/options.hpp>
+
+namespace ndnSIM
+{
+
+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 detail::multi_type_container< typename boost::mpl::transform1<policy_traits, getHook>::type > policy_hook_type;
+
+ template<class Container>
+ struct container_hook
+ {
+ typedef policy_hook_type type;
+ };
+
+ template<class Base,
+ class Container,
+ class Hook>
+ struct policy
+ {
+ typedef boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value> policies_range;
+
+ struct getPolicy
+ {
+ template<class Number>
+ struct apply
+ {
+ typedef
+ typename boost::mpl::at_c<policy_traits, Number::value>::type::
+ template policy<Base,
+ Container,
+ boost::intrusive::function_hook< detail::FunctorHook <Hook,
+ Container,
+ Number::value> > >::type
+ type;
+ };
+ };
+
+ typedef
+ typename boost::mpl::transform1<policies_range,
+ getPolicy,
+ boost::mpl::back_inserter< boost::mpl::vector0<> > >::type policies;
+
+
+ typedef detail::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);
+ }
+ };
+ };
+};
+
+} // ndnSIM
+
+#endif // MULTI_POLICY_H_
diff --git a/utils/random-policy.h b/utils/random-policy.h
index ebf0a59..705bcf3 100644
--- a/utils/random-policy.h
+++ b/utils/random-policy.h
@@ -23,16 +23,22 @@
#include "ns3/random-variable.h"
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/set.hpp>
+
+namespace ndnSIM
+{
+
struct random_policy_traits
{
- struct policy_hook_type : public bi::set_member_hook<> { uint32_t randomOrder; };
+ struct policy_hook_type : public boost::intrusive::set_member_hook<> { uint32_t randomOrder; };
template<class Container>
struct container_hook
{
- typedef bi::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ typedef boost::intrusive::member_hook< Container,
+ policy_hook_type,
+ &Container::policy_hook_ > type;
};
template<class Base,
@@ -61,9 +67,9 @@
}
};
- typedef bi::set< Container,
- bi::compare< MemberHookLess< Container > >,
- Hook > policy_container;
+ typedef boost::intrusive::set< Container,
+ boost::intrusive::compare< MemberHookLess< Container > >,
+ Hook > policy_container;
// could be just typedef
class type : public policy_container
@@ -93,7 +99,7 @@
{
if (MemberHookLess<Container>() (*item, *policy_container::begin ()))
{
- std::cout << "Cannot add. Signaling fail\n";
+ // std::cout << "Cannot add. Signaling fail\n";
// just return false. Indicating that insert "failed"
return false;
}
@@ -143,4 +149,6 @@
};
};
+} // ndnSIM
+
#endif // RANDOM_POLICY_H
diff --git a/utils/trie-with-policy.h b/utils/trie-with-policy.h
index 46fbe69..c674ef2 100644
--- a/utils/trie-with-policy.h
+++ b/utils/trie-with-policy.h
@@ -23,6 +23,9 @@
#include "trie.h"
+namespace ndnSIM
+{
+
template<typename FullKey,
typename PayloadTraits,
typename PolicyTraits
@@ -184,6 +187,7 @@
policy_container policy_;
};
+} // ndnSIM
#endif // TRIE_WITH_POLICY_H_
diff --git a/utils/trie.h b/utils/trie.h
index f65e242..47e62e5 100644
--- a/utils/trie.h
+++ b/utils/trie.h
@@ -30,7 +30,8 @@
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
#include <boost/tuple/tuple.hpp>
-namespace bi = boost::intrusive;
+namespace ndnSIM
+{
/////////////////////////////////////////////////////
// Allow customization for payload
@@ -211,13 +212,14 @@
PolicyHook policy_hook_;
private:
- bi::unordered_set_member_hook<> unordered_set_member_hook_;
+ boost::intrusive::unordered_set_member_hook<> unordered_set_member_hook_;
// necessary typedefs
typedef trie self_type;
- typedef bi::member_hook< trie,
- bi::unordered_set_member_hook< >, &trie::unordered_set_member_hook_ > member_hook;
- typedef bi::unordered_set< trie, member_hook > unordered_set;
+ typedef boost::intrusive::member_hook< trie,
+ boost::intrusive::unordered_set_member_hook< >,
+ &trie::unordered_set_member_hook_ > member_hook;
+ typedef boost::intrusive::unordered_set< trie, member_hook > unordered_set;
typedef typename unordered_set::bucket_type bucket_type;
typedef typename unordered_set::bucket_traits bucket_traits;
@@ -469,4 +471,6 @@
return boost::hash_value (trie_node.key_);
}
+} // ndnSIM
+
#endif // TRIE_H_