Adjust code to perform to C++ standard according to gcc-3.4
interpretation... (Have not compiled/checked/changed paradisEO.) That is, the current code compiles with gcc-3.4 and the checks (besides t-MGE1bit) all pass.
This commit is contained in:
parent
faaadf7599
commit
85a326c5e4
35 changed files with 1057 additions and 864 deletions
|
|
@ -1,26 +1,26 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoParseTree.h : eoParseTree class (for Tree-based Genetic Programming)
|
||||
// (c) Maarten Keijzer 2000
|
||||
// (c) Maarten Keijzer 2000
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
mak@dhi.dk
|
||||
|
||||
mak@dhi.dk
|
||||
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -57,27 +57,31 @@ using namespace gp_parse_tree;
|
|||
template <class FType, class Node>
|
||||
class eoParseTree : public EO<FType>, public parse_tree<Node>
|
||||
{
|
||||
public :
|
||||
public:
|
||||
|
||||
using eoParseTree<FType, Node >::back;
|
||||
using eoParseTree<FType, Node >::ebegin;
|
||||
using eoParseTree<FType, Node >::eend;
|
||||
using eoParseTree<FType, Node >::size;
|
||||
|
||||
|
||||
typedef typename parse_tree<Node>::subtree Subtree;
|
||||
|
||||
/* For Compatibility with the intel C++ compiler for Linux 5.x */
|
||||
typedef Node reference;
|
||||
typedef const reference const_reference;
|
||||
|
||||
|
||||
/* For Compatibility with the intel C++ compiler for Linux 5.x */
|
||||
typedef Node reference;
|
||||
typedef const reference const_reference;
|
||||
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
eoParseTree(void) {}
|
||||
/**
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
* @param tree The tree to copy
|
||||
*/
|
||||
eoParseTree(const parse_tree<Node>& tree) : parse_tree<Node>(tree) {}
|
||||
|
||||
|
||||
// eoParseTree(const eoParseTree<FType, Node>& tree) : parse_tree<Node>(tree) {}
|
||||
/**
|
||||
* To prune me to a certain size
|
||||
|
|
@ -90,7 +94,7 @@ public :
|
|||
|
||||
while (size() > _size)
|
||||
{
|
||||
back() = operator[](size()-2);
|
||||
back() = operator[](size()-2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,8 +102,8 @@ public :
|
|||
* To read me from a stream
|
||||
* @param is The std::istream
|
||||
*/
|
||||
|
||||
eoParseTree(std::istream& is) : EO<FType>(), parse_tree<Node>()
|
||||
|
||||
eoParseTree(std::istream& is) : EO<FType>(), parse_tree<Node>()
|
||||
{
|
||||
readFrom(is);
|
||||
}
|
||||
|
|
@ -120,21 +124,21 @@ public :
|
|||
|
||||
std::copy(ebegin(), eend(), std::ostream_iterator<Node>(os, " "));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To read me from a stream
|
||||
* @param is The std::istream
|
||||
*/
|
||||
void readFrom(std::istream& is)
|
||||
void readFrom(std::istream& is)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
EO<FType>::readFrom(is);
|
||||
|
||||
unsigned sz;
|
||||
is >> sz;
|
||||
|
||||
|
||||
|
||||
std::vector<Node> v(sz);
|
||||
|
||||
unsigned i;
|
||||
|
|
@ -147,19 +151,19 @@ public :
|
|||
}
|
||||
parse_tree<Node> tmp(v.begin(), v.end());
|
||||
swap(tmp);
|
||||
|
||||
|
||||
/*
|
||||
* old code which caused problems for paradisEO
|
||||
*
|
||||
* this can be removed once it has proved itself
|
||||
EO<FType>::readFrom(is);
|
||||
|
||||
// even older code
|
||||
|
||||
// even older code
|
||||
FType fit;
|
||||
is >> fit;
|
||||
|
||||
fitness(fit);
|
||||
|
||||
|
||||
|
||||
std::copy(std::istream_iterator<Node>(is), std::istream_iterator<Node>(), back_inserter(*this));
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
/**
|
||||
|
||||
* Parse_tree and subtree classes
|
||||
* (c) copyright Maarten Keijzer 1999, 2000
|
||||
* Parse_tree and subtree classes
|
||||
* (c) copyright Maarten Keijzer 1999, 2000
|
||||
|
||||
* Permission to copy, use, modify, sell and distribute this software is granted provided
|
||||
* Permission to copy, use, modify, sell and distribute this software is granted provided
|
||||
* this copyright notice appears in all copies. This software is provided "as is" without
|
||||
* express or implied warranty, and with no claim as to its suitability for
|
||||
* any purpose.
|
||||
|
||||
|
||||
* Permission to modify the code and to distribute modified code is granted,
|
||||
* provided the above notices as well as this one are retained, and a notice that the code was
|
||||
* modified is included with the above copyright notice.
|
||||
|
|
@ -22,31 +22,31 @@
|
|||
class Node (your node in the tree) must have the following implemented:
|
||||
|
||||
****** Arity ******
|
||||
|
||||
|
||||
int arity(void) const
|
||||
|
||||
Note: the default constructor of a Node should provide a
|
||||
Note: the default constructor of a Node should provide a
|
||||
Node with arity 0!
|
||||
|
||||
****** Evaluation ******
|
||||
|
||||
A parse_tree is evaluated through one of it's apply() members:
|
||||
|
||||
1) parse_tree::apply(RetVal)
|
||||
|
||||
is the simplest evaluation, it will call
|
||||
|
||||
|
||||
1) parse_tree::apply(RetVal)
|
||||
|
||||
is the simplest evaluation, it will call
|
||||
|
||||
RetVal Node::operator()(RetVal, subtree<Node, RetVal>::const_iterator)
|
||||
|
||||
(Unfortunately the first RetVal argument is mandatory (although you
|
||||
|
||||
(Unfortunately the first RetVal argument is mandatory (although you
|
||||
might not need it. This is because MSVC does not support member template
|
||||
functions properly. If it cannot deduce the template arguments (as is
|
||||
the case in templatizing over return value) you are not allowed to
|
||||
functions properly. If it cannot deduce the template arguments (as is
|
||||
the case in templatizing over return value) you are not allowed to
|
||||
specify them. calling tree.apply<double>() would result in a syntax
|
||||
error. That is why you have to call tree.apply(double()) instead.)
|
||||
|
||||
|
||||
2) parse_tree::apply(RetVal v, It values)
|
||||
2) parse_tree::apply(RetVal v, It values)
|
||||
|
||||
will call:
|
||||
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
will call:
|
||||
|
||||
RetVal Node::operator()(RetVal, subtree<... , It values, It2 moreValues)
|
||||
|
||||
|
||||
although I do not see the immediate use of this, however...
|
||||
|
||||
4) parse_tree::apply(RetVal, It values, It2 args, It3 adfs)
|
||||
|
|
@ -70,10 +70,10 @@
|
|||
|
||||
RetVal Node::operator()(subtree<... , It values, It2 args, It3 adfs)
|
||||
|
||||
can be useful for implementing adfs.
|
||||
can be useful for implementing adfs.
|
||||
|
||||
|
||||
In general it is a good idea to leave the specifics of the
|
||||
|
||||
In general it is a good idea to leave the specifics of the
|
||||
arguments open so that different ways of evaluation remain
|
||||
possible. Implement the simplest eval as:
|
||||
|
||||
|
|
@ -85,24 +85,24 @@
|
|||
A parse_tree has two template arguments: the Node and the ReturnValue
|
||||
produced by evaluating the node. The structure of the tree is defined
|
||||
through a subtree class that has the same two template arguments.
|
||||
|
||||
|
||||
The nodes are stored in a tree like :
|
||||
|
||||
node4
|
||||
/ \
|
||||
node3 node2
|
||||
/ \
|
||||
node1 node0
|
||||
node1 node0
|
||||
|
||||
where nodes 2 and 4 have arity 2 and nodes 0,1 and 3 arity 0 (terminals)
|
||||
|
||||
The nodes are subtrees, containing the structure of the tree, together
|
||||
with its size and depth. They contain a Node, the user defined template
|
||||
argument. To access these nodes from a subtree, use operator-> or operator*.
|
||||
|
||||
The numbers behind the nodes define a reverse-polish or postfix
|
||||
|
||||
The numbers behind the nodes define a reverse-polish or postfix
|
||||
traversel through the tree. The parse_tree defines iterators
|
||||
on the tree such that
|
||||
on the tree such that
|
||||
|
||||
tree.begin() points at the subtree at node0 and
|
||||
tree.back() returns the subtree at node4, the complete tree
|
||||
|
|
@ -134,9 +134,9 @@
|
|||
std::vector<Node> vec(tree.size());
|
||||
copy(tree.ebegin(), tree.eend(), vec.begin());
|
||||
|
||||
You can also copy it to an std::ostream_iterator with this
|
||||
You can also copy it to an std::ostream_iterator with this
|
||||
technique, given that your Node implements an appropriate
|
||||
operator<<. Reinitializing a tree with the std::vector is also
|
||||
operator<<. Reinitializing a tree with the std::vector is also
|
||||
simple:
|
||||
|
||||
tree.clear();
|
||||
|
|
@ -158,7 +158,7 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4786) // disable this nagging warning about the limitations of the mirkosoft debugger
|
||||
#endif
|
||||
|
||||
|
||||
namespace gp_parse_tree
|
||||
{
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ namespace gp_parse_tree
|
|||
|
||||
/// This ones defined because gcc does not always implement namespaces
|
||||
template <class T>
|
||||
inline void do_the_swap(T& a, T& b)
|
||||
inline void do_the_swap(T& a, T& b)
|
||||
{
|
||||
T tmp = a;
|
||||
a = b;
|
||||
|
|
@ -181,7 +181,7 @@ template <class T> class parse_tree
|
|||
class subtree
|
||||
{
|
||||
|
||||
/*
|
||||
/*
|
||||
a bit nasty way to use a pool allocator (which would otherwise use slooow new and delete)
|
||||
TODO: use the std::allocator interface
|
||||
*/
|
||||
|
|
@ -198,42 +198,42 @@ public :
|
|||
|
||||
typedef subtree* iterator;
|
||||
typedef const subtree* const_iterator;
|
||||
|
||||
|
||||
/* Constructors, assignments */
|
||||
|
||||
subtree(void) : content(node_allocator.allocate()), args(0), parent(0), _cumulative_size(0), _depth(0), _size(1)
|
||||
subtree(void) : content(node_allocator.allocate()), args(0), parent(0), _cumulative_size(0), _depth(0), _size(1)
|
||||
{}
|
||||
subtree(const subtree& s)
|
||||
: content(node_allocator.allocate()),
|
||||
args(0),
|
||||
parent(0),
|
||||
_cumulative_size(1),
|
||||
_depth(1),
|
||||
_size(1)
|
||||
subtree(const subtree& s)
|
||||
: content(node_allocator.allocate()),
|
||||
args(0),
|
||||
parent(0),
|
||||
_cumulative_size(1),
|
||||
_depth(1),
|
||||
_size(1)
|
||||
{
|
||||
copy(s);
|
||||
}
|
||||
}
|
||||
|
||||
subtree(const T& t) : content(node_allocator.allocate()), args(0), parent(0), _cumulative_size(0), _depth(0), _size(1)
|
||||
{ copy(t); }
|
||||
{ copy(t); }
|
||||
|
||||
template <class It>
|
||||
subtree(It b, It e) : content(node_allocator.allocate()), args(0), parent(0), _cumulative_size(0), _depth(0), _size(1)
|
||||
subtree(It b, It e) : content(node_allocator.allocate()), args(0), parent(0), _cumulative_size(0), _depth(0), _size(1)
|
||||
{ // initialize in prefix order for efficiency reasons
|
||||
init(b, --e);
|
||||
}
|
||||
|
||||
virtual ~subtree(void) { tree_allocator.deallocate(args, arity()); node_allocator.deallocate(content); }
|
||||
|
||||
subtree& operator=(const subtree& s)
|
||||
{
|
||||
|
||||
subtree& operator=(const subtree& s)
|
||||
{
|
||||
if (s.get_root() == get_root())
|
||||
{ // from the same tree, maybe a child. Don't take any chances
|
||||
subtree anotherS = s;
|
||||
return copy(anotherS);
|
||||
}
|
||||
|
||||
copy(s);
|
||||
copy(s);
|
||||
updateAfterInsert();
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -242,9 +242,9 @@ public :
|
|||
|
||||
/* Access to the nodes */
|
||||
|
||||
T& operator*(void) { return *content; }
|
||||
T& operator*(void) { return *content; }
|
||||
const T& operator*(void) const { return *content; }
|
||||
T* operator->(void) { return content; }
|
||||
T* operator->(void) { return content; }
|
||||
const T* operator->(void) const { return content; }
|
||||
|
||||
/* Equality, inequality check, Node needs to implement operator== */
|
||||
|
|
@ -274,11 +274,11 @@ public :
|
|||
/* Evaluation with an increasing amount of user defined arguments */
|
||||
template <class RetVal>
|
||||
void apply(RetVal& v) const { (*content)(v, begin()); }
|
||||
|
||||
|
||||
template <class RetVal, class It>
|
||||
void apply(RetVal& v, It values) const
|
||||
{
|
||||
(*content)(v, begin(), values);
|
||||
void apply(RetVal& v, It values) const
|
||||
{
|
||||
(*content)(v, begin(), values);
|
||||
}
|
||||
|
||||
template <class RetVal, class It>
|
||||
|
|
@ -289,11 +289,11 @@ public :
|
|||
|
||||
|
||||
/* template <class RetVal, class It, class It2>
|
||||
void apply(RetVal& v, It values, It2 moreValues) const
|
||||
void apply(RetVal& v, It values, It2 moreValues) const
|
||||
{ (*content)(v, begin(), values, moreValues); }
|
||||
|
||||
template <class RetVal, class It, class It2, class It3>
|
||||
void apply(RetVal& v, It values, It2 moreValues, It3 evenMoreValues) const
|
||||
void apply(RetVal& v, It values, It2 moreValues, It3 evenMoreValues) const
|
||||
{ (*content)(v, begin(), values, moreValues, evenMoreValues); }
|
||||
*/
|
||||
|
||||
|
|
@ -310,7 +310,7 @@ public :
|
|||
args[i].find_nodes(result, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class Pred>
|
||||
void find_nodes(std::vector<const subtree*>& result, Pred& p) const
|
||||
{
|
||||
|
|
@ -324,7 +324,7 @@ public :
|
|||
args[i].find_nodes(result, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Iterators */
|
||||
|
||||
iterator begin(void) { return args; }
|
||||
|
|
@ -339,21 +339,21 @@ public :
|
|||
/* Some statistics */
|
||||
|
||||
size_t size(void) const { return _size; }
|
||||
|
||||
|
||||
size_t cumulative_size(void) const { return _cumulative_size; }
|
||||
size_t depth(void) const { return _depth; }
|
||||
|
||||
|
||||
const subtree& select_cumulative(size_t which) const
|
||||
{ return imp_select_cumulative(which); }
|
||||
|
||||
subtree& select_cumulative(size_t which)
|
||||
subtree& select_cumulative(size_t which)
|
||||
{ return const_cast<subtree&>(imp_select_cumulative(which)); }
|
||||
|
||||
subtree& get_node(size_t which)
|
||||
{ return const_cast<subtree&>(imp_get_node(which));}
|
||||
const subtree& get_node(size_t which) const
|
||||
{ return imp_get_node(which); }
|
||||
|
||||
|
||||
subtree* get_parent(void) { return parent; }
|
||||
const subtree* get_parent(void) const { return parent; }
|
||||
|
||||
|
|
@ -364,7 +364,7 @@ public :
|
|||
{
|
||||
do_the_swap(content, y.content);
|
||||
do_the_swap(args, y.args);
|
||||
|
||||
|
||||
adopt();
|
||||
y.adopt();
|
||||
|
||||
|
|
@ -381,7 +381,7 @@ protected :
|
|||
virtual void updateAfterInsert(void)
|
||||
{
|
||||
_depth = 0;
|
||||
_size = 1;
|
||||
_size = 1;
|
||||
_cumulative_size = 0;
|
||||
|
||||
for (iterator it = begin(); it != end(); ++it)
|
||||
|
|
@ -411,7 +411,7 @@ private :
|
|||
return args[i].imp_select_cumulative(which);
|
||||
which -= args[i]._cumulative_size;
|
||||
}
|
||||
|
||||
|
||||
return *this; // error!
|
||||
}
|
||||
|
||||
|
|
@ -419,7 +419,7 @@ private :
|
|||
{
|
||||
if (which == size() - 1)
|
||||
return *this;
|
||||
|
||||
|
||||
for (int i = arity() - 1; i >= 0; --i)
|
||||
{
|
||||
unsigned c_size = args[i].size();
|
||||
|
|
@ -442,9 +442,9 @@ private :
|
|||
subtree& copy(const subtree& s)
|
||||
{
|
||||
int old_arity = arity();
|
||||
|
||||
|
||||
int new_arity = s.arity();
|
||||
|
||||
|
||||
if (new_arity != old_arity)
|
||||
{
|
||||
tree_allocator.deallocate(args, old_arity);
|
||||
|
|
@ -455,7 +455,7 @@ private :
|
|||
switch(new_arity)
|
||||
{
|
||||
case 3 : args[2].copy(s.args[2]); args[2].parent = this; // no break!
|
||||
case 2 : args[1].copy(s.args[1]); args[1].parent = this;
|
||||
case 2 : args[1].copy(s.args[1]); args[1].parent = this;
|
||||
case 1 : args[0].copy(s.args[0]); args[0].parent = this;
|
||||
case 0 : break;
|
||||
default :
|
||||
|
|
@ -467,8 +467,8 @@ private :
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
*content = *s.content;
|
||||
|
||||
*content = *s.content;
|
||||
_size = s._size;
|
||||
_depth = s._depth;
|
||||
_cumulative_size = s._cumulative_size;
|
||||
|
|
@ -479,24 +479,24 @@ private :
|
|||
subtree& copy(const T& t)
|
||||
{
|
||||
int oldArity = arity();
|
||||
|
||||
|
||||
if (content != &t)
|
||||
*content = t;
|
||||
else
|
||||
oldArity = -1;
|
||||
|
||||
oldArity = -1;
|
||||
|
||||
int ar = arity();
|
||||
|
||||
|
||||
if (ar != oldArity)
|
||||
{
|
||||
if (oldArity != -1)
|
||||
tree_allocator.deallocate(args, oldArity);
|
||||
|
||||
args = tree_allocator.allocate(ar);
|
||||
|
||||
|
||||
//if (ar > 0)
|
||||
// args = new subtree [ar];
|
||||
//else
|
||||
//else
|
||||
// args = 0;
|
||||
}
|
||||
|
||||
|
|
@ -521,7 +521,7 @@ private :
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void adopt(void)
|
||||
|
|
@ -539,7 +539,7 @@ private :
|
|||
it->parent = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class It>
|
||||
|
|
@ -582,22 +582,22 @@ private :
|
|||
parse_tree(void) : _root(), pushed() {}
|
||||
parse_tree(const parse_tree& org) : _root(org._root), pushed(org.pushed) { }
|
||||
parse_tree(const subtree& sub) : _root(sub), pushed() { }
|
||||
|
||||
|
||||
template <class It>
|
||||
parse_tree(It b, It e) : _root(b, e), pushed() {}
|
||||
|
||||
|
||||
virtual ~parse_tree(void) {}
|
||||
|
||||
parse_tree& operator=(const parse_tree& org) { return copy(org); }
|
||||
parse_tree& operator=(const subtree& sub)
|
||||
parse_tree& operator=(const subtree& sub)
|
||||
{ return copy(sub); }
|
||||
|
||||
|
||||
|
||||
/* Equality and inequality */
|
||||
|
||||
bool operator==(const parse_tree& other) const
|
||||
{ return _root == other._root; }
|
||||
|
||||
|
||||
bool operator !=(const parse_tree& other) const
|
||||
{ return !operator==(other); }
|
||||
|
||||
|
|
@ -610,13 +610,13 @@ private :
|
|||
/* Evaluation (application), with an increasing number of user defined arguments */
|
||||
|
||||
template <class RetVal>
|
||||
void apply(RetVal& v) const
|
||||
void apply(RetVal& v) const
|
||||
{ _root.apply(v); }
|
||||
|
||||
template <class RetVal, class It>
|
||||
void apply(RetVal& v, It varValues) const
|
||||
void apply(RetVal& v, It varValues) const
|
||||
{ _root.apply(v, varValues); }
|
||||
|
||||
|
||||
template <class RetVal, class It>
|
||||
void apply_mem_func(RetVal& v, It misc, void (T::* f)(RetVal&, typename subtree::iterator, It))
|
||||
{
|
||||
|
|
@ -624,11 +624,11 @@ private :
|
|||
}
|
||||
|
||||
//template <class RetVal, class It, class It2>
|
||||
// void apply(RetVal& v, It varValues, It2 moreValues) const
|
||||
// void apply(RetVal& v, It varValues, It2 moreValues) const
|
||||
// { _root.apply(v, varValues, moreValues); }
|
||||
|
||||
|
||||
//template <class RetVal, class It, class It2, class It3>
|
||||
// void apply(RetVal& v, It varValues, It2 moreValues, It3 evenMoreValues) const
|
||||
// void apply(RetVal& v, It varValues, It2 moreValues, It3 evenMoreValues) const
|
||||
// { _root.apply(v, varValues, moreValues, evenMoreValues); }
|
||||
|
||||
template <class Pred>
|
||||
|
|
@ -636,13 +636,13 @@ private :
|
|||
{
|
||||
_root.find_nodes(result, p);
|
||||
}
|
||||
|
||||
|
||||
template <class Pred>
|
||||
void find_nodes(std::vector<const subtree*>& result, Pred& p) const
|
||||
{
|
||||
_root.find_nodes(p);
|
||||
}
|
||||
|
||||
|
||||
/* Customized Swap */
|
||||
void swap(parse_tree<T>& other)
|
||||
{
|
||||
|
|
@ -655,8 +655,8 @@ private :
|
|||
class base_iterator
|
||||
{
|
||||
public :
|
||||
|
||||
base_iterator() {}
|
||||
|
||||
base_iterator() {}
|
||||
base_iterator(subtree* n) { node = n; }
|
||||
|
||||
base_iterator& operator=(const base_iterator& org)
|
||||
|
|
@ -670,7 +670,7 @@ private :
|
|||
base_iterator operator+(size_t n) const
|
||||
{
|
||||
base_iterator tmp = *this;
|
||||
|
||||
|
||||
for(;n != 0; --n)
|
||||
{
|
||||
++tmp;
|
||||
|
|
@ -678,7 +678,7 @@ private :
|
|||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
base_iterator& operator++(void)
|
||||
{
|
||||
subtree* parent = node->get_parent();
|
||||
|
|
@ -702,7 +702,7 @@ private :
|
|||
{
|
||||
node = &(--it)->get_node(0);
|
||||
}
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -719,13 +719,16 @@ private :
|
|||
|
||||
class iterator : public base_iterator
|
||||
{
|
||||
public :
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef subtree value_type;
|
||||
typedef size_t distance_type;
|
||||
typedef size_t difference_type;
|
||||
typedef subtree* pointer;
|
||||
typedef subtree& reference;
|
||||
public:
|
||||
|
||||
using base_iterator::node;
|
||||
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef subtree value_type;
|
||||
typedef size_t distance_type;
|
||||
typedef size_t difference_type;
|
||||
typedef subtree* pointer;
|
||||
typedef subtree& reference;
|
||||
|
||||
iterator() : base_iterator() {}
|
||||
iterator(subtree* n): base_iterator(n) {}
|
||||
|
|
@ -736,15 +739,20 @@ private :
|
|||
subtree* operator->(void) { return node; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class embedded_iterator : public base_iterator
|
||||
{
|
||||
public :
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef T value_type;
|
||||
typedef size_t distance_type;
|
||||
typedef size_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
public:
|
||||
|
||||
using base_iterator::node;
|
||||
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef T value_type;
|
||||
typedef size_t distance_type;
|
||||
typedef size_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
|
||||
embedded_iterator() : base_iterator() {}
|
||||
embedded_iterator(subtree* n): base_iterator(n) {}
|
||||
|
|
@ -757,7 +765,8 @@ private :
|
|||
|
||||
class base_const_iterator
|
||||
{
|
||||
public :
|
||||
public:
|
||||
|
||||
base_const_iterator() {}
|
||||
base_const_iterator(const subtree* n) { node = n; }
|
||||
|
||||
|
|
@ -802,19 +811,22 @@ private :
|
|||
}
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
const subtree* node;
|
||||
};
|
||||
|
||||
class const_iterator : public base_const_iterator
|
||||
{
|
||||
public :
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef const subtree value_type;
|
||||
typedef size_t distance_type;
|
||||
typedef size_t difference_type;
|
||||
typedef const subtree* pointer;
|
||||
typedef const subtree& reference;
|
||||
public:
|
||||
|
||||
using base_iterator::node;
|
||||
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef const subtree value_type;
|
||||
typedef size_t distance_type;
|
||||
typedef size_t difference_type;
|
||||
typedef const subtree* pointer;
|
||||
typedef const subtree& reference;
|
||||
|
||||
const_iterator() : base_const_iterator() {}
|
||||
const_iterator(const subtree* n): base_const_iterator(n) {}
|
||||
|
|
@ -827,7 +839,10 @@ private :
|
|||
|
||||
class embedded_const_iterator : public base_const_iterator
|
||||
{
|
||||
public :
|
||||
public:
|
||||
|
||||
using base_const_iterator::node;
|
||||
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef const T value_type;
|
||||
typedef size_t distance_type;
|
||||
|
|
@ -843,7 +858,7 @@ private :
|
|||
embedded_const_iterator operator+(size_t n) const
|
||||
{
|
||||
embedded_const_iterator tmp = *this;
|
||||
|
||||
|
||||
for(;n != 0; --n)
|
||||
{
|
||||
++tmp;
|
||||
|
|
@ -858,12 +873,12 @@ private :
|
|||
|
||||
/* Iterator access */
|
||||
|
||||
iterator begin(void) { return iterator(&operator[](0)); }
|
||||
iterator begin(void) { return iterator(&operator[](0)); }
|
||||
const_iterator begin(void) const { return const_iterator(&operator[](0)); }
|
||||
iterator end(void) { return iterator(0); }
|
||||
const_iterator end(void) const { return const_iterator(0);}
|
||||
|
||||
embedded_iterator ebegin(void) { return embedded_iterator(&operator[](0)); }
|
||||
embedded_iterator ebegin(void) { return embedded_iterator(&operator[](0)); }
|
||||
embedded_const_iterator ebegin(void) const { return embedded_const_iterator(&operator[](0)); }
|
||||
embedded_iterator eend(void) { return embedded_iterator(0); }
|
||||
embedded_const_iterator eend(void) const { return embedded_const_iterator(0);}
|
||||
|
|
@ -885,12 +900,12 @@ private :
|
|||
{
|
||||
if (!empty())
|
||||
pushed.push_back(_root);
|
||||
|
||||
|
||||
_root = t;
|
||||
|
||||
for (typename subtree::iterator it = _root.begin(); it != _root.end(); it++)
|
||||
{
|
||||
*it = pushed.back();
|
||||
*it = pushed.back();
|
||||
pushed.pop_back();
|
||||
}
|
||||
|
||||
|
|
@ -902,7 +917,7 @@ private :
|
|||
const subtree& back(void) const { return _root; }
|
||||
subtree& root(void) { return _root; }
|
||||
const subtree& root(void) const { return _root; }
|
||||
|
||||
|
||||
subtree& front(void) { return _root[0]; }
|
||||
const subtree& front(void) const { return _root[0]; }
|
||||
|
||||
|
|
@ -917,13 +932,13 @@ private :
|
|||
{ return get_cumulative(i); }
|
||||
|
||||
private :
|
||||
|
||||
|
||||
parse_tree& copy(const parse_tree& org)
|
||||
{
|
||||
_root = org._root;
|
||||
pushed = org.pushed;
|
||||
|
||||
return *this;
|
||||
{
|
||||
_root = org._root;
|
||||
pushed = org.pushed;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
parse_tree& copy(const subtree& sub)
|
||||
|
|
@ -939,25 +954,25 @@ private :
|
|||
namespace std
|
||||
{ // for use with stlport on MSVC
|
||||
|
||||
template <class T> inline
|
||||
template <class T> inline
|
||||
std::forward_iterator_tag iterator_category(typename gp_parse_tree::parse_tree<T>::embedded_iterator)
|
||||
{
|
||||
return std::forward_iterator_tag();
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
template <class T> inline
|
||||
ptrdiff_t* distance_type(typename gp_parse_tree::parse_tree<T>::embedded_iterator)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
template <class T> inline
|
||||
std::forward_iterator_tag iterator_category(typename gp_parse_tree::parse_tree<T>::iterator)
|
||||
{
|
||||
return std::forward_iterator_tag();
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
template <class T> inline
|
||||
ptrdiff_t* distance_type(typename gp_parse_tree::parse_tree<T>::iterator)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
|||
Reference in a new issue