src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/utils/trie/trie-with-policy.hpp b/utils/trie/trie-with-policy.hpp
index f09f13b..790dd0f 100644
--- a/utils/trie/trie-with-policy.hpp
+++ b/utils/trie/trie-with-policy.hpp
@@ -27,93 +27,86 @@
namespace ndn {
namespace ndnSIM {
-template<typename FullKey,
- typename PayloadTraits,
- typename PolicyTraits
- >
-class trie_with_policy
-{
+template<typename FullKey, typename PayloadTraits, typename PolicyTraits>
+class trie_with_policy {
public:
- typedef trie< FullKey,
- PayloadTraits,
- typename PolicyTraits::policy_hook_type > parent_trie;
+ typedef trie<FullKey, PayloadTraits, typename PolicyTraits::policy_hook_type> parent_trie;
typedef typename parent_trie::iterator iterator;
typedef typename parent_trie::const_iterator const_iterator;
- typedef typename PolicyTraits::template policy<
- trie_with_policy<FullKey, PayloadTraits, PolicyTraits>,
- parent_trie,
- typename PolicyTraits::template container_hook<parent_trie>::type >::type policy_container;
+ typedef typename PolicyTraits::
+ template policy<trie_with_policy<FullKey, PayloadTraits, PolicyTraits>, parent_trie,
+ typename PolicyTraits::template container_hook<parent_trie>::type>::type
+ policy_container;
- inline
- trie_with_policy (size_t bucketSize = 1, size_t bucketIncrement = 1)
- : trie_ (name::Component (), bucketSize, bucketIncrement)
- , policy_ (*this)
+ inline trie_with_policy(size_t bucketSize = 1, size_t bucketIncrement = 1)
+ : trie_(name::Component(), bucketSize, bucketIncrement)
+ , policy_(*this)
{
}
- inline std::pair< iterator, bool >
- insert (const FullKey &key, typename PayloadTraits::insert_type payload)
+ inline std::pair<iterator, bool>
+ insert(const FullKey& key, typename PayloadTraits::insert_type payload)
{
- std::pair<iterator, bool> item =
- trie_.insert (key, payload);
+ std::pair<iterator, bool> item = trie_.insert(key, payload);
if (item.second) // real insert
- {
- bool ok = policy_.insert (s_iterator_to (item.first));
- if (!ok)
- {
- item.first->erase (); // cannot insert
- return std::make_pair (end (), false);
- }
+ {
+ bool ok = policy_.insert(s_iterator_to(item.first));
+ if (!ok) {
+ item.first->erase(); // cannot insert
+ return std::make_pair(end(), false);
}
- else
- {
- return std::make_pair (s_iterator_to (item.first), false);
- }
+ }
+ else {
+ return std::make_pair(s_iterator_to(item.first), false);
+ }
return item;
}
inline void
- erase (const FullKey &key)
+ erase(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
- if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload)
+ if (!reachLast || lastItem->payload() == PayloadTraits::empty_payload)
return; // nothing to invalidate
- erase (lastItem);
+ erase(lastItem);
}
inline void
- erase (iterator node)
+ erase(iterator node)
{
- if (node == end ()) return;
+ if (node == end())
+ return;
- policy_.erase (s_iterator_to (node));
- node->erase (); // will do cleanup here
+ policy_.erase(s_iterator_to(node));
+ node->erase(); // will do cleanup here
}
inline void
- clear ()
+ clear()
{
- policy_.clear ();
- trie_.clear ();
+ policy_.clear();
+ trie_.clear();
}
template<typename Modifier>
bool
- modify (iterator position, Modifier mod)
+ modify(iterator position, Modifier mod)
{
- if (position == end ()) return false;
- if (position->payload () == PayloadTraits::empty_payload) return false;
+ if (position == end())
+ return false;
+ if (position->payload() == PayloadTraits::empty_payload)
+ return false;
- mod (*position->payload ());
- policy_.update (position);
+ mod(*position->payload());
+ policy_.update(position);
return true;
}
@@ -121,14 +114,14 @@
* @brief Find a node that has the exact match with the key
*/
inline iterator
- find_exact (const FullKey &key)
+ find_exact(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
- if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload)
- return end ();
+ if (!reachLast || lastItem->payload() == PayloadTraits::empty_payload)
+ return end();
return lastItem;
}
@@ -137,15 +130,14 @@
* @brief Find a node that has the longest common prefix with key (FIB/PIT lookup)
*/
inline iterator
- longest_prefix_match (const FullKey &key)
+ longest_prefix_match(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
- if (foundItem != trie_.end ())
- {
- policy_.lookup (s_iterator_to (foundItem));
- }
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
+ if (foundItem != trie_.end()) {
+ policy_.lookup(s_iterator_to(foundItem));
+ }
return foundItem;
}
@@ -154,15 +146,14 @@
*/
template<class Predicate>
inline iterator
- longest_prefix_match_if (const FullKey &key, Predicate pred)
+ longest_prefix_match_if(const FullKey& key, Predicate pred)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find_if (key, pred);
- if (foundItem != trie_.end ())
- {
- policy_.lookup (s_iterator_to (foundItem));
- }
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find_if(key, pred);
+ if (foundItem != trie_.end()) {
+ policy_.lookup(s_iterator_to(foundItem));
+ }
return foundItem;
}
@@ -180,29 +171,26 @@
* @brief Find a node that has prefix at least as the key (cache lookup)
*/
inline iterator
- deepest_prefix_match (const FullKey &key)
+ deepest_prefix_match(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
// guard in case we don't have anything in the trie
- if (lastItem == trie_.end ())
- return trie_.end ();
+ if (lastItem == trie_.end())
+ return trie_.end();
- if (reachLast)
- {
- if (foundItem == trie_.end ())
- {
- foundItem = lastItem->find (); // should be something
- }
- policy_.lookup (s_iterator_to (foundItem));
- return foundItem;
+ if (reachLast) {
+ if (foundItem == trie_.end()) {
+ foundItem = lastItem->find(); // should be something
}
- else
- { // couldn't find a node that has prefix at least as key
- return trie_.end ();
- }
+ policy_.lookup(s_iterator_to(foundItem));
+ return foundItem;
+ }
+ else { // couldn't find a node that has prefix at least as key
+ return trie_.end();
+ }
}
/**
@@ -210,30 +198,27 @@
*/
template<class Predicate>
inline iterator
- deepest_prefix_match_if (const FullKey &key, Predicate pred)
+ deepest_prefix_match_if(const FullKey& key, Predicate pred)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
// guard in case we don't have anything in the trie
- if (lastItem == trie_.end ())
- return trie_.end ();
+ if (lastItem == trie_.end())
+ return trie_.end();
- if (reachLast)
- {
- foundItem = lastItem->find_if (pred); // may or may not find something
- if (foundItem == trie_.end ())
- {
- return trie_.end ();
- }
- policy_.lookup (s_iterator_to (foundItem));
- return foundItem;
+ if (reachLast) {
+ foundItem = lastItem->find_if(pred); // may or may not find something
+ if (foundItem == trie_.end()) {
+ return trie_.end();
}
- else
- { // couldn't find a node that has prefix at least as key
- return trie_.end ();
- }
+ policy_.lookup(s_iterator_to(foundItem));
+ return foundItem;
+ }
+ else { // couldn't find a node that has prefix at least as key
+ return trie_.end();
+ }
}
/**
@@ -244,51 +229,61 @@
*/
template<class Predicate>
inline iterator
- deepest_prefix_match_if_next_level (const FullKey &key, Predicate pred)
+ deepest_prefix_match_if_next_level(const FullKey& key, Predicate pred)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
// guard in case we don't have anything in the trie
- if (lastItem == trie_.end ())
- return trie_.end ();
+ if (lastItem == trie_.end())
+ return trie_.end();
- if (reachLast)
- {
- foundItem = lastItem->find_if_next_level (pred); // may or may not find something
- if (foundItem == trie_.end ())
- {
- return trie_.end ();
- }
- policy_.lookup (s_iterator_to (foundItem));
- return foundItem;
+ if (reachLast) {
+ foundItem = lastItem->find_if_next_level(pred); // may or may not find something
+ if (foundItem == trie_.end()) {
+ return trie_.end();
}
- else
- { // couldn't find a node that has prefix at least as key
- return trie_.end ();
- }
+ policy_.lookup(s_iterator_to(foundItem));
+ return foundItem;
+ }
+ else { // couldn't find a node that has prefix at least as key
+ return trie_.end();
+ }
}
-
- iterator end () const
+
+ iterator
+ end() const
{
return 0;
}
- const parent_trie &
- getTrie () const { return trie_; }
+ const parent_trie&
+ getTrie() const
+ {
+ return trie_;
+ }
- parent_trie &
- getTrie () { return trie_; }
+ parent_trie&
+ getTrie()
+ {
+ return trie_;
+ }
- const policy_container &
- getPolicy () const { return policy_; }
+ const policy_container&
+ getPolicy() const
+ {
+ return policy_;
+ }
- policy_container &
- getPolicy () { return policy_; }
+ policy_container&
+ getPolicy()
+ {
+ return policy_;
+ }
static inline iterator
- s_iterator_to (typename parent_trie::iterator item)
+ s_iterator_to(typename parent_trie::iterator item)
{
if (item == 0)
return 0;
@@ -297,7 +292,7 @@
}
private:
- parent_trie trie_;
+ parent_trie trie_;
mutable policy_container policy_;
};