zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #24691
[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.
Commit message:
renamed files implementing our various item sequences + fixed bug in SingletonItemSequence::next()
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178040
renamed files implementing our various item sequences + fixed bug in SingletonItemSequence::next()
--
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178040
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.cpp'
--- modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-05-28 00:58:27 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-08-01 11:25:40 +0000
@@ -424,6 +424,7 @@
lIter->open();
lIter->next(lItem);
lIter->close();
+ lIter = NULL;
if (lItem.isNull())
return NULL;
=== modified file 'src/api/CMakeLists.txt'
--- src/api/CMakeLists.txt 2013-06-21 06:20:46 +0000
+++ src/api/CMakeLists.txt 2013-08-01 11:25:40 +0000
@@ -43,11 +43,11 @@
vectoriterator.cpp
iterator_singleton.cpp
serialization_callback.cpp
- vector_item_sequence.cpp
- singleton_item_sequence.cpp
- invoke_item_sequence.cpp
- item_sequence_chainer.cpp
- empty_sequence.cpp
+ item_seq_vector.cpp
+ item_seq_singleton.cpp
+ item_seq_invoke.cpp
+ item_seq_chainer.cpp
+ item_seq_empty.cpp
serializerimpl.cpp
base64impl.cpp
base64_streambuf.cpp
=== renamed file 'src/api/item_sequence_chainer.cpp' => 'src/api/item_seq_chainer.cpp'
=== renamed file 'src/api/empty_sequence.cpp' => 'src/api/item_seq_empty.cpp'
--- src/api/empty_sequence.cpp 2013-08-01 10:36:40 +0000
+++ src/api/item_seq_empty.cpp 2013-08-01 11:25:40 +0000
@@ -17,34 +17,45 @@
#include <zorba/singleton_item_sequence.h>
#include <zorba/empty_sequence.h>
+
#include "diagnostics/assert.h"
-namespace zorba {
+namespace zorba
+{
Iterator_t EmptySequence::getIterator()
{
return new InternalIterator(this);
}
-EmptySequence::InternalIterator::InternalIterator(ItemSequence *item_sequence) : theItemSequence(item_sequence)
-{
- theIsOpen = false;
-}
+
+EmptySequence::InternalIterator::InternalIterator(ItemSequence* seq)
+ :
+ theItemSequence(seq),
+ theIsOpen(false)
+{
+}
+
+
+bool EmptySequence::InternalIterator::isOpen() const
+{
+ return theIsOpen;
+}
+
void EmptySequence::InternalIterator::open()
{
+ ZORBA_ASSERT(!theIsOpen);
theIsOpen = true;
}
+
void EmptySequence::InternalIterator::close()
{
+ ZORBA_ASSERT(theIsOpen);
theIsOpen = false;
}
-bool EmptySequence::InternalIterator::isOpen() const
-{
- return theIsOpen;
-}
bool EmptySequence::InternalIterator::next(Item& aItem)
{
=== renamed file 'src/api/invoke_item_sequence.cpp' => 'src/api/item_seq_invoke.cpp'
--- src/api/invoke_item_sequence.cpp 2013-02-07 17:24:36 +0000
+++ src/api/item_seq_invoke.cpp 2013-08-01 11:25:40 +0000
@@ -16,30 +16,30 @@
#include "stdafx.h"
#include <zorba/iterator.h>
-#include "api/invoke_item_sequence.h"
+
+#include "api/item_seq_invoke.h"
#include "api/xqueryimpl.h"
#include "api/staticcontextimpl.h"
-namespace zorba {
+namespace zorba
+{
-InvokeItemSequence::InvokeItemSequence(
- XQueryImpl* aQuery,
- Iterator_t aIter,
- StaticContext* aSctx)
- : theIterator(aIter),
- theXQuery(aQuery),
- theSctx(aSctx)
+InvokeItemSequence::InvokeItemSequence(const XQuery_t& query, StaticContext* sctx)
+ :
+ theXQuery(query),
+ theSctx(sctx)
{
}
+
InvokeItemSequence::~InvokeItemSequence()
{
- delete theXQuery;
}
+
Iterator_t InvokeItemSequence::getIterator()
{
- return theIterator;
+ return theXQuery->iterator();
}
} // namespace zorba
=== renamed file 'src/api/invoke_item_sequence.h' => 'src/api/item_seq_invoke.h'
--- src/api/invoke_item_sequence.h 2013-02-07 17:24:36 +0000
+++ src/api/item_seq_invoke.h 2013-08-01 11:25:40 +0000
@@ -14,47 +14,48 @@
* limitations under the License.
*/
#pragma once
-#ifndef ZORBA_ITERATOR_ITEM_SEQUENCE_API_H
-#define ZORBA_ITERATOR_ITEM_SEQUENCE_API_H
+#ifndef ZORBA_API_ITEM_SEQUENCE_INVOKE
+#define ZORBA_API_ITEM_SEQUENCE_INVOKE
#include <zorba/config.h>
#include <zorba/item_sequence.h>
namespace zorba {
- class XQueryImpl;
-
- /** \brief A sequence backed by an iterator and it's corresponding query.
- *
- * See ItemSequence
- */
- class ZORBA_DLL_PUBLIC InvokeItemSequence : public ItemSequence
- {
- public:
- /**
- * Construct a sequence using an Iterator and its XQuery
- */
- InvokeItemSequence(
- XQueryImpl* aQuery,
- Iterator_t aIter,
- StaticContext* aSctx);
-
- /** \brief Destructor
- */
- virtual ~InvokeItemSequence();
-
- /** \brief get the Iterator over the items
- * @return an iterator over the items
- */
- virtual Iterator_t getIterator();
-
- protected:
- Iterator_t theIterator;
- XQueryImpl* theXQuery; // have ownership and destroy in destructor
- // used to make sure the ctx lives longer then this sequence
- StaticContext_t theSctx;
-
- }; /* class InvokeItemSequence */
+class XQueryImpl;
+
+/*******************************************************************************
+ An ItemSequence representing the result of a function invocation via the c++
+ API (see StaticContextImpl::invoke() method).
+
+ theXQuery:
+ ----------
+ The XQuery obj that is created internally to execute the function invocation
+ This Xquery obj is owned by "this".
+
+ theIterator:
+ ------------
+ The ResultIteratorImpl obj for iterating over the result of theXQuery.
+
+ theSctx:
+ --------
+ A smart ptr to the StaticContextImpl that created this InvokeItemSequence.
+ Used to make sure the ctx lives longer then this sequence.
+********************************************************************************/
+class InvokeItemSequence : public ItemSequence
+{
+ public:
+ InvokeItemSequence(const XQuery_t& query, StaticContext* sctx);
+
+ virtual ~InvokeItemSequence();
+
+ virtual Iterator_t getIterator();
+
+ protected:
+ XQuery_t theXQuery;
+
+ StaticContext_t theSctx;
+};
} // namespace zorba
#endif
=== renamed file 'src/api/singleton_item_sequence.cpp' => 'src/api/item_seq_singleton.cpp'
--- src/api/singleton_item_sequence.cpp 2013-08-01 10:36:40 +0000
+++ src/api/item_seq_singleton.cpp 2013-08-01 11:25:40 +0000
@@ -21,47 +21,59 @@
namespace zorba {
-SingletonItemSequence::SingletonItemSequence(
- const Item& aItem)
- : theItem(aItem)
+SingletonItemSequence::SingletonItemSequence(const Item& aItem)
+ :
+ theItem(aItem)
{
}
+
Iterator_t SingletonItemSequence::getIterator()
{
return new InternalIterator(this);
}
-SingletonItemSequence::InternalIterator::InternalIterator(SingletonItemSequence *item_sequence) : theItemSequence(item_sequence)
-{
- theIsOpen = false;
- theIsDone = false;
-}
+
+SingletonItemSequence::InternalIterator::InternalIterator(SingletonItemSequence* seq)
+ :
+ theItemSequence(seq),
+ theIsOpen(false),
+ theIsDone(false)
+{
+}
+
+
+bool SingletonItemSequence::InternalIterator::isOpen() const
+{
+ return theIsOpen;
+}
+
void SingletonItemSequence::InternalIterator::open()
{
+ ZORBA_ASSERT(!theIsOpen);
theIsOpen = true;
theIsDone = false;
}
+
void SingletonItemSequence::InternalIterator::close()
{
+ ZORBA_ASSERT(theIsOpen);
theIsOpen = false;
}
-bool SingletonItemSequence::InternalIterator::isOpen() const
-{
- return theIsOpen;
-}
bool SingletonItemSequence::InternalIterator::next(Item& aItem)
{
ZORBA_ASSERT(theIsOpen);
- if(theIsDone)
+
+ if (theIsDone)
return false;
+
aItem = theItemSequence->theItem;
theIsDone = true;
- return !theItemSequence->theItem.isNull();
+ return true;
}
} // namespace zorba
=== renamed file 'src/api/vector_item_sequence.cpp' => 'src/api/item_seq_vector.cpp'
--- src/api/vector_item_sequence.cpp 2013-08-01 10:36:40 +0000
+++ src/api/item_seq_vector.cpp 2013-08-01 11:25:40 +0000
@@ -16,16 +16,18 @@
#include "stdafx.h"
#include <zorba/vector_item_sequence.h>
-
#include <zorba/item.h>
+
#include "diagnostics/assert.h"
-namespace zorba {
+namespace zorba
+{
-VectorItemSequence::VectorItemSequence(
- const std::vector<Item>& aSequence)
- : theSequence(aSequence)
-{ }
+VectorItemSequence::VectorItemSequence(const std::vector<Item>& seq)
+ :
+ theSequence(seq)
+{
+}
Iterator_t VectorItemSequence::getIterator()
@@ -33,39 +35,52 @@
return new InternalIterator(this);
}
-VectorItemSequence::InternalIterator::InternalIterator(VectorItemSequence *item_sequence) : theItemSequence(item_sequence)
-{
- theIsOpen = false;
-}
+
+VectorItemSequence::InternalIterator::InternalIterator(VectorItemSequence* seq)
+ :
+ theItemSequence(seq),
+ theIsOpen(false)
+{
+}
+
+
+bool VectorItemSequence::InternalIterator::isOpen() const
+{
+ return theIsOpen;
+}
+
void VectorItemSequence::InternalIterator::open()
{
+ ZORBA_ASSERT(!theIsOpen);
theIsOpen = true;
theIterator = theItemSequence->theSequence.begin();
theEnd = theItemSequence->theSequence.end();
}
+
void VectorItemSequence::InternalIterator::close()
{
+ ZORBA_ASSERT(theIsOpen);
theIsOpen = false;
}
-bool VectorItemSequence::InternalIterator::isOpen() const
-{
- return theIsOpen;
-}
-bool
-VectorItemSequence::InternalIterator::next(Item& val)
+bool VectorItemSequence::InternalIterator::next(Item& val)
{
ZORBA_ASSERT(theIsOpen);
- if (theIterator == theEnd) {
- return false;
+
+ if (theIterator == theEnd)
+ {
+ return false;
}
+
val = *theIterator;
++theIterator;
+
return true;
}
+
} // namespace zorba
/* vim:set et sw=2 ts=2: */
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-07-01 09:26:16 +0000
+++ src/api/staticcontextimpl.cpp 2013-08-01 11:25:40 +0000
@@ -35,7 +35,7 @@
#include "api/functionimpl.h"
#include "api/annotationimpl.h"
#include "api/xqueryimpl.h"
-#include "api/invoke_item_sequence.h"
+#include "api/item_seq_invoke.h"
#include "api/staticcollectionmanagerimpl.h"
#include "api/vectoriterator.h"
@@ -1570,9 +1570,7 @@
// because the iterator returned as a result of the query
// contains a reference to the query in order to do cleanup work.
// The same is true for this sctx
- Iterator_t lIter = impl->iterator();
return new InvokeItemSequence(impl.release(),
- lIter,
const_cast<StaticContextImpl*>(this));
}
catch (ZorbaException const& e)
Follow ups