|
Boost-Commit : |
From: chintanraoh_at_[hidden]
Date: 2008-06-08 13:04:04
Author: chintanraoh
Date: 2008-06-08 13:04:04 EDT (Sun, 08 Jun 2008)
New Revision: 46244
URL: http://svn.boost.org/trac/boost/changeset/46244
Log:
Added const functions
Text files modified:
sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/node_cursor.hpp | 83 ++++++++++++++++++++++++++-------------
1 files changed, 56 insertions(+), 27 deletions(-)
Modified: sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/node_cursor.hpp
==============================================================================
--- sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/node_cursor.hpp (original)
+++ sandbox/SOC/2008/digital_searching/dsearch/boost/dsearch/node_cursor.hpp 2008-06-08 13:04:04 EDT (Sun, 08 Jun 2008)
@@ -2,6 +2,8 @@
#define BOOST_DSEARCH_NODE_CURSOR_HPP
#include <boost/dsearch/from_tree/cursor_helpers.hpp> //namespace boost::tree
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/identity.hpp>
#include<assert.h>
namespace boost {
@@ -21,12 +23,17 @@
friend class boost::tree::cursor_core_access;
template<class K,class M,template<class K1,class M1,class K_t1,class A1 > class t_n,class K_t,class A >
friend class trie;
+ template<class K,class M,class N> friend class trie_cursor;
+ struct enabler {};
+ typedef typename mpl::eval_if<is_const<Node>, typename Node::const_iterator,
+ typename Node::iterator>::type node_iterator;
+
unsigned char only_root;
bool top;
-
- Node *cur;
- typedef typename Node::iterator node_iterator;
node_iterator pos;
+ Node *cur;
+
+
public:
trie_cursor()// :only_root(0),cur(0),top(0) (gave warnings!?!)
@@ -34,38 +41,30 @@
only_root=0;cur=0;top=0;
}
+ template<class K,class M,class N>
+ trie_cursor( trie_cursor<K,M,N> const& other,
+ typename enable_if< is_convertible<N*,Node*>,
+ enabler >::type = enabler()
+ )
+ {
+ this->only_root=other.only_root;
+ this->top=other.top;
+ this->pos=other.pos;
+ this->cur=other.cur;
+ }
+
trie_cursor(Node * const n_ptr): only_root(1) , top(false)
{
cur=n_ptr;
}
- trie_cursor(const Node * n_ptr,const node_iterator it): only_root(0), top(false)
+ trie_cursor(Node *n_ptr,const node_iterator &it): only_root(0), top(false)
{
cur=const_cast<Node *>(n_ptr);
pos=it;
}
private:
- bool equal(cursor const& other) const
- {
- if(top==other.top)
- {
- if(top) return true;
- }
- else
- return false;
- if(only_root==other.only_root)
- {
- if (only_root==1 || only_root==2)
- return true;
- assert(only_root==0);
- }
- else
- return false;
-
- if(cur==other.cur && pos==other.pos) return true;
- return false;
- }
cursor left() const
{
@@ -94,7 +93,7 @@
else
pos--;
}
-
+
bool empty_() const
{
return get_node()->empty();
@@ -112,6 +111,13 @@
return *pos;
}
+ Node *get_node()
+ {
+ if(only_root)
+ return cur;
+ return *pos;
+ }
+
void increment()
{
if(only_root)
@@ -120,20 +126,43 @@
pos++;
}
+ template<class K,class M,class N>
+ bool equal(trie_cursor<K,M,N> const& other) const
+ {
+ if(top==other.top)
+ {
+ if(top) return true;
+ }
+ else
+ return false;
+ if(only_root==other.only_root)
+ {
+ if (only_root==1 || only_root==2)
+ return true;
+ assert(only_root==0);
+ }
+ else
+ return false;
+
+ if(cur==other.cur && pos==other.pos) return true;
+ return false;
+ }
+
public:
bool has_value() const
{
return get_node()->has_value();
}
+ //const because dereference is const
Mapped &get_value() const
{
return get_node()->get_value_ref();
}
- cursor find(const element_type &e)
+ cursor find(const element_type &e) const
{
- return cursor(get_node(),get_node()->find(e));
+ return cursor(this->get_node(),get_node()->find(e));
}
};
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk