zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #07317
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/serializer into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/serializer/+merge/101441
file renaming + comments + cosmetic
--
https://code.launchpad.net/~zorba-coders/zorba/serializer/+merge/101441
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/annotations/annotations.cpp'
--- src/annotations/annotations.cpp 2012-04-08 21:39:25 +0000
+++ src/annotations/annotations.cpp 2012-04-10 20:15:33 +0000
@@ -22,13 +22,14 @@
#include "compiler/expression/expr.h"
-#include "zorbaserialization/serialization_engine.h"
-
#include "diagnostics/assert.h"
#include "diagnostics/util_macros.h"
#include "system/globalenv.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba {
SERIALIZABLE_CLASS_VERSIONS(AnnotationInternal)
=== modified file 'src/api/dynamiccontextimpl.cpp'
--- src/api/dynamiccontextimpl.cpp 2012-03-28 05:19:57 +0000
+++ src/api/dynamiccontextimpl.cpp 2012-04-10 20:15:33 +0000
@@ -53,6 +53,9 @@
#include "diagnostics/assert.h"
#include "diagnostics/util_macros.h"
+#include "diagnostics/xquery_exception.h"
+#include "diagnostics/zorba_exception.h"
+#include "diagnostics/dict.h"
namespace zorba {
=== modified file 'src/api/xqueryimpl.cpp'
--- src/api/xqueryimpl.cpp 2012-04-08 21:39:25 +0000
+++ src/api/xqueryimpl.cpp 2012-04-10 20:15:33 +0000
@@ -71,6 +71,7 @@
#include "zorbaserialization/xml_archiver.h"
#include "zorbaserialization/bin_archiver.h"
#include "zorbaserialization/class_serializer.h"
+#include "zorbaserialization/serialize_zorba_types.h"
#ifdef ZORBA_WITH_DEBUGGER
#include "debugger/debugger_server.h"
=== modified file 'src/capi/csequence.cpp'
--- src/capi/csequence.cpp 2012-03-28 05:19:57 +0000
+++ src/capi/csequence.cpp 2012-04-10 20:15:33 +0000
@@ -27,6 +27,8 @@
#include <zorbamisc/ns_consts.h>
#include <zorbatypes/numconversions.h>
+#include "util/string_util.h"
+
#include "error.h"
using namespace zorba;
=== modified file 'src/compiler/api/compilercb.cpp'
--- src/compiler/api/compilercb.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/api/compilercb.cpp 2012-04-10 20:15:33 +0000
@@ -26,9 +26,11 @@
#include "system/properties.h"
-#include "zorbaserialization/serialization_engine.h"
#include "functions/udf.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/compiler/expression/expr.cpp'
--- src/compiler/expression/expr.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/expr.cpp 2012-04-10 20:15:33 +0000
@@ -43,6 +43,9 @@
#include "compiler/expression/expr_visitor.h"
#include "compiler/parser/parse_constants.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
#include "store/api/store.h"
#include "store/api/item_factory.h"
@@ -534,6 +537,13 @@
}
+void promote_expr::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (cast_base_expr*)this);
+ ar & theFnQName;
+}
+
+
expr_t promote_expr::clone(substitution_t& subst) const
{
return new promote_expr(theSctx,
=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h 2012-03-28 05:19:57 +0000
+++ src/compiler/expression/expr.h 2012-04-10 20:15:33 +0000
@@ -35,6 +35,8 @@
#include "types/node_test.h"
+#include "zorbaserialization/class_serializer.h"
+
#include "store/api/item.h"
namespace zorba
@@ -385,11 +387,7 @@
public:
SERIALIZABLE_CLASS(promote_expr)
SERIALIZABLE_CLASS_CONSTRUCTOR2(promote_expr, cast_base_expr)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (cast_base_expr*)this);
- ar & theFnQName;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
promote_expr(
=== modified file 'src/compiler/expression/expr_base.cpp'
--- src/compiler/expression/expr_base.cpp 2012-03-28 05:19:57 +0000
+++ src/compiler/expression/expr_base.cpp 2012-04-10 20:15:33 +0000
@@ -36,8 +36,9 @@
#include "diagnostics/xquery_diagnostics.h"
#include "diagnostics/assert.h"
-#include "zorbaserialization/serialization_engine.h"
-
+#include "zorbaserialization/serialize_basic_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+#include "zorbaserialization/serialize_template_types.h"
namespace zorba
{
=== modified file 'src/compiler/expression/flwor_expr.cpp'
--- src/compiler/expression/flwor_expr.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/flwor_expr.cpp 2012-04-10 20:15:33 +0000
@@ -32,7 +32,9 @@
#include "compiler/expression/expr.h"
#include "compiler/expression/expr_visitor.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/compiler/expression/fo_expr.cpp'
--- src/compiler/expression/fo_expr.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/fo_expr.cpp 2012-04-10 20:15:33 +0000
@@ -29,6 +29,9 @@
#include "diagnostics/assert.h"
#include "diagnostics/util_macros.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/compiler/expression/function_item_expr.cpp'
--- src/compiler/expression/function_item_expr.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/function_item_expr.cpp 2012-04-10 20:15:33 +0000
@@ -23,6 +23,8 @@
#include "functions/udf.h"
#include "functions/signature.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
namespace zorba {
@@ -48,6 +50,14 @@
}
+void dynamic_function_invocation_expr::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (expr*)this);
+ ar & theExpr;
+ ar & theArgs;
+}
+
+
void dynamic_function_invocation_expr::compute_scripting_kind()
{
// TODO ????
=== modified file 'src/compiler/expression/function_item_expr.h'
--- src/compiler/expression/function_item_expr.h 2012-03-28 05:19:57 +0000
+++ src/compiler/expression/function_item_expr.h 2012-04-10 20:15:33 +0000
@@ -42,12 +42,7 @@
public:
SERIALIZABLE_CLASS(dynamic_function_invocation_expr)
SERIALIZABLE_CLASS_CONSTRUCTOR2(dynamic_function_invocation_expr, expr)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (expr*)this);
- ar & theExpr;
- ar & theArgs;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
protected:
expr_t theExpr;
=== modified file 'src/compiler/expression/path_expr.cpp'
--- src/compiler/expression/path_expr.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/path_expr.cpp 2012-04-10 20:15:33 +0000
@@ -20,15 +20,13 @@
#include "system/globalenv.h"
-//#include "types/root_typemanager.h"
-
#include "context/static_context.h"
#include "compiler/expression/path_expr.h"
#include "compiler/expression/expr_visitor.h"
-#include "zorbaserialization/serialization_engine.h"
-
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
namespace zorba
{
=== modified file 'src/compiler/expression/script_exprs.cpp'
--- src/compiler/expression/script_exprs.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/script_exprs.cpp 2012-04-10 20:15:33 +0000
@@ -25,6 +25,9 @@
#include "diagnostics/assert.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/compiler/expression/update_exprs.cpp'
--- src/compiler/expression/update_exprs.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/update_exprs.cpp 2012-04-10 20:15:33 +0000
@@ -21,6 +21,9 @@
#include "diagnostics/assert.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/compiler/expression/var_expr.cpp'
--- src/compiler/expression/var_expr.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/var_expr.cpp 2012-04-10 20:15:33 +0000
@@ -24,7 +24,8 @@
#include "types/typeops.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
#include "diagnostics/assert.h"
=== modified file 'src/compiler/parser/query_loc.cpp'
--- src/compiler/parser/query_loc.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/parser/query_loc.cpp 2012-04-10 20:15:33 +0000
@@ -20,7 +20,7 @@
#include "compiler/parser/query_loc.h"
-#include "zorbaserialization/template_serializer.h"
+#include "zorbaserialization/serialize_template_types.h"
namespace zorba
=== modified file 'src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp 2012-03-28 05:19:57 +0000
+++ src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp 2012-04-10 20:15:33 +0000
@@ -24,12 +24,19 @@
#include <compiler/parsetree/parsenode_visitor.h>
#include <compiler/parser/xqdoc_comment.h>
+
+#include "diagnostics/zorba_exception.h"
+#include "diagnostics/xquery_exception.h"
+#include "diagnostics/dict.h"
+
#include "types/root_typemanager.h"
+
#include "store/api/item_factory.h"
#include "store/api/item.h"
#include "store/api/store.h"
#include "store/api/copymode.h"
#include "store/api/iterator.h"
+
#include "system/globalenv.h"
using namespace std;
=== modified file 'src/compiler/rewriter/tools/udf_graph.cpp'
--- src/compiler/rewriter/tools/udf_graph.cpp 2012-03-28 05:19:57 +0000
+++ src/compiler/rewriter/tools/udf_graph.cpp 2012-04-10 20:15:33 +0000
@@ -39,6 +39,7 @@
#include "util/indent.h"
#include "diagnostics/util_macros.h"
+#include "diagnostics/xquery_exception.h"
namespace zorba
=== modified file 'src/compiler/translator/prolog_graph.cpp'
--- src/compiler/translator/prolog_graph.cpp 2012-03-28 05:19:57 +0000
+++ src/compiler/translator/prolog_graph.cpp 2012-04-10 20:15:33 +0000
@@ -20,8 +20,11 @@
#include "context/static_context.h"
#include "util/string_util.h"
+
#include "zorbatypes/zstring.h"
+#include "diagnostics/xquery_exception.h"
+
namespace zorba
{
=== modified file 'src/compiler/xqddf/collection_decl.cpp'
--- src/compiler/xqddf/collection_decl.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/xqddf/collection_decl.cpp 2012-04-10 20:15:33 +0000
@@ -22,6 +22,9 @@
#include "types/typeimpl.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba {
SERIALIZABLE_CLASS_VERSIONS(StaticallyKnownCollection)
=== modified file 'src/compiler/xqddf/collection_decl.h'
--- src/compiler/xqddf/collection_decl.h 2012-03-28 05:19:57 +0000
+++ src/compiler/xqddf/collection_decl.h 2012-04-10 20:15:33 +0000
@@ -24,7 +24,7 @@
#include "types/typeconstants.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
namespace zorba
{
=== modified file 'src/context/decimal_format.cpp'
--- src/context/decimal_format.cpp 2012-04-08 21:39:25 +0000
+++ src/context/decimal_format.cpp 2012-04-10 20:15:33 +0000
@@ -19,6 +19,9 @@
#include "context/decimal_format.h"
#include "common/shared_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+#include "zorbaserialization/serialize_template_types.h"
+
#include "store/api/item.h"
namespace zorba {
@@ -37,6 +40,15 @@
{
}
+
+void DecimalFormat::serialize(::zorba::serialization::Archiver& ar)
+{
+ ar & theIsDefault;
+ ar & theName;
+ ar & theParams;
+}
+
+
bool DecimalFormat::isPictureStringProperty(zstring propertyName)
{
if (propertyName == "decimal-separator" ||
=== modified file 'src/context/decimal_format.h'
--- src/context/decimal_format.h 2012-03-28 05:19:57 +0000
+++ src/context/decimal_format.h 2012-04-10 20:15:33 +0000
@@ -20,8 +20,13 @@
#include <vector>
#include "common/shared_types.h"
+
#include "zorbatypes/zstring.h"
-#include "zorbaserialization/serialization_engine.h"
+
+#include "zorbaserialization/class_serializer.h"
+
+#include "store/api/item.h"
+
namespace zorba
{
@@ -39,12 +44,7 @@
public:
SERIALIZABLE_CLASS(DecimalFormat)
SERIALIZABLE_CLASS_CONSTRUCTOR2(DecimalFormat, SimpleRCObject)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- ar & theIsDefault;
- ar & theName;
- ar & theParams;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
protected:
// Returns true if the given property represents characters used in a
=== modified file 'src/context/namespace_context.cpp'
--- src/context/namespace_context.cpp 2012-04-08 21:39:25 +0000
+++ src/context/namespace_context.cpp 2012-04-10 20:15:33 +0000
@@ -21,7 +21,12 @@
#include "compiler/parser/query_loc.h"
-namespace zorba {
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
+
+namespace zorba
+{
SERIALIZABLE_CLASS_VERSIONS(namespace_context)
@@ -48,7 +53,6 @@
********************************************************************************/
void namespace_context::serialize(::zorba::serialization::Archiver& ar)
{
- //serialize_baseclass(ar, (SimpleRCObject*)this);
ar & m_sctx;
ar & m_parent;
ar & m_bindings;
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2012-04-08 21:39:25 +0000
+++ src/context/static_context.cpp 2012-04-10 20:15:33 +0000
@@ -23,7 +23,6 @@
#include <zorba/serialization_callback.h>
#include "functions/udf.h"
-#include "zorbaserialization/serialization_engine.h"
#include "zorbamisc/ns_consts.h"
#include "util/string_util.h"
@@ -72,6 +71,9 @@
#include "compiler/translator/module_version.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+#include "zorbaserialization/serialize_template_types.h"
+
#include "store/api/store.h"
#include "store/api/item_factory.h"
#include "store/api/iterator.h"
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2012-03-28 05:19:57 +0000
+++ src/context/static_context.h 2012-04-10 20:15:33 +0000
@@ -26,6 +26,8 @@
#include <zorba/config.h>
#include <zorba/api_shared_types.h>
#include <zorba/function.h>
+#include <zorba/error.h>
+#include <zorba/diagnostic_list.h>
#ifdef WIN32
#include "store/api/item.h"
=== modified file 'src/debugger/debugger_commons.h'
--- src/debugger/debugger_commons.h 2012-03-28 05:19:57 +0000
+++ src/debugger/debugger_commons.h 2012-04-10 20:15:33 +0000
@@ -25,7 +25,7 @@
#include "compiler/parser/query_loc.h"
#include "runtime/core/item_iterator.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
#include "zorbatypes/zstring.h"
#include "debugger_common.h"
=== modified file 'src/diagnostics/user_error.cpp'
--- src/diagnostics/user_error.cpp 2012-03-28 05:19:57 +0000
+++ src/diagnostics/user_error.cpp 2012-04-10 20:15:33 +0000
@@ -16,7 +16,9 @@
#include "stdafx.h"
#include <zorba/error.h>
-#include "zorbaserialization/serialization_engine.h"
+
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
namespace zorba {
=== modified file 'src/functions/external_function.cpp'
--- src/functions/external_function.cpp 2012-04-08 21:39:25 +0000
+++ src/functions/external_function.cpp 2012-04-10 20:15:33 +0000
@@ -22,6 +22,9 @@
#include "diagnostics/util_macros.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/functions/function.cpp'
--- src/functions/function.cpp 2012-04-08 21:39:25 +0000
+++ src/functions/function.cpp 2012-04-10 20:15:33 +0000
@@ -29,6 +29,8 @@
#include "diagnostics/assert.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
namespace zorba {
=== modified file 'src/functions/signature.cpp'
--- src/functions/signature.cpp 2012-04-08 21:39:25 +0000
+++ src/functions/signature.cpp 2012-04-10 20:15:33 +0000
@@ -16,9 +16,14 @@
#include "stdafx.h"
#include "signature.h"
+
#include "store/api/item.h"
+
#include "types/typeops.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
#include <iterator>
@@ -36,68 +41,68 @@
:
theQName(name),
theIsVariadic(variadic)
-{
- theTypes.push_back(returnType);
- theTypes.push_back(paramType1);
-}
-
-
-signature::signature(
- const store::Item_t& name,
- const xqtref_t& returnType)
- :
- theQName(name),
- theIsVariadic(false)
-{
- theTypes.push_back(returnType);
-}
-
-
-signature::signature(
- const store::Item_t& name,
- const xqtref_t& paramType1,
- const xqtref_t& returnType)
- :
- theQName(name),
- theIsVariadic(false)
-{
- theTypes.push_back(returnType);
- theTypes.push_back(paramType1);
-}
-
-
-signature::signature(
- const store::Item_t& name,
- const xqtref_t& paramType1,
- const xqtref_t& paramType2,
- const xqtref_t& returnType)
- :
- theQName(name),
- theIsVariadic(false)
-{
- theTypes.push_back(returnType);
- theTypes.push_back(paramType1);
- theTypes.push_back(paramType2);
-}
-
-
-signature::signature(
- const store::Item_t& name,
- const xqtref_t& paramType1,
- const xqtref_t& paramType2,
+{
+ theTypes.push_back(returnType);
+ theTypes.push_back(paramType1);
+}
+
+
+signature::signature(
+ const store::Item_t& name,
+ const xqtref_t& returnType)
+ :
+ theQName(name),
+ theIsVariadic(false)
+{
+ theTypes.push_back(returnType);
+}
+
+
+signature::signature(
+ const store::Item_t& name,
+ const xqtref_t& paramType1,
+ const xqtref_t& returnType)
+ :
+ theQName(name),
+ theIsVariadic(false)
+{
+ theTypes.push_back(returnType);
+ theTypes.push_back(paramType1);
+}
+
+
+signature::signature(
+ const store::Item_t& name,
+ const xqtref_t& paramType1,
+ const xqtref_t& paramType2,
+ const xqtref_t& returnType)
+ :
+ theQName(name),
+ theIsVariadic(false)
+{
+ theTypes.push_back(returnType);
+ theTypes.push_back(paramType1);
+ theTypes.push_back(paramType2);
+}
+
+
+signature::signature(
+ const store::Item_t& name,
+ const xqtref_t& paramType1,
+ const xqtref_t& paramType2,
const xqtref_t& paramType3,
- const xqtref_t& returnType)
- :
- theQName(name),
- theIsVariadic(false)
-{
- theTypes.push_back(returnType);
- theTypes.push_back(paramType1);
- theTypes.push_back(paramType2);
+ const xqtref_t& returnType)
+ :
+ theQName(name),
+ theIsVariadic(false)
+{
+ theTypes.push_back(returnType);
+ theTypes.push_back(paramType1);
+ theTypes.push_back(paramType2);
theTypes.push_back(paramType3);
}
-
-
+
+
signature::signature(
const store::Item_t& name,
const xqtref_t& paramType1,
=== modified file 'src/functions/udf.cpp'
--- src/functions/udf.cpp 2012-04-08 21:39:25 +0000
+++ src/functions/udf.cpp 2012-04-10 20:15:33 +0000
@@ -33,6 +33,9 @@
#include "types/typeops.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
#include "store/api/index.h" // needed for destruction of the cache
=== modified file 'src/runtime/base/plan_iterator.h'
--- src/runtime/base/plan_iterator.h 2012-04-08 21:39:25 +0000
+++ src/runtime/base/plan_iterator.h 2012-04-10 20:15:33 +0000
@@ -27,7 +27,9 @@
#include "compiler/parser/query_loc.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
#if ZORBA_BATCHING_TYPE == 1
=== modified file 'src/runtime/core/item_iterator.cpp'
--- src/runtime/core/item_iterator.cpp 2012-04-08 21:39:25 +0000
+++ src/runtime/core/item_iterator.cpp 2012-04-10 20:15:33 +0000
@@ -49,6 +49,17 @@
/*******************************************************************************
********************************************************************************/
+void SingletonIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (NoaryBaseIterator<SingletonIterator,
+ PlanIteratorState>*)this);
+ ar & theValue;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
bool SingletonIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
PlanIteratorState* state;
@@ -81,7 +92,19 @@
theElseIter(aElseIter),
theIsUpdating(aIsUpdating),
theIsBooleanIter(aIsBooleanIter)
-{ }
+{
+}
+
+
+void IfThenElseIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (Batcher<IfThenElseIterator>*)this);
+ ar & theCondIter;
+ ar & theThenIter;
+ ar & theElseIter;
+ ar & theIsUpdating;
+ ar & theIsBooleanIter;
+}
void IfThenElseIterator::accept(PlanIterVisitor& v) const
=== modified file 'src/runtime/core/item_iterator.h'
--- src/runtime/core/item_iterator.h 2012-03-28 05:19:57 +0000
+++ src/runtime/core/item_iterator.h 2012-04-10 20:15:33 +0000
@@ -48,18 +48,13 @@
SERIALIZABLE_CLASS_CONSTRUCTOR2T(SingletonIterator,
NoaryBaseIterator<SingletonIterator,
PlanIteratorState>)
- void serialize(::zorba::serialization::Archiver &ar)
- {
- serialize_baseclass(ar, (NoaryBaseIterator<SingletonIterator,
- PlanIteratorState>*)this);
- ar & theValue;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
SingletonIterator(
- static_context* sctx,
- const QueryLoc& loc,
- const store::Item* value)
+ static_context* sctx,
+ const QueryLoc& loc,
+ const store::Item* value)
:
NoaryBaseIterator<SingletonIterator, PlanIteratorState>(sctx, loc),
theValue(const_cast<store::Item*>(value))
@@ -99,15 +94,8 @@
public:
SERIALIZABLE_CLASS(IfThenElseIterator)
SERIALIZABLE_CLASS_CONSTRUCTOR2(IfThenElseIterator, Batcher<IfThenElseIterator>)
- void serialize(::zorba::serialization::Archiver &ar)
- {
- serialize_baseclass(ar, (Batcher<IfThenElseIterator>*)this);
- ar & theCondIter;
- ar & theThenIter;
- ar & theElseIter;
- ar & theIsUpdating;
- ar & theIsBooleanIter;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
+
public:
/**
* Constructor
=== modified file 'src/runtime/core/path_iterators.cpp'
--- src/runtime/core/path_iterators.cpp 2012-04-08 21:39:25 +0000
+++ src/runtime/core/path_iterators.cpp 2012-04-10 20:15:33 +0000
@@ -347,6 +347,12 @@
/*******************************************************************************
********************************************************************************/
+void SelfAxisIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (AxisIterator<SelfAxisIterator, SelfAxisState>*)this);
+}
+
+
bool SelfAxisIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
SelfAxisState* state;
@@ -396,6 +402,13 @@
}
+void AttributeAxisIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (AxisIterator<AttributeAxisIterator,
+ AttributeAxisState>*)this);
+}
+
+
bool AttributeAxisIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
store::Item* attr;
@@ -452,6 +465,12 @@
/*******************************************************************************
********************************************************************************/
+void ParentAxisIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (AxisIterator<ParentAxisIterator, ParentAxisState>*)this);
+}
+
+
bool ParentAxisIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
ParentAxisState* state;
@@ -485,6 +504,13 @@
/*******************************************************************************
Returns the ancestors in document order (top-down)
********************************************************************************/
+void AncestorAxisIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar,
+ (AxisIterator<AncestorAxisIterator, AncestorAxisState>*)this);
+}
+
+
bool AncestorAxisIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
store::Item* ancestor;
@@ -534,6 +560,13 @@
/*******************************************************************************
Returns the ancestors in reverse document order (bottom-up)
********************************************************************************/
+void AncestorReverseAxisIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar,
+ (AxisIterator<AncestorReverseAxisIterator, AncestorReverseAxisState>*)this);
+}
+
+
bool AncestorReverseAxisIterator::nextImpl(
store::Item_t& result,
PlanState& planState) const
@@ -594,6 +627,13 @@
/*******************************************************************************
********************************************************************************/
+void AncestorSelfAxisIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar,
+ (AxisIterator<AncestorSelfAxisIterator, AncestorAxisState>*)this);
+}
+
+
bool AncestorSelfAxisIterator::nextImpl(
store::Item_t& result,
PlanState& planState) const
=== modified file 'src/runtime/core/path_iterators.h'
--- src/runtime/core/path_iterators.h 2012-03-28 05:19:57 +0000
+++ src/runtime/core/path_iterators.h 2012-04-10 20:15:33 +0000
@@ -152,7 +152,7 @@
void serialize(::zorba::serialization::Archiver& ar)
{
- serialize_baseclass(ar, (UnaryBaseIterator<AxisIter, State>*)this);
+ serialize_baseclass(ar, (UnaryBaseIterator<AxisIter, AxisState>*)this);
SERIALIZE_TYPEMANAGER(TypeManager, theTypeManager);
SERIALIZE_ENUM(match_test_t, theTestKind);
SERIALIZE_ENUM(match_test_t, theDocTestKind);
@@ -189,14 +189,10 @@
public:
SERIALIZABLE_CLASS(SelfAxisIterator);
- SERIALIZABLE_CLASS_CONSTRUCTOR2T(
- SelfAxisIterator,
+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(SelfAxisIterator,
AxisIterator<SelfAxisIterator, SelfAxisState>);
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (AxisIterator<SelfAxisIterator, SelfAxisState>*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
SelfAxisIterator(static_context* sctx, const QueryLoc& loc, PlanIter_t input)
@@ -237,15 +233,10 @@
public:
SERIALIZABLE_CLASS(AttributeAxisIterator);
- SERIALIZABLE_CLASS_CONSTRUCTOR2T(
- AttributeAxisIterator,
+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(AttributeAxisIterator,
AxisIterator<AttributeAxisIterator, AttributeAxisState>);
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (AxisIterator<AttributeAxisIterator,
- AttributeAxisState>*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
AttributeAxisIterator(static_context* sctx, const QueryLoc& loc, PlanIter_t input)
@@ -275,14 +266,10 @@
public:
SERIALIZABLE_CLASS(ParentAxisIterator);
- SERIALIZABLE_CLASS_CONSTRUCTOR2T(
- ParentAxisIterator,
+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(ParentAxisIterator,
AxisIterator<ParentAxisIterator, ParentAxisState>);
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (AxisIterator<ParentAxisIterator, ParentAxisState>*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
ParentAxisIterator(static_context* sctx, const QueryLoc& loc, PlanIter_t input)
@@ -315,15 +302,10 @@
public:
SERIALIZABLE_CLASS(AncestorAxisIterator);
- SERIALIZABLE_CLASS_CONSTRUCTOR2T(
- AncestorAxisIterator,
+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(AncestorAxisIterator,
AxisIterator<AncestorAxisIterator, AncestorAxisState>);
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar,
- (AxisIterator<AncestorAxisIterator, AncestorAxisState>*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
AncestorAxisIterator(static_context* sctx, const QueryLoc& loc, PlanIter_t input)
@@ -360,11 +342,7 @@
AncestorReverseAxisIterator,
AxisIterator<AncestorReverseAxisIterator, AncestorReverseAxisState>);
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar,
- (AxisIterator<AncestorReverseAxisIterator, AncestorReverseAxisState>*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
AncestorReverseAxisIterator(static_context* sctx, const QueryLoc& loc, PlanIter_t input)
@@ -394,11 +372,7 @@
AncestorSelfAxisIterator,
AxisIterator<AncestorSelfAxisIterator, AncestorAxisState>);
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar,
- (AxisIterator<AncestorSelfAxisIterator, AncestorAxisState>*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
AncestorSelfAxisIterator(static_context* sctx, const QueryLoc& loc, PlanIter_t input)
=== modified file 'src/runtime/function_item/function_item.cpp'
--- src/runtime/function_item/function_item.cpp 2012-04-08 21:39:25 +0000
+++ src/runtime/function_item/function_item.cpp 2012-04-10 20:15:33 +0000
@@ -25,7 +25,9 @@
#include "functions/signature.h"
#include "functions/function.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
=== modified file 'src/store/api/item_handle.h'
--- src/store/api/item_handle.h 2012-03-28 05:19:57 +0000
+++ src/store/api/item_handle.h 2012-04-10 20:15:33 +0000
@@ -39,6 +39,7 @@
T** t;
void** v;
};
+
public:
ItemHandle() : p(0)
{
=== modified file 'src/store/api/store.h'
--- src/store/api/store.h 2012-03-28 05:19:57 +0000
+++ src/store/api/store.h 2012-04-10 20:15:33 +0000
@@ -31,6 +31,8 @@
SYNC_CODE(class Lock;)
+class TokenizerProvider;
+
namespace store
{
@@ -336,7 +338,7 @@
*
* @param provider The TokenizerProvider to use or NULL to use the default.
*/
- virtual void setTokenizerProvider(TokenizerProvider const *provider) = 0;
+ virtual void setTokenizerProvider(const TokenizerProvider* provider) = 0;
/**
* Gets the TokenizerProvider in use.
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp 2012-04-04 15:59:01 +0000
+++ src/store/naive/node_items.cpp 2012-04-10 20:15:33 +0000
@@ -19,6 +19,7 @@
#include <stack>
#include <zorba/config.h>
+#include <zorba/item.h>
#include "diagnostics/assert.h"
#include "diagnostics/xquery_diagnostics.h"
=== modified file 'src/types/node_test.cpp'
--- src/types/node_test.cpp 2012-04-08 21:39:25 +0000
+++ src/types/node_test.cpp 2012-04-10 20:15:33 +0000
@@ -19,6 +19,10 @@
#include "node_test.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
+
namespace zorba
{
=== modified file 'src/types/node_test.h'
--- src/types/node_test.h 2012-03-28 05:19:57 +0000
+++ src/types/node_test.h 2012-04-10 20:15:33 +0000
@@ -22,7 +22,7 @@
#include "zorbatypes/rchandle.h"
#include "store/api/item.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
namespace zorba {
=== modified file 'src/types/schema/schema.cpp'
--- src/types/schema/schema.cpp 2012-04-08 21:39:25 +0000
+++ src/types/schema/schema.cpp 2012-04-10 20:15:33 +0000
@@ -54,7 +54,9 @@
#endif /* ZORBA_NO_XMLSCHEMA */
-//using namespace std;
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
@@ -89,6 +91,7 @@
XMLString::release(&trStr);
}
+
/**
* A Xerces BinInputStream that returns bytes from a std::istream.
*/
@@ -96,7 +99,8 @@
{
public:
IstreamBinInputStream(std::istream* aStream)
- : theStream(aStream)
+ :
+ theStream(aStream)
{
}
@@ -125,6 +129,7 @@
std::istream* theStream;
};
+
/**
* A Xerces InputSource that returns a IstreamBinInputStream.
*/
@@ -139,7 +144,8 @@
~IstreamInputSource()
{
- if (theStreamReleaser) {
+ if (theStreamReleaser)
+ {
theStreamReleaser(theStream);
}
}
@@ -154,6 +160,7 @@
StreamReleaser theStreamReleaser;
};
+
/**
* A Xerces EntityResolver that looks for a specific URL and returns
* InputSource that reads from a particular std::istream.
=== modified file 'src/types/schema/schema.h'
--- src/types/schema/schema.h 2012-03-28 05:19:57 +0000
+++ src/types/schema/schema.h 2012-04-10 20:15:33 +0000
@@ -37,7 +37,7 @@
#include "util/hashmap.h"
#undef ZORBA_HASHMAP_WITH_SERIALIZATION
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
namespace XERCES_CPP_NAMESPACE {
@@ -65,14 +65,14 @@
static const char* XSD_NAMESPACE;
private:
- static bool theIsInitialized;
+ static bool theIsInitialized;
- TypeManager * theTypeManager;
+ TypeManager * theTypeManager;
#ifndef ZORBA_NO_XMLSCHEMA
- XERCES_CPP_NAMESPACE::XMLGrammarPool * theGrammarPool;
+ XERCES_CPP_NAMESPACE::XMLGrammarPool * theGrammarPool;
// QQQ use zstring?
- serializable_hashmap<std::string,xqtref_t> * theUdTypesCache;
+ serializable_hashmap<std::string,xqtref_t> * theUdTypesCache;
#endif // ZORBA_NO_XMLSCHEMA
public:
=== modified file 'src/types/typeimpl.cpp'
--- src/types/typeimpl.cpp 2012-04-08 21:39:25 +0000
+++ src/types/typeimpl.cpp 2012-04-10 20:15:33 +0000
@@ -25,6 +25,10 @@
#include "types/root_typemanager.h"
#include "types/schema/schema.h"
+#include "zorbaserialization/serialize_basic_types.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
namespace zorba
{
@@ -155,6 +159,42 @@
/*******************************************************************************
********************************************************************************/
+XQType::XQType(
+ const TypeManager* manager,
+ type_kind_t type_kind,
+ TypeConstants::quantifier_t quantifier,
+ bool builtin)
+ :
+ m_manager((TypeManager*)manager),
+ m_type_kind(type_kind),
+ m_quantifier(quantifier),
+ theIsBuiltin(builtin)
+{
+ if (theIsBuiltin)
+ {
+ // register this hardcoded object to help plan serialization
+ XQType* this_ptr = this;
+ *::zorba::serialization::ClassSerializer::getInstance()->
+ getArchiverForHardcodedObjects() & this_ptr;
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void XQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ SERIALIZE_TYPEMANAGER(TypeManager, m_manager);
+ SERIALIZE_ENUM(type_kind_t, m_type_kind);
+ SERIALIZE_ENUM(TypeConstants::quantifier_t, m_quantifier);
+ ar & theIsBuiltin;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
std::string XQType::toString() const
{
std::ostringstream os;
@@ -238,6 +278,42 @@
/*******************************************************************************
********************************************************************************/
+void NoneXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void EmptyXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void ItemXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void AnyXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
store::Item_t AnyXQType::get_qname() const
{
return GENV_TYPESYSTEM.XS_ANY_TYPE_QNAME;
@@ -247,6 +323,15 @@
/*******************************************************************************
********************************************************************************/
+void AnySimpleXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
store::Item_t AnySimpleXQType::get_qname() const
{
return GENV_TYPESYSTEM.XS_ANY_SIMPLE_TYPE_QNAME;
@@ -256,6 +341,15 @@
/*******************************************************************************
********************************************************************************/
+void UntypedXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
store::Item_t UntypedXQType::get_qname() const
{
return GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
@@ -265,6 +359,16 @@
/*******************************************************************************
********************************************************************************/
+void AtomicXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+ SERIALIZE_ENUM(store::SchemaTypeCode, m_type_code);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
NodeXQType::NodeXQType(
const TypeManager* manager,
store::StoreConsts::NodeKind nodeKind,
@@ -534,6 +638,15 @@
/*******************************************************************************
+
+********************************************************************************/
+void AnyFunctionXQType::serialize(::zorba::serialization::Archiver& ar)
+{
+ serialize_baseclass(ar, (XQType*)this);
+}
+
+
+/*******************************************************************************
Constructor for user-defined Atomic and Complex types
********************************************************************************/
FunctionXQType::FunctionXQType(
=== modified file 'src/types/typeimpl.h'
--- src/types/typeimpl.h 2012-03-28 05:19:57 +0000
+++ src/types/typeimpl.h 2012-04-10 20:15:33 +0000
@@ -30,7 +30,7 @@
#include "system/globalenv.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
namespace zorba
{
@@ -290,14 +290,7 @@
public:
SERIALIZABLE_ABSTRACT_CLASS(XQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(XQType, SimpleRCObject)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- //serialize_baseclass(ar, (SimpleRCObject*)this);
- SERIALIZE_TYPEMANAGER(TypeManager, m_manager);
- SERIALIZE_ENUM(type_kind_t, m_type_kind)
- SERIALIZE_ENUM(TypeConstants::quantifier_t, m_quantifier);
- ar & theIsBuiltin;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
virtual ~XQType() { }
@@ -332,23 +325,10 @@
protected:
XQType(
- const TypeManager* manager,
- type_kind_t type_kind,
- TypeConstants::quantifier_t quantifier,
- bool builtin)
- :
- m_manager((TypeManager*)manager),
- m_type_kind(type_kind),
- m_quantifier(quantifier),
- theIsBuiltin(builtin)
- {
- if (theIsBuiltin)
- {
- // register this hardcoded object to help plan serialization
- XQType* this_ptr = this;
- *::zorba::serialization::ClassSerializer::getInstance()->getArchiverForHardcodedObjects() & this_ptr;
- }
- }
+ const TypeManager* manager,
+ type_kind_t type_kind,
+ TypeConstants::quantifier_t quantifier,
+ bool builtin);
};
@@ -365,13 +345,11 @@
}
content_kind_t content_kind() const { return EMPTY_CONTENT_KIND; };
+
public:
SERIALIZABLE_CLASS(NoneXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(NoneXQType, XQType)
- void serialize(::zorba::serialization::Archiver &ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
@@ -388,13 +366,11 @@
}
content_kind_t content_kind() const { return EMPTY_CONTENT_KIND; };
+
public:
SERIALIZABLE_CLASS(EmptyXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(EmptyXQType, XQType)
- void serialize(::zorba::serialization::Archiver &ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
@@ -412,13 +388,11 @@
XQType(manager, ITEM_KIND, quantifier, builtin)
{
}
+
public:
SERIALIZABLE_CLASS(ItemXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(ItemXQType, XQType)
- void serialize(::zorba::serialization::Archiver &ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
@@ -435,13 +409,11 @@
}
store::Item_t get_qname() const;
+
public:
SERIALIZABLE_CLASS(AnyXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(AnyXQType, XQType)
- void serialize(::zorba::serialization::Archiver &ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
@@ -460,13 +432,11 @@
content_kind_t content_kind() const { return SIMPLE_CONTENT_KIND; };
store::Item_t get_qname() const;
+
public:
SERIALIZABLE_CLASS(AnySimpleXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(AnySimpleXQType, XQType)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
@@ -485,11 +455,7 @@
public:
SERIALIZABLE_CLASS(AtomicXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(AtomicXQType, XQType)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- SERIALIZE_ENUM(store::SchemaTypeCode, m_type_code);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
AtomicXQType(
@@ -593,10 +559,7 @@
public:
SERIALIZABLE_CLASS(UntypedXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(UntypedXQType, XQType)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
@@ -624,10 +587,7 @@
public:
SERIALIZABLE_CLASS(AnyFunctionXQType)
SERIALIZABLE_CLASS_CONSTRUCTOR2(AnyFunctionXQType, XQType)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- serialize_baseclass(ar, (XQType*)this);
- }
+ void serialize(::zorba::serialization::Archiver& ar);
};
=== modified file 'src/types/typemanager.h'
--- src/types/typemanager.h 2012-03-28 05:19:57 +0000
+++ src/types/typemanager.h 2012-04-10 20:15:33 +0000
@@ -20,6 +20,7 @@
#include <ostream>
#include <zorba/typeident.h>
#include <zorba/store_consts.h>
+#include <zorba/diagnostic_list.h>
#include "common/shared_types.h"
@@ -29,7 +30,7 @@
#include "compiler/parser/query_loc.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
#include "store/api/xs_type_codes.h"
@@ -62,11 +63,7 @@
public:
SERIALIZABLE_ABSTRACT_CLASS(TypeManager)
SERIALIZABLE_CLASS_CONSTRUCTOR2(TypeManager, SimpleRCObject)
- void serialize(::zorba::serialization::Archiver& ar)
- {
- //serialize_baseclass(ar, (SimpleRCObject*)this);
- ar & m_level;
- }
+ void serialize(::zorba::serialization::Archiver& ar);
public:
TypeManager(int level) : m_level(level) { }
=== modified file 'src/types/typemanagerimpl.cpp'
--- src/types/typemanagerimpl.cpp 2012-04-08 21:39:25 +0000
+++ src/types/typemanagerimpl.cpp 2012-04-10 20:15:33 +0000
@@ -39,8 +39,12 @@
#include "compiler/parser/query_loc.h"
#include "functions/signature.h"
+
#include "util/string_util.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+
#ifdef ZORBA_XBROWSER
#include "DOMQName.h"
#endif
@@ -59,6 +63,15 @@
/***************************************************************************//**
********************************************************************************/
+void TypeManager::serialize(::zorba::serialization::Archiver& ar)
+{
+ ar & m_level;
+}
+
+
+/***************************************************************************//**
+
+********************************************************************************/
void TypeManagerImpl::serialize(::zorba::serialization::Archiver &ar)
{
serialize_baseclass(ar, (TypeManager*)this);
=== modified file 'src/zorbaserialization/CMakeLists.txt'
--- src/zorbaserialization/CMakeLists.txt 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/CMakeLists.txt 2012-04-10 20:15:33 +0000
@@ -15,13 +15,13 @@
SET(ZORBA_PLAN_SERIALIZER_STATISTICS OFF CACHE BOOL "Set to ON to get some statistics on saved plan")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/zorbaserialization/plan_settings.h.in ${CMAKE_CURRENT_BINARY_DIR}/zorbaserialization/plan_settings.h)
SET(ZORBASERIALIZATION_SRCS
+ class_serializer.cpp
archiver.cpp
mem_archiver.cpp
xml_archiver.cpp
bin_archiver.cpp
serialize_basic_types.cpp
+ serialize_zorba_types.cpp
base64impl.cpp
- class_serializer.cpp
- zorba_class_serializer.cpp
zorba_class_versions.cpp
)
=== modified file 'src/zorbaserialization/archiver.cpp'
--- src/zorbaserialization/archiver.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/archiver.cpp 2012-04-10 20:15:33 +0000
@@ -514,12 +514,15 @@
new_field->theParent = current_compound_field;
new_field->theId = ++nr_ids;
new_field->theOrder = new_field->theId;
- if(current_compound_field->theLastChild)
+
+ if (current_compound_field->theLastChild)
current_compound_field->theLastChild->theNextSibling = new_field;
else
current_compound_field->theFirstChild = new_field;
+
current_compound_field->theLastChild = new_field;
- if(!ref_field && ptr)
+
+ if (!ref_field && ptr)
current_compound_field = new_field;
}
else
@@ -559,14 +562,14 @@
********************************************************************************/
archive_field* Archiver::lookup_class_field(const SerializeBaseClass* ptr)
{
- if(!ptr)
+ if (!ptr)
return NULL;
archive_field* duplicate_field = NULL;
hash_out_fields->get((uint64_t)ptr, duplicate_field);
- if(!duplicate_field)
+ if (!duplicate_field)
{
Archiver* har = ::zorba::serialization::ClassSerializer::getInstance()->
getArchiverForHardcodedObjects();
@@ -747,14 +750,14 @@
enum ArchiveFieldKind field_treat,
const void* ptr)
{
- if(get_is_temp_field())// && (field_treat != ARCHIVE_FIELD_PTR))
- return;
- if(get_is_temp_field_one_level() && ((field_treat != ARCHIVE_FIELD_PTR) || get_is_temp_field_also_for_ptr()))
- return;
-
-// all_reference_list->put((uint32_t)id, (void*)ptr);
+ if (get_is_temp_field())// && (field_treat != ARCHIVE_FIELD_PTR))
+ return;
+
+ if (get_is_temp_field_one_level() &&
+ ((field_treat != ARCHIVE_FIELD_PTR) || get_is_temp_field_also_for_ptr()))
+ return;
+
all_reference_list[id] = (void*)ptr;
-
}
@@ -880,26 +883,25 @@
}
else
{
- class_deserializer *cls_factory;
+ ClassDeserializer* cls_factory;
+
cls_factory = ClassSerializer::getInstance()->get_class_factory((*it).class_name);
- if(cls_factory == NULL)
+
+ if (cls_factory == NULL)
{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0003_UNRECOGNIZED_CLASS_FIELD,
- ERROR_PARAMS( it->class_name )
- );
+ throw ZORBA_EXCEPTION(zerr::ZCSE0003_UNRECOGNIZED_CLASS_FIELD,
+ ERROR_PARAMS(it->class_name));
}
+
cls_factory->cast_ptr((SerializeBaseClass*)ptr, (*it).ptr);
SimpleRCObject* rcobj1;
store::Item* rcobj2;
- //zStringStore* rcobj3;
-
-
- if(!(*it).to_add_ref)
+
+ if (!(*it).to_add_ref)
{
}
- else if((rcobj1 = dynamic_cast<SimpleRCObject*>((SerializeBaseClass*)ptr)) != NULL)
+ else if ((rcobj1 = dynamic_cast<SimpleRCObject*>((SerializeBaseClass*)ptr)) != NULL)
{
RCHelper::addReference(rcobj1); //this can lead to memory leaks
}
=== modified file 'src/zorbaserialization/class_serializer.cpp'
--- src/zorbaserialization/class_serializer.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/class_serializer.cpp 2012-04-10 20:15:33 +0000
@@ -56,13 +56,13 @@
********************************************************************************/
class ClassFactoriesMap : public zorba::HashMap<const char*,
- class_deserializer*,
+ ClassDeserializer*,
ClassFactoriesCompare>
{
public:
ClassFactoriesMap(ulong sz = 1024)
:
- zorba::HashMap<const char*, class_deserializer*, ClassFactoriesCompare>(sz, false)
+ zorba::HashMap<const char*, ClassDeserializer*, ClassFactoriesCompare>(sz, false)
{
}
};
@@ -78,16 +78,12 @@
********************************************************************************/
ClassSerializer::ClassSerializer()
- :
- class_names(1000),
- class_names_count(0)
{
- class_factories = NULL;
+ theClassFactories = new ClassFactoriesMap;
t0 = clock();
- harcoded_objects_archive = NULL;
- harcoded_objects_archive = new MemArchiver(true, true);//simulate serialize out
+ harcoded_objects_archive = new MemArchiver(true, true);
}
@@ -96,7 +92,7 @@
********************************************************************************/
ClassSerializer::~ClassSerializer()
{
- delete class_factories;
+ delete theClassFactories;
delete harcoded_objects_archive;
}
@@ -116,16 +112,9 @@
********************************************************************************/
void ClassSerializer::register_class_factory(
const char* class_name,
- class_deserializer* class_factory)
+ ClassDeserializer* class_factory)
{
- if (class_factories)
- {
- class_factories->insert(class_name, class_factory);
- }
- else
- {
- class_names[class_names_count++] = std::pair<const char *, class_deserializer*>(class_name, class_factory);
- }
+ theClassFactories->insert(class_name, class_factory);
t1 = clock();
}
@@ -134,24 +123,11 @@
/*******************************************************************************
********************************************************************************/
-class_deserializer* ClassSerializer::get_class_factory(const char* classname)
+ClassDeserializer* ClassSerializer::get_class_factory(const char* classname)
{
- if (class_factories == NULL)
- {
- class_factories = new ClassFactoriesMap;
-
- int i;
- std::vector<std::pair<const char*, class_deserializer*> >::iterator cls_it = class_names.begin();
-
- for (i = 0; i < class_names_count; i++, cls_it++)
- {
- class_factories->insert((*cls_it).first, (*cls_it).second);
- }
- }
-
- class_deserializer* cls_factory = NULL;
- class_factories->get(classname, cls_factory);
- return cls_factory;
+ ClassDeserializer* factory = NULL;
+ theClassFactories->get(classname, factory);
+ return factory;
}
=== modified file 'src/zorbaserialization/class_serializer.h'
--- src/zorbaserialization/class_serializer.h 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/class_serializer.h 2012-04-10 20:15:33 +0000
@@ -43,6 +43,7 @@
class Archiver;
class MemArchiver;
class ClassFactoriesMap;
+class ClassDeserializer;
/*******************************************************************************
@@ -53,7 +54,58 @@
/*******************************************************************************
- A base class for other c++ classes that need to be serialized.
+ There is only one global instance of this class.
+
+ theClassFactories:
+ ------------------
+ This map associates the name of a class C with a pointer to the ClassDeserializer
+ obj associated with C (if any such obj actually exists). The map is populated
+ "automatically", during the instantiation of each ClassDeserializer obj; the
+ constructor of each such obj places an entry into the map.
+
+ harcoded_objects_archive:
+ -------------------------
+
+********************************************************************************/
+class ClassSerializer
+{
+ friend class Archiver;
+
+public:
+ static const unsigned long g_zorba_classes_version;
+
+private:
+ ClassFactoriesMap * theClassFactories;
+
+ MemArchiver * harcoded_objects_archive;
+
+public:
+ clock_t t0;
+ clock_t t1;
+
+public:
+ static ClassSerializer* getInstance();
+
+public:
+ ClassSerializer();
+
+ ~ClassSerializer();
+
+ void register_class_factory(const char* className, ClassDeserializer* d);
+
+ ClassDeserializer* get_class_factory(const char* classname);
+
+ Archiver* getArchiverForHardcodedObjects();
+
+ void destroyArchiverForHardcodedObjects();
+
+ clock_t get_registration_time() { return t1 - t0; }
+};
+
+
+/*******************************************************************************
+ A class that may be used as the base for other c++ classes that need to be
+ serialized.
********************************************************************************/
class ZORBA_DLL_PUBLIC SerializeBaseClass
{
@@ -66,16 +118,15 @@
/*******************************************************************************
Every serializable class C has a nested member class D that is a subclass of
- class_deserializer. Furthermore, every serializable class has a static data
+ ClassDeserializer. Furthermore, every serializable class has a static data
member of type D, whose initilization (via its default constructor) causes
class C to be registered in the global ClassSerializer instance.
********************************************************************************/
-class class_deserializer
+class ClassDeserializer
{
public:
- virtual ~class_deserializer()
+ virtual ~ClassDeserializer()
{
- // std::cout << "~class_deserializer" << std::endl;
}
virtual SerializeBaseClass* create_new(Archiver& ar) = 0;
@@ -89,7 +140,7 @@
********************************************************************************/
#define SERIALIZABLE_CLASS_FACTORY_DECL(class_name, creator) \
template<class T_serialized_class> \
-class class_factory : public ::zorba::serialization::class_deserializer \
+class class_factory : public ::zorba::serialization::ClassDeserializer \
{ \
public: \
class_factory() \
@@ -111,72 +162,13 @@
/*******************************************************************************
- stateless class, multithreading safe
-
- class_names:
- ------------
- For each serializable class C, this vector stores the name of C and a pointer
- to the static class_deserializer obj associated with C. The vector is populated
- "automatically", during the instantiation of each static class_deserializer obj
- associated with each serializable class. The constructor of each such obj places
- an entry into the vector.
-
- class_names_count:
- ------------------
-
- class_factories:
- ----------------
-
- harcoded_objects_archive:
- -------------------------
-
-********************************************************************************/
-class ClassSerializer
-{
- friend class Archiver;
-
-public:
- static const unsigned long g_zorba_classes_version;
-
-private:
- std::vector<std::pair<const char*, class_deserializer*> > class_names;
- int class_names_count;
- ClassFactoriesMap * class_factories;
-
- MemArchiver * harcoded_objects_archive;
-
-public:
- clock_t t0;
- clock_t t1;
-
-public:
- static ClassSerializer* getInstance();
-
-public:
- ClassSerializer();
-
- ~ClassSerializer();
-
- void register_class_factory(const char* className, class_deserializer* d);
-
- class_deserializer* get_class_factory(const char* classname);
-
- Archiver* getArchiverForHardcodedObjects();
-
- void destroyArchiverForHardcodedObjects();
-
- clock_t get_registration_time() { return t1-t0;}
-};
-
-
-/*******************************************************************************
********************************************************************************/
#define SERIALIZABLE_CLASS_NO_FACTORY(class_name) \
virtual void serialize_internal(::zorba::serialization::Archiver& ar) \
{ \
/*CHECK_CLASS_NAME(class_name)*/ \
- if(ar.is_serialize_base_class()) \
+ if (ar.is_serialize_base_class()) \
ar.set_serialize_base_class(false); \
\
class_name::serialize(ar); \
@@ -193,13 +185,13 @@
#define SERIALIZABLE_CLASS(class_name) \
SERIALIZABLE_CLASS_PREFIX(class_name) \
SERIALIZABLE_CLASS_FACTORY_DECL(class_name, new class_name(ar)) \
-static class_factory<class_name> g_class_factory;
+static class_factory<class_name> g_class_factory;
#define SERIALIZABLE_ABSTRACT_CLASS(class_name) \
SERIALIZABLE_CLASS_PREFIX(class_name) \
SERIALIZABLE_CLASS_FACTORY_DECL(class_name, NULL) \
-static class_factory<class_name> g_class_factory;
+static class_factory<class_name> g_class_factory;
#define SERIALIZABLE_CLASS_PREFIX(class_name) \
@@ -253,11 +245,6 @@
static const char* get_class_name_str_static() { return class_name_str; }
-/*******************************************************************************
- Init the serialization-related static members of a serializable class.
-********************************************************************************/
-
-
//
// Static members of template classes with one template param.
//
=== removed file 'src/zorbaserialization/serialization_engine.h'
--- src/zorbaserialization/serialization_engine.h 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/serialization_engine.h 1970-01-01 00:00:00 +0000
@@ -1,24 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-#ifndef ZORBA_SERIALIZATION_ENGINE
-#define ZORBA_SERIALIZATION_ENGINE
-
-#include "zorbaserialization/template_serializer.h"
-#include "zorbaserialization/zorba_class_serializer.h"
-
-#endif
-/* vim:set et sw=2 ts=2: */
=== added file 'src/zorbaserialization/serialize_template_types.h'
--- src/zorbaserialization/serialize_template_types.h 1970-01-01 00:00:00 +0000
+++ src/zorbaserialization/serialize_template_types.h 2012-04-10 20:15:33 +0000
@@ -0,0 +1,929 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+#ifndef TEMPLATE_SERIALIZATION_OPERATORS
+#define TEMPLATE_SERIALIZATION_OPERATORS
+
+#include <list>
+#include <vector>
+#include <map>
+#include <stdio.h>
+
+#include <zorba/diagnostic_list.h>
+#include <zorba/internal/unique_ptr.h>
+
+#include "util/string_util.h"
+#include "util/stl_util.h"
+#include "diagnostics/xquery_diagnostics.h"
+#include "zorbatypes/zstring.h"
+
+#include "archiver.h"
+#include "class_serializer.h"
+#include "serialize_basic_types.h"
+
+namespace zorba
+{
+namespace serialization
+{
+/////////////////////////////templates
+
+#define ZORBA_SER_ERROR_DESC_OSS(QNAME,MSG) \
+ do { \
+ std::ostringstream oss; \
+ oss << MSG; \
+ throw XQUERY_EXCEPTION( QNAME, ERROR_PARAMS( oss.str() ) ); \
+ } while (0)
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<class T>
+void operator&(Archiver& ar, T& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ bool is_ref;
+
+ is_ref = ar.add_compound_field(obj.get_class_name_str(),
+ FIELD_IS_CLASS,
+ "0",//strtemp,
+ (SerializeBaseClass*)&obj,
+ ARCHIVE_FIELD_NORMAL);
+ if (!is_ref)
+ {
+ obj.serialize_internal(ar);
+
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = true;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+
+ bool retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat,
+ &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_class_field(retval, type, obj.get_class_name_str(),
+ is_simple, is_class, field_treat,
+ ARCHIVE_FIELD_NORMAL,
+ id);
+
+ ar.register_reference(id, field_treat, (SerializeBaseClass*)&obj);
+
+ obj.serialize_internal(ar);
+
+ ar.read_end_current_level();
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<class T>
+void operator&(Archiver& ar, T*& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ if (obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ FIELD_IS_CLASS,
+ "NULL",
+ NULL,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+
+ bool is_ref = ar.add_compound_field((ar.is_serialize_base_class() ?
+ obj->T::get_class_name_str() :
+ obj->get_class_name_str()),
+ FIELD_IS_CLASS,
+ "0",
+ (SerializeBaseClass*)obj,
+ (ar.is_serialize_base_class() ?
+ ARCHIVE_FIELD_BASECLASS :
+ ARCHIVE_FIELD_PTR));
+ if (!is_ref)
+ {
+ if (!ar.is_serialize_base_class())
+ {
+ obj->serialize_internal(ar);
+ }
+ else
+ {
+ obj->T::serialize_internal(ar);
+ }
+
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = true;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+
+ bool retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat,
+ &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_class_field(retval, "", "",
+ is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+
+ if (field_treat == ARCHIVE_FIELD_NULL)
+ {
+ assert(!ar.is_serialize_base_class());
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+
+ if (ar.is_serialize_base_class())
+ {
+#ifndef NDEBUG
+ if (strcmp(type, T::get_class_name_str_static()))
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+ }
+#endif
+ if (field_treat != ARCHIVE_FIELD_BASECLASS)
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+ }
+ }
+ else
+ {
+ if (field_treat != ARCHIVE_FIELD_PTR && field_treat != ARCHIVE_FIELD_REFERENCING)
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+ }
+ }
+
+ SerializeBaseClass* new_obj = NULL;
+
+ if (field_treat == ARCHIVE_FIELD_PTR)
+ {
+ ClassDeserializer* cls_factory;
+ cls_factory = ClassSerializer::getInstance()->get_class_factory(type);
+
+ if (cls_factory == NULL)
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0003_UNRECOGNIZED_CLASS_FIELD,
+ ERROR_PARAMS(type));
+ }
+
+ new_obj = cls_factory->create_new(ar);
+
+ obj = dynamic_cast<T*>(new_obj);
+
+ if (!obj)
+ {
+ delete new_obj;obj=NULL;
+
+ throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD,
+ ERROR_PARAMS(id, type, typeid(T).name()));
+ }
+
+ ar.register_reference(id, field_treat, new_obj);
+ try
+ {
+ new_obj->serialize_internal(ar);
+ }
+ catch(...)
+ {
+ delete new_obj;obj=NULL;
+ throw;
+ }
+ ar.read_end_current_level();
+ }
+ else if (field_treat == ARCHIVE_FIELD_BASECLASS)
+ {
+ obj->T::serialize_internal(ar);
+ ar.read_end_current_level();
+ }
+ else if ((new_obj = (SerializeBaseClass*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ {
+ try
+ {
+ obj = dynamic_cast<T*>(new_obj);
+ }
+ catch(...)
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0004_UNRESOLVED_FIELD_REFERENCE,
+ ERROR_PARAMS(id));
+ }
+
+ if (!obj)
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+ }
+ }
+ else
+ {
+ ar.register_delay_reference((void**)&obj,
+ FIELD_IS_CLASS,
+ obj->T::get_class_name_str(),
+ referencing);
+ }
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<class T>
+void serialize_baseclass(Archiver& ar, T* obj)
+{
+ ar.set_serialize_base_class(true);
+
+ ar & obj;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<class RepType>
+void operator&(Archiver& ar, zorba::rstring<RepType>& obj)
+{
+ bool is_normal_str = true;
+ if(ar.is_serializing_out())
+ {
+ if(obj.size() != strlen(obj.c_str()))
+ is_normal_str = false;
+ }
+ ar.set_is_temp_field(true);
+ ar & is_normal_str;
+ ar.set_is_temp_field(false);
+
+ if(is_normal_str)
+ {
+ if(ar.is_serializing_out())
+ {
+ ar.add_simple_field("rstring", obj.c_str(), &obj, ARCHIVE_FIELD_NORMAL);
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = true;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_simple_field(retval, type, "rstring", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ obj = value;
+ ar.register_reference(id, field_treat, &obj);
+ }
+ }
+ else
+ {
+ //for strings which contain '\0' inside
+ if(ar.is_serializing_out())
+ {
+ const char *cstr = obj.c_str();
+ zorba::zstring::size_type s = obj.size();
+
+ ar.set_is_temp_field(true);
+ ar & s;
+ serialize_array(ar, (unsigned char*)cstr, s);
+ ar.set_is_temp_field(false);
+ }
+ else
+ {
+ std::unique_ptr<unsigned char[]> cstr;
+ zorba::zstring::size_type s;
+
+ ar.set_is_temp_field(true);
+ ar & s;
+ cstr.reset(new unsigned char[s]);
+ serialize_array(ar, (unsigned char*)cstr.get(), s);
+ obj.assign((const char*)cstr.get(), s);
+ ar.set_is_temp_field(false);
+ }
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T>
+void operator&(Archiver& ar, std::list<T>& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ char strtemp[20];
+#ifndef WIN32
+ sprintf(strtemp, "%d", (int)obj.size());
+#else
+ sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj.size());
+#endif
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::list<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ typename std::list<T>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::list<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ ar.register_reference(id, field_treat, &obj);
+
+ int size;
+ sscanf(value.c_str(), "%d", &size);
+ obj.resize(size);
+ typename std::list<T>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.read_end_current_level();
+
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T>
+void operator&(Archiver& ar, std::vector<T>& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ char strtemp[20];
+#ifndef WIN32
+ sprintf(strtemp, "%d", (int)obj.size());
+#else
+ sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj.size());
+#endif
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::vector<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ typename std::vector<T>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::vector<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ ar.register_reference(id, field_treat, &obj);
+
+ int size;
+ sscanf(value.c_str(), "%d", &size);
+ obj.resize(size);
+ typename std::vector<T>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.read_end_current_level();
+
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T>
+void operator&(Archiver& ar, std::vector<T>*& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ if(obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ !FIELD_IS_CLASS, "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+ char strtemp[20];
+#ifndef WIN32
+ sprintf(strtemp, "%d", (int)obj->size());
+#else
+ sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj->size());
+#endif
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::vector<T>*", !FIELD_IS_CLASS, strtemp, obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
+ if(ar.is_serialize_base_class())
+ ar.set_serialize_base_class(false);
+ if(!is_ref)
+ {
+ typename std::vector<T>::iterator it;
+ for(it=obj->begin(); it != obj->end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::vector<T>*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+ if(field_treat == ARCHIVE_FIELD_NULL)
+ {
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+ if(ar.is_serialize_base_class())
+ ar.set_serialize_base_class(false);
+ void *new_obj;
+ if(field_treat == ARCHIVE_FIELD_PTR)
+ {
+ obj = new std::vector<T>;
+ ar.register_reference(id, field_treat, obj);
+
+ int size;
+ sscanf(value.c_str(), "%d", &size);
+ obj->resize(size);
+ typename std::vector<T>::iterator it;
+ for(it=obj->begin(); it != obj->end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.read_end_current_level();
+ }
+ else if(field_treat == ARCHIVE_FIELD_BASECLASS)
+ {
+ int size;
+ sscanf(value.c_str(), "%d", &size);
+ obj->resize(size);
+ typename std::vector<T>::iterator it;
+ for(it=obj->begin(); it != obj->end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.read_end_current_level();
+ }
+ else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ {
+ obj = (std::vector<T>*)new_obj;
+ if(!obj)
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
+ );
+ }
+ }
+ else
+ ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "std::vector<T>*", referencing);
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T>
+void operator&(Archiver& ar, std::vector<T*>& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ char strtemp[20];
+#ifndef WIN32
+ sprintf(strtemp, "%d", (int)obj.size());
+#else
+ sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj.size());
+#endif
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::vector<T*>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ typename std::vector<T*>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::vector<T*>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ ar.register_reference(id, field_treat, &obj);
+
+ int size;
+ sscanf(value.c_str(), "%d", &size);
+ obj.resize(size);
+ typename std::vector<T*>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ ar & (*it);
+ }
+ ar.read_end_current_level();
+
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T1, typename T2>
+void operator&(Archiver& ar, std::pair<T1, T2>& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::pair<T1, T2>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ ar & obj.first;
+ ar & obj.second;
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ ar.register_reference(id, field_treat, &obj);
+
+ ar & obj.first;
+ ar & obj.second;
+ ar.read_end_current_level();
+
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T1, typename T2>
+void operator&(Archiver& ar, std::pair<T1, T2>*& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ if(obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ !FIELD_IS_CLASS, "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::pair<T1, T2>", !FIELD_IS_CLASS, "", &obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
+ if(ar.is_serialize_base_class())
+ ar.set_serialize_base_class(false);
+ if(!is_ref)
+ {
+ ar & obj->first;
+ ar & obj->second;
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+ if(field_treat == ARCHIVE_FIELD_NULL)
+ {
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+ if(ar.is_serialize_base_class())
+ ar.set_serialize_base_class(false);
+
+ void *new_obj;
+ if(field_treat == ARCHIVE_FIELD_PTR)
+ {
+ obj = new std::pair<T1, T2>;
+ ar.register_reference(id, field_treat, &obj);
+
+ ar & obj->first;
+ ar & obj->second;
+ ar.read_end_current_level();
+ }
+ else if(field_treat == ARCHIVE_FIELD_BASECLASS)
+ {
+ ar & obj->first;
+ ar & obj->second;
+ ar.read_end_current_level();
+ }
+ else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ {
+ obj = (std::pair<T1, T2>*)new_obj;
+ if(!obj)
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
+ );
+ }
+ }
+ else
+ ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "std::pair<T1, T2>", referencing);
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T1, typename T2>
+void operator&(Archiver& ar, std::map<T1, T2>*& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ if(obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ !FIELD_IS_CLASS, "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::map<T1, T2>", !FIELD_IS_CLASS, "", obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
+ if(ar.is_serialize_base_class())
+ ar.set_serialize_base_class(false);
+ if(!is_ref)
+ {
+ ar.set_is_temp_field_one_level(true);
+ int s = (int)obj->size();
+ ar & s;
+ typename std::map<T1, T2>::iterator it;
+ for(it=obj->begin(); it != obj->end(); it++)
+ {
+ ar.dont_allow_delay();
+ T1 t1 = (*it).first;
+ ar & t1;
+ ar.dont_allow_delay();
+ ar & (*it).second;
+ }
+ ar.set_is_temp_field_one_level(false);
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+ if(field_treat == ARCHIVE_FIELD_NULL)
+ {
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+ if(ar.is_serialize_base_class())
+ ar.set_serialize_base_class(false);
+ void *new_obj;
+ if(field_treat == ARCHIVE_FIELD_PTR)
+ {
+ obj = new std::map<T1, T2>;
+ ar.register_reference(id, field_treat, obj);
+
+ ar.set_is_temp_field_one_level(true);
+ int s;
+ ar & s;
+ typename std::map<T1, T2>::iterator it;
+ std::pair<T1, T2> p;
+ for(int i=0;i<s;i++)
+ {
+ ar & p.first;
+ ar & p.second;
+ obj->insert(p);
+ }
+ ar.set_is_temp_field_one_level(false);
+ ar.read_end_current_level();
+ }
+ else if(field_treat == ARCHIVE_FIELD_BASECLASS)
+ {
+ ar.set_is_temp_field_one_level(true);
+ int s;
+ ar & s;
+ typename std::map<T1, T2>::iterator it;
+ std::pair<T1, T2> p;
+ for(int i=0;i<s;i++)
+ {
+ ar & p.first;
+ ar & p.second;
+ obj->insert(p);
+ }
+ ar.set_is_temp_field_one_level(false);
+ ar.read_end_current_level();
+ }
+ else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ {
+ obj = (std::map<T1, T2>*)new_obj;
+ if(!obj)
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
+ );
+ }
+ }
+ else
+ ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "std::map<T1, T2>", referencing);
+ }
+}
+
+void operator&(Archiver &ar, short &obj);
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<typename T1, typename T2, class Tcomp>
+void operator&(Archiver& ar, std::map<T1, T2, Tcomp>& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("std::map<T1, T2>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ ar.set_is_temp_field_one_level(true);
+ int s = (int)obj.size();
+ ar & s;
+ typename std::map<T1, T2, Tcomp>::iterator it;
+ for(it=obj.begin(); it != obj.end(); it++)
+ {
+ T1 t1 = (*it).first;
+ ar.dont_allow_delay();
+ ar & t1;
+ ar.dont_allow_delay();
+ ar & (*it).second;
+ }
+ ar.set_is_temp_field_one_level(false);
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar.register_reference(id, field_treat, &obj);
+
+ ar.set_is_temp_field_one_level(true);
+ int s;
+ ar & s;
+ //typename std::map<T1, T2>::iterator it;
+ std::pair<T1, T2> p;
+ for(int i=0;i<s;i++)
+ {
+ ar & p.first;
+ ar & p.second;
+ obj.insert(p);
+ }
+ ar.set_is_temp_field_one_level(false);
+ ar.read_end_current_level();
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<class T>
+void read_optional_field(Archiver& ar, T& obj)
+{
+ ar.set_read_optional_field(true);
+ ar & obj;
+ ar.set_read_optional_field(false);
+}
+
+} // namespace serialization
+} // namespace zorba
+
+#endif /* TEMPLATE_SERIALIZATION_OPERATORS */
+/* vim:set et sw=2 ts=2: */
=== added file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp 1970-01-01 00:00:00 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp 2012-04-10 20:15:33 +0000
@@ -0,0 +1,1512 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "stdafx.h"
+
+#include <zorba/error.h>
+#include <zorba/diagnostic_list.h>
+#include <zorba/internal/qname.h>
+#include <zorba/item.h>
+#include <zorba/user_exception.h>
+
+#include "zorbaserialization/serialize_zorba_types.h"
+#include "zorbaserialization/serialize_template_types.h"
+
+#include "types/typeimpl.h"
+#include "types/root_typemanager.h"
+
+#include "system/globalenv.h"
+
+#include "store/api/item.h"
+#include "store/api/item_handle.h"
+#include "store/api/iterator.h"
+#include "store/api/item_factory.h"
+//#include "store/api/tuples.h"
+
+#include "zorbatypes/datetime.h"
+#include "zorbatypes/collation_manager.h"
+#include "zorbatypes/integer.h"
+
+#include "functions/function.h"
+#include "runtime/function_item/function_item.h"
+
+#include "context/static_context.h"
+
+#include "diagnostics/xquery_diagnostics.h"
+#include "diagnostics/assert.h"
+#include "util/string_util.h"
+
+#include <zorba/store_consts.h>
+
+namespace zorba
+{
+namespace serialization
+{
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class store_item_class_factory : public ::zorba::serialization::ClassDeserializer
+{
+public:
+ store_item_class_factory()
+ {
+ ::zorba::serialization::ClassSerializer::getInstance()->
+ register_class_factory("store::Item*", this);
+ }
+
+ virtual ::zorba::serialization::SerializeBaseClass* create_new(
+ ::zorba::serialization::Archiver& ar)
+ {
+ return NULL;
+ }
+
+ virtual void cast_ptr(::zorba::serialization::SerializeBaseClass* ptr, void** class_ptr)
+ {
+ *class_ptr = (void*)dynamic_cast<store::Item*>(ptr);
+ }
+
+};
+
+
+store_item_class_factory g_store_item_class_factory;
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class xqpcollator_class_factory : public ::zorba::serialization::ClassDeserializer
+{
+public:
+ xqpcollator_class_factory()
+ {
+ ::zorba::serialization::ClassSerializer::getInstance()->
+ register_class_factory("XQPCollator*", this);
+ }
+
+ virtual ::zorba::serialization::SerializeBaseClass* create_new(
+ ::zorba::serialization::Archiver& ar)
+ {
+ return NULL;
+ }
+
+ virtual void cast_ptr(::zorba::serialization::SerializeBaseClass* ptr, void** class_ptr)
+ {
+ *class_ptr = (void*)dynamic_cast<XQPCollator*>(ptr);
+ }
+};
+
+xqpcollator_class_factory g_xqpcollator_class_factory;
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, const XQType*& obj)
+{
+ XQType* obj2 = (XQType*)obj;
+
+ ar.dont_allow_delay();
+
+ operator&(ar, obj2);
+
+ if (!ar.is_serializing_out())
+ obj = (const XQType*)obj2;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, XQPCollator*& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ if (obj == NULL)
+ {
+ ar.add_simple_field("XQPCollator*",
+ "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+
+ ar.add_simple_field("XQPCollator*", obj->getURI().c_str(), obj, ARCHIVE_FIELD_PTR);
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ int id;
+ bool is_simple = true;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+
+ bool retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat,
+ &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_simple_field(retval, type, "XQPCollator*",
+ is_simple, field_treat, ARCHIVE_FIELD_PTR, id);
+
+ if (field_treat == ARCHIVE_FIELD_NULL)
+ {
+ obj = NULL;
+ return;
+ }
+
+ if(!value.empty())
+ obj = CollationFactory::createCollator(value);
+ else
+ obj = CollationFactory::createCollator();
+
+ ar.register_reference(id, field_treat, &obj);
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, MAPM& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ int nr_digits = obj.significant_digits();
+ char *lBuffer = (char*)malloc(nr_digits + 20);
+ obj.toString(lBuffer, nr_digits);//ZORBA_FLOAT_POINT_PRECISION);
+ if(strchr(lBuffer, '.'))
+ {//save only necessary decimals
+ char *e_ptr = strrchr(lBuffer, 'E');
+ char *tail = e_ptr ? e_ptr-1 : lBuffer+strlen(lBuffer)-1;
+ while(*tail == '0')
+ tail--;
+ if(*tail == '.')
+ tail++;
+ if(e_ptr)
+ {
+ int i;
+ for(i=0;e_ptr[i];i++)
+ tail[i+1] = e_ptr[i];
+ tail[i+1] = 0;
+ }
+ else
+ tail[1] = 0;
+ }
+
+ ar.add_simple_field("MAPM", lBuffer, &obj, ARCHIVE_FIELD_NORMAL);
+ free(lBuffer);
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = true;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_simple_field(retval, type, "MAPM", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ obj = value.c_str();
+
+ ar.register_reference(id, field_treat, &obj);
+ }
+}
+
+#ifdef ZORBA_WITH_BIG_INTEGER
+void operator&(serialization::Archiver &ar, IntegerImpl &obj)
+#else
+template<typename IntType>
+void operator&(serialization::Archiver &ar, IntegerImpl<IntType> &obj)
+#endif /* ZORBA_WITH_BIG_INTEGER */
+{
+ ar & obj.value_;
+}
+#ifndef ZORBA_WITH_BIG_INTEGER
+template void operator&(serialization::Archiver&, IntegerImpl<long long>&);
+template void operator&(serialization::Archiver&, IntegerImpl<unsigned long long>&);
+#endif /* ZORBA_WITH_BIG_INTEGER */
+
+/*******************************************************************************
+
+********************************************************************************/
+void iterator_to_vector(store::Iterator_t iter, std::vector<store::Item_t> &items)
+{
+ store::Item_t i;
+ iter->open();
+ while(iter->next(i))
+ {
+ items.push_back(i);
+ }
+ iter->close();
+}
+
+void serialize_node_tree(Archiver &ar, store::Item *&obj, bool all_tree);
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void serialize_my_children(Archiver &ar, store::Iterator_t iter)
+{
+ if(ar.is_serializing_out())
+ {
+ std::vector<store::Item_t> childs;
+ iterator_to_vector(iter, childs);
+ std::vector<store::Item_t>::iterator child_it;
+ int child_count = (int)childs.size();
+ ar & child_count;
+
+ for(child_it = childs.begin(); child_it != childs.end(); child_it++)
+ {
+ store::Item* p = (*child_it).getp();
+
+ ar.dont_allow_delay(SERIALIZE_NOW);
+ //ar & p;
+ serialize_node_tree(ar, p, false);
+ }
+ }
+ else
+ {
+ int child_count;
+ ar & child_count;
+
+ for(int i=0;i<child_count;i++)
+ {
+ store::Item* p = NULL;
+ //ar & p;//should be automatically added to DocumentNode or ElementNode
+ serialize_node_tree(ar, p, false);
+ }
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void serialize_my_children2(Archiver &ar, store::Iterator_t iter)
+{
+ serialize_my_children(ar, iter);
+}
+
+#define SERIALIZE_FIELD(type, var, get_func)\
+ type var; \
+ if(ar.is_serializing_out()) \
+ var = obj->get_func; \
+ ar.dont_allow_delay(); \
+ ar & var;
+
+#define SERIALIZE_FIELD2(type, var, get_func)\
+ type var; \
+ if(ar.is_serializing_out()) \
+ obj->get_func(var); \
+ ar.dont_allow_delay(); \
+ ar & var;
+
+#define SERIALIZE_REF_FIELD(type, var, get_func) \
+ type var##_in; \
+ if(ar.is_serializing_out()) \
+ { \
+ const type &var = obj->get_func; \
+ var##_in = var; \
+ } \
+ ar.dont_allow_delay(); \
+ ar & var##_in; \
+
+#define SERIALIZE_PARENT \
+ store::Item* parent = NULL; \
+ if(ar.is_serializing_out()) \
+ parent = obj->getParent(); \
+ ar.dont_allow_delay(); \
+ serialize_node_tree(ar, parent, false);
+
+#define FINALIZE_SERIALIZE(create_func, func_params) \
+ if (!ar.is_serializing_out()) \
+ { \
+ store::Item_t result; \
+ GENV_ITEMFACTORY->create_func func_params; \
+ obj = result.getp(); \
+ if(obj) \
+ obj->addReference(); \
+ ar.set_is_temp_field(false); \
+ ar.register_reference(id, ARCHIVE_FIELD_PTR, obj); \
+ ar.set_is_temp_field(true); \
+ }
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, store::Item*& obj)
+{
+ bool is_ref = false;
+ int is_node = 0;
+ int is_atomic = 0;
+ int is_pul = 0;
+ int is_error = 0;
+ int is_function = 0;
+
+ int id;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+
+ if (ar.is_serializing_out())
+ {
+ if (obj == NULL)
+ {
+ ar.add_compound_field("store::Item*",
+ FIELD_IS_CLASS, "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+
+ char strtemp[100];
+ is_node = obj->isNode();
+ is_atomic = obj->isAtomic();
+ is_pul = obj->isPul();
+ is_error = obj->isError();
+ is_function = obj->isFunction();
+
+ assert(is_node || is_atomic || is_pul || is_error || is_function);
+
+ sprintf(strtemp, "n%da%dp%de%df%d",
+ is_node, is_atomic, is_pul, is_error, is_function);
+
+ if (is_node || is_function)
+ ar.set_is_temp_field(true);
+
+ is_ref = ar.add_compound_field("store::Item*",
+ FIELD_IS_CLASS,
+ strtemp,
+ obj,
+ ARCHIVE_FIELD_PTR);
+
+ if (is_node || is_function)
+ ar.set_is_temp_field(false);
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ bool is_simple = false;
+ bool is_class = true;
+ bool retval;
+
+ retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat, &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_class_field(retval, type, "store::Item*",
+ is_simple, is_class, field_treat, (enum ArchiveFieldKind)-1, id);
+
+ if (field_treat == ARCHIVE_FIELD_NULL)
+ {
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+
+ if ((field_treat != ARCHIVE_FIELD_PTR) && (field_treat != ARCHIVE_FIELD_REFERENCING))
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+ }
+
+ is_ref = (field_treat == ARCHIVE_FIELD_REFERENCING);
+
+ if (!is_ref)
+ {
+ sscanf(value.c_str(), "n%da%dp%de%df%d",
+ &is_node, &is_atomic, &is_pul, &is_error, &is_function);
+ }
+ }
+
+ if (!is_ref)
+ {
+ ar.set_is_temp_field(true);
+ ar.set_is_temp_field_one_level(true);
+
+ if (is_atomic)
+ {
+ store::Item_t type;
+ zstring name_of_type;
+ bool is_qname;
+
+ if (ar.is_serializing_out())
+ {
+ type = obj->getType();
+ name_of_type = type->getLocalName();
+ const zstring& ns =type->getNamespace();
+ is_qname = (name_of_type == "QName" && ns == "http://www.w3.org/2001/XMLSchema");
+ }
+
+ ar & is_qname;
+
+ if (!is_qname)
+ {
+ ar.dont_allow_delay();
+ ar & type;//save qname of type
+
+ ar.set_is_temp_field(false);
+ ar.dont_allow_delay();
+
+ ///check for User Typed Atomic Item
+ store::Item* baseItem;
+ if(ar.is_serializing_out())
+ baseItem = (store::Item*)obj->getBaseItem();
+
+ ar & baseItem;
+ ar.set_is_temp_field(true);
+ if(baseItem)
+ {
+ store::Item_t baseItem_rc(baseItem);
+ FINALIZE_SERIALIZE(createUserTypedAtomicItem, (result, baseItem_rc, type));
+ goto EndAtomicItem;
+ }
+ }
+ else if (!ar.is_serializing_out())
+ {
+ GENV_ITEMFACTORY->createQName(type, "http://www.w3.org/2001/XMLSchema", "xs", "QName");
+ }
+
+ if(!ar.is_serializing_out())
+ name_of_type = type->getLocalName();
+
+ if (name_of_type == "untyped")
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS(name_of_type));
+ }
+ else if(name_of_type == "untypedAtomic")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createUntypedAtomic, (result, value));
+ }
+ else if(name_of_type == "anyType")
+ {
+ throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS(name_of_type));
+ }
+ else if(name_of_type == "anySimpleType")
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS( name_of_type )
+ );
+ }
+ else if(name_of_type == "anyAtomicType")
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS( name_of_type )
+ );
+ }
+ else if(name_of_type == "string")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createString, (result, value));
+ }
+ else if(name_of_type == "normalizedString")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createNormalizedString, (result, value));
+ }
+ else if(name_of_type == "language")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createLanguage, (result, value));
+ }
+ else if(name_of_type == "token")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createToken, (result, value));
+ }
+ else if(name_of_type == "NMTOKEN")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createNMTOKEN, (result, value));
+ }
+ else if(name_of_type == "anyURI")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createAnyURI, (result, value));
+ }
+ else if(name_of_type == "Name")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createName, (result, value));
+ }
+ else if(name_of_type == "NCName")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createNCName, (result, value));
+ }
+ else if(name_of_type == "QName")
+ {
+ SERIALIZE_FIELD(zstring, ns, getNamespace());
+ SERIALIZE_FIELD(zstring, prefix, getPrefix());
+ SERIALIZE_FIELD(zstring, local, getLocalName());
+ FINALIZE_SERIALIZE(createQName, (result, ns, prefix, local));
+ }
+ else if(name_of_type == "NOTATION")
+ {
+ SERIALIZE_FIELD(zstring, ns, getNamespace());
+ SERIALIZE_FIELD(zstring, prefix, getPrefix());
+ SERIALIZE_FIELD(zstring, local, getLocalName());
+ FINALIZE_SERIALIZE(createNOTATION, (result, ns, prefix, local));
+ }
+ else if(name_of_type == "ID")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createID, (result, value));
+ }
+ else if(name_of_type == "IDREF")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createIDREF, (result, value));
+ }
+ else if(name_of_type == "ENTITY")
+ {
+ SERIALIZE_FIELD(zstring, value, getStringValue());
+ FINALIZE_SERIALIZE(createENTITY, (result, value));
+ }
+ else if(name_of_type == "dateTime")
+ {
+ SERIALIZE_REF_FIELD(xs_dateTime, value, getDateTimeValue());
+ FINALIZE_SERIALIZE(createDateTime, (result, &value_in));
+ }
+ else if(name_of_type == "date")
+ {
+ SERIALIZE_REF_FIELD(xs_date, value, getDateValue());
+ FINALIZE_SERIALIZE(createDate, (result, &value_in));
+ }
+ else if(name_of_type == "time")
+ {
+ SERIALIZE_REF_FIELD(xs_time, value, getTimeValue());
+ FINALIZE_SERIALIZE(createTime, (result, &value_in));
+ }
+ else if(name_of_type == "duration")
+ {
+ SERIALIZE_REF_FIELD(xs_duration, value, getDurationValue());
+ FINALIZE_SERIALIZE(createDuration, (result, &value_in));
+ }
+ else if(name_of_type == "dayTimeDuration")
+ {
+ SERIALIZE_REF_FIELD(xs_dayTimeDuration, value, getDayTimeDurationValue());
+ FINALIZE_SERIALIZE(createDayTimeDuration, (result, &value_in));
+ }
+ else if(name_of_type == "yearMonthDuration")
+ {
+ SERIALIZE_REF_FIELD(xs_yearMonthDuration, value, getYearMonthDurationValue());
+ FINALIZE_SERIALIZE(createYearMonthDuration, (result, &value_in));
+ }
+
+ else if(name_of_type == "float")
+ {
+ SERIALIZE_FIELD(xs_float, value, getFloatValue());
+ FINALIZE_SERIALIZE(createFloat, (result, value));
+ }
+ else if(name_of_type == "double")
+ {
+ SERIALIZE_FIELD(xs_double, value, getDoubleValue());
+ FINALIZE_SERIALIZE(createDouble, (result, value));
+ }
+ else if(name_of_type == "decimal")
+ {
+ SERIALIZE_FIELD(xs_decimal, value, getDecimalValue());
+ FINALIZE_SERIALIZE(createDecimal, (result, value));
+ }
+ else if(name_of_type == "integer")
+ {
+ SERIALIZE_FIELD(xs_integer, value, getIntegerValue());
+ FINALIZE_SERIALIZE(createInteger, (result, value));
+ }
+ else if(name_of_type == "nonPositiveInteger")
+ {
+ SERIALIZE_FIELD(xs_integer, value, getIntegerValue());
+ FINALIZE_SERIALIZE(createNonPositiveInteger, (result, value));
+ }
+ else if(name_of_type == "nonNegativeInteger")
+ {
+ SERIALIZE_FIELD(xs_nonNegativeInteger, value, getUnsignedIntegerValue());
+ FINALIZE_SERIALIZE(createNonNegativeInteger, (result, value));
+ }
+ else if(name_of_type == "negativeInteger")
+ {
+ SERIALIZE_FIELD(xs_integer, value, getIntegerValue());
+ FINALIZE_SERIALIZE(createNegativeInteger, (result, value));
+ }
+ else if(name_of_type == "positiveInteger")
+ {
+ SERIALIZE_FIELD(xs_positiveInteger, value, getUnsignedIntegerValue());
+ FINALIZE_SERIALIZE(createPositiveInteger, (result, value));
+ }
+
+ else if(name_of_type == "long")
+ {
+ SERIALIZE_FIELD(xs_long, value, getLongValue());
+ FINALIZE_SERIALIZE(createLong, (result, value));
+ }
+ else if(name_of_type == "int")
+ {
+ SERIALIZE_FIELD(xs_int, value, getIntValue());
+ FINALIZE_SERIALIZE(createInt, (result, value));
+ }
+ else if(name_of_type == "short")
+ {
+ SERIALIZE_FIELD(xs_short, value, getShortValue());
+ FINALIZE_SERIALIZE(createShort, (result, value));
+ }
+ else if(name_of_type == "byte")
+ {
+ SERIALIZE_FIELD(xs_byte, value, getByteValue());
+ FINALIZE_SERIALIZE(createByte, (result, value));
+ }
+ else if(name_of_type == "unsignedLong")
+ {
+ SERIALIZE_FIELD(xs_unsignedLong, value, getUnsignedLongValue());
+ FINALIZE_SERIALIZE(createUnsignedLong, (result, value));
+ }
+ else if(name_of_type == "unsignedInt")
+ {
+ SERIALIZE_FIELD(xs_unsignedInt, value, getUnsignedIntValue());
+ FINALIZE_SERIALIZE(createUnsignedInt, (result, value));
+ }
+ else if(name_of_type == "unsignedShort")
+ {
+ SERIALIZE_FIELD(xs_unsignedShort, value, getUnsignedShortValue());
+ FINALIZE_SERIALIZE(createUnsignedShort, (result, value));
+ }
+ else if(name_of_type == "unsignedByte")
+ {
+ SERIALIZE_FIELD(xs_unsignedByte, value, getUnsignedByteValue());
+ FINALIZE_SERIALIZE(createUnsignedByte, (result, value));
+ }
+
+ else if(name_of_type == "gYearMonth")
+ {
+ SERIALIZE_REF_FIELD(xs_gYearMonth, value, getGYearMonthValue());
+ FINALIZE_SERIALIZE(createGYearMonth, (result, &value_in));
+ }
+ else if(name_of_type == "gYear")
+ {
+ SERIALIZE_REF_FIELD(xs_gYear, value, getGYearValue());
+ FINALIZE_SERIALIZE(createGYear, (result, &value_in));
+ }
+ else if(name_of_type == "gMonthDay")
+ {
+ SERIALIZE_REF_FIELD(xs_gMonthDay, value, getGMonthDayValue());
+ FINALIZE_SERIALIZE(createGMonthDay, (result, &value_in));
+ }
+ else if(name_of_type == "gDay")
+ {
+ SERIALIZE_REF_FIELD(xs_gDay, value, getGDayValue());
+ FINALIZE_SERIALIZE(createGDay, (result, &value_in));
+ }
+ else if(name_of_type == "gMonth")
+ {
+ SERIALIZE_REF_FIELD(xs_gMonth, value, getGMonthValue());
+ FINALIZE_SERIALIZE(createGMonth, (result, &value_in));
+ }
+
+ else if(name_of_type == "base64Binary")
+ {
+ if (ar.is_serializing_out())
+ {
+ size_t s;
+ const char* c = obj->getBase64BinaryValue(s);
+ if (obj->isEncoded())
+ {
+ Base64 tmp;
+ Base64::parseString(c, s, tmp);
+ ar.dont_allow_delay();
+ ar & tmp;
+ }
+ else
+ {
+ Base64 tmp((const unsigned char*)c, s);
+ ar.dont_allow_delay();
+ ar & tmp;
+ }
+ }
+ else
+ {
+ ar.dont_allow_delay();
+ Base64 tmp;
+ ar & tmp;
+ FINALIZE_SERIALIZE(createBase64Binary, (result, tmp));
+ }
+ }
+ else if(name_of_type == "hexBinary")
+ {
+ SERIALIZE_REF_FIELD(xs_hexBinary, value, getHexBinaryValue());
+ FINALIZE_SERIALIZE(createHexBinary, (result, value_in));
+ }
+ else if(name_of_type == "boolean")
+ {
+ SERIALIZE_FIELD(bool, value, getBooleanValue());
+ FINALIZE_SERIALIZE(createBoolean, (result, value));
+ }
+ else
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS( name_of_type )
+ );
+ }
+EndAtomicItem:;
+ }
+ else if(is_node)
+ {
+ serialize_node_tree(ar, obj, true);
+ }
+ else if(is_pul)
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "Pul" )
+ );
+ }
+ else if(is_error)
+ {
+ ZORBA_ASSERT(false);
+ SERIALIZE_FIELD(ZorbaException*, value, getError());
+ FINALIZE_SERIALIZE(createError, (result, value));
+ }
+ else if(is_function)
+ {
+ FunctionItem *fitem = NULL;
+ if(ar.is_serializing_out())
+ {
+ fitem = dynamic_cast<FunctionItem*>(obj);
+ }
+ ar.dont_allow_delay();
+ ar.set_is_temp_field(false);
+ ar & fitem;
+ if(!ar.is_serializing_out())
+ {
+ assert(fitem);
+ obj = fitem;
+ if(obj)
+ obj->addReference();
+ ar.register_reference(id, ARCHIVE_FIELD_PTR, obj);
+ }
+ ar.set_is_temp_field(true);
+ }
+ else
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS( "[Unknown item type]" )
+ );
+ }
+
+ ar.set_is_temp_field(false);
+ ar.set_is_temp_field_one_level(false);
+ }
+
+ if(ar.is_serializing_out())
+ {
+ if(!is_ref)
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ if(!is_ref)
+ {
+ if(!is_node)
+ ar.register_item(obj);
+ ar.read_end_current_level();
+ }
+ else
+ {
+ store::Item *new_obj = NULL;
+ if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ {
+ obj = dynamic_cast<store::Item*>(new_obj);
+ if(!obj)
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
+ );
+ }
+ }
+ else if(!ar.get_is_temp_field() && !ar.get_is_temp_field_one_level())
+ ar.register_delay_reference((void**)&obj, FIELD_IS_CLASS, "store::Item*", referencing);
+ else
+ obj = NULL;
+ }
+ }
+
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void serialize_node_tree(Archiver &ar, store::Item *&obj, bool all_tree)
+{
+ //only for node items
+ //serialize first whole tree and then the item (will surely be a reference)
+ if(all_tree)
+ {
+ store::Item *parent = NULL;
+ if(ar.is_serializing_out())
+ {
+ if(obj != NULL)
+ parent = obj->getParent();
+ if(parent)
+ {
+ while(parent->getParent())
+ parent = parent->getParent();
+ }
+ if(!parent)
+ {
+ parent = obj;
+ }
+ }
+ serialize_node_tree(ar, parent, false);
+ }
+
+ ar.set_is_temp_field(false);
+
+ int id;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+ bool is_ref;
+
+ if (ar.is_serializing_out())
+ {
+ if (obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ !FIELD_IS_CLASS,
+ "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+
+ ar.set_is_temp_field(true);
+ return;
+ }
+
+ is_ref = ar.add_compound_field("store::Item*",
+ FIELD_IS_CLASS,
+ "",
+ obj,
+ ARCHIVE_FIELD_PTR);
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ bool is_simple = false;
+ bool is_class = true;
+
+ bool retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat,
+ &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ if (field_treat == ARCHIVE_FIELD_NULL)
+ {
+ obj = NULL;
+ ar.read_end_current_level();
+ ar.set_is_temp_field(true);
+ return;
+ }
+ ar.check_class_field(retval, type, "store::Item*", is_simple, is_class, field_treat, (enum ArchiveFieldKind)-1, id);
+ //ar.register_reference(id, &obj);
+ if((field_treat != ARCHIVE_FIELD_PTR) && (field_treat != ARCHIVE_FIELD_REFERENCING))
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
+ );
+ }
+ is_ref = (field_treat == ARCHIVE_FIELD_REFERENCING);
+ }
+ ar.set_is_temp_field(true);
+
+ if(!is_ref)
+ {
+ store::StoreConsts::NodeKind nodekind = store::StoreConsts::anyNode;
+ if(ar.is_serializing_out())
+ nodekind = obj->getNodeKind();
+ SERIALIZE_ENUM(store::StoreConsts::NodeKind, nodekind);
+ switch(nodekind)
+ {
+ case store::StoreConsts::anyNode:
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "anyNode" )
+ );
+ case store::StoreConsts::documentNode:
+ {
+ SERIALIZE_FIELD2(zstring, baseUri, getBaseURI);
+ SERIALIZE_FIELD2(zstring, docUri, getDocumentURI);
+ FINALIZE_SERIALIZE(createDocumentNode, (result, baseUri, docUri));
+ serialize_my_children(ar, obj->getChildren());
+ }break;
+ case store::StoreConsts::elementNode:
+ {
+ SERIALIZE_PARENT;
+ //pos = -1
+ SERIALIZE_FIELD(store::Item_t, nodename, getNodeName());
+ SERIALIZE_FIELD(store::Item_t, name_of_type, getType());
+ SERIALIZE_FIELD(bool, isInSubstGroup, isInSubstitutionGroup());
+ bool haveTypedValue = false;
+ bool haveEmptyValue = true;
+ if(ar.is_serializing_out())
+ {
+ //workaround
+ // store::simplestore::ElementNode *elem_node = dynamic_cast<store::simplestore::ElementNode*>(obj);
+ // haveTypedValue = elem_node->haveTypedValue();
+ // haveEmptyValue = elem_node->haveEmptyValue();
+ if(!ZSTREQ(name_of_type->getNamespace(), "http://www.w3.org/2001/XMLSchema") ||
+ !ZSTREQ(name_of_type->getLocalName(), "untyped"))
+ haveTypedValue = true;
+ }
+ ar & haveTypedValue;
+ ar & haveEmptyValue;
+ store::NsBindings ns_bindings;
+ if(ar.is_serializing_out())
+ obj->getNamespaceBindings(ns_bindings, store::StoreConsts::ONLY_LOCAL_NAMESPACES);
+ ar & ns_bindings;
+ SERIALIZE_FIELD2(zstring, baseUri, getBaseURI);
+ FINALIZE_SERIALIZE(createElementNode, (result, parent, nodename, name_of_type, haveTypedValue, haveEmptyValue, ns_bindings, baseUri, isInSubstGroup));
+
+ serialize_my_children2(ar, obj->getAttributes());
+
+ serialize_my_children(ar, obj->getChildren());
+ }break;
+ case store::StoreConsts::attributeNode:
+ {
+ SERIALIZE_PARENT;
+ SERIALIZE_FIELD(store::Item_t, nodename, getNodeName());
+ SERIALIZE_FIELD(store::Item_t, name_of_type, getType());
+ store::Item_t val;
+ store::Iterator_t val_it;
+ if(ar.is_serializing_out())
+ obj->getTypedValue(val, val_it);
+ ar & val;
+ std::vector<store::Item_t> val_vector;
+ if(val == NULL)
+ {
+ iterator_to_vector(val_it, val_vector);
+ }
+ ar & val_vector;
+ if(val != NULL)
+ {
+ FINALIZE_SERIALIZE(createAttributeNode, (result, parent, nodename, name_of_type, val));
+ }
+ else
+ {
+ FINALIZE_SERIALIZE(createAttributeNode, (result, parent, nodename, name_of_type, val_vector));
+ }
+ }break;
+ case store::StoreConsts::textNode:
+ {
+ SERIALIZE_PARENT;
+ SERIALIZE_FIELD(zstring, content, getStringValue());
+ FINALIZE_SERIALIZE(createTextNode, (result, parent, content));
+ }break;
+ case store::StoreConsts::piNode:
+ {
+ SERIALIZE_PARENT;
+ SERIALIZE_FIELD(zstring, target, getTarget());
+ SERIALIZE_FIELD(zstring, content, getStringValue());
+ SERIALIZE_FIELD2(zstring, baseUri, getBaseURI);
+ FINALIZE_SERIALIZE(createPiNode, (result, parent, target, content, baseUri));
+ }break;
+ case store::StoreConsts::commentNode:
+ {
+ SERIALIZE_PARENT;
+ SERIALIZE_FIELD(zstring, content, getStringValue());
+ FINALIZE_SERIALIZE(createCommentNode, (result, parent, content));
+ }break;
+ default:
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "unknown" )
+ );
+ }
+ }//end is_ref
+
+ if(ar.is_serializing_out())
+ {
+ if(!is_ref)
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ if(!is_ref)
+ {
+ ar.register_item(obj);
+ ar.read_end_current_level();
+ }
+ else
+ {
+ store::Item *new_obj = NULL;
+ if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ {
+ obj = dynamic_cast<store::Item*>(new_obj);
+ if(!obj)
+ {
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
+ );
+ }
+ }
+ else if(!ar.get_is_temp_field() && !ar.get_is_temp_field_one_level())
+ ar.register_delay_reference((void**)&obj, FIELD_IS_CLASS, "store::Item*", referencing);
+ else
+ obj = NULL;
+ }
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver &ar, zorba::store::TempSeq *obj)
+{
+ throw ZORBA_EXCEPTION(
+ zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "TempSeq" )
+ );
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver &ar, const Diagnostic *&obj)
+{
+ if(ar.is_serializing_out())
+ {
+ if(obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ !FIELD_IS_CLASS, "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+ bool is_ref;
+ assert(!ar.is_serialize_base_class());
+ Diagnostic *diagnostic = const_cast<Diagnostic*>(obj);
+ UserError *user_err = dynamic_cast<UserError*>(diagnostic);
+ XQueryErrorCode *xquery_err = dynamic_cast<XQueryErrorCode*>(diagnostic);
+ ZorbaErrorCode *zorba_err = dynamic_cast<ZorbaErrorCode*>(diagnostic);
+ char err_type[20];
+ sprintf(err_type, "u%dx%dz%d",
+ user_err != NULL ? 1 : 0,
+ xquery_err != NULL ? 1 : 0,
+ zorba_err != NULL ? 1 : 0);
+ is_ref = ar.add_compound_field("Diagnostic*",
+ !FIELD_IS_CLASS, err_type,
+ obj,
+ ARCHIVE_FIELD_PTR);
+ if(!is_ref)
+ {
+ if(user_err)
+ {
+ ar & user_err->qname_;
+ }
+ else
+ {
+ ar.set_is_temp_field(true);
+ const diagnostic::QName &errqn = obj->qname();
+ char* strtemp = (char*)errqn.localname();
+ ar & strtemp;
+ ar.set_is_temp_field(false);
+ }
+
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "Diagnostic*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+ if(field_treat == ARCHIVE_FIELD_NULL)
+ {
+ assert(!ar.is_serialize_base_class());
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+ if(field_treat == ARCHIVE_FIELD_PTR)
+ {
+ int is_user, is_xquery, is_zorba;
+ sscanf(value.c_str(), "u%dx%dz%d", &is_user, &is_xquery, &is_zorba);
+ if(is_user)
+ {
+ UserError *user_error = new UserError(ar);
+ ar & user_error->qname_;
+ obj = user_error;
+ }
+ else if(is_xquery || is_zorba)
+ {
+ ar.set_is_temp_field(true);
+ char* local;
+ ar & local;
+ ar.set_is_temp_field(false);
+ obj = internal::SystemDiagnosticBase::find(local);
+ free(local);
+ ZORBA_ASSERT(obj);
+ }
+ else
+ {
+ ZORBA_ASSERT(false);//unreachable, maybe a new Error class has been added
+ }
+ ar.register_reference(id, field_treat, obj);
+ ar.read_end_current_level();
+ }
+ else if((obj = (Diagnostic*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ {
+ }
+ else
+ {
+ ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "Diagnostic*", referencing);
+ }
+ }
+
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver &ar, ZorbaException *&obj)
+{
+ if(ar.is_serializing_out())
+ {
+ if(obj == NULL)
+ {
+ ar.add_compound_field("NULL",
+ !FIELD_IS_CLASS, "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
+ return;
+ }
+ bool is_ref;
+ assert(!ar.is_serialize_base_class());
+ UserException *user_ex = dynamic_cast<UserException*>(obj);
+ XQueryException *xquery_ex = dynamic_cast<XQueryException*>(obj);
+ char ex_type[20];
+ sprintf(ex_type, "u%dx%d",
+ user_ex != NULL ? 1 : 0,
+ xquery_ex != NULL ? 1 : 0);
+ is_ref = ar.add_compound_field("ZorbaException*",
+ !FIELD_IS_CLASS, ex_type,
+ obj,
+ ARCHIVE_FIELD_PTR);
+ if(!is_ref)
+ {
+ ar & obj->diagnostic_;
+ ar & obj->raise_file_;
+ ar & obj->raise_line_;
+ ar & obj->message_;
+
+ if(xquery_ex)
+ {
+ ar & xquery_ex->source_loc_;
+ ar & xquery_ex->query_trace_;
+ }
+ if(user_ex)
+ {
+ ar & user_ex->error_object_;
+ }
+
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "ZorbaException*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+ if(field_treat == ARCHIVE_FIELD_NULL)
+ {
+ assert(!ar.is_serialize_base_class());
+ obj = NULL;
+ ar.read_end_current_level();
+ return;
+ }
+ if(field_treat == ARCHIVE_FIELD_PTR)
+ {
+ int is_user, is_xquery;
+ sscanf(value.c_str(), "u%dx%d", &is_user, &is_xquery);
+ UserException *user_ex = NULL;
+ XQueryException *xquery_ex = NULL;
+ if(is_user)
+ {
+ user_ex = new UserException(ar);
+ xquery_ex = user_ex;
+ obj = user_ex;
+ }
+ else if(is_xquery)
+ {
+ xquery_ex = new XQueryException(ar);
+ obj = xquery_ex;
+ }
+ else
+ obj = new ZorbaException(ar);
+
+ ar & obj->diagnostic_;
+ ar & obj->raise_file_;
+ ar & obj->raise_line_;
+ ar & obj->message_;
+
+ if(xquery_ex)
+ {
+ ar & xquery_ex->source_loc_;
+ ar & xquery_ex->query_trace_;
+ }
+ if(user_ex)
+ {
+ ar & user_ex->error_object_;
+ }
+
+ ar.register_reference(id, field_treat, obj);
+ ar.read_end_current_level();
+ }
+ else if((obj = (ZorbaException*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ {
+ }
+ else
+ {
+ ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "ZorbaException*", referencing);
+ }
+ }
+
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver &ar, zorba::internal::diagnostic::location &obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("internal::diagnostic::location", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ ar & obj.file_;
+ ar & obj.line_;
+ ar & obj.column_;
+ ar & obj.line_end_;
+ ar & obj.column_end_;
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "internal::diagnostic::location", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar & obj.file_;
+ ar & obj.line_;
+ ar & obj.column_;
+ ar & obj.line_end_;
+ ar & obj.column_end_;
+ ar.read_end_current_level();
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver &ar, zorba::Item &obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("zorba::Item", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ ar & obj.m_item;
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "zorba::Item", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar & obj.m_item;
+ ar.read_end_current_level();
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, zorba::XQueryStackTrace& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("XQueryStackTrace", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ ar & obj.trace_;
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "XQueryStackTrace", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar & obj.trace_;
+ ar.read_end_current_level();
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, zorba::XQueryStackTrace::Entry& obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("XQueryStackTrace::Entry", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ ar & obj.getFnNameRef();
+ ar & obj.getFnArityRef();
+ ar & obj.getFileNameRef();
+ ar & obj.getLineRef();
+ ar & obj.getColumnRef();
+ ar & obj.getLineEndRef();
+ ar & obj.getColumnEndRef();
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_nonclass_field(retval, type, "XQueryStackTrace::Entry", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar & obj.getFnNameRef();
+ ar & obj.getFnArityRef();
+ ar & obj.getFileNameRef();
+ ar & obj.getLineRef();
+ ar & obj.getColumnRef();
+ ar & obj.getLineEndRef();
+ ar & obj.getColumnEndRef();
+ ar.read_end_current_level();
+ }
+}
+
+
+}
+} // namespace zorba
+/* vim:set et sw=2 ts=2: */
=== added file 'src/zorbaserialization/serialize_zorba_types.h'
--- src/zorbaserialization/serialize_zorba_types.h 1970-01-01 00:00:00 +0000
+++ src/zorbaserialization/serialize_zorba_types.h 2012-04-10 20:15:33 +0000
@@ -0,0 +1,459 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+#ifndef ZORBA_SPECIFIC_CLASS_SERIALIZATION
+#define ZORBA_SPECIFIC_CLASS_SERIALIZATION
+
+#include <zorba/item.h>
+#include <zorba/xquery_exception.h>
+#include "zorbatypes/rchandle.h"
+#include "zorbatypes/m_apm.h"
+#include "zorbatypes/floatimpl.h"
+#include "zorbautils/checked_vector.h"
+
+#include "zorbaserialization/class_serializer.h"
+#include "zorbaserialization/archiver.h"
+
+#include "store/api/shared_types.h"
+#include "diagnostics/assert.h"
+
+#include <stdio.h>
+#include <map>
+
+namespace zorba
+{
+ class XQType;
+ class function;
+ class Diagnostic;
+ class ZorbaException;
+#ifdef ZORBA_WITH_BIG_INTEGER
+ class IntegerImpl;
+#else
+ template<typename IntType> class IntegerImpl;
+#endif /* ZORBA_WITH_BIG_INTEGER */
+
+namespace serialization
+{
+
+void operator&(Archiver &ar, const XQType *&obj);
+void operator&(Archiver &ar, MAPM &obj);
+#ifdef ZORBA_WITH_BIG_INTEGER
+void operator&(Archiver &ar, IntegerImpl &obj);
+#else
+template<typename IntType>
+void operator&(Archiver &ar, IntegerImpl<IntType> &obj);
+#endif /* ZORBA_WITH_BIG_INTEGER */
+
+void operator&(Archiver &ar, XQPCollator *&obj);
+void operator&(Archiver &ar, store::Item* &obj);
+
+void operator&(Archiver &ar, const Diagnostic *&obj);
+void operator&(Archiver &ar, ZorbaException *&obj);
+void operator&(Archiver &ar, zorba::internal::diagnostic::location &obj);
+void operator&(Archiver &ar, zorba::Item &obj);
+void operator&(Archiver &ar, zorba::XQueryStackTrace &obj);
+void operator&(Archiver &ar, zorba::XQueryStackTrace::Entry &obj);
+
+
+#define SERIALIZE_TYPEMANAGER(type_mgr_type, type_mgr) \
+ bool is_root_type_mgr = ar.is_serializing_out() && (!GENV.isRootStaticContextInitialized() || ((TypeManager*)type_mgr == (TypeManager*)&GENV_TYPESYSTEM)) && ar.is_serializing_out(); \
+ ar.set_is_temp_field_one_level(true); \
+ ar & is_root_type_mgr; \
+ ar.set_is_temp_field_one_level(false); \
+ if(is_root_type_mgr) \
+ { \
+ if(!ar.is_serializing_out()) \
+ { \
+ type_mgr = (type_mgr_type*)&GENV_TYPESYSTEM; \
+ /*RCHelper::addReference(type_mgr);*/ \
+ } \
+ } \
+ else \
+ { \
+ ar & type_mgr; \
+ }
+
+#define SERIALIZE_TYPEMANAGER_RCHANDLE(type_mgr_type, type_mgr) \
+ bool is_root_type_mgr = (!GENV.isRootStaticContextInitialized() || ((TypeManager*)type_mgr.getp() == (TypeManager*)&GENV_TYPESYSTEM)); \
+ ar.set_is_temp_field_one_level(true); \
+ ar & is_root_type_mgr; \
+ ar.set_is_temp_field_one_level(false); \
+ if(is_root_type_mgr) \
+ { \
+ if(!ar.is_serializing_out()) \
+ type_mgr = (type_mgr_type*)&GENV_TYPESYSTEM; \
+ } \
+ else \
+ { \
+ ar & type_mgr; \
+ }
+
+
+template<class T>
+void operator&(Archiver& ar, checked_vector<T>& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ char strtemp[20];
+ sprintf(strtemp, "%d", (int)obj.size());
+
+ bool is_ref;
+ is_ref = ar.add_compound_field("checked_vector<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
+
+ if (!is_ref)
+ {
+ typename checked_vector<T>::iterator it;
+ for(it = obj.begin(); it != obj.end(); ++it)
+ {
+ ar & (*it);
+ }
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+
+ retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat, &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_nonclass_field(retval, type, "checked_vector<T>",
+ is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar.register_reference(id, field_treat, &obj);
+
+ int size;
+ sscanf(value.c_str(), "%d", &size);
+ obj.resize(size);
+ typename checked_vector<T>::iterator it;
+ for(it = obj.begin(); it != obj.end(); ++it)
+ {
+ ar & (*it);
+ }
+ ar.read_end_current_level();
+ }
+}
+
+
+template<class T>
+void operator&(Archiver& ar, store::ItemHandle<T>& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ bool is_ref;
+ ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
+ is_ref = ar.add_compound_field("ItemHandle<T>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ if(!is_ref)
+ {
+ T *p = obj.getp();
+ if(allow_delay != ALLOW_DELAY)
+ ar.dont_allow_delay(allow_delay);
+ bool is_temp = false;
+ if(ar.get_is_temp_field_one_level())
+ {
+ is_temp = true;
+ ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
+ if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
+ ar.dont_allow_delay();
+ }
+ ar & p;
+ if(is_temp)
+ ar.set_is_temp_field_one_level(false);
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "ItemHandle<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ //ar.register_reference(id, field_treat, &obj);
+
+ bool is_temp = false;
+ if(ar.get_is_temp_field_one_level())
+ {
+ is_temp = true;
+ ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
+ }
+ T *p;
+ ar & p;
+ if(is_temp)
+ ar.set_is_temp_field_one_level(false);
+ obj = p;
+ if(p == NULL)
+ {
+ //workaround for the strict_aliasing warning in gcc
+ union
+ {
+ T **t;
+ void **v;
+ }u_p;
+ u_p.t = &p;
+ ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
+ }
+ ar.read_end_current_level();
+
+ }
+}
+
+
+template<class T>
+void operator&(Archiver &ar, zorba::rchandle<T> &obj)
+{
+ if(ar.is_serializing_out())
+ {
+ bool is_ref;
+ ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
+ is_ref = ar.add_compound_field("rchandle<T>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
+ assert(!is_ref);
+ ZORBA_ASSERT(!is_ref);
+ {
+ T *p = obj.getp();
+ if(allow_delay != ALLOW_DELAY)
+ ar.dont_allow_delay(allow_delay);
+ bool is_temp = false;
+ if(ar.get_is_temp_field_one_level())
+ {
+ is_temp = true;
+ ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
+ if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
+ ar.dont_allow_delay();
+ }
+ ar & p;
+ if(is_temp)
+ ar.set_is_temp_field_one_level(false);
+ ar.add_end_compound_field();
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+ retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
+ if(!retval && ar.get_read_optional_field())
+ return;
+ ar.check_nonclass_field(retval, type, "rchandle<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+ //ar.register_reference(id, field_treat, &obj);
+
+ bool is_temp = false;
+ if(ar.get_is_temp_field_one_level())
+ {
+ is_temp = true;
+ ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
+ }
+ T *p;
+ ar & p;
+ if(is_temp)
+ ar.set_is_temp_field_one_level(false);
+ obj = p;
+ if(p == NULL)
+ {
+ //workaround for the strict_aliasing warning in gcc
+ union
+ {
+ T **t;
+ void **v;
+ }u_p;
+ u_p.t = &p;
+ ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
+ }
+ ar.read_end_current_level();
+
+ }
+}
+
+
+template<class T>
+void operator&(Archiver& ar, zorba::const_rchandle<T>& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ bool is_ref;
+ ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
+
+ is_ref = ar.add_compound_field("const_rchandle<T>",
+ !FIELD_IS_CLASS,
+ "",
+ &obj,
+ ARCHIVE_FIELD_NORMAL);
+ if (!is_ref)
+ {
+ T *p = (T*)obj.getp();
+
+ if(allow_delay != ALLOW_DELAY)
+ ar.dont_allow_delay(allow_delay);
+
+ bool is_temp = false;
+
+ if(ar.get_is_temp_field_one_level())
+ {
+ is_temp = true;
+ ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
+ if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
+ ar.dont_allow_delay();
+ }
+ ar & p;
+ if(is_temp)
+ ar.set_is_temp_field_one_level(false);
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char *type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+
+ retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat, &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_nonclass_field(retval, type, "const_rchandle<T>",
+ is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ bool is_temp = false;
+
+ if (ar.get_is_temp_field_one_level())
+ {
+ is_temp = true;
+ ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
+ }
+
+ T *p;
+ ar & p;
+ obj = p;
+
+ if(is_temp)
+ ar.set_is_temp_field_one_level(false);
+
+ if(p == NULL)
+ {
+ //workaround for the strict_aliasing warning in gcc
+ union
+ {
+ T **t;
+ void **v;
+ }u_p;
+ u_p.t = &p;
+ ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
+ }
+ ar.read_end_current_level();
+ }
+}
+
+
+template<typename StringType>
+void operator&(Archiver& ar, zorba::internal::VariableQName<StringType>& obj)
+{
+ if (ar.is_serializing_out())
+ {
+ bool is_ref;
+ is_ref = ar.add_compound_field("VariableQName<StringType>",
+ !FIELD_IS_CLASS,
+ "",
+ &obj,
+ ARCHIVE_FIELD_NORMAL);
+ if (!is_ref)
+ {
+ ar & obj.ns_;
+ ar & obj.prefix_;
+ ar & obj.localname_;
+ ar.add_end_compound_field();
+ }
+ else
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ char* type;
+ std::string value;
+ int id;
+ bool is_simple = false;
+ bool is_class = false;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+ int referencing;
+ bool retval;
+
+ retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat, &referencing);
+
+ if (!retval && ar.get_read_optional_field())
+ return;
+
+ ar.check_nonclass_field(retval, type, "VariableQName<StringType>",
+ is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ ar & obj.ns_;
+ ar & obj.prefix_;
+ ar & obj.localname_;
+ ar.read_end_current_level();
+ }
+}
+
+
+template<typename FloatType>
+void operator&(Archiver& ar, FloatImpl<FloatType>& obj)
+{
+ ar & obj.value_;
+ ar & obj.precision_;
+}
+
+} // namespace serialization
+} // namespae zorba
+#endif
+/* vim:set et sw=2 ts=2: */
=== removed file 'src/zorbaserialization/template_serializer.h'
--- src/zorbaserialization/template_serializer.h 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/template_serializer.h 1970-01-01 00:00:00 +0000
@@ -1,911 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-#ifndef TEMPLATE_SERIALIZATION_OPERATORS
-#define TEMPLATE_SERIALIZATION_OPERATORS
-
-#include <list>
-#include <vector>
-#include <map>
-#include <stdio.h>
-
-#include <zorba/diagnostic_list.h>
-#include <zorba/internal/unique_ptr.h>
-
-#include "util/string_util.h"
-#include "util/stl_util.h"
-#include "diagnostics/xquery_diagnostics.h"
-#include "zorbatypes/zstring.h"
-
-#include "archiver.h"
-#include "class_serializer.h"
-#include "serialize_basic_types.h"
-
-namespace zorba
-{
-namespace serialization
-{
-/////////////////////////////templates
-
-#define ZORBA_SER_ERROR_DESC_OSS(QNAME,MSG) \
- do { \
- std::ostringstream oss; \
- oss << MSG; \
- throw XQUERY_EXCEPTION( QNAME, ERROR_PARAMS( oss.str() ) ); \
- } while (0)
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<class RepType>
-void operator&(Archiver& ar, zorba::rstring<RepType>& obj)
-{
- bool is_normal_str = true;
- if(ar.is_serializing_out())
- {
- if(obj.size() != strlen(obj.c_str()))
- is_normal_str = false;
- }
- ar.set_is_temp_field(true);
- ar & is_normal_str;
- ar.set_is_temp_field(false);
-
- if(is_normal_str)
- {
- if(ar.is_serializing_out())
- {
- ar.add_simple_field("rstring", obj.c_str(), &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = true;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "rstring", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- obj = value;
- ar.register_reference(id, field_treat, &obj);
- }
- }
- else
- {
- //for strings which contain '\0' inside
- if(ar.is_serializing_out())
- {
- const char *cstr = obj.c_str();
- zorba::zstring::size_type s = obj.size();
-
- ar.set_is_temp_field(true);
- ar & s;
- serialize_array(ar, (unsigned char*)cstr, s);
- ar.set_is_temp_field(false);
- }
- else
- {
- std::unique_ptr<unsigned char[]> cstr;
- zorba::zstring::size_type s;
-
- ar.set_is_temp_field(true);
- ar & s;
- cstr.reset(new unsigned char[s]);
- serialize_array(ar, (unsigned char*)cstr.get(), s);
- obj.assign((const char*)cstr.get(), s);
- ar.set_is_temp_field(false);
- }
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T>
-void operator&(Archiver& ar, std::list<T>& obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[20];
-#ifndef WIN32
- sprintf(strtemp, "%d", (int)obj.size());
-#else
- sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj.size());
-#endif
- bool is_ref;
- is_ref = ar.add_compound_field("std::list<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- typename std::list<T>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- ar & (*it);
- }
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::list<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- ar.register_reference(id, field_treat, &obj);
-
- int size;
- sscanf(value.c_str(), "%d", &size);
- obj.resize(size);
- typename std::list<T>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- ar & (*it);
- }
- ar.read_end_current_level();
-
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T>
-void operator&(Archiver& ar, std::vector<T>& obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[20];
-#ifndef WIN32
- sprintf(strtemp, "%d", (int)obj.size());
-#else
- sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj.size());
-#endif
- bool is_ref;
- is_ref = ar.add_compound_field("std::vector<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- typename std::vector<T>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- ar & (*it);
- }
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::vector<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- ar.register_reference(id, field_treat, &obj);
-
- int size;
- sscanf(value.c_str(), "%d", &size);
- obj.resize(size);
- typename std::vector<T>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- ar & (*it);
- }
- ar.read_end_current_level();
-
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T>
-void operator&(Archiver& ar, std::vector<T>*& obj)
-{
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
- char strtemp[20];
-#ifndef WIN32
- sprintf(strtemp, "%d", (int)obj->size());
-#else
- sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj->size());
-#endif
- bool is_ref;
- is_ref = ar.add_compound_field("std::vector<T>*", !FIELD_IS_CLASS, strtemp, obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
- if(ar.is_serialize_base_class())
- ar.set_serialize_base_class(false);
- if(!is_ref)
- {
- typename std::vector<T>::iterator it;
- for(it=obj->begin(); it != obj->end(); it++)
- {
- ar & (*it);
- }
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::vector<T>*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
- if(ar.is_serialize_base_class())
- ar.set_serialize_base_class(false);
- void *new_obj;
- if(field_treat == ARCHIVE_FIELD_PTR)
- {
- obj = new std::vector<T>;
- ar.register_reference(id, field_treat, obj);
-
- int size;
- sscanf(value.c_str(), "%d", &size);
- obj->resize(size);
- typename std::vector<T>::iterator it;
- for(it=obj->begin(); it != obj->end(); it++)
- {
- ar & (*it);
- }
- ar.read_end_current_level();
- }
- else if(field_treat == ARCHIVE_FIELD_BASECLASS)
- {
- int size;
- sscanf(value.c_str(), "%d", &size);
- obj->resize(size);
- typename std::vector<T>::iterator it;
- for(it=obj->begin(); it != obj->end(); it++)
- {
- ar & (*it);
- }
- ar.read_end_current_level();
- }
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
- {
- obj = (std::vector<T>*)new_obj;
- if(!obj)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
- else
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "std::vector<T>*", referencing);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T>
-void operator&(Archiver& ar, std::vector<T*>& obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[20];
-#ifndef WIN32
- sprintf(strtemp, "%d", (int)obj.size());
-#else
- sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj.size());
-#endif
- bool is_ref;
- is_ref = ar.add_compound_field("std::vector<T*>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- typename std::vector<T*>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- ar & (*it);
- }
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::vector<T*>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- ar.register_reference(id, field_treat, &obj);
-
- int size;
- sscanf(value.c_str(), "%d", &size);
- obj.resize(size);
- typename std::vector<T*>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- ar & (*it);
- }
- ar.read_end_current_level();
-
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T1, typename T2>
-void operator&(Archiver& ar, std::pair<T1, T2>& obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("std::pair<T1, T2>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- ar & obj.first;
- ar & obj.second;
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- ar.register_reference(id, field_treat, &obj);
-
- ar & obj.first;
- ar & obj.second;
- ar.read_end_current_level();
-
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T1, typename T2>
-void operator&(Archiver& ar, std::pair<T1, T2>*& obj)
-{
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
- bool is_ref;
- is_ref = ar.add_compound_field("std::pair<T1, T2>", !FIELD_IS_CLASS, "", &obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
- if(ar.is_serialize_base_class())
- ar.set_serialize_base_class(false);
- if(!is_ref)
- {
- ar & obj->first;
- ar & obj->second;
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
- if(ar.is_serialize_base_class())
- ar.set_serialize_base_class(false);
-
- void *new_obj;
- if(field_treat == ARCHIVE_FIELD_PTR)
- {
- obj = new std::pair<T1, T2>;
- ar.register_reference(id, field_treat, &obj);
-
- ar & obj->first;
- ar & obj->second;
- ar.read_end_current_level();
- }
- else if(field_treat == ARCHIVE_FIELD_BASECLASS)
- {
- ar & obj->first;
- ar & obj->second;
- ar.read_end_current_level();
- }
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
- {
- obj = (std::pair<T1, T2>*)new_obj;
- if(!obj)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
- else
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "std::pair<T1, T2>", referencing);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T1, typename T2>
-void operator&(Archiver& ar, std::map<T1, T2>*& obj)
-{
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
- bool is_ref;
- is_ref = ar.add_compound_field("std::map<T1, T2>", !FIELD_IS_CLASS, "", obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
- if(ar.is_serialize_base_class())
- ar.set_serialize_base_class(false);
- if(!is_ref)
- {
- ar.set_is_temp_field_one_level(true);
- int s = (int)obj->size();
- ar & s;
- typename std::map<T1, T2>::iterator it;
- for(it=obj->begin(); it != obj->end(); it++)
- {
- ar.dont_allow_delay();
- T1 t1 = (*it).first;
- ar & t1;
- ar.dont_allow_delay();
- ar & (*it).second;
- }
- ar.set_is_temp_field_one_level(false);
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
- if(ar.is_serialize_base_class())
- ar.set_serialize_base_class(false);
- void *new_obj;
- if(field_treat == ARCHIVE_FIELD_PTR)
- {
- obj = new std::map<T1, T2>;
- ar.register_reference(id, field_treat, obj);
-
- ar.set_is_temp_field_one_level(true);
- int s;
- ar & s;
- typename std::map<T1, T2>::iterator it;
- std::pair<T1, T2> p;
- for(int i=0;i<s;i++)
- {
- ar & p.first;
- ar & p.second;
- obj->insert(p);
- }
- ar.set_is_temp_field_one_level(false);
- ar.read_end_current_level();
- }
- else if(field_treat == ARCHIVE_FIELD_BASECLASS)
- {
- ar.set_is_temp_field_one_level(true);
- int s;
- ar & s;
- typename std::map<T1, T2>::iterator it;
- std::pair<T1, T2> p;
- for(int i=0;i<s;i++)
- {
- ar & p.first;
- ar & p.second;
- obj->insert(p);
- }
- ar.set_is_temp_field_one_level(false);
- ar.read_end_current_level();
- }
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
- {
- obj = (std::map<T1, T2>*)new_obj;
- if(!obj)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
- else
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "std::map<T1, T2>", referencing);
- }
-}
-
-void operator&(Archiver &ar, short &obj);
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<typename T1, typename T2, class Tcomp>
-void operator&(Archiver& ar, std::map<T1, T2, Tcomp>& obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("std::map<T1, T2>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- ar.set_is_temp_field_one_level(true);
- int s = (int)obj.size();
- ar & s;
- typename std::map<T1, T2, Tcomp>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
- {
- T1 t1 = (*it).first;
- ar.dont_allow_delay();
- ar & t1;
- ar.dont_allow_delay();
- ar & (*it).second;
- }
- ar.set_is_temp_field_one_level(false);
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar.register_reference(id, field_treat, &obj);
-
- ar.set_is_temp_field_one_level(true);
- int s;
- ar & s;
- //typename std::map<T1, T2>::iterator it;
- std::pair<T1, T2> p;
- for(int i=0;i<s;i++)
- {
- ar & p.first;
- ar & p.second;
- obj.insert(p);
- }
- ar.set_is_temp_field_one_level(false);
- ar.read_end_current_level();
- }
-}
-
-/*******************************************************************************
-
-********************************************************************************/
-template<class T>
-void operator&(Archiver& ar, T& obj)
-{
- if (ar.is_serializing_out())
- {
- bool is_ref;
-
- is_ref = ar.add_compound_field(obj.get_class_name_str(),//typeid(obj).name()+6,
- FIELD_IS_CLASS,
- "0",//strtemp,
- (SerializeBaseClass*)&obj,
- ARCHIVE_FIELD_NORMAL);
- if (!is_ref)
- {
- obj.serialize_internal(ar);
- ar.add_end_compound_field();
- }
- }
- else
- {
- char* type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = true;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_class_field(retval, type, obj.get_class_name_str(), is_simple, is_class, field_treat,
- ARCHIVE_FIELD_NORMAL,
- id);
- ar.register_reference(id, field_treat, (SerializeBaseClass*)&obj);
-
- obj.serialize_internal(ar);
-
- ar.read_end_current_level();
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<class T>
-void operator&(Archiver& ar, T*& obj)
-{
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
- bool is_ref;
-
- is_ref = ar.add_compound_field((ar.is_serialize_base_class() ?
- obj->T::get_class_name_str() :
- obj->get_class_name_str()),
- FIELD_IS_CLASS,
- "0",//strtemp,
- (SerializeBaseClass*)obj,
- ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
- if(!is_ref)
- {
- if(!ar.is_serialize_base_class())
- {
- obj->serialize_internal(ar);
- }
- else
- {
- obj->T::serialize_internal(ar);
- }
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = true;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_class_field(retval, "", "", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- assert(!ar.is_serialize_base_class());
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
-
- if (ar.is_serialize_base_class())
- {
-#ifndef NDEBUG
- if(strcmp(type, T::get_class_name_str_static()))
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
- }
-#endif
- if(field_treat != ARCHIVE_FIELD_BASECLASS)
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
- }
- }
- else
- {
- if((field_treat != ARCHIVE_FIELD_PTR) && (field_treat != ARCHIVE_FIELD_REFERENCING))
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
-
- SerializeBaseClass* new_obj = NULL;
- if(field_treat == ARCHIVE_FIELD_PTR)
- {
- class_deserializer* cls_factory;
- cls_factory = ClassSerializer::getInstance()->get_class_factory(type);
- if(cls_factory == NULL)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0003_UNRECOGNIZED_CLASS_FIELD, ERROR_PARAMS( type )
- );
- }
- new_obj = cls_factory->create_new(ar);
- obj = dynamic_cast<T*>(new_obj);
- if(!obj)
- {
- delete new_obj;obj=NULL;
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD,
- ERROR_PARAMS( id, type, typeid(T).name() )
- );
- }
-
- ar.register_reference(id, field_treat, new_obj);
- try
- {
- new_obj->serialize_internal(ar);
- }
- catch(...)
- {
- delete new_obj;obj=NULL;
- throw;
- }
- ar.read_end_current_level();
- }
- else if(field_treat == ARCHIVE_FIELD_BASECLASS)
- {
- obj->T::serialize_internal(ar);
- ar.read_end_current_level();
- }
- else if((new_obj = (SerializeBaseClass*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
- {
- try
- {
- obj = dynamic_cast<T*>(new_obj);
- }
- catch(...)
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0004_UNRESOLVED_FIELD_REFERENCE,
- ERROR_PARAMS(id));
- }
- if(!obj)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
- else
- {
- ar.register_delay_reference((void**)&obj, FIELD_IS_CLASS, obj->T::get_class_name_str(), referencing);
- }
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<class T>
-void serialize_baseclass(Archiver& ar, T* obj)
-{
- ar.set_serialize_base_class(true);
-
- ar & obj;
-
- //ar.set_serialize_base_class(false);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-template<class T>
-void read_optional_field(Archiver& ar, T& obj)
-{
- ar.set_read_optional_field(true);
- ar & obj;
- ar.set_read_optional_field(false);
-}
-
-} // namespace serialization
-} // namespace zorba
-
-#endif /* TEMPLATE_SERIALIZATION_OPERATORS */
-/* vim:set et sw=2 ts=2: */
=== removed file 'src/zorbaserialization/zorba_class_serializer.cpp'
--- src/zorbaserialization/zorba_class_serializer.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/zorba_class_serializer.cpp 1970-01-01 00:00:00 +0000
@@ -1,1497 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "stdafx.h"
-
-#include <zorba/error.h>
-#include <zorba/diagnostic_list.h>
-#include <zorba/internal/qname.h>
-#include <zorba/item.h>
-#include <zorba/user_exception.h>
-
-#include "zorbaserialization/serialization_engine.h"
-
-#include "types/typeimpl.h"
-#include "types/root_typemanager.h"
-
-#include "system/globalenv.h"
-
-#include "store/api/item.h"
-#include "store/api/item_handle.h"
-#include "store/api/iterator.h"
-#include "store/api/item_factory.h"
-//#include "store/api/tuples.h"
-
-#include "zorbatypes/datetime.h"
-#include "zorbatypes/collation_manager.h"
-#include "zorbatypes/integer.h"
-
-#include "functions/function.h"
-#include "runtime/function_item/function_item.h"
-
-#include "context/static_context.h"
-
-#include "diagnostics/xquery_diagnostics.h"
-#include "diagnostics/assert.h"
-#include "util/string_util.h"
-
-#include <zorba/store_consts.h>
-
-namespace zorba{
- namespace serialization{
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class store_item_class_factory : public ::zorba::serialization::class_deserializer
-{
-public:
- store_item_class_factory()
- {
- ::zorba::serialization::ClassSerializer::getInstance()->
- register_class_factory("store::Item*", this);
- }
-
- virtual ::zorba::serialization::SerializeBaseClass* create_new(
- ::zorba::serialization::Archiver& ar)
- {
- return NULL;
- }
-
- virtual void cast_ptr(::zorba::serialization::SerializeBaseClass* ptr, void** class_ptr)
- {
- *class_ptr = (void*)dynamic_cast<store::Item*>(ptr);
- }
-
-};
-
-
-store_item_class_factory g_store_item_class_factory;
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class xqpcollator_class_factory : public ::zorba::serialization::class_deserializer
-{
-public:
- xqpcollator_class_factory()
- {
- ::zorba::serialization::ClassSerializer::getInstance()->
- register_class_factory("XQPCollator*", this);
- }
-
- virtual ::zorba::serialization::SerializeBaseClass* create_new(
- ::zorba::serialization::Archiver& ar)
- {
- return NULL;
- }
-
- virtual void cast_ptr(::zorba::serialization::SerializeBaseClass* ptr, void** class_ptr)
- {
- *class_ptr = (void*)dynamic_cast<XQPCollator*>(ptr);
- }
-};
-
-xqpcollator_class_factory g_xqpcollator_class_factory;
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, const XQType*& obj)
-{
- XQType* obj2 = (XQType*)obj;
-
- ar.dont_allow_delay();
-
- operator&(ar, obj2);
-
- if (!ar.is_serializing_out())
- obj = (const XQType*)obj2;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, XQPCollator*& obj)
-{
- if (ar.is_serializing_out())
- {
- if (obj == NULL)
- {
- ar.add_simple_field("XQPCollator*",
- "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
-
- ar.add_simple_field("XQPCollator*", obj->getURI().c_str(), obj, ARCHIVE_FIELD_PTR);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- bool is_simple = true;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
-
- bool retval = ar.read_next_field(&type, &value, &id,
- &is_simple, &is_class, &field_treat,
- &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "XQPCollator*",
- is_simple, field_treat, ARCHIVE_FIELD_PTR, id);
-
- if (field_treat == ARCHIVE_FIELD_NULL)
- {
- obj = NULL;
- return;
- }
-
- if(!value.empty())
- obj = CollationFactory::createCollator(value);
- else
- obj = CollationFactory::createCollator();
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, MAPM& obj)
-{
- if (ar.is_serializing_out())
- {
- int nr_digits = obj.significant_digits();
- char *lBuffer = (char*)malloc(nr_digits + 20);
- obj.toString(lBuffer, nr_digits);//ZORBA_FLOAT_POINT_PRECISION);
- if(strchr(lBuffer, '.'))
- {//save only necessary decimals
- char *e_ptr = strrchr(lBuffer, 'E');
- char *tail = e_ptr ? e_ptr-1 : lBuffer+strlen(lBuffer)-1;
- while(*tail == '0')
- tail--;
- if(*tail == '.')
- tail++;
- if(e_ptr)
- {
- int i;
- for(i=0;e_ptr[i];i++)
- tail[i+1] = e_ptr[i];
- tail[i+1] = 0;
- }
- else
- tail[1] = 0;
- }
-
- ar.add_simple_field("MAPM", lBuffer, &obj, ARCHIVE_FIELD_NORMAL);
- free(lBuffer);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = true;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "MAPM", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- obj = value.c_str();
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-#ifdef ZORBA_WITH_BIG_INTEGER
-void operator&(serialization::Archiver &ar, IntegerImpl &obj)
-#else
-template<typename IntType>
-void operator&(serialization::Archiver &ar, IntegerImpl<IntType> &obj)
-#endif /* ZORBA_WITH_BIG_INTEGER */
-{
- ar & obj.value_;
-}
-#ifndef ZORBA_WITH_BIG_INTEGER
-template void operator&(serialization::Archiver&, IntegerImpl<long long>&);
-template void operator&(serialization::Archiver&, IntegerImpl<unsigned long long>&);
-#endif /* ZORBA_WITH_BIG_INTEGER */
-
-/*******************************************************************************
-
-********************************************************************************/
-void iterator_to_vector(store::Iterator_t iter, std::vector<store::Item_t> &items)
-{
- store::Item_t i;
- iter->open();
- while(iter->next(i))
- {
- items.push_back(i);
- }
- iter->close();
-}
-
-void serialize_node_tree(Archiver &ar, store::Item *&obj, bool all_tree);
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void serialize_my_children(Archiver &ar, store::Iterator_t iter)
-{
- if(ar.is_serializing_out())
- {
- std::vector<store::Item_t> childs;
- iterator_to_vector(iter, childs);
- std::vector<store::Item_t>::iterator child_it;
- int child_count = (int)childs.size();
- ar & child_count;
-
- for(child_it = childs.begin(); child_it != childs.end(); child_it++)
- {
- store::Item* p = (*child_it).getp();
-
- ar.dont_allow_delay(SERIALIZE_NOW);
- //ar & p;
- serialize_node_tree(ar, p, false);
- }
- }
- else
- {
- int child_count;
- ar & child_count;
-
- for(int i=0;i<child_count;i++)
- {
- store::Item* p = NULL;
- //ar & p;//should be automatically added to DocumentNode or ElementNode
- serialize_node_tree(ar, p, false);
- }
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void serialize_my_children2(Archiver &ar, store::Iterator_t iter)
-{
- serialize_my_children(ar, iter);
-}
-
-#define SERIALIZE_FIELD(type, var, get_func)\
- type var; \
- if(ar.is_serializing_out()) \
- var = obj->get_func; \
- ar.dont_allow_delay(); \
- ar & var;
-
-#define SERIALIZE_FIELD2(type, var, get_func)\
- type var; \
- if(ar.is_serializing_out()) \
- obj->get_func(var); \
- ar.dont_allow_delay(); \
- ar & var;
-
-#define SERIALIZE_REF_FIELD(type, var, get_func) \
- type var##_in; \
- if(ar.is_serializing_out()) \
- { \
- const type &var = obj->get_func; \
- var##_in = var; \
- } \
- ar.dont_allow_delay(); \
- ar & var##_in; \
-
-#define SERIALIZE_PARENT \
- store::Item* parent = NULL; \
- if(ar.is_serializing_out()) \
- parent = obj->getParent(); \
- ar.dont_allow_delay(); \
- serialize_node_tree(ar, parent, false);
-
-#define FINALIZE_SERIALIZE(create_func, func_params) \
- if (!ar.is_serializing_out()) \
- { \
- store::Item_t result; \
- GENV_ITEMFACTORY->create_func func_params; \
- obj = result.getp(); \
- if(obj) \
- obj->addReference(); \
- ar.set_is_temp_field(false); \
- ar.register_reference(id, ARCHIVE_FIELD_PTR, obj); \
- ar.set_is_temp_field(true); \
- }
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, store::Item*& obj)
-{
- bool is_ref = false;
- int is_node = 0;
- int is_atomic = 0;
- int is_pul = 0;
- int is_error = 0;
- int is_function = 0;
-
- int id;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
-
- if (ar.is_serializing_out())
- {
- if (obj == NULL)
- {
- ar.add_compound_field("store::Item*",
- FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
-
- char strtemp[100];
- is_node = obj->isNode();
- is_atomic = obj->isAtomic();
- is_pul = obj->isPul();
- is_error = obj->isError();
- is_function = obj->isFunction();
-
- assert(is_node || is_atomic || is_pul || is_error || is_function);
-
- sprintf(strtemp, "n%da%dp%de%df%d",
- is_node, is_atomic, is_pul, is_error, is_function);
-
- if (is_node || is_function)
- ar.set_is_temp_field(true);
-
- is_ref = ar.add_compound_field("store::Item*",
- FIELD_IS_CLASS,
- strtemp,
- obj,
- ARCHIVE_FIELD_PTR);
-
- if (is_node || is_function)
- ar.set_is_temp_field(false);
- }
- else
- {
- char* type;
- std::string value;
- bool is_simple = false;
- bool is_class = true;
- bool retval;
-
- retval = ar.read_next_field(&type, &value, &id,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_class_field(retval, type, "store::Item*",
- is_simple, is_class, field_treat, (enum ArchiveFieldKind)-1, id);
-
- if (field_treat == ARCHIVE_FIELD_NULL)
- {
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
-
- if ((field_treat != ARCHIVE_FIELD_PTR) && (field_treat != ARCHIVE_FIELD_REFERENCING))
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
- }
-
- is_ref = (field_treat == ARCHIVE_FIELD_REFERENCING);
-
- if (!is_ref)
- {
- sscanf(value.c_str(), "n%da%dp%de%df%d",
- &is_node, &is_atomic, &is_pul, &is_error, &is_function);
- }
- }
-
- if (!is_ref)
- {
- ar.set_is_temp_field(true);
- ar.set_is_temp_field_one_level(true);
-
- if (is_atomic)
- {
- store::Item_t type;
- zstring name_of_type;
- bool is_qname;
-
- if (ar.is_serializing_out())
- {
- type = obj->getType();
- name_of_type = type->getLocalName();
- const zstring& ns =type->getNamespace();
- is_qname = (name_of_type == "QName" && ns == "http://www.w3.org/2001/XMLSchema");
- }
-
- ar & is_qname;
-
- if (!is_qname)
- {
- ar.dont_allow_delay();
- ar & type;//save qname of type
-
- ar.set_is_temp_field(false);
- ar.dont_allow_delay();
-
- ///check for User Typed Atomic Item
- store::Item* baseItem;
- if(ar.is_serializing_out())
- baseItem = (store::Item*)obj->getBaseItem();
-
- ar & baseItem;
- ar.set_is_temp_field(true);
- if(baseItem)
- {
- store::Item_t baseItem_rc(baseItem);
- FINALIZE_SERIALIZE(createUserTypedAtomicItem, (result, baseItem_rc, type));
- goto EndAtomicItem;
- }
- }
- else if (!ar.is_serializing_out())
- {
- GENV_ITEMFACTORY->createQName(type, "http://www.w3.org/2001/XMLSchema", "xs", "QName");
- }
-
- if(!ar.is_serializing_out())
- name_of_type = type->getLocalName();
-
- if (name_of_type == "untyped")
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
- ERROR_PARAMS(name_of_type));
- }
- else if(name_of_type == "untypedAtomic")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createUntypedAtomic, (result, value));
- }
- else if(name_of_type == "anyType")
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
- ERROR_PARAMS(name_of_type));
- }
- else if(name_of_type == "anySimpleType")
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
- ERROR_PARAMS( name_of_type )
- );
- }
- else if(name_of_type == "anyAtomicType")
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
- ERROR_PARAMS( name_of_type )
- );
- }
- else if(name_of_type == "string")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createString, (result, value));
- }
- else if(name_of_type == "normalizedString")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createNormalizedString, (result, value));
- }
- else if(name_of_type == "language")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createLanguage, (result, value));
- }
- else if(name_of_type == "token")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createToken, (result, value));
- }
- else if(name_of_type == "NMTOKEN")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createNMTOKEN, (result, value));
- }
- else if(name_of_type == "anyURI")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createAnyURI, (result, value));
- }
- else if(name_of_type == "Name")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createName, (result, value));
- }
- else if(name_of_type == "NCName")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createNCName, (result, value));
- }
- else if(name_of_type == "QName")
- {
- SERIALIZE_FIELD(zstring, ns, getNamespace());
- SERIALIZE_FIELD(zstring, prefix, getPrefix());
- SERIALIZE_FIELD(zstring, local, getLocalName());
- FINALIZE_SERIALIZE(createQName, (result, ns, prefix, local));
- }
- else if(name_of_type == "NOTATION")
- {
- SERIALIZE_FIELD(zstring, ns, getNamespace());
- SERIALIZE_FIELD(zstring, prefix, getPrefix());
- SERIALIZE_FIELD(zstring, local, getLocalName());
- FINALIZE_SERIALIZE(createNOTATION, (result, ns, prefix, local));
- }
- else if(name_of_type == "ID")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createID, (result, value));
- }
- else if(name_of_type == "IDREF")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createIDREF, (result, value));
- }
- else if(name_of_type == "ENTITY")
- {
- SERIALIZE_FIELD(zstring, value, getStringValue());
- FINALIZE_SERIALIZE(createENTITY, (result, value));
- }
- else if(name_of_type == "dateTime")
- {
- SERIALIZE_REF_FIELD(xs_dateTime, value, getDateTimeValue());
- FINALIZE_SERIALIZE(createDateTime, (result, &value_in));
- }
- else if(name_of_type == "date")
- {
- SERIALIZE_REF_FIELD(xs_date, value, getDateValue());
- FINALIZE_SERIALIZE(createDate, (result, &value_in));
- }
- else if(name_of_type == "time")
- {
- SERIALIZE_REF_FIELD(xs_time, value, getTimeValue());
- FINALIZE_SERIALIZE(createTime, (result, &value_in));
- }
- else if(name_of_type == "duration")
- {
- SERIALIZE_REF_FIELD(xs_duration, value, getDurationValue());
- FINALIZE_SERIALIZE(createDuration, (result, &value_in));
- }
- else if(name_of_type == "dayTimeDuration")
- {
- SERIALIZE_REF_FIELD(xs_dayTimeDuration, value, getDayTimeDurationValue());
- FINALIZE_SERIALIZE(createDayTimeDuration, (result, &value_in));
- }
- else if(name_of_type == "yearMonthDuration")
- {
- SERIALIZE_REF_FIELD(xs_yearMonthDuration, value, getYearMonthDurationValue());
- FINALIZE_SERIALIZE(createYearMonthDuration, (result, &value_in));
- }
-
- else if(name_of_type == "float")
- {
- SERIALIZE_FIELD(xs_float, value, getFloatValue());
- FINALIZE_SERIALIZE(createFloat, (result, value));
- }
- else if(name_of_type == "double")
- {
- SERIALIZE_FIELD(xs_double, value, getDoubleValue());
- FINALIZE_SERIALIZE(createDouble, (result, value));
- }
- else if(name_of_type == "decimal")
- {
- SERIALIZE_FIELD(xs_decimal, value, getDecimalValue());
- FINALIZE_SERIALIZE(createDecimal, (result, value));
- }
- else if(name_of_type == "integer")
- {
- SERIALIZE_FIELD(xs_integer, value, getIntegerValue());
- FINALIZE_SERIALIZE(createInteger, (result, value));
- }
- else if(name_of_type == "nonPositiveInteger")
- {
- SERIALIZE_FIELD(xs_integer, value, getIntegerValue());
- FINALIZE_SERIALIZE(createNonPositiveInteger, (result, value));
- }
- else if(name_of_type == "nonNegativeInteger")
- {
- SERIALIZE_FIELD(xs_nonNegativeInteger, value, getUnsignedIntegerValue());
- FINALIZE_SERIALIZE(createNonNegativeInteger, (result, value));
- }
- else if(name_of_type == "negativeInteger")
- {
- SERIALIZE_FIELD(xs_integer, value, getIntegerValue());
- FINALIZE_SERIALIZE(createNegativeInteger, (result, value));
- }
- else if(name_of_type == "positiveInteger")
- {
- SERIALIZE_FIELD(xs_positiveInteger, value, getUnsignedIntegerValue());
- FINALIZE_SERIALIZE(createPositiveInteger, (result, value));
- }
-
- else if(name_of_type == "long")
- {
- SERIALIZE_FIELD(xs_long, value, getLongValue());
- FINALIZE_SERIALIZE(createLong, (result, value));
- }
- else if(name_of_type == "int")
- {
- SERIALIZE_FIELD(xs_int, value, getIntValue());
- FINALIZE_SERIALIZE(createInt, (result, value));
- }
- else if(name_of_type == "short")
- {
- SERIALIZE_FIELD(xs_short, value, getShortValue());
- FINALIZE_SERIALIZE(createShort, (result, value));
- }
- else if(name_of_type == "byte")
- {
- SERIALIZE_FIELD(xs_byte, value, getByteValue());
- FINALIZE_SERIALIZE(createByte, (result, value));
- }
- else if(name_of_type == "unsignedLong")
- {
- SERIALIZE_FIELD(xs_unsignedLong, value, getUnsignedLongValue());
- FINALIZE_SERIALIZE(createUnsignedLong, (result, value));
- }
- else if(name_of_type == "unsignedInt")
- {
- SERIALIZE_FIELD(xs_unsignedInt, value, getUnsignedIntValue());
- FINALIZE_SERIALIZE(createUnsignedInt, (result, value));
- }
- else if(name_of_type == "unsignedShort")
- {
- SERIALIZE_FIELD(xs_unsignedShort, value, getUnsignedShortValue());
- FINALIZE_SERIALIZE(createUnsignedShort, (result, value));
- }
- else if(name_of_type == "unsignedByte")
- {
- SERIALIZE_FIELD(xs_unsignedByte, value, getUnsignedByteValue());
- FINALIZE_SERIALIZE(createUnsignedByte, (result, value));
- }
-
- else if(name_of_type == "gYearMonth")
- {
- SERIALIZE_REF_FIELD(xs_gYearMonth, value, getGYearMonthValue());
- FINALIZE_SERIALIZE(createGYearMonth, (result, &value_in));
- }
- else if(name_of_type == "gYear")
- {
- SERIALIZE_REF_FIELD(xs_gYear, value, getGYearValue());
- FINALIZE_SERIALIZE(createGYear, (result, &value_in));
- }
- else if(name_of_type == "gMonthDay")
- {
- SERIALIZE_REF_FIELD(xs_gMonthDay, value, getGMonthDayValue());
- FINALIZE_SERIALIZE(createGMonthDay, (result, &value_in));
- }
- else if(name_of_type == "gDay")
- {
- SERIALIZE_REF_FIELD(xs_gDay, value, getGDayValue());
- FINALIZE_SERIALIZE(createGDay, (result, &value_in));
- }
- else if(name_of_type == "gMonth")
- {
- SERIALIZE_REF_FIELD(xs_gMonth, value, getGMonthValue());
- FINALIZE_SERIALIZE(createGMonth, (result, &value_in));
- }
-
- else if(name_of_type == "base64Binary")
- {
- if (ar.is_serializing_out())
- {
- size_t s;
- const char* c = obj->getBase64BinaryValue(s);
- if (obj->isEncoded())
- {
- Base64 tmp;
- Base64::parseString(c, s, tmp);
- ar.dont_allow_delay();
- ar & tmp;
- }
- else
- {
- Base64 tmp((const unsigned char*)c, s);
- ar.dont_allow_delay();
- ar & tmp;
- }
- }
- else
- {
- ar.dont_allow_delay();
- Base64 tmp;
- ar & tmp;
- FINALIZE_SERIALIZE(createBase64Binary, (result, tmp));
- }
- }
- else if(name_of_type == "hexBinary")
- {
- SERIALIZE_REF_FIELD(xs_hexBinary, value, getHexBinaryValue());
- FINALIZE_SERIALIZE(createHexBinary, (result, value_in));
- }
- else if(name_of_type == "boolean")
- {
- SERIALIZE_FIELD(bool, value, getBooleanValue());
- FINALIZE_SERIALIZE(createBoolean, (result, value));
- }
- else
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
- ERROR_PARAMS( name_of_type )
- );
- }
-EndAtomicItem:;
- }
- else if(is_node)
- {
- serialize_node_tree(ar, obj, true);
- }
- else if(is_pul)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "Pul" )
- );
- }
- else if(is_error)
- {
- ZORBA_ASSERT(false);
- SERIALIZE_FIELD(ZorbaException*, value, getError());
- FINALIZE_SERIALIZE(createError, (result, value));
- }
- else if(is_function)
- {
- FunctionItem *fitem = NULL;
- if(ar.is_serializing_out())
- {
- fitem = dynamic_cast<FunctionItem*>(obj);
- }
- ar.dont_allow_delay();
- ar.set_is_temp_field(false);
- ar & fitem;
- if(!ar.is_serializing_out())
- {
- assert(fitem);
- obj = fitem;
- if(obj)
- obj->addReference();
- ar.register_reference(id, ARCHIVE_FIELD_PTR, obj);
- }
- ar.set_is_temp_field(true);
- }
- else
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
- ERROR_PARAMS( "[Unknown item type]" )
- );
- }
-
- ar.set_is_temp_field(false);
- ar.set_is_temp_field_one_level(false);
- }
-
- if(ar.is_serializing_out())
- {
- if(!is_ref)
- ar.add_end_compound_field();
- }
- else
- {
- if(!is_ref)
- {
- if(!is_node)
- ar.register_item(obj);
- ar.read_end_current_level();
- }
- else
- {
- store::Item *new_obj = NULL;
- if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
- {
- obj = dynamic_cast<store::Item*>(new_obj);
- if(!obj)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
- else if(!ar.get_is_temp_field() && !ar.get_is_temp_field_one_level())
- ar.register_delay_reference((void**)&obj, FIELD_IS_CLASS, "store::Item*", referencing);
- else
- obj = NULL;
- }
- }
-
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void serialize_node_tree(Archiver &ar, store::Item *&obj, bool all_tree)
-{
- //only for node items
- //serialize first whole tree and then the item (will surely be a reference)
- if(all_tree)
- {
- store::Item *parent = NULL;
- if(ar.is_serializing_out())
- {
- if(obj != NULL)
- parent = obj->getParent();
- if(parent)
- {
- while(parent->getParent())
- parent = parent->getParent();
- }
- if(!parent)
- {
- parent = obj;
- }
- }
- serialize_node_tree(ar, parent, false);
- }
-
- ar.set_is_temp_field(false);
-
- int id;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool is_ref;
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- ar.set_is_temp_field(true);
- return;
- }
- is_ref = ar.add_compound_field("store::Item*", FIELD_IS_CLASS, "", obj, ARCHIVE_FIELD_PTR);
- }
- else
- {
- char *type;
- std::string value;
- bool is_simple = false;
- bool is_class = true;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- obj = NULL;
- ar.read_end_current_level();
- ar.set_is_temp_field(true);
- return;
- }
- ar.check_class_field(retval, type, "store::Item*", is_simple, is_class, field_treat, (enum ArchiveFieldKind)-1, id);
- //ar.register_reference(id, &obj);
- if((field_treat != ARCHIVE_FIELD_PTR) && (field_treat != ARCHIVE_FIELD_REFERENCING))
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- is_ref = (field_treat == ARCHIVE_FIELD_REFERENCING);
- }
- ar.set_is_temp_field(true);
-
- if(!is_ref)
- {
- store::StoreConsts::NodeKind nodekind = store::StoreConsts::anyNode;
- if(ar.is_serializing_out())
- nodekind = obj->getNodeKind();
- SERIALIZE_ENUM(store::StoreConsts::NodeKind, nodekind);
- switch(nodekind)
- {
- case store::StoreConsts::anyNode:
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "anyNode" )
- );
- case store::StoreConsts::documentNode:
- {
- SERIALIZE_FIELD2(zstring, baseUri, getBaseURI);
- SERIALIZE_FIELD2(zstring, docUri, getDocumentURI);
- FINALIZE_SERIALIZE(createDocumentNode, (result, baseUri, docUri));
- serialize_my_children(ar, obj->getChildren());
- }break;
- case store::StoreConsts::elementNode:
- {
- SERIALIZE_PARENT;
- //pos = -1
- SERIALIZE_FIELD(store::Item_t, nodename, getNodeName());
- SERIALIZE_FIELD(store::Item_t, name_of_type, getType());
- SERIALIZE_FIELD(bool, isInSubstGroup, isInSubstitutionGroup());
- bool haveTypedValue = false;
- bool haveEmptyValue = true;
- if(ar.is_serializing_out())
- {
- //workaround
- // store::simplestore::ElementNode *elem_node = dynamic_cast<store::simplestore::ElementNode*>(obj);
- // haveTypedValue = elem_node->haveTypedValue();
- // haveEmptyValue = elem_node->haveEmptyValue();
- if(!ZSTREQ(name_of_type->getNamespace(), "http://www.w3.org/2001/XMLSchema") ||
- !ZSTREQ(name_of_type->getLocalName(), "untyped"))
- haveTypedValue = true;
- }
- ar & haveTypedValue;
- ar & haveEmptyValue;
- store::NsBindings ns_bindings;
- if(ar.is_serializing_out())
- obj->getNamespaceBindings(ns_bindings, store::StoreConsts::ONLY_LOCAL_NAMESPACES);
- ar & ns_bindings;
- SERIALIZE_FIELD2(zstring, baseUri, getBaseURI);
- FINALIZE_SERIALIZE(createElementNode, (result, parent, nodename, name_of_type, haveTypedValue, haveEmptyValue, ns_bindings, baseUri, isInSubstGroup));
-
- serialize_my_children2(ar, obj->getAttributes());
-
- serialize_my_children(ar, obj->getChildren());
- }break;
- case store::StoreConsts::attributeNode:
- {
- SERIALIZE_PARENT;
- SERIALIZE_FIELD(store::Item_t, nodename, getNodeName());
- SERIALIZE_FIELD(store::Item_t, name_of_type, getType());
- store::Item_t val;
- store::Iterator_t val_it;
- if(ar.is_serializing_out())
- obj->getTypedValue(val, val_it);
- ar & val;
- std::vector<store::Item_t> val_vector;
- if(val == NULL)
- {
- iterator_to_vector(val_it, val_vector);
- }
- ar & val_vector;
- if(val != NULL)
- {
- FINALIZE_SERIALIZE(createAttributeNode, (result, parent, nodename, name_of_type, val));
- }
- else
- {
- FINALIZE_SERIALIZE(createAttributeNode, (result, parent, nodename, name_of_type, val_vector));
- }
- }break;
- case store::StoreConsts::textNode:
- {
- SERIALIZE_PARENT;
- SERIALIZE_FIELD(zstring, content, getStringValue());
- FINALIZE_SERIALIZE(createTextNode, (result, parent, content));
- }break;
- case store::StoreConsts::piNode:
- {
- SERIALIZE_PARENT;
- SERIALIZE_FIELD(zstring, target, getTarget());
- SERIALIZE_FIELD(zstring, content, getStringValue());
- SERIALIZE_FIELD2(zstring, baseUri, getBaseURI);
- FINALIZE_SERIALIZE(createPiNode, (result, parent, target, content, baseUri));
- }break;
- case store::StoreConsts::commentNode:
- {
- SERIALIZE_PARENT;
- SERIALIZE_FIELD(zstring, content, getStringValue());
- FINALIZE_SERIALIZE(createCommentNode, (result, parent, content));
- }break;
- default:
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "unknown" )
- );
- }
- }//end is_ref
-
- if(ar.is_serializing_out())
- {
- if(!is_ref)
- ar.add_end_compound_field();
- }
- else
- {
- if(!is_ref)
- {
- ar.register_item(obj);
- ar.read_end_current_level();
- }
- else
- {
- store::Item *new_obj = NULL;
- if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
- {
- obj = dynamic_cast<store::Item*>(new_obj);
- if(!obj)
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- }
- else if(!ar.get_is_temp_field() && !ar.get_is_temp_field_one_level())
- ar.register_delay_reference((void**)&obj, FIELD_IS_CLASS, "store::Item*", referencing);
- else
- obj = NULL;
- }
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, zorba::store::TempSeq *obj)
-{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "TempSeq" )
- );
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, const Diagnostic *&obj)
-{
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
- bool is_ref;
- assert(!ar.is_serialize_base_class());
- Diagnostic *diagnostic = const_cast<Diagnostic*>(obj);
- UserError *user_err = dynamic_cast<UserError*>(diagnostic);
- XQueryErrorCode *xquery_err = dynamic_cast<XQueryErrorCode*>(diagnostic);
- ZorbaErrorCode *zorba_err = dynamic_cast<ZorbaErrorCode*>(diagnostic);
- char err_type[20];
- sprintf(err_type, "u%dx%dz%d",
- user_err != NULL ? 1 : 0,
- xquery_err != NULL ? 1 : 0,
- zorba_err != NULL ? 1 : 0);
- is_ref = ar.add_compound_field("Diagnostic*",
- !FIELD_IS_CLASS, err_type,
- obj,
- ARCHIVE_FIELD_PTR);
- if(!is_ref)
- {
- if(user_err)
- {
- ar & user_err->qname_;
- }
- else
- {
- ar.set_is_temp_field(true);
- const diagnostic::QName &errqn = obj->qname();
- char* strtemp = (char*)errqn.localname();
- ar & strtemp;
- ar.set_is_temp_field(false);
- }
-
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "Diagnostic*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- assert(!ar.is_serialize_base_class());
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
- if(field_treat == ARCHIVE_FIELD_PTR)
- {
- int is_user, is_xquery, is_zorba;
- sscanf(value.c_str(), "u%dx%dz%d", &is_user, &is_xquery, &is_zorba);
- if(is_user)
- {
- UserError *user_error = new UserError(ar);
- ar & user_error->qname_;
- obj = user_error;
- }
- else if(is_xquery || is_zorba)
- {
- ar.set_is_temp_field(true);
- char* local;
- ar & local;
- ar.set_is_temp_field(false);
- obj = internal::SystemDiagnosticBase::find(local);
- free(local);
- ZORBA_ASSERT(obj);
- }
- else
- {
- ZORBA_ASSERT(false);//unreachable, maybe a new Error class has been added
- }
- ar.register_reference(id, field_treat, obj);
- ar.read_end_current_level();
- }
- else if((obj = (Diagnostic*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
- {
- }
- else
- {
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "Diagnostic*", referencing);
- }
- }
-
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, ZorbaException *&obj)
-{
- if(ar.is_serializing_out())
- {
- if(obj == NULL)
- {
- ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_NULL);
- return;
- }
- bool is_ref;
- assert(!ar.is_serialize_base_class());
- UserException *user_ex = dynamic_cast<UserException*>(obj);
- XQueryException *xquery_ex = dynamic_cast<XQueryException*>(obj);
- char ex_type[20];
- sprintf(ex_type, "u%dx%d",
- user_ex != NULL ? 1 : 0,
- xquery_ex != NULL ? 1 : 0);
- is_ref = ar.add_compound_field("ZorbaException*",
- !FIELD_IS_CLASS, ex_type,
- obj,
- ARCHIVE_FIELD_PTR);
- if(!is_ref)
- {
- ar & obj->diagnostic_;
- ar & obj->raise_file_;
- ar & obj->raise_line_;
- ar & obj->message_;
-
- if(xquery_ex)
- {
- ar & xquery_ex->source_loc_;
- ar & xquery_ex->query_trace_;
- }
- if(user_ex)
- {
- ar & user_ex->error_object_;
- }
-
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "ZorbaException*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
- {
- assert(!ar.is_serialize_base_class());
- obj = NULL;
- ar.read_end_current_level();
- return;
- }
- if(field_treat == ARCHIVE_FIELD_PTR)
- {
- int is_user, is_xquery;
- sscanf(value.c_str(), "u%dx%d", &is_user, &is_xquery);
- UserException *user_ex = NULL;
- XQueryException *xquery_ex = NULL;
- if(is_user)
- {
- user_ex = new UserException(ar);
- xquery_ex = user_ex;
- obj = user_ex;
- }
- else if(is_xquery)
- {
- xquery_ex = new XQueryException(ar);
- obj = xquery_ex;
- }
- else
- obj = new ZorbaException(ar);
-
- ar & obj->diagnostic_;
- ar & obj->raise_file_;
- ar & obj->raise_line_;
- ar & obj->message_;
-
- if(xquery_ex)
- {
- ar & xquery_ex->source_loc_;
- ar & xquery_ex->query_trace_;
- }
- if(user_ex)
- {
- ar & user_ex->error_object_;
- }
-
- ar.register_reference(id, field_treat, obj);
- ar.read_end_current_level();
- }
- else if((obj = (ZorbaException*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
- {
- }
- else
- {
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "ZorbaException*", referencing);
- }
- }
-
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, zorba::internal::diagnostic::location &obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("internal::diagnostic::location", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- ar & obj.file_;
- ar & obj.line_;
- ar & obj.column_;
- ar & obj.line_end_;
- ar & obj.column_end_;
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "internal::diagnostic::location", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar & obj.file_;
- ar & obj.line_;
- ar & obj.column_;
- ar & obj.line_end_;
- ar & obj.column_end_;
- ar.read_end_current_level();
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, zorba::Item &obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("zorba::Item", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- ar & obj.m_item;
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "zorba::Item", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar & obj.m_item;
- ar.read_end_current_level();
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, zorba::XQueryStackTrace& obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("XQueryStackTrace", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- ar & obj.trace_;
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "XQueryStackTrace", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar & obj.trace_;
- ar.read_end_current_level();
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, zorba::XQueryStackTrace::Entry& obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("XQueryStackTrace::Entry", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- ar & obj.getFnNameRef();
- ar & obj.getFnArityRef();
- ar & obj.getFileNameRef();
- ar & obj.getLineRef();
- ar & obj.getColumnRef();
- ar & obj.getLineEndRef();
- ar & obj.getColumnEndRef();
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char* type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_nonclass_field(retval, type, "XQueryStackTrace::Entry", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar & obj.getFnNameRef();
- ar & obj.getFnArityRef();
- ar & obj.getFileNameRef();
- ar & obj.getLineRef();
- ar & obj.getColumnRef();
- ar & obj.getLineEndRef();
- ar & obj.getColumnEndRef();
- ar.read_end_current_level();
- }
-}
-
-
-}
-} // namespace zorba
-/* vim:set et sw=2 ts=2: */
=== removed file 'src/zorbaserialization/zorba_class_serializer.h'
--- src/zorbaserialization/zorba_class_serializer.h 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/zorba_class_serializer.h 1970-01-01 00:00:00 +0000
@@ -1,459 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-#ifndef ZORBA_SPECIFIC_CLASS_SERIALIZATION
-#define ZORBA_SPECIFIC_CLASS_SERIALIZATION
-
-#include <zorba/item.h>
-#include <zorba/xquery_exception.h>
-#include "zorbatypes/rchandle.h"
-#include "zorbatypes/m_apm.h"
-#include "zorbatypes/floatimpl.h"
-#include "zorbautils/checked_vector.h"
-
-#include "zorbaserialization/class_serializer.h"
-#include "zorbaserialization/archiver.h"
-
-#include "store/api/shared_types.h"
-#include "diagnostics/assert.h"
-
-#include <stdio.h>
-#include <map>
-
-namespace zorba
-{
- class XQType;
- class function;
- class Diagnostic;
- class ZorbaException;
-#ifdef ZORBA_WITH_BIG_INTEGER
- class IntegerImpl;
-#else
- template<typename IntType> class IntegerImpl;
-#endif /* ZORBA_WITH_BIG_INTEGER */
-
-namespace serialization
-{
-
-void operator&(Archiver &ar, const XQType *&obj);
-void operator&(Archiver &ar, MAPM &obj);
-#ifdef ZORBA_WITH_BIG_INTEGER
-void operator&(Archiver &ar, IntegerImpl &obj);
-#else
-template<typename IntType>
-void operator&(Archiver &ar, IntegerImpl<IntType> &obj);
-#endif /* ZORBA_WITH_BIG_INTEGER */
-
-void operator&(Archiver &ar, XQPCollator *&obj);
-void operator&(Archiver &ar, store::Item* &obj);
-
-void operator&(Archiver &ar, const Diagnostic *&obj);
-void operator&(Archiver &ar, ZorbaException *&obj);
-void operator&(Archiver &ar, zorba::internal::diagnostic::location &obj);
-void operator&(Archiver &ar, zorba::Item &obj);
-void operator&(Archiver &ar, zorba::XQueryStackTrace &obj);
-void operator&(Archiver &ar, zorba::XQueryStackTrace::Entry &obj);
-
-
-#define SERIALIZE_TYPEMANAGER(type_mgr_type, type_mgr) \
- bool is_root_type_mgr = ar.is_serializing_out() && (!GENV.isRootStaticContextInitialized() || ((TypeManager*)type_mgr == (TypeManager*)&GENV_TYPESYSTEM)) && ar.is_serializing_out(); \
- ar.set_is_temp_field_one_level(true); \
- ar & is_root_type_mgr; \
- ar.set_is_temp_field_one_level(false); \
- if(is_root_type_mgr) \
- { \
- if(!ar.is_serializing_out()) \
- { \
- type_mgr = (type_mgr_type*)&GENV_TYPESYSTEM; \
- /*RCHelper::addReference(type_mgr);*/ \
- } \
- } \
- else \
- { \
- ar & type_mgr; \
- }
-
-#define SERIALIZE_TYPEMANAGER_RCHANDLE(type_mgr_type, type_mgr) \
- bool is_root_type_mgr = (!GENV.isRootStaticContextInitialized() || ((TypeManager*)type_mgr.getp() == (TypeManager*)&GENV_TYPESYSTEM)); \
- ar.set_is_temp_field_one_level(true); \
- ar & is_root_type_mgr; \
- ar.set_is_temp_field_one_level(false); \
- if(is_root_type_mgr) \
- { \
- if(!ar.is_serializing_out()) \
- type_mgr = (type_mgr_type*)&GENV_TYPESYSTEM; \
- } \
- else \
- { \
- ar & type_mgr; \
- }
-
-
-template<class T>
-void operator&(Archiver& ar, checked_vector<T>& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[20];
- sprintf(strtemp, "%d", (int)obj.size());
-
- bool is_ref;
- is_ref = ar.add_compound_field("checked_vector<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
-
- if (!is_ref)
- {
- typename checked_vector<T>::iterator it;
- for(it = obj.begin(); it != obj.end(); ++it)
- {
- ar & (*it);
- }
- ar.add_end_compound_field();
- }
- }
- else
- {
- char* type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
-
- retval = ar.read_next_field(&type, &value, &id,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_nonclass_field(retval, type, "checked_vector<T>",
- is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar.register_reference(id, field_treat, &obj);
-
- int size;
- sscanf(value.c_str(), "%d", &size);
- obj.resize(size);
- typename checked_vector<T>::iterator it;
- for(it = obj.begin(); it != obj.end(); ++it)
- {
- ar & (*it);
- }
- ar.read_end_current_level();
- }
-}
-
-
-template<class T>
-void operator&(Archiver& ar, store::ItemHandle<T>& obj)
-{
- if (ar.is_serializing_out())
- {
- bool is_ref;
- ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
- is_ref = ar.add_compound_field("ItemHandle<T>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
- {
- T *p = obj.getp();
- if(allow_delay != ALLOW_DELAY)
- ar.dont_allow_delay(allow_delay);
- bool is_temp = false;
- if(ar.get_is_temp_field_one_level())
- {
- is_temp = true;
- ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
- if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
- ar.dont_allow_delay();
- }
- ar & p;
- if(is_temp)
- ar.set_is_temp_field_one_level(false);
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "ItemHandle<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- //ar.register_reference(id, field_treat, &obj);
-
- bool is_temp = false;
- if(ar.get_is_temp_field_one_level())
- {
- is_temp = true;
- ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
- }
- T *p;
- ar & p;
- if(is_temp)
- ar.set_is_temp_field_one_level(false);
- obj = p;
- if(p == NULL)
- {
- //workaround for the strict_aliasing warning in gcc
- union
- {
- T **t;
- void **v;
- }u_p;
- u_p.t = &p;
- ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
- }
- ar.read_end_current_level();
-
- }
-}
-
-
-template<class T>
-void operator&(Archiver &ar, zorba::rchandle<T> &obj)
-{
- if(ar.is_serializing_out())
- {
- bool is_ref;
- ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
- is_ref = ar.add_compound_field("rchandle<T>", !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
- assert(!is_ref);
- ZORBA_ASSERT(!is_ref);
- {
- T *p = obj.getp();
- if(allow_delay != ALLOW_DELAY)
- ar.dont_allow_delay(allow_delay);
- bool is_temp = false;
- if(ar.get_is_temp_field_one_level())
- {
- is_temp = true;
- ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
- if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
- ar.dont_allow_delay();
- }
- ar & p;
- if(is_temp)
- ar.set_is_temp_field_one_level(false);
- ar.add_end_compound_field();
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_nonclass_field(retval, type, "rchandle<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- //ar.register_reference(id, field_treat, &obj);
-
- bool is_temp = false;
- if(ar.get_is_temp_field_one_level())
- {
- is_temp = true;
- ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
- }
- T *p;
- ar & p;
- if(is_temp)
- ar.set_is_temp_field_one_level(false);
- obj = p;
- if(p == NULL)
- {
- //workaround for the strict_aliasing warning in gcc
- union
- {
- T **t;
- void **v;
- }u_p;
- u_p.t = &p;
- ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
- }
- ar.read_end_current_level();
-
- }
-}
-
-
-template<class T>
-void operator&(Archiver& ar, zorba::const_rchandle<T>& obj)
-{
- if (ar.is_serializing_out())
- {
- bool is_ref;
- ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
-
- is_ref = ar.add_compound_field("const_rchandle<T>",
- !FIELD_IS_CLASS,
- "",
- &obj,
- ARCHIVE_FIELD_NORMAL);
- if (!is_ref)
- {
- T *p = (T*)obj.getp();
-
- if(allow_delay != ALLOW_DELAY)
- ar.dont_allow_delay(allow_delay);
-
- bool is_temp = false;
-
- if(ar.get_is_temp_field_one_level())
- {
- is_temp = true;
- ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
- if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
- ar.dont_allow_delay();
- }
- ar & p;
- if(is_temp)
- ar.set_is_temp_field_one_level(false);
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char *type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
-
- retval = ar.read_next_field(&type, &value, &id,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_nonclass_field(retval, type, "const_rchandle<T>",
- is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- bool is_temp = false;
-
- if (ar.get_is_temp_field_one_level())
- {
- is_temp = true;
- ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
- }
-
- T *p;
- ar & p;
- obj = p;
-
- if(is_temp)
- ar.set_is_temp_field_one_level(false);
-
- if(p == NULL)
- {
- //workaround for the strict_aliasing warning in gcc
- union
- {
- T **t;
- void **v;
- }u_p;
- u_p.t = &p;
- ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
- }
- ar.read_end_current_level();
- }
-}
-
-
-template<typename StringType>
-void operator&(Archiver& ar, zorba::internal::VariableQName<StringType>& obj)
-{
- if (ar.is_serializing_out())
- {
- bool is_ref;
- is_ref = ar.add_compound_field("VariableQName<StringType>",
- !FIELD_IS_CLASS,
- "",
- &obj,
- ARCHIVE_FIELD_NORMAL);
- if (!is_ref)
- {
- ar & obj.ns_;
- ar & obj.prefix_;
- ar & obj.localname_;
- ar.add_end_compound_field();
- }
- else
- {
- assert(false);
- }
- }
- else
- {
- char* type;
- std::string value;
- int id;
- bool is_simple = false;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
- int referencing;
- bool retval;
-
- retval = ar.read_next_field(&type, &value, &id,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_nonclass_field(retval, type, "VariableQName<StringType>",
- is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- ar & obj.ns_;
- ar & obj.prefix_;
- ar & obj.localname_;
- ar.read_end_current_level();
- }
-}
-
-
-template<typename FloatType>
-void operator&(Archiver& ar, FloatImpl<FloatType>& obj)
-{
- ar & obj.value_;
- ar & obj.precision_;
-}
-
-} // namespace serialization
-} // namespae zorba
-#endif
-/* vim:set et sw=2 ts=2: */
=== modified file 'src/zorbaserialization/zorba_class_versions.cpp'
--- src/zorbaserialization/zorba_class_versions.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/zorba_class_versions.cpp 2012-04-10 20:15:33 +0000
@@ -37,7 +37,7 @@
#include "zorbautils/hashmap_itemp.h"
#undef ZORBA_UTILS_HASHMAP_WITH_SERIALIZATION
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
#include "zorbatypes/rchandle.h"
=== removed file 'src/zorbaserialization/zorba_classes_version.cpp'
--- src/zorbaserialization/zorba_classes_version.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/zorba_classes_version.cpp 1970-01-01 00:00:00 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "stdafx.h"
-
-#include "zorbaserialization/class_serializer.h"
-
-namespace zorba
-{
-namespace serialization
-{
-
-
-
-}}/* vim:set et sw=2 ts=2: */
=== modified file 'src/zorbatypes/binary.cpp'
--- src/zorbatypes/binary.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbatypes/binary.cpp 2012-04-10 20:15:33 +0000
@@ -21,10 +21,13 @@
#include <string>
#include "zorbatypes/binary.h"
+
#include "diagnostics/xquery_diagnostics.h"
+
#include "util/ascii_util.h"
#include "util/stl_util.h"
-#include "zorbaserialization/template_serializer.h"
+
+#include "zorbaserialization/serialize_template_types.h"
using namespace std;
=== modified file 'src/zorbatypes/datetime/datetimetype.cpp'
--- src/zorbatypes/datetime/datetimetype.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbatypes/datetime/datetimetype.cpp 2012-04-10 20:15:33 +0000
@@ -35,8 +35,10 @@
#include <zorbatypes/zstring.h>
#include "zorbatypes/datetime/parse.h"
+
#include "util/ascii_util.h"
-#include "zorbaserialization/template_serializer.h"
+
+#include "zorbaserialization/serialize_template_types.h"
=== modified file 'src/zorbatypes/datetime/timezone.cpp'
--- src/zorbatypes/datetime/timezone.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbatypes/datetime/timezone.cpp 2012-04-10 20:15:33 +0000
@@ -19,10 +19,14 @@
#include <exception>
#include <zorbatypes/timezone.h>
+
#include "zorbatypes/datetime/parse.h"
+
#include "zorbautils/hashfun.h"
+
#include "util/ascii_util.h"
-#include "zorbaserialization/template_serializer.h"
+
+#include "zorbaserialization/serialize_template_types.h"
namespace zorba
=== modified file 'src/zorbatypes/decimal.cpp'
--- src/zorbatypes/decimal.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbatypes/decimal.cpp 2012-04-10 20:15:33 +0000
@@ -22,7 +22,8 @@
#include "common/common.h"
#include "util/ascii_util.h"
#include "util/string_util.h"
-#include "zorbaserialization/zorba_class_serializer.h"
+
+#include "zorbaserialization/serialize_zorba_types.h"
#include "decimal.h"
#include "integer.h"
=== modified file 'src/zorbatypes/floatimpl.cpp'
--- src/zorbatypes/floatimpl.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbatypes/floatimpl.cpp 2012-04-10 20:15:33 +0000
@@ -27,7 +27,8 @@
#include "floatimpl.h"
#include "integer.h"
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/serialize_zorba_types.h"
+#include "zorbaserialization/serialize_template_types.h"
#ifdef ZORBA_WITH_BIG_INTEGER
# define TEMPLATE_DECL(T) /* nothing */
=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h 2012-03-28 05:19:57 +0000
+++ src/zorbatypes/integer.h 2012-04-10 20:15:33 +0000
@@ -25,8 +25,6 @@
#include "common/common.h"
#include "util/stl_util.h"
-#include "zorbaserialization/archiver.h"
-#include "zorbaserialization/zorba_class_serializer.h"
#include "m_apm.h"
#include "schema_types_base.h"
@@ -48,7 +46,10 @@
TEMPLATE_DECL(T)
class IntegerImpl;
-namespace serialization {
+namespace serialization
+{
+ class Archiver;
+
TEMPLATE_DECL(T) void operator&( Archiver&, INTEGER_IMPL(T)& );
}
=== modified file 'src/zorbautils/hashmap.h'
--- src/zorbautils/hashmap.h 2012-03-28 05:19:57 +0000
+++ src/zorbautils/hashmap.h 2012-04-10 20:15:33 +0000
@@ -31,7 +31,8 @@
#include "zorbautils/mutex.h"
#ifdef ZORBA_UTILS_HASHMAP_WITH_SERIALIZATION
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
+#include "zorbaserialization/serialize_basic_types.h"
#endif
namespace zorba
=== modified file 'src/zorbautils/hashmap_itemp.h'
--- src/zorbautils/hashmap_itemp.h 2012-03-28 05:19:57 +0000
+++ src/zorbautils/hashmap_itemp.h 2012-04-10 20:15:33 +0000
@@ -26,7 +26,9 @@
#include "zorbatypes/collation_manager.h"
#ifdef ZORBA_UTILS_HASHMAP_WITH_SERIALIZATION
-#include "zorbaserialization/serialization_engine.h"
+#include "zorbaserialization/class_serializer.h"
+#include "zorbaserialization/serialize_template_types.h"
+#include "zorbaserialization/serialize_zorba_types.h"
#endif
#include "store/api/item.h"
=== modified file 'test/rbkt/testdriver.cpp'
--- test/rbkt/testdriver.cpp 2012-04-08 21:39:25 +0000
+++ test/rbkt/testdriver.cpp 2012-04-10 20:15:33 +0000
@@ -26,7 +26,7 @@
#include <time.h>
#endif
-//#define ZORBA_TEST_PLAN_SERIALIZATION
+#define ZORBA_TEST_PLAN_SERIALIZATION
#include "testdriverconfig.h" // SRC and BIN dir definitions
#include "specification.h" // parsing spec files
Follow ups