zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #07726
[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/101957
abstract classes don't need class factory for serialization + cosmetic + comments + cleanup
--
https://code.launchpad.net/~zorba-coders/zorba/serializer/+merge/101957
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/expression/expr.cpp'
--- src/compiler/expression/expr.cpp 2012-04-10 20:59:34 +0000
+++ src/compiler/expression/expr.cpp 2012-04-13 18:57:21 +0000
@@ -52,8 +52,6 @@
namespace zorba
{
-SERIALIZABLE_CLASS_VERSIONS(expr)
-
SERIALIZABLE_CLASS_VERSIONS(catch_clause)
SERIALIZABLE_CLASS_VERSIONS(trycatch_expr)
@@ -68,16 +66,8 @@
SERIALIZABLE_CLASS_VERSIONS(wrapper_expr)
-SERIALIZABLE_CLASS_VERSIONS(namespace_context_base_expr)
-
-SERIALIZABLE_CLASS_VERSIONS(cast_or_castable_base_expr)
-
-SERIALIZABLE_CLASS_VERSIONS(cast_base_expr)
-
SERIALIZABLE_CLASS_VERSIONS(promote_expr)
-SERIALIZABLE_CLASS_VERSIONS(castable_base_expr)
-
SERIALIZABLE_CLASS_VERSIONS(instanceof_expr)
SERIALIZABLE_CLASS_VERSIONS(treat_expr)
=== modified file 'src/compiler/expression/expr_utils.h'
--- src/compiler/expression/expr_utils.h 2012-04-04 13:25:43 +0000
+++ src/compiler/expression/expr_utils.h 2012-04-13 18:57:21 +0000
@@ -33,7 +33,7 @@
bool theEmptyLeast;
std::string theCollation;
- SERIALIZABLE_ABSTRACT_CLASS(OrderModifier)
+ SERIALIZABLE_CLASS(OrderModifier)
SERIALIZABLE_CLASS_CONSTRUCTOR2(OrderModifier, SimpleRCObject)
void serialize(::zorba::serialization::Archiver& ar)
{
=== modified file 'src/compiler/expression/flwor_expr.cpp'
--- src/compiler/expression/flwor_expr.cpp 2012-04-10 20:59:34 +0000
+++ src/compiler/expression/flwor_expr.cpp 2012-04-13 18:57:21 +0000
@@ -39,10 +39,6 @@
namespace zorba
{
-SERIALIZABLE_CLASS_VERSIONS(flwor_clause)
-
-SERIALIZABLE_CLASS_VERSIONS(forletwin_clause)
-
SERIALIZABLE_CLASS_VERSIONS(for_clause)
SERIALIZABLE_CLASS_VERSIONS(let_clause)
=== modified file 'src/compiler/expression/ftnode.cpp'
--- src/compiler/expression/ftnode.cpp 2012-04-08 21:39:25 +0000
+++ src/compiler/expression/ftnode.cpp 2012-04-13 18:57:21 +0000
@@ -52,24 +52,14 @@
SERIALIZABLE_CLASS_VERSIONS(ftlanguage_option)
-SERIALIZABLE_CLASS_VERSIONS(ftmatch_option)
-
SERIALIZABLE_CLASS_VERSIONS(ftmatch_options)
SERIALIZABLE_CLASS_VERSIONS(ftmild_not)
-SERIALIZABLE_CLASS_VERSIONS(ftnode)
-
-SERIALIZABLE_CLASS_VERSIONS(ftnode_list)
-
SERIALIZABLE_CLASS_VERSIONS(ftor)
SERIALIZABLE_CLASS_VERSIONS(ftorder_filter)
-SERIALIZABLE_CLASS_VERSIONS(ftpos_filter)
-
-SERIALIZABLE_CLASS_VERSIONS(ftprimary)
-
SERIALIZABLE_CLASS_VERSIONS(ftprimary_with_options)
SERIALIZABLE_CLASS_VERSIONS(ftrange)
=== modified file 'src/compiler/expression/update_exprs.cpp'
--- src/compiler/expression/update_exprs.cpp 2012-04-10 20:59:34 +0000
+++ src/compiler/expression/update_exprs.cpp 2012-04-13 18:57:21 +0000
@@ -27,8 +27,6 @@
namespace zorba
{
-SERIALIZABLE_CLASS_VERSIONS(update_expr_base)
-
SERIALIZABLE_CLASS_VERSIONS(insert_expr)
SERIALIZABLE_CLASS_VERSIONS(delete_expr)
=== modified file 'src/functions/function.cpp'
--- src/functions/function.cpp 2012-04-10 20:59:34 +0000
+++ src/functions/function.cpp 2012-04-13 18:57:21 +0000
@@ -34,8 +34,6 @@
namespace zorba {
-SERIALIZABLE_CLASS_VERSIONS(function)
-
/*******************************************************************************
=== modified file 'src/runtime/base/binarybase.h'
--- src/runtime/base/binarybase.h 2012-04-08 21:39:25 +0000
+++ src/runtime/base/binarybase.h 2012-04-13 18:57:21 +0000
@@ -38,7 +38,7 @@
PlanIter_t theChild1;
public:
- SERIALIZABLE_CLASS_NO_FACTORY(BinaryBaseIterator)
+ SERIALIZABLE_ABSTRACT_CLASS(BinaryBaseIterator)
SERIALIZABLE_CLASS_CONSTRUCTOR2(BinaryBaseIterator, Batcher<IterType>)
void serialize(::zorba::serialization::Archiver& ar)
{
=== modified file 'src/runtime/base/narybase.h'
--- src/runtime/base/narybase.h 2012-04-08 21:39:25 +0000
+++ src/runtime/base/narybase.h 2012-04-13 18:57:21 +0000
@@ -40,7 +40,7 @@
std::vector<PlanIter_t> theChildren;
public:
- SERIALIZABLE_CLASS_NO_FACTORY(NaryBaseIterator)
+ SERIALIZABLE_ABSTRACT_CLASS(NaryBaseIterator)
SERIALIZABLE_CLASS_CONSTRUCTOR2(NaryBaseIterator, Batcher<IterType>)
void serialize(::zorba::serialization::Archiver& ar)
{
@@ -50,9 +50,9 @@
public:
NaryBaseIterator(
- static_context* sctx,
- const QueryLoc& loc,
- std::vector<PlanIter_t>& args);
+ static_context* sctx,
+ const QueryLoc& loc,
+ std::vector<PlanIter_t>& args);
virtual ~NaryBaseIterator(){}
=== modified file 'src/runtime/base/noarybase.h'
--- src/runtime/base/noarybase.h 2012-04-08 21:39:25 +0000
+++ src/runtime/base/noarybase.h 2012-04-13 18:57:21 +0000
@@ -34,7 +34,7 @@
class NoaryBaseIterator : public Batcher<IterType>
{
public:
- SERIALIZABLE_CLASS_NO_FACTORY(NoaryBaseIterator);
+ SERIALIZABLE_ABSTRACT_CLASS(NoaryBaseIterator);
SERIALIZABLE_CLASS_CONSTRUCTOR2(NoaryBaseIterator, Batcher<IterType>);
=== modified file 'src/runtime/base/plan_iterator.cpp'
--- src/runtime/base/plan_iterator.cpp 2012-04-08 21:39:25 +0000
+++ src/runtime/base/plan_iterator.cpp 2012-04-13 18:57:21 +0000
@@ -26,9 +26,6 @@
namespace zorba
{
-SERIALIZABLE_CLASS_VERSIONS(PlanIterator)
-
-
/*******************************************************************************
class PlanState
********************************************************************************/
=== modified file 'src/runtime/base/plan_iterator.h'
--- src/runtime/base/plan_iterator.h 2012-04-10 20:59:34 +0000
+++ src/runtime/base/plan_iterator.h 2012-04-13 18:57:21 +0000
@@ -482,7 +482,7 @@
class Batcher: public PlanIterator
{
public:
- SERIALIZABLE_CLASS_NO_FACTORY(Batcher)
+ SERIALIZABLE_ABSTRACT_CLASS(Batcher)
SERIALIZABLE_CLASS_CONSTRUCTOR2(Batcher, PlanIterator)
void serialize(::zorba::serialization::Archiver& ar)
{
=== modified file 'src/runtime/base/unarybase.h'
--- src/runtime/base/unarybase.h 2012-04-08 21:39:25 +0000
+++ src/runtime/base/unarybase.h 2012-04-13 18:57:21 +0000
@@ -37,7 +37,7 @@
PlanIter_t theChild;
public:
- SERIALIZABLE_CLASS_NO_FACTORY(UnaryBaseIterator)
+ SERIALIZABLE_ABSTRACT_CLASS(UnaryBaseIterator)
SERIALIZABLE_CLASS_CONSTRUCTOR2(UnaryBaseIterator, Batcher<IterType>)
void serialize(::zorba::serialization::Archiver& ar)
{
=== modified file 'src/runtime/collections/collections_base.cpp'
--- src/runtime/collections/collections_base.cpp 2012-04-08 21:39:25 +0000
+++ src/runtime/collections/collections_base.cpp 2012-04-13 18:57:21 +0000
@@ -22,35 +22,47 @@
namespace zorba {
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaInsertNodesIterator, PlanIteratorState>, 1)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesIterator, ZorbaApplyInsertNodesIteratorState>, 2)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaInsertNodesLastIterator, PlanIteratorState>, 3)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesLastIterator, ZorbaApplyInsertNodesLastIteratorState>, 4)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaInsertNodesFirstIterator, PlanIteratorState>, 5)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesFirstIterator, ZorbaApplyInsertNodesFirstIteratorState>, 6)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaInsertNodesBeforeIterator, PlanIteratorState>, 7)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesBeforeIterator, ZorbaApplyInsertNodesBeforeIteratorState>, 8)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaInsertNodesAfterIterator, PlanIteratorState>, 9)
-
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(ZorbaCollectionIteratorHelper,
- ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesAfterIterator, ZorbaApplyInsertNodesAfterIteratorState>, 10)
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaInsertNodesIterator, PlanIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaInsertNodesIterator, PlanIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesIterator, ZorbaApplyInsertNodesIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesIterator, ZorbaApplyInsertNodesIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaInsertNodesLastIterator, PlanIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaInsertNodesLastIterator, PlanIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesLastIterator, ZorbaApplyInsertNodesLastIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesLastIterator, ZorbaApplyInsertNodesLastIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaInsertNodesFirstIterator, PlanIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaInsertNodesFirstIterator, PlanIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesFirstIterator, ZorbaApplyInsertNodesFirstIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesFirstIterator, ZorbaApplyInsertNodesFirstIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaInsertNodesBeforeIterator, PlanIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaInsertNodesBeforeIterator, PlanIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesBeforeIterator, ZorbaApplyInsertNodesBeforeIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesBeforeIterator, ZorbaApplyInsertNodesBeforeIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaInsertNodesAfterIterator, PlanIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaInsertNodesAfterIterator, PlanIteratorState>";
+
+template<> const char*
+ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesAfterIterator, ZorbaApplyInsertNodesAfterIteratorState>::class_name_str =
+"ZorbaCollectionIteratorHelper<ZorbaApplyInsertNodesAfterIterator, ZorbaApplyInsertNodesAfterIteratorState>";
+
void checkNodeType(
const static_context* sctx,
=== modified file 'src/runtime/core/path_iterators.cpp'
--- src/runtime/core/path_iterators.cpp 2012-04-10 20:59:34 +0000
+++ src/runtime/core/path_iterators.cpp 2012-04-13 18:57:21 +0000
@@ -43,22 +43,69 @@
namespace zorba
{
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<SelfAxisIterator, SelfAxisState>, 1)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<AttributeAxisIterator, AttributeAxisState>, 2)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<ParentAxisIterator, ParentAxisState>, 3)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<AncestorAxisIterator, AncestorAxisState>, 4)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<AncestorReverseAxisIterator, AncestorReverseAxisState>, 5)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<AncestorSelfAxisIterator, AncestorAxisState>, 6)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<AncestorSelfReverseAxisIterator, AncestorReverseAxisState>, 7)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<RSiblingAxisIterator, SiblingAxisState>, 8)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<LSiblingAxisIterator, SiblingAxisState>, 9)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<LSiblingReverseAxisIterator, LSiblingReverseAxisState>, 10)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<ChildAxisIterator, ChildAxisState>, 11)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<DescendantAxisIterator,DescendantAxisState>, 12)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<DescendantSelfAxisIterator,DescendantAxisState>, 13)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<PrecedingAxisIterator, PrecedingAxisState>, 14)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<PrecedingReverseAxisIterator, PrecedingReverseAxisState>, 15)
-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(AxisIterator, AxisIterator<FollowingAxisIterator,FollowingAxisState>, 16)
+template<> const char*
+AxisIterator<SelfAxisIterator, SelfAxisState>::class_name_str =
+"AxisIterator<SelfAxisIterator, SelfAxisState>";
+
+template<> const char*
+AxisIterator<AttributeAxisIterator, AttributeAxisState>::class_name_str =
+"AxisIterator<AttributeAxisIterator, AttributeAxisState>";
+
+template<> const char*
+AxisIterator<ParentAxisIterator, ParentAxisState>::class_name_str =
+"AxisIterator<ParentAxisIterator, ParentAxisState>";
+
+template<> const char*
+AxisIterator<AncestorAxisIterator, AncestorAxisState>::class_name_str =
+"AxisIterator<AncestorAxisIterator, AncestorAxisState>";
+
+template<> const char*
+AxisIterator<AncestorReverseAxisIterator, AncestorReverseAxisState>::class_name_str =
+"AxisIterator<AncestorReverseAxisIterator, AncestorReverseAxisState>";
+
+template<> const char*
+AxisIterator<AncestorSelfAxisIterator, AncestorAxisState>::class_name_str =
+"AxisIterator<AncestorSelfAxisIterator, AncestorAxisState>";
+
+template<> const char*
+AxisIterator<AncestorSelfReverseAxisIterator, AncestorReverseAxisState>::class_name_str =
+"AxisIterator<AncestorSelfReverseAxisIterator, AncestorReverseAxisState>";
+
+template<> const char*
+AxisIterator<RSiblingAxisIterator, SiblingAxisState>::class_name_str =
+"AxisIterator<RSiblingAxisIterator, SiblingAxisStat>";
+
+template<> const char*
+AxisIterator<LSiblingAxisIterator, SiblingAxisState>::class_name_str =
+"AxisIterator<LSiblingAxisIterator, SiblingAxisState>";
+
+template<> const char*
+AxisIterator<LSiblingReverseAxisIterator, LSiblingReverseAxisState>::class_name_str =
+"AxisIterator<LSiblingReverseAxisIterator, LSiblingReverseAxisState>";
+
+template<> const char*
+AxisIterator<ChildAxisIterator, ChildAxisState>::class_name_str =
+"AxisIterator<ChildAxisIterator, ChildAxisState>";
+
+template<> const char*
+AxisIterator<DescendantAxisIterator,DescendantAxisState>::class_name_str =
+"AxisIterator<DescendantAxisIterator,DescendantAxisState>";
+
+template<> const char*
+AxisIterator<DescendantSelfAxisIterator,DescendantAxisState>::class_name_str =
+"AxisIterator<DescendantSelfAxisIterator,DescendantAxisState>";
+
+template<> const char*
+AxisIterator<PrecedingAxisIterator, PrecedingAxisState>::class_name_str =
+"AxisIterator<PrecedingAxisIterator, PrecedingAxisState>";
+
+template<> const char*
+AxisIterator<PrecedingReverseAxisIterator, PrecedingReverseAxisState>::class_name_str =
+"AxisIterator<PrecedingReverseAxisIterator, PrecedingReverseAxisState>";
+
+template<> const char*
+AxisIterator<FollowingAxisIterator, FollowingAxisState>::class_name_str =
+"AxisIterator<FollowingAxisIterator, FollowingAxisState>";
SERIALIZABLE_CLASS_VERSIONS(SelfAxisIterator)
=== modified file 'src/types/typeimpl.cpp'
--- src/types/typeimpl.cpp 2012-04-10 20:59:34 +0000
+++ src/types/typeimpl.cpp 2012-04-13 18:57:21 +0000
@@ -44,8 +44,6 @@
#endif
-SERIALIZABLE_CLASS_VERSIONS(XQType)
-
SERIALIZABLE_CLASS_VERSIONS(AtomicXQType)
SERIALIZABLE_CLASS_VERSIONS(NodeXQType)
=== modified file 'src/types/typemanagerimpl.cpp'
--- src/types/typemanagerimpl.cpp 2012-04-10 20:59:34 +0000
+++ src/types/typemanagerimpl.cpp 2012-04-13 18:57:21 +0000
@@ -55,8 +55,6 @@
XERCES_CPP_NAMESPACE_USE
#endif
-SERIALIZABLE_CLASS_VERSIONS(TypeManager)
-
SERIALIZABLE_CLASS_VERSIONS(TypeManagerImpl)
=== modified file 'src/zorbaserialization/archiver.cpp'
--- src/zorbaserialization/archiver.cpp 2012-04-10 20:59:34 +0000
+++ src/zorbaserialization/archiver.cpp 2012-04-13 18:57:21 +0000
@@ -119,7 +119,7 @@
all_reference_list(0),
theArchiveVersion(ClassSerializer::g_zorba_classes_version),
theRootField(0),
- current_compound_field(0),
+ theCurrentCompoundField(0),
theSimpleFieldsMap(0),
hash_out_fields(0),
nr_ids(0),
@@ -149,7 +149,7 @@
ALLOW_DELAY,
0); // level
- current_compound_field = theRootField;
+ theCurrentCompoundField = theRootField;
theSimpleFieldsMap = new HashMap<SIMPLE_HASHOUT_FIELD, archive_field*,
SimpleHashoutFieldCompare>(1000, false);
@@ -242,6 +242,32 @@
/*******************************************************************************
+ Check whether there exists already a field for the class object at the given
+ memory address.
+********************************************************************************/
+archive_field* Archiver::lookup_class_field(const SerializeBaseClass* ptr)
+{
+ if (!ptr)
+ return NULL;
+
+ archive_field* duplicate_field = NULL;
+
+ hash_out_fields->get((uint64_t)ptr, duplicate_field);
+
+ if (!duplicate_field)
+ {
+ Archiver* har = ::zorba::serialization::ClassSerializer::getInstance()->
+ getArchiverForHardcodedObjects();
+
+ if (har != this)
+ duplicate_field = har->lookup_class_field(ptr);
+ }
+
+ return duplicate_field;
+}
+
+
+/*******************************************************************************
Create a "simple" field (ARCHIVE_FIELD_PTR, or ARCHIVE_FIELD_NUL, or
ARCHIVE_FIELD_NORMAL).
@@ -286,12 +312,14 @@
if (ref_field)
{
+ assert(ref_field->theKind == ARCHIVE_FIELD_PTR ||
+ ref_field->theKind == ARCHIVE_FIELD_NORMAL);
+
// If we are trying to register the actual obj (i.e. fieldKind == FIELD_NORMAL)
// and there is already a field for the same obj, then the pre-existing field
// must be a PTR or REFERENCING field.
assert(fieldKind != ARCHIVE_FIELD_NORMAL ||
- ref_field->theKind == ARCHIVE_FIELD_PTR ||
- ref_field->theKind == ARCHIVE_FIELD_REFERENCING);
+ ref_field->theKind == ARCHIVE_FIELD_PTR);
if (get_is_temp_field_one_level() &&
fieldKind == ARCHIVE_FIELD_PTR &&
@@ -302,8 +330,8 @@
if (fieldKind == ARCHIVE_FIELD_NORMAL)
{
- // special case: we registered a pointer to the obj before the obj itself
- // and now we try to register the obj itself.
+ // special case: we have registered already a pointer to the obj (before
+ // the obj itself) and now we try to register the obj itself.
exch_fields = true;
}
@@ -342,14 +370,14 @@
new_field->theId = ++nr_ids;
new_field->theOrder = new_field->theId;
- new_field->theParent = current_compound_field;
+ new_field->theParent = theCurrentCompoundField;
- if (current_compound_field->theLastChild)
- current_compound_field->theLastChild->theNextSibling = new_field;
+ if (theCurrentCompoundField->theLastChild)
+ theCurrentCompoundField->theLastChild->theNextSibling = new_field;
else
- current_compound_field->theFirstChild = new_field;
+ theCurrentCompoundField->theFirstChild = new_field;
- current_compound_field->theLastChild = new_field;
+ theCurrentCompoundField->theLastChild = new_field;
}
else
{
@@ -401,22 +429,21 @@
{
ref_field->theKind = ARCHIVE_FIELD_NORMAL;
- new_field->theKind = ARCHIVE_FIELD_REFERENCING;
+ assert(new_field->theKind == ARCHIVE_FIELD_REFERENCING);
new_field->theId = ++nr_ids;
- new_field->referencing = ref_field->theId;
new_field->theAllowDelay2 = ref_field->theAllowDelay2;
replace_field(new_field, ref_field);
- ref_field->theParent = current_compound_field;
+ ref_field->theParent = theCurrentCompoundField;
- if(current_compound_field->theLastChild)
- current_compound_field->theLastChild->theNextSibling = ref_field;
+ if(theCurrentCompoundField->theLastChild)
+ theCurrentCompoundField->theLastChild->theNextSibling = ref_field;
else
- current_compound_field->theFirstChild = ref_field;
+ theCurrentCompoundField->theFirstChild = ref_field;
ref_field->theNextSibling = NULL;
- current_compound_field->theLastChild = ref_field;
+ theCurrentCompoundField->theLastChild = ref_field;
ref_field->theOrder = nr_ids;
}
@@ -429,7 +456,7 @@
const char* type,
bool is_class,
const void* info,
- const void* ptr,//for classes, pointer to SerializeBaseClass
+ const void* ptr,
enum ArchiveFieldKind fieldKind)
{
archive_field* new_field;
@@ -457,6 +484,9 @@
if (ref_field)
{
+ assert(ref_field->theKind == ARCHIVE_FIELD_PTR ||
+ ref_field->theKind == ARCHIVE_FIELD_NORMAL);
+
assert(fieldKind != ARCHIVE_FIELD_NORMAL ||
ref_field->theKind != ARCHIVE_FIELD_NORMAL);
@@ -469,8 +499,6 @@
if (fieldKind == ARCHIVE_FIELD_NORMAL)
{
- //special case
- //move the prev field into this one
exch_fields = true;
}
@@ -511,19 +539,19 @@
if (!exch_fields)
{
- new_field->theParent = current_compound_field;
+ new_field->theParent = theCurrentCompoundField;
new_field->theId = ++nr_ids;
new_field->theOrder = new_field->theId;
- if (current_compound_field->theLastChild)
- current_compound_field->theLastChild->theNextSibling = new_field;
+ if (theCurrentCompoundField->theLastChild)
+ theCurrentCompoundField->theLastChild->theNextSibling = new_field;
else
- current_compound_field->theFirstChild = new_field;
+ theCurrentCompoundField->theFirstChild = new_field;
- current_compound_field->theLastChild = new_field;
+ theCurrentCompoundField->theLastChild = new_field;
if (!ref_field && ptr)
- current_compound_field = new_field;
+ theCurrentCompoundField = new_field;
}
else
{
@@ -542,7 +570,7 @@
********************************************************************************/
void Archiver::add_end_compound_field()
{
- current_compound_field = current_compound_field->theParent;
+ theCurrentCompoundField = theCurrentCompoundField->theParent;
theCurrentLevel--;
}
@@ -550,41 +578,6 @@
/*******************************************************************************
********************************************************************************/
-void Archiver::set_class_type(const char* class_name)
-{
- free(current_compound_field->theTypeName);
- current_compound_field->theTypeName = strdup(class_name);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-archive_field* Archiver::lookup_class_field(const SerializeBaseClass* ptr)
-{
- if (!ptr)
- return NULL;
-
- archive_field* duplicate_field = NULL;
-
- hash_out_fields->get((uint64_t)ptr, duplicate_field);
-
- if (!duplicate_field)
- {
- Archiver* har = ::zorba::serialization::ClassSerializer::getInstance()->
- getArchiverForHardcodedObjects();
-
- if (har != this)
- duplicate_field = har->lookup_class_field(ptr);
- }
-
- return duplicate_field;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
bool Archiver::read_next_field(
char** type,
std::string* value,
@@ -766,7 +759,7 @@
********************************************************************************/
void Archiver::register_item(store::Item* i)
{
- if(i)
+ if (i)
registered_items.push_back(i);
}
@@ -780,16 +773,17 @@
const char* class_name,
int referencing)
{
- struct fwd_ref fid;
+ struct fwd_ref fid;
fid.referencing = referencing;
fid.is_class = is_class;
fid.ptr = ptr;
*ptr = NULL;
- //fid.add_ref_to_rcobject = true;
+
if(class_name)
fid.class_name = strdup(class_name);
else
fid.class_name = NULL;
+
fid.to_add_ref = false;
fwd_reference_list.push_back(fid);
}
@@ -803,12 +797,11 @@
void** new_last_obj,
bool to_add_ref)
{
- if(fwd_reference_list.size() > 0)
+ if (fwd_reference_list.size() > 0)
{
- struct fwd_ref &fid = fwd_reference_list.back();
- if(fid.ptr == last_obj)
+ struct fwd_ref& fid = fwd_reference_list.back();
+ if (fid.ptr == last_obj)
{
- //fid.add_ref_to_rcobject = false;
fid.ptr = new_last_obj;
fid.to_add_ref = to_add_ref;
}
@@ -866,18 +859,19 @@
{
std::list<fwd_ref>::iterator it;
void* ptr;
+
for (it = fwd_reference_list.begin(); it != fwd_reference_list.end(); it++)
{
ptr = get_reference_value((*it).referencing);
- if(!ptr)
+
+ if (!ptr)
{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0004_UNRESOLVED_FIELD_REFERENCE,
- ERROR_PARAMS( it->referencing )
- );
+ throw ZORBA_EXCEPTION(zerr::ZCSE0004_UNRESOLVED_FIELD_REFERENCE,
+ ERROR_PARAMS(it->referencing));
}
+
//search the list for the pointer
- if(!(*it).is_class)
+ if (!(*it).is_class)
{
*((*it).ptr) = ptr;
}
@@ -909,10 +903,6 @@
{
rcobj2->addReference(); //this can lead to memory leaks
}
- //else if ((rcobj3 = dynamic_cast<zStringStore*>((SerializeBaseClass*)ptr)) != NULL)
- //{
- // RCHelper::addReference(rcobj3); //this can lead to memory leaks
- //}
else
{
ZORBA_FATAL(0, (*it).class_name);
@@ -922,8 +912,9 @@
//decrement RC on Items
std::vector<store::Item*>::iterator item_it;
- int j=0;
- for(item_it = registered_items.begin(); item_it != registered_items.end(); item_it++)
+ int j = 0;
+
+ for (item_it = registered_items.begin(); item_it != registered_items.end(); item_it++)
{
j++;
if((*item_it)->isNode())
=== modified file 'src/zorbaserialization/archiver.h'
--- src/zorbaserialization/archiver.h 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/archiver.h 2012-04-13 18:57:21 +0000
@@ -43,48 +43,67 @@
#define FIELD_IS_SIMPLE true
#define FIELD_IS_CLASS true
+class ClassSerializer;
+
+
/*******************************************************************************
- Archiver is working with fields. One archive contains a sequence of fields.
- They can be simple fields or combo fields.
-
- Simple fields: have values of simple types.
- Combo fields: contain a sequence of fields. Are like list, vector, class etc.
+ Archiver is working with fields. During serialization, an intermediate tree of
+ fields is constructed in memory to represent all the objects that need to be
+ serialized. Then, the fields are written to disk in depth-first order, creating
+ an archive. During deserialization, the fields in the archive are read and the
+ associated objects recreated directly in memory, without going through the
+ intermediate representation of the fields-tree.
+
+ Notice that in the context of the serializer, an "object" is defined as any
+ address in memory that contains information to be serialized. For example,
+ it can be a C++ class object, an std::vector<> or a C++ integer. The object
+ can be heap-allocated, or on the stack.
+
+ Fileds can be "simple" or "compound". Simple fields represent values of simple
+ types; they always appear as leaves in the fields-tree. Compound fields represent
+ C++-class objects and other structured types like vectors, maps, etc. They
+ typically contain subtrees of other fields.
Each field has a unique id.
- Special field is a field that points to a previous field. This is to resolve
- serialization of pointers to the same object.
-
********************************************************************************/
-class ClassSerializer;
-
-
/*******************************************************************************
+ ARCHIVE_FIELD_NORMAL:
+ ---------------------
+ A field of kind NORMAL or PTR acts as the root of a tree of fields representing
+ the serialization of a concrete obj. If the kind is PTR, then the obj was
+ serialized when a pointer to it was encountered. In this case, during
+ deserialization, the archiver will allocate the obj on the heap and fill-in
+ its data members. If the kind is NORMAL, then the obj was serialized when the
+ objitself was encountered (e.g., the object was an embedded data member of
+ another obj, or was residing on the program stack). In this case, during
+ deserialization, the object exists already (in an uninitialized state) and a
+ reference to it is given to the archiver, which will fill-in the obj's data.
+
+ ARCHIVE_FIELD_PTR:
+ ------------------
+ See comment for ARCHIVE_FIELD_NORMAL.
+
ARCHIVE_FIELD_REFERENCING :
------------------------------
- A field A that references another field B, where both A and B represent the
- "same" object.
+ A field A that references another field B (of kind NORMAL or PTR), where both
+ A and B represent the "same" object.
ARCHIVE_FIELD_BASECLASS :
----------------------------
- A field representing a "partial" class object: If an obj O belong to a class C
- and C is a subclass of a base class B, then a field of ARCHIVE_FIELD_IS_BASECLASS
- kind is created to represent the serialization of the data members of B.
-
- ARCHIVE_FIELD_PTR :
- ----------------------
+ A field representing a "partial" class object: If an obj Os belong to a class C
+ and C is a subclass of a base class B, then a field of IS_BASECLASS kind is
+ created to represent the serialization of the data members of B. This field
+ is placed as a child of the NORMAL or PTR field
ARCHIVE_FIELD_NULL :
-----------------------
A field representing a NULL pointer.
- ARCHIVE_FIELD_NORMAL :
- ----------------------
-
********************************************************************************/
enum ArchiveFieldKind
{
@@ -134,6 +153,7 @@
Whether this field represents a class obj or not. Class objs are always
considered as "compound", so if theIsClass is true, theIsSimple is false.
However, the reverse is not true: a non-class obj may be simple or compound.
+ For example, an std::vector<> is a compound, non-class obj.
theKind:
--------
@@ -144,19 +164,25 @@
theTypeNamePosInPool:
---------------------
+ The position of theTypeName string within the string pool. The string pool
+ is created after the fields tree has been fully built and just before we
+ start actually writting stuff out to "disk". theTypeName string is copied
+ into the string pool only if theKind is PTR and theIsClass is true.
theValue:
---------
- For simple fields
theValuePosInPool:
------------------
- Not initialized by constructor.
+ The position of theValue string within the string pool. The string pool
+ is created after the fields tree has been fully built and just before we
+ start actually writting stuff out to "disk". theValue string is copied
+ into the string pool only if theKind is PTR or NORMAL.
thePtr :
--------
- Pointer to the obj represented by this field. NULL if this field is referencing
- another field that represents the same obj.
+ Pointer to the obj represented by this field. NULL for FIELD_REFERENCING and
+ FIELD_NULL fields.
theReferredField:
-----------------
@@ -170,20 +196,24 @@
theLevel:
---------
- The level of this field, i.e., the nuber of fields in the paths from this
+ The level of this field, i.e., the nuber of fields in the path from this
field to the root. The root is at level 0.
theNextSibling:
---------------
+ The right sibling of this field (if any).
theFirstChild:
--------------
+ The 1st child of this field (if any).
theLastChild:
-------------
+ The last child of this field (if any).
theParent:
----------
+ The parent field in the fields tree.
theOnlyForEval:
---------------
@@ -199,8 +229,8 @@
The following data members are serialized:
- 1. theTypeName : only if theKind is PTR
- 2. theValue : except if theKind is REFERENCING
+ 1. theTypeName : only if theKind is PTR and theIsClass is true.
+ 2. theValue : except if theKind is REFERENCING or NULL
3. theReferedId : only if theKind is REFERENCING
4. theKind
5. theId
@@ -284,6 +314,10 @@
--------------
The root of the fields tree.
+ theCurrentCompoundField:
+ ------------------------
+ The compound field under which the next field to be created will be placed.
+
theCurrentLevel:
----------------
The tree level of the most recently added field
@@ -350,7 +384,7 @@
archive_field * theRootField;
- archive_field * current_compound_field;
+ archive_field * theCurrentCompoundField;
SimpleFieldMap * theSimpleFieldsMap;
@@ -397,6 +431,10 @@
void setUserCallback(SerializationCallback* cb) { theUserCallback = cb; }
+ //
+ // Methods used during serialization only
+ //
+
bool add_simple_field(
const char* type,
const char* value,
@@ -407,13 +445,14 @@
const char* type,
bool is_class,
const void* info,
- const void* ptr,//for classes, pointer to SerializeBaseClass
+ const void* ptr,
enum ArchiveFieldKind field_treat);
void add_end_compound_field();
- void set_class_type(const char* class_name);
-
+ //
+ // Methods used during de-serialization only
+ //
bool read_next_field(
char** type,
std::string* value,
@@ -436,14 +475,22 @@
virtual void read_end_current_level_impl() = 0;
-
protected:
+
+ //
+ // Methods used during serialization only
+ //
+
archive_field* lookup_nonclass_field(const char* type, const void* ptr);
archive_field* lookup_class_field(const SerializeBaseClass* ptr);
virtual void serialize_out() = 0;
+ //
+ // Methods used during de-serialization only
+ //
+
virtual void read_archive_description(
std::string* archive_name,
std::string* archive_info,
@@ -456,6 +503,9 @@
*nr_ids = this->nr_ids;
}
+ //
+ //
+ //
void replace_field(archive_field* new_field, archive_field* ref_field);
void exchange_fields(archive_field* new_field, archive_field* ref_field);
@@ -542,9 +592,9 @@
void register_item(store::Item* i);
//to help check class name at runtime
- void set_serialize_base_class(bool s)
+ void set_serialize_base_class(bool s)
{
- if(s)
+ if (s)
serialize_base_class++;
else
serialize_base_class--;
@@ -600,7 +650,7 @@
else
{
unsigned int lastlevel = limit_temp_level_stack.top().first;
- archive_field* temp_field = current_compound_field;
+ archive_field* temp_field = theCurrentCompoundField;
while (temp_field && (temp_field->theLevel >= lastlevel))
{
=== modified file 'src/zorbaserialization/bin_archiver.cpp'
--- src/zorbaserialization/bin_archiver.cpp 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/bin_archiver.cpp 2012-04-13 18:57:21 +0000
@@ -272,26 +272,34 @@
/*******************************************************************************
********************************************************************************/
-int BinArchiver::add_to_string_pool(const char *str)
+int BinArchiver::add_to_string_pool(const char* str)
{
- if(!str)
+ if (!str)
return 0;
- int str_pos = 0;
- if(string_pool.get(str, str_pos))
+
+ int str_pos = 0;
+
+ if (string_pool.get(str, str_pos))
{
- STRING_POS &str_struct = strings.at(str_pos-1);
+ STRING_POS& str_struct = strings.at(str_pos-1);
str_struct.count++;
return str_pos;
}
+
STRING_POS str_struct;
str_struct.str = str;
str_struct.count = 1;
str_struct.final_pos = (unsigned int)strings.size()+1;
+
strings.push_back(str_struct);
+
str_pos = (int)strings.size();
strings_pos.push_back(str_pos-1);
- const char *str_dup = strdup(str);
+
+ const char* str_dup = strdup(str);
+
string_pool.insert(str_dup, str_pos);
+
return str_pos;
}
@@ -304,21 +312,21 @@
archive_field* current_field = parent_field->theFirstChild;
while (current_field)
{
- if(current_field->theKind != ARCHIVE_FIELD_NULL)
+ if (current_field->theKind != ARCHIVE_FIELD_NULL)
{
#ifdef NDEBUG
- if(current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_PTR))
+ if (current_field->theIsClass && current_field->theKind == ARCHIVE_FIELD_PTR)
#endif
current_field->theTypeNamePosInPool = add_to_string_pool(current_field->theTypeName);
- if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
+ if (current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
current_field->theValuePosInPool = add_to_string_pool(current_field->theValue);
}
}
- if(!current_field->theIsSimple)
+ if (!current_field->theIsSimple)
{
- if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
+ if (current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
collect_strings(current_field);
}
@@ -353,7 +361,8 @@
}
write_int((unsigned int)strings.size());
- if(bitfill)
+
+ if (bitfill)
{
current_byte <<= (8-bitfill);
os->write((char*)¤t_byte, 1);
@@ -363,8 +372,11 @@
bytes_saved++;
#endif
}
+
std::vector<unsigned int>::iterator strings_pos_it;
- for(strings_pos_it = strings_pos.begin(); strings_pos_it != strings_pos.end(); strings_pos_it++)
+ for (strings_pos_it = strings_pos.begin();
+ strings_pos_it != strings_pos.end();
+ strings_pos_it++)
{
write_string(strings.at(*strings_pos_it).str.c_str());
}
@@ -374,7 +386,7 @@
/*******************************************************************************
********************************************************************************/
-void BinArchiver::serialize_compound_fields(archive_field *parent_field)
+void BinArchiver::serialize_compound_fields(archive_field* parent_field)
{
#ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
unsigned int bytes_saved1 = bytes_saved;
@@ -404,7 +416,7 @@
write_bits(small_treat, 2);
#endif
- if(current_field->theKind != ARCHIVE_FIELD_NULL)
+ if (current_field->theKind != ARCHIVE_FIELD_NULL)
{
#ifdef NDEBUG
if (current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_PTR))
@@ -420,10 +432,10 @@
last_id = current_field->theId;
- if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
+ if (current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
- if(!current_field->theValuePosInPool)
- write_int_exp2(current_field->theValuePosInPool);
+ if (!current_field->theValuePosInPool)
+ write_int_exp2(0);
else
write_int_exp2(strings.at(current_field->theValuePosInPool-1).final_pos);
}
@@ -439,7 +451,7 @@
if (!current_field->theIsSimple)
{
- if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
+ if (current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
serialize_compound_fields(current_field);
#ifndef NDEBUG
=== modified file 'src/zorbaserialization/class_serializer.h'
--- src/zorbaserialization/class_serializer.h 2012-04-10 20:59:34 +0000
+++ src/zorbaserialization/class_serializer.h 2012-04-13 18:57:21 +0000
@@ -47,9 +47,19 @@
/*******************************************************************************
+
The classes and macros defined in this file provide a generic infrastructure
for making an arbitrary c++ class serializable. This infrastructure is provided
- for convenience; not every c++ type has to adopt this inftrasture.
+ for convenience; not every c++ type has to adopt this inftrasture. Class that
+ do follow this infrastructure can be serialized via the template operators:
+
+ void operator&(Archiver& ar, T& obj) and
+ void operator&(Archiver& ar, T*& obj),
+
+ which are defined in serialize_template_types.h. These operators assume that
+ T is a class that has the following 2 methods:
+
+ get_class_name_str() and serialize_internal()
********************************************************************************/
@@ -106,6 +116,11 @@
/*******************************************************************************
A class that may be used as the base for other c++ classes that need to be
serialized.
+
+ The serialize_internal() method is called by the template operators:
+ void operator&(Archiver& ar, T& obj) and
+ void operator&(Archiver& ar, T*& obj).
+
********************************************************************************/
class ZORBA_DLL_PUBLIC SerializeBaseClass
{
@@ -116,6 +131,29 @@
};
+#define SERIALIZE_INTERNAL_METHOD(class_name) \
+virtual void serialize_internal(::zorba::serialization::Archiver& ar) \
+{ \
+ CHECK_CLASS_NAME(class_name); \
+ \
+ if (ar.is_serialize_base_class()) \
+ ar.set_serialize_base_class(false); \
+ \
+ class_name::serialize(ar); \
+}
+
+
+#ifndef NDEBUG
+#define CHECK_CLASS_NAME(class_name)\
+if (ar.is_serializing_out() && !ar.is_serialize_base_class()) \
+{ \
+ assert(strstr(typeid(*this).name(), #class_name)); \
+}
+#else
+#define CHECK_CLASS_NAME(class_name)
+#endif
+
+
/*******************************************************************************
Every serializable class C has a nested member class D that is a subclass of
ClassDeserializer. Furthermore, every serializable class has a static data
@@ -125,9 +163,7 @@
class ClassDeserializer
{
public:
- virtual ~ClassDeserializer()
- {
- }
+ virtual ~ClassDeserializer() { }
virtual SerializeBaseClass* create_new(Archiver& ar) = 0;
@@ -135,9 +171,6 @@
};
-/*******************************************************************************
-
-********************************************************************************/
#define SERIALIZABLE_CLASS_FACTORY_DECL(class_name, creator) \
template<class T_serialized_class> \
class class_factory : public ::zorba::serialization::ClassDeserializer \
@@ -164,81 +197,48 @@
/*******************************************************************************
********************************************************************************/
-#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()) \
- ar.set_serialize_base_class(false); \
- \
- class_name::serialize(ar); \
-} \
- \
-virtual const char* get_class_name_str() const { return #class_name; } \
- \
-static const char* get_class_name_str_static() { return #class_name; }
-
-
-/*******************************************************************************
-
-********************************************************************************/
-#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;
-
-
-#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;
-
-
-#define SERIALIZABLE_CLASS_PREFIX(class_name) \
-virtual void serialize_internal(::zorba::serialization::Archiver& ar) \
-{ \
- CHECK_CLASS_NAME(class_name); \
- \
- if (ar.is_serialize_base_class()) \
- ar.set_serialize_base_class(false); \
- \
- class_name::serialize(ar); \
-} \
- \
-virtual const char* get_class_name_str() const { return #class_name; } \
- \
-static const char* get_class_name_str_static() { return #class_name; }
-
-
-#define SERIALIZABLE_CLASS_VERSIONS(class_name) \
+#define SERIALIZABLE_CLASS(class_name) \
+SERIALIZE_INTERNAL_METHOD(class_name) \
+ \
+virtual const char* get_class_name_str() const { return #class_name; } \
+ \
+static const char* get_class_name_str_static() { return #class_name; } \
+ \
+SERIALIZABLE_CLASS_FACTORY_DECL(class_name, new class_name(ar)) \
+static class_factory<class_name> g_class_factory; \
+
+
+#define SERIALIZABLE_ABSTRACT_CLASS(class_name) \
+SERIALIZE_INTERNAL_METHOD(class_name) \
+ \
+virtual const char* get_class_name_str() const { return #class_name; } \
+ \
+static const char* get_class_name_str_static() { return #class_name; }
+
+
+#define SERIALIZABLE_CLASS_VERSIONS(class_name) \
class_name::class_factory<class_name> class_name::g_class_factory;
/*******************************************************************************
********************************************************************************/
-#define SERIALIZABLE_TEMPLATE_CLASS(class_name) \
-SERIALIZABLE_TEMPLATE_CLASS_PREFIX(class_name) \
-SERIALIZABLE_CLASS_FACTORY_DECL(class_name, new class_name(ar)) \
-static const char * class_name_str;
-
-
-#define SERIALIZABLE_TEMPLATE_ABSTRACT_CLASS(class_name) \
-SERIALIZABLE_TEMPLATE_CLASS_PREFIX(class_name) \
-SERIALIZABLE_CLASS_FACTORY_DECL(class_name, NULL) \
-static const char * class_name_str;
-
-
-#define SERIALIZABLE_TEMPLATE_CLASS_PREFIX(class_name) \
-virtual void serialize_internal(::zorba::serialization::Archiver& ar) \
-{ \
- CHECK_CLASS_NAME(class_name); \
- \
- if (ar.is_serialize_base_class()) \
- ar.set_serialize_base_class(false); \
- \
- class_name::serialize(ar); \
-} \
+#define SERIALIZABLE_TEMPLATE_CLASS(class_name) \
+SERIALIZE_INTERNAL_METHOD(class_name) \
+ \
+static const char * class_name_str; \
+ \
+virtual const char* get_class_name_str() const { return class_name_str; } \
+ \
+static const char* get_class_name_str_static() { return class_name_str; } \
+ \
+SERIALIZABLE_CLASS_FACTORY_DECL(class_name, new class_name(ar))
+
+
+#define SERIALIZABLE_TEMPLATE_ABSTRACT_CLASS(class_name) \
+SERIALIZE_INTERNAL_METHOD(class_name) \
+ \
+static const char * class_name_str; \
\
virtual const char* get_class_name_str() const { return class_name_str; } \
\
@@ -375,19 +375,6 @@
}
-/*******************************************************************************
-
-********************************************************************************/
-#ifndef NDEBUG
-#define CHECK_CLASS_NAME(class_name)\
-if (ar.is_serializing_out() && !ar.is_serialize_base_class()) \
-{ \
- assert(strstr(typeid(*this).name(), #class_name)); \
-}
-#else
-#define CHECK_CLASS_NAME(class_name)
-#endif
-
} // namespace serialization
} // namespace zorba
=== modified file 'src/zorbaserialization/serialize_template_types.h'
--- src/zorbaserialization/serialize_template_types.h 2012-04-10 20:10:08 +0000
+++ src/zorbaserialization/serialize_template_types.h 2012-04-13 18:57:21 +0000
@@ -52,6 +52,18 @@
********************************************************************************/
template<class T>
+void serialize_baseclass(Archiver& ar, T* obj)
+{
+ ar.set_serialize_base_class(true);
+
+ ar & obj;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+template<class T>
void operator&(Archiver& ar, T& obj)
{
if (ar.is_serializing_out())
@@ -60,7 +72,7 @@
is_ref = ar.add_compound_field(obj.get_class_name_str(),
FIELD_IS_CLASS,
- "0",//strtemp,
+ "0",
(SerializeBaseClass*)&obj,
ARCHIVE_FIELD_NORMAL);
if (!is_ref)
@@ -80,16 +92,16 @@
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);
+ 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,
+ is_simple, is_class,
+ field_treat, ARCHIVE_FIELD_NORMAL,
id);
ar.register_reference(id, field_treat, (SerializeBaseClass*)&obj);
@@ -160,7 +172,8 @@
return;
ar.check_class_field(retval, "", "",
- is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
+ is_simple, is_class,
+ field_treat, (ArchiveFieldKind)-1, id);
if (field_treat == ARCHIVE_FIELD_NULL)
{
@@ -210,30 +223,35 @@
if (!obj)
{
- delete new_obj;obj=NULL;
+ 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);
+ 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
+ // ARCHIVE_FIELD_REFERENCING
+ else if ((new_obj = (SerializeBaseClass*)ar.get_reference_value(referencing)))
{
try
{
@@ -261,139 +279,65 @@
}
-/*******************************************************************************
-
-********************************************************************************/
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())
+void operator&(Archiver& ar, checked_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::list<T>", !FIELD_IS_CLASS, strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- if(!is_ref)
+
+ bool is_ref = ar.add_compound_field("checked_vector<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++)
+ typename checked_vector<T>::iterator it = obj.begin();
+ typename checked_vector<T>::iterator end = obj.end();
+ for(; it != end; ++it)
{
ar & (*it);
}
+
ar.add_end_compound_field();
}
}
else
{
- char *type;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::list<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ 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 std::list<T>::iterator it;
- for(it=obj.begin(); it != obj.end(); it++)
+
+ typename checked_vector<T>::iterator it = obj.begin();
+ typename checked_vector<T>::iterator end = obj.end();
+ for(; it != end; ++it)
{
ar & (*it);
}
+
ar.read_end_current_level();
-
}
}
@@ -404,7 +348,7 @@
template<typename T>
void operator&(Archiver& ar, std::vector<T>& obj)
{
- if(ar.is_serializing_out())
+ if (ar.is_serializing_out())
{
char strtemp[20];
#ifndef WIN32
@@ -412,44 +356,56 @@
#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)
+ bool 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++)
+ typename std::vector<T>::iterator it = obj.begin();
+ typename std::vector<T>::iterator end = obj.end();
+ for(; it != end; ++it)
{
ar & (*it);
}
+
ar.add_end_compound_field();
}
}
else
{
- char *type;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::vector<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ 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++)
+
+ typename std::vector<T>::iterator it = obj.begin();
+ typename std::vector<T>::iterator end = obj.end();
+ for(; it != end; ++it)
{
ar & (*it);
}
+
ar.read_end_current_level();
-
}
}
@@ -460,60 +416,72 @@
template<typename T>
void operator&(Archiver& ar, std::vector<T>*& obj)
{
- if(ar.is_serializing_out())
+ assert(!ar.is_serialize_base_class());
+
+ if (ar.is_serializing_out())
{
- if(obj == NULL)
+ if (obj == NULL)
{
ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "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)
+ bool is_ref = ar.add_compound_field("std::vector<T>*",
+ !FIELD_IS_CLASS,
+ strtemp,
+ obj,
+ ARCHIVE_FIELD_PTR);
+ if (!is_ref)
{
- typename std::vector<T>::iterator it;
- for(it=obj->begin(); it != obj->end(); it++)
+ typename std::vector<T>::iterator it = obj->begin();
+ typename std::vector<T>::iterator end = obj->end();
+ for(; it != end; ++it)
{
ar & (*it);
}
+
ar.add_end_compound_field();
}
}
else
{
- char *type;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::vector<T>*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
+
+ 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)
+
+ void* new_obj;
+
+ if (field_treat == ARCHIVE_FIELD_PTR)
{
obj = new std::vector<T>;
ar.register_reference(id, field_treat, obj);
@@ -521,37 +489,36 @@
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++)
+
+ typename std::vector<T>::iterator it = obj->begin();
+ typename std::vector<T>::iterator end = obj->end();
+ for(; it != end; ++it)
{
ar & (*it);
}
+
ar.read_end_current_level();
}
- else if(field_treat == ARCHIVE_FIELD_BASECLASS)
+ 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();
+ assert(false);
}
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ else if ((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = (std::vector<T>*)new_obj;
- if(!obj)
+
+ if (!obj)
{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
+ 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);
+ {
+ ar.register_delay_reference((void**)&obj,
+ !FIELD_IS_CLASS,
+ "std::vector<T>*",
+ referencing);
+ }
}
}
@@ -562,7 +529,7 @@
template<typename T>
void operator&(Archiver& ar, std::vector<T*>& obj)
{
- if(ar.is_serializing_out())
+ if (ar.is_serializing_out())
{
char strtemp[20];
#ifndef WIN32
@@ -570,44 +537,126 @@
#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();
-
+
+ bool 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 = obj.begin();
+ typename std::vector<T*>::iterator end = obj.end();
+ for(; it != 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 = 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 = obj.begin();
+ typename std::vector<T*>::iterator end = obj.end();
+ for(; it != end; ++it)
+ {
+ ar & (*it);
+ }
+
+ ar.read_end_current_level();
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+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 = ar.add_compound_field("std::list<T>",
+ !FIELD_IS_CLASS,
+ strtemp,
+ &obj,
+ ARCHIVE_FIELD_NORMAL);
+ if (!is_ref)
+ {
+ typename std::list<T>::iterator it = obj.begin();
+ typename std::list<T>::iterator end = obj.end();
+ for (; it != 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 = 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 = obj.begin();
+ typename std::list<T>::iterator end = obj.end();
+ for (; it != end; ++it)
+ {
+ ar & (*it);
+ }
+
+ ar.read_end_current_level();
}
}
@@ -618,11 +667,14 @@
template<typename T1, typename T2>
void operator&(Archiver& ar, std::pair<T1, T2>& obj)
{
- if(ar.is_serializing_out())
+ 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)
+ bool 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;
@@ -631,24 +683,29 @@
}
else
{
- char *type;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ 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();
-
}
}
@@ -659,78 +716,93 @@
template<typename T1, typename T2>
void operator&(Archiver& ar, std::pair<T1, T2>*& obj)
{
- if(ar.is_serializing_out())
+ assert(!ar.is_serialize_base_class());
+
+ if (ar.is_serializing_out())
{
- if(obj == NULL)
+ if (obj == NULL)
{
ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
+ !FIELD_IS_CLASS,
+ "NULL",
+ NULL,
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)
+
+ bool is_ref = ar.add_compound_field("std::pair<T1, T2>",
+ !FIELD_IS_CLASS,
+ "",
+ &obj,
+ ARCHIVE_FIELD_PTR);
+
+ if (!is_ref)
{
ar & obj->first;
ar & obj->second;
+
ar.add_end_compound_field();
}
}
else
{
- char *type;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
+
+ 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)
+
+ 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)
+ else if (field_treat == ARCHIVE_FIELD_BASECLASS)
{
- ar & obj->first;
- ar & obj->second;
- ar.read_end_current_level();
+ assert(false);
}
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ else if ((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = (std::pair<T1, T2>*)new_obj;
- if(!obj)
+
+ if (!obj)
{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
+ 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);
+ {
+ ar.register_delay_reference((void**)&obj,
+ !FIELD_IS_CLASS,
+ "std::pair<T1, T2>",
+ referencing);
+ }
}
}
@@ -741,113 +813,126 @@
template<typename T1, typename T2>
void operator&(Archiver& ar, std::map<T1, T2>*& obj)
{
- if(ar.is_serializing_out())
+ assert(!ar.is_serialize_base_class());
+
+ if (ar.is_serializing_out())
{
- if(obj == NULL)
+ if (obj == NULL)
{
ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
+ !FIELD_IS_CLASS,
+ "NULL",
+ NULL,
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)
+
+ bool is_ref = ar.add_compound_field("std::map<T1, T2>",
+ !FIELD_IS_CLASS,
+ "",
+ obj,
+ ARCHIVE_FIELD_PTR);
+
+ 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++)
+
+ typename std::map<T1, T2>::iterator it = obj->begin();
+ typename std::map<T1, T2>::iterator end = obj->end();
+
+ for(; it != 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;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_NULL)
+
+ 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)
+
+ 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++)
+
+ 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)
+ 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();
+ assert(false);
}
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
+ else if ((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = (std::map<T1, T2>*)new_obj;
- if(!obj)
+ if (!obj)
{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
+ 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);
+ {
+ ar.register_delay_reference((void**)&obj,
+ !FIELD_IS_CLASS,
+ "std::map<T1, T2>",
+ referencing);
+ }
}
}
-void operator&(Archiver &ar, short &obj);
-
/*******************************************************************************
@@ -855,57 +940,77 @@
template<typename T1, typename T2, class Tcomp>
void operator&(Archiver& ar, std::map<T1, T2, Tcomp>& obj)
{
- if(ar.is_serializing_out())
+ 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)
+ bool 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++)
+
+ typename std::map<T1, T2, Tcomp>::iterator it = obj.begin();
+ typename std::map<T1, T2, Tcomp>::iterator end = obj.end();
+
+ for (; it != end; ++it)
{
- T1 t1 = (*it).first;
+ 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;
+ 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())
+
+ 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_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ 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++)
+
+ 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();
}
}
@@ -914,6 +1019,86 @@
/*******************************************************************************
********************************************************************************/
+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 = 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<class T>
void read_optional_field(Archiver& ar, T& obj)
{
=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp 2012-04-10 20:10:08 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp 2012-04-13 18:57:21 +0000
@@ -377,8 +377,9 @@
if (obj == NULL)
{
ar.add_compound_field("store::Item*",
- FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
+ FIELD_IS_CLASS,
+ "NULL",
+ NULL,
ARCHIVE_FIELD_NULL);
return;
}
@@ -867,7 +868,7 @@
/*******************************************************************************
********************************************************************************/
-void serialize_node_tree(Archiver &ar, store::Item *&obj, bool all_tree)
+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)
@@ -905,7 +906,7 @@
ar.add_compound_field("NULL",
!FIELD_IS_CLASS,
"NULL",
- NULL,//(SerializeBaseClass*)obj,
+ NULL,
ARCHIVE_FIELD_NULL);
ar.set_is_temp_field(true);
@@ -1091,47 +1092,50 @@
/*******************************************************************************
********************************************************************************/
-void operator&(Archiver &ar, zorba::store::TempSeq *obj)
+void operator&(Archiver& ar, zorba::store::TempSeq* obj)
{
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE, ERROR_PARAMS( "TempSeq" )
- );
+ throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+ ERROR_PARAMS("TempSeq"));
}
/*******************************************************************************
********************************************************************************/
-void operator&(Archiver &ar, const Diagnostic *&obj)
+void operator&(Archiver& ar, const Diagnostic*& obj)
{
- if(ar.is_serializing_out())
+ if (ar.is_serializing_out())
{
- if(obj == NULL)
+ if (obj == NULL)
{
ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
+ !FIELD_IS_CLASS,
+ "NULL",
+ NULL,
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);
+ 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,
+ !FIELD_IS_CLASS,
+ err_type,
obj,
ARCHIVE_FIELD_PTR);
- if(!is_ref)
+ if (!is_ref)
{
- if(user_err)
+ if (user_err)
{
ar & user_err->qname_;
}
@@ -1210,43 +1214,48 @@
/*******************************************************************************
********************************************************************************/
-void operator&(Archiver &ar, ZorbaException *&obj)
+void operator&(Archiver& ar, ZorbaException*& obj)
{
- if(ar.is_serializing_out())
+ if (ar.is_serializing_out())
{
- if(obj == NULL)
+ if (obj == NULL)
{
ar.add_compound_field("NULL",
- !FIELD_IS_CLASS, "NULL",
- NULL,//(SerializeBaseClass*)obj,
+ !FIELD_IS_CLASS,
+ "NULL",
+ NULL,
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);
+
+ 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)
+
+ bool 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)
+ if (xquery_ex)
{
ar & xquery_ex->source_loc_;
ar & xquery_ex->query_trace_;
}
- if(user_ex)
+
+ if (user_ex)
{
ar & user_ex->error_object_;
}
=== modified file 'src/zorbaserialization/serialize_zorba_types.h'
--- src/zorbaserialization/serialize_zorba_types.h 2012-04-10 20:10:08 +0000
+++ src/zorbaserialization/serialize_zorba_types.h 2012-04-13 18:57:21 +0000
@@ -103,85 +103,42 @@
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)
+
+ 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)
+ 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())
+
+ 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))
+
+ 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
@@ -191,94 +148,121 @@
}
else
{
- char *type;
+ 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())
+
+ 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_nonclass_field(retval, type, "ItemHandle<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+ 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())
+
+ 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;
+
+ T* p;
ar & p;
- if(is_temp)
+
+ if (is_temp)
ar.set_is_temp_field_one_level(false);
+
obj = p;
- if(p == NULL)
+
+ if (p == NULL)
{
//workaround for the strict_aliasing warning in gcc
union
{
T **t;
void **v;
- }u_p;
+ } 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)
+void operator&(Archiver& ar, zorba::rchandle<T>& obj)
{
- if(ar.is_serializing_out())
+ 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);
+
+ 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)
+ 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())
+
+ 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))
+
+ 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;
+ 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())
+
+ 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_nonclass_field(retval, type, "rchandle<T>", is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
- //ar.register_reference(id, field_treat, &obj);
+
+ ar.check_nonclass_field(retval, type, "rchandle<T>",
+ is_simple, is_class, field_treat, ARCHIVE_FIELD_NORMAL, id);
bool is_temp = false;
- if(ar.get_is_temp_field_one_level())
+
+ 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());
@@ -295,12 +279,14 @@
{
T **t;
void **v;
- }u_p;
+ } u_p;
+
u_p.t = &p;
+
ar.reconf_last_delayed_rcobject(u_p.v, obj.getp_ref().v, true);
}
+
ar.read_end_current_level();
-
}
}
@@ -322,12 +308,12 @@
{
T *p = (T*)obj.getp();
- if(allow_delay != ALLOW_DELAY)
+ if (allow_delay != ALLOW_DELAY)
ar.dont_allow_delay(allow_delay);
bool is_temp = false;
- if(ar.get_is_temp_field_one_level())
+ 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());
@@ -335,8 +321,10 @@
ar.dont_allow_delay();
}
ar & p;
- if(is_temp)
+
+ if (is_temp)
ar.set_is_temp_field_one_level(false);
+
ar.add_end_compound_field();
}
else
@@ -346,17 +334,16 @@
}
else
{
- char *type;
+ 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);
+ bool retval = ar.read_next_field(&type, &value, &id,
+ &is_simple, &is_class, &field_treat, &referencing);
if (!retval && ar.get_read_optional_field())
return;
@@ -372,14 +359,14 @@
ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
}
- T *p;
+ T* p;
ar & p;
obj = p;
- if(is_temp)
+ if (is_temp)
ar.set_is_temp_field_one_level(false);
- if(p == NULL)
+ if (p == NULL)
{
//workaround for the strict_aliasing warning in gcc
union
=== modified file 'src/zorbaserialization/xml_archiver.h'
--- src/zorbaserialization/xml_archiver.h 2012-04-08 21:39:25 +0000
+++ src/zorbaserialization/xml_archiver.h 2012-04-13 18:57:21 +0000
@@ -21,54 +21,63 @@
#include "zorbaserialization/archiver.h"
namespace zorba{
- namespace serialization{
+namespace serialization{
class XmlArchiver : public Archiver
{
- std::istream *is;
- std::ostream *os;
- char indent_spaces[101];
- int indent_off;
-
- int read_tag_level;
- char field_type[1000];
- bool has_attributes;
- bool is_compound_field_without_children;
- int last_id;
+ std::istream * is;
+ std::ostream * os;
+
+ char indent_spaces[101];
+ int indent_off;
+
+ int read_tag_level;
+ char field_type[1000];
+ bool has_attributes;
+ bool is_compound_field_without_children;
+ int last_id;
+
public:
- XmlArchiver(std::istream *is);
- XmlArchiver(std::ostream *os);
-
- virtual bool read_next_field_impl( char **type,
- std::string *value,
- int *id,
- bool *is_simple,
- bool *is_class,
- enum ArchiveFieldKind *field_treat,
- int *referencing);
-
- virtual void read_end_current_level_impl();
-
-
-///////////////////////////////////
- virtual void serialize_out();
-
+ XmlArchiver(std::istream* is);
+
+ XmlArchiver(std::ostream* os);
+
+ void serialize_out();
+
+ bool read_next_field_impl(
+ char** type,
+ std::string* value,
+ int* id,
+ bool* is_simple,
+ bool* is_class,
+ enum ArchiveFieldKind* field_treat,
+ int* referencing);
+
+ void read_end_current_level_impl();
protected:
//writing
- void serialize_compound_fields(archive_field *parent_field);
- void encode_string(const char *value);
- const char *get_field_treat_string(enum ArchiveFieldKind field_treat);
- void write_string(const char *str);
+ void serialize_compound_fields(archive_field* parent_field);
+
+ void encode_string(const char* value);
+
+ const char* get_field_treat_string(enum ArchiveFieldKind field_treat);
+
+ void write_string(const char* str);
//reading
- bool match_string(char c, const char *match);
+ bool match_string(char c, const char* match);
+
bool read_root_tag(char c);
- bool read_attrib_name(char *attrib_name);
- void read_attrib_value(char *attrib_value);
- void read_attrib_value(std::string *attrib_value);
+
+ bool read_attrib_name(char* attrib_name);
+
+ void read_attrib_value(char* attrib_value);
+
+ void read_attrib_value(std::string* attrib_value);
void skip_tag();
+
void skip_comment_tag();
};
=== modified file 'src/zorbaserialization/zorba_class_versions.cpp'
--- src/zorbaserialization/zorba_class_versions.cpp 2012-04-10 20:59:34 +0000
+++ src/zorbaserialization/zorba_class_versions.cpp 2012-04-13 18:57:21 +0000
@@ -46,12 +46,6 @@
namespace zorba{
-SERIALIZABLE_CLASS_VERSIONS(RCObject)
-
-SERIALIZABLE_CLASS_VERSIONS(SimpleRCObject)
-
-SERIALIZABLE_CLASS_VERSIONS(store::Iterator)
-
// QQQ should be zstring?
typedef serializable_hashmap<std::string,xqtref_t> SER_HASHMAP_T;
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(serializable_hashmap, SER_HASHMAP_T, 3)
=== modified file 'test/rbkt/testdriver.cpp'
--- test/rbkt/testdriver.cpp 2012-04-10 20:59:34 +0000
+++ test/rbkt/testdriver.cpp 2012-04-13 18:57:21 +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