zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #07136
[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/100758
small code refactoring + cosmetic
--
https://code.launchpad.net/~zorba-coders/zorba/serializer/+merge/100758
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/expression/expr_utils.h'
--- src/compiler/expression/expr_utils.h 2012-03-28 05:19:57 +0000
+++ src/compiler/expression/expr_utils.h 2012-04-04 09:34:21 +0000
@@ -17,6 +17,8 @@
#ifndef ZORBA_COMPILER_EXPR_UTILS
#define ZORBA_COMPILER_EXPR_UTILS
+#include "zorbaserialization/serialize_basic_types.h"
+
namespace zorba
{
=== modified file 'src/util/hashmap.h'
--- src/util/hashmap.h 2012-03-28 05:19:57 +0000
+++ src/util/hashmap.h 2012-04-04 09:34:21 +0000
@@ -36,8 +36,11 @@
#include "zorbautils/hashfun.h"
#include "zorbautils/checked_vector.h"
#include "zorbautils/latch.h"
+
#include "diagnostics/xquery_diagnostics.h"
+#include "zorbaserialization/serialize_basic_types.h"
+
namespace zorba {
=== modified file 'src/zorbaserialization/CMakeLists.txt'
--- src/zorbaserialization/CMakeLists.txt 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/CMakeLists.txt 2012-04-04 09:34:21 +0000
@@ -16,12 +16,13 @@
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/zorbaserialization/plan_settings.h.in ${CMAKE_CURRENT_BINARY_DIR}/zorbaserialization/plan_settings.h)
SET(ZORBASERIALIZATION_SRCS
archiver.cpp
+ mem_archiver.cpp
+ xml_archiver.cpp
+ bin_archiver.cpp
+ serialize_basic_types.cpp
base64impl.cpp
class_serializer.cpp
zorba_classes_version.cpp
- mem_archiver.cpp
- xml_archiver.cpp
- bin_archiver.cpp
zorba_class_serializer.cpp
zorba_class_versions.cpp
- )
\ No newline at end of file
+ )
=== modified file 'src/zorbaserialization/archiver.cpp'
--- src/zorbaserialization/archiver.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/archiver.cpp 2012-04-04 09:34:21 +0000
@@ -123,7 +123,7 @@
theArchiveVersion(g_zorba_classes_version),
theRootField(0),
current_compound_field(0),
- simple_hashout_fields(0),
+ theSimpleFieldsMap(0),
hash_out_fields(0),
nr_ids(0),
current_class_version(0),
@@ -155,7 +155,7 @@
current_compound_field = theRootField;
- simple_hashout_fields = new HashMap<SIMPLE_HASHOUT_FIELD, archive_field*,
+ theSimpleFieldsMap = new HashMap<SIMPLE_HASHOUT_FIELD, archive_field*,
SimpleHashoutFieldCompare>(1000, false);
hash_out_fields = new hash64map<archive_field*>(10000, 0.6f);
}
@@ -175,7 +175,7 @@
{
delete theRootField;
delete [] all_reference_list;
- delete simple_hashout_fields;
+ delete theSimpleFieldsMap;
delete hash_out_fields;
std::list<fwd_ref>::iterator it;
@@ -218,7 +218,7 @@
/*******************************************************************************
- Check whether there exists already a field for the simple object at the given
+ Check whether there exists already a field for the nonclass object at the given
memory address.
********************************************************************************/
archive_field* Archiver::lookup_nonclass_field(const char* type, const void* ptr)
@@ -230,7 +230,7 @@
SIMPLE_HASHOUT_FIELD f(type, ptr);
- simple_hashout_fields->get(f, duplicate_field);
+ theSimpleFieldsMap->get(f, duplicate_field);
if (!duplicate_field)
{
@@ -246,14 +246,14 @@
/*******************************************************************************
- Create a "simple" field (ARCHIVE_FIELD_IS_PTR, or ARCHIVE_FIELD_IS_NUL, or
+ Create a "simple" field (ARCHIVE_FIELD_PTR, or ARCHIVE_FIELD_NUL, or
ARCHIVE_FIELD_NORMAL).
@param type : The type of the object to serialize.
@param value : The value of the object to serialize, if it is not a pointer).
@param ptr : Pointer to the object being serialized (may be NULL)
@param fieldKind : The kind of the field (if ptr is NULL, then the fieldKind is
- set unconditionally to ARCHIVE_FIELD_IS_NUL).
+ set unconditionally to ARCHIVE_FIELD_NUL).
Return true if field is not referencing
********************************************************************************/
@@ -267,29 +267,38 @@
archive_field* ref_field = NULL;
bool exch_fields = false;
- assert(fieldKind != ARCHIVE_FIELD_IS_BASECLASS);
- assert(fieldKind != ARCHIVE_FIELD_IS_REFERENCING);
+ assert(fieldKind != ARCHIVE_FIELD_BASECLASS);
+ assert(fieldKind != ARCHIVE_FIELD_REFERENCING);
theCurrentLevel++;
if (!ptr)
{
- fieldKind = ARCHIVE_FIELD_IS_NULL;
+ fieldKind = ARCHIVE_FIELD_NULL;
}
- else if (!get_is_temp_field() &&
- (!get_is_temp_field_one_level() ||
- (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
+ else
{
- ref_field = lookup_nonclass_field(type, ptr);
+ assert(fieldKind == ARCHIVE_FIELD_NORMAL || fieldKind == ARCHIVE_FIELD_PTR);
+
+ if (!get_is_temp_field() &&
+ (!get_is_temp_field_one_level() ||
+ (fieldKind == ARCHIVE_FIELD_PTR && !get_is_temp_field_also_for_ptr())))
+ {
+ ref_field = lookup_nonclass_field(type, ptr);
+ }
}
if (ref_field)
{
+ // 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_NORMAL);
+ ref_field->theKind == ARCHIVE_FIELD_PTR ||
+ ref_field->theKind == ARCHIVE_FIELD_REFERENCING);
if (get_is_temp_field_one_level() &&
- fieldKind == ARCHIVE_FIELD_IS_PTR &&
+ fieldKind == ARCHIVE_FIELD_PTR &&
theAllowDelay2 == ALLOW_DELAY)
{
theAllowDelay2 = DONT_ALLOW_DELAY;
@@ -297,11 +306,12 @@
if (fieldKind == ARCHIVE_FIELD_NORMAL)
{
- //special case: move the prev field into this one
+ // special case: we registered a pointer to the obj before the obj itself
+ // and now we try to register the obj itself.
exch_fields = true;
}
- fieldKind = ARCHIVE_FIELD_IS_REFERENCING;
+ fieldKind = ARCHIVE_FIELD_REFERENCING;
value = NULL;
ptr = NULL;
}
@@ -324,10 +334,12 @@
ptr &&
!get_is_temp_field() &&
(!get_is_temp_field_one_level() ||
- (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
+ (fieldKind == ARCHIVE_FIELD_PTR && !get_is_temp_field_also_for_ptr())))
{
+ assert(fieldKind == ARCHIVE_FIELD_NORMAL || fieldKind == ARCHIVE_FIELD_PTR);
+
SIMPLE_HASHOUT_FIELD f(type, ptr);
- simple_hashout_fields->insert(f, new_field);
+ theSimpleFieldsMap->insert(f, new_field);
}
if (!exch_fields)
@@ -356,7 +368,8 @@
/*******************************************************************************
-
+ Place new_field in the position occupied by ref_field, and disconnect
+ ref_field from the tree.
********************************************************************************/
void Archiver::replace_field(archive_field* new_field, archive_field* ref_field)
{
@@ -391,24 +404,26 @@
********************************************************************************/
void Archiver::exchange_fields(archive_field* new_field, archive_field* ref_field)
{
- new_field->theKind = ARCHIVE_FIELD_IS_REFERENCING;
ref_field->theKind = ARCHIVE_FIELD_NORMAL;
+ 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;
+
if(current_compound_field->theLastChild)
current_compound_field->theLastChild->theNextSibling = ref_field;
else
current_compound_field->theFirstChild = ref_field;
+
ref_field->theNextSibling = NULL;
current_compound_field->theLastChild = ref_field;
+
ref_field->theOrder = nr_ids;
-
- new_field->theAllowDelay2 = ref_field->theAllowDelay2;
}
@@ -431,14 +446,14 @@
if (!ptr)
{
- fieldKind = ARCHIVE_FIELD_IS_NULL;
+ fieldKind = ARCHIVE_FIELD_NULL;
theCurrentLevel--;
}
- else if(fieldKind != ARCHIVE_FIELD_IS_BASECLASS &&
- ptr &&
- !get_is_temp_field() &&
- (!get_is_temp_field_one_level() ||
- (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
+ else if (fieldKind != ARCHIVE_FIELD_BASECLASS &&
+ ptr &&
+ !get_is_temp_field() &&
+ (!get_is_temp_field_one_level() ||
+ (fieldKind == ARCHIVE_FIELD_PTR && !get_is_temp_field_also_for_ptr())))
{
if (!is_class)
ref_field = lookup_nonclass_field(type, ptr);
@@ -452,18 +467,20 @@
ref_field->theKind != ARCHIVE_FIELD_NORMAL);
if (get_is_temp_field_one_level() &&
- fieldKind == ARCHIVE_FIELD_IS_PTR &&
+ fieldKind == ARCHIVE_FIELD_PTR &&
theAllowDelay2 == ALLOW_DELAY)
+ {
theAllowDelay2 = DONT_ALLOW_DELAY;
+ }
- if(fieldKind == ARCHIVE_FIELD_NORMAL)
+ if (fieldKind == ARCHIVE_FIELD_NORMAL)
{
//special case
//move the prev field into this one
exch_fields = true;
}
- fieldKind = ARCHIVE_FIELD_IS_REFERENCING;
+ fieldKind = ARCHIVE_FIELD_REFERENCING;
ptr = NULL;
}
@@ -482,16 +499,16 @@
theAllowDelay2 = ALLOW_DELAY;
if (!ref_field &&
- fieldKind != ARCHIVE_FIELD_IS_BASECLASS &&
+ fieldKind != ARCHIVE_FIELD_BASECLASS &&
ptr &&
!get_is_temp_field() &&
(!get_is_temp_field_one_level() ||
- (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
+ (fieldKind == ARCHIVE_FIELD_PTR && !get_is_temp_field_also_for_ptr())))
{
if (!is_class)
{
SIMPLE_HASHOUT_FIELD f(type, ptr);
- simple_hashout_fields->insert(f, new_field);
+ theSimpleFieldsMap->insert(f, new_field);
}
else
{
@@ -583,7 +600,7 @@
int* referencing)
{
bool retval = read_next_field_impl(type, value, id, version, is_simple, is_class, fieldKind, referencing);
- if(retval && !*is_simple && (*fieldKind != ARCHIVE_FIELD_IS_REFERENCING))
+ if(retval && !*is_simple && (*fieldKind != ARCHIVE_FIELD_REFERENCING))
theCurrentLevel++;
return retval;
}
@@ -623,7 +640,7 @@
}
#endif
- if(field_treat == ARCHIVE_FIELD_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
return;
#ifndef NDEBUG
@@ -666,7 +683,7 @@
}
#endif
- if (field_treat == ARCHIVE_FIELD_IS_NULL)
+ if (field_treat == ARCHIVE_FIELD_NULL)
return;
#ifndef NDEBUG
@@ -709,7 +726,7 @@
}
#endif
- if (field_treat == ARCHIVE_FIELD_IS_NULL)
+ if (field_treat == ARCHIVE_FIELD_NULL)
return;
#ifndef NDEBUG
@@ -735,9 +752,9 @@
enum ArchiveFieldKind field_treat,
const void* ptr)
{
- if(get_is_temp_field())// && (field_treat != ARCHIVE_FIELD_IS_PTR))
+ if(get_is_temp_field())// && (field_treat != ARCHIVE_FIELD_PTR))
return;
- if(get_is_temp_field_one_level() && ((field_treat != ARCHIVE_FIELD_IS_PTR) || get_is_temp_field_also_for_ptr()))
+ 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);
@@ -997,7 +1014,7 @@
"",
NULL,
0,
- ARCHIVE_FIELD_IS_NULL,
+ ARCHIVE_FIELD_NULL,
NULL,
false,
ALLOW_DELAY,
@@ -1062,7 +1079,7 @@
if(child->theOnlyForEval)
{
}
- else if((child->theKind == ARCHIVE_FIELD_IS_REFERENCING) &&
+ else if((child->theKind == ARCHIVE_FIELD_REFERENCING) &&
get_only_for_eval(child->theReferredField))
{
int new_depth = compute_field_depth(child->theReferredField);
@@ -1181,7 +1198,7 @@
{
if(current_field->theOnlyForEval && (current_field->theKind != ARCHIVE_FIELD_NORMAL))
{
- if((current_field->theKind == ARCHIVE_FIELD_IS_REFERENCING) &&
+ if((current_field->theKind == ARCHIVE_FIELD_REFERENCING) &&
(current_field->theAllowDelay2 != ALLOW_DELAY) &&
(!current_field->theReferredField->theOnlyForEval))
{
@@ -1222,7 +1239,7 @@
{
if(current_field->theOnlyForEval &&
(current_field->theKind != ARCHIVE_FIELD_NORMAL) &&
- (current_field->theKind != ARCHIVE_FIELD_IS_BASECLASS))
+ (current_field->theKind != ARCHIVE_FIELD_BASECLASS))
{
//don't save it, replace it with NULL if possible
archive_field *null_field = replace_with_null(current_field);
@@ -1313,7 +1330,7 @@
while (child)
{
- if (child->theKind == ARCHIVE_FIELD_IS_REFERENCING &&
+ if (child->theKind == ARCHIVE_FIELD_REFERENCING &&
((child->theAllowDelay2 == DONT_ALLOW_DELAY &&
check_order(theRootField, child, child->theReferredField) < 1 &&
child->theAllowDelay2 == DONT_ALLOW_DELAY) ||
=== modified file 'src/zorbaserialization/archiver.h'
--- src/zorbaserialization/archiver.h 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/archiver.h 2012-04-04 09:34:21 +0000
@@ -40,10 +40,11 @@
namespace serialization
{
-#define FIELD_IS_SIMPLE true
-#define FIELD_IS_CLASS true
-
-/*
+#define FIELD_IS_SIMPLE true
+#define FIELD_IS_CLASS true
+
+/*******************************************************************************
+
Archiver is working with fields. One archive contains a sequence of fields.
They can be simple fields or combo fields.
@@ -54,28 +55,30 @@
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_IS_REFERENCING :
+ ARCHIVE_FIELD_REFERENCING :
------------------------------
A field A that references another field B, where both A and B represent the
"same" object.
- ARCHIVE_FIELD_IS_BASECLASS :
+ 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_IS_PTR :
+ ARCHIVE_FIELD_PTR :
----------------------
- ARCHIVE_FIELD_IS_NULL :
+ ARCHIVE_FIELD_NULL :
-----------------------
A field representing a NULL pointer.
@@ -86,10 +89,10 @@
enum ArchiveFieldKind
{
ARCHIVE_FIELD_NORMAL,
- ARCHIVE_FIELD_IS_PTR,
- ARCHIVE_FIELD_IS_NULL,
- ARCHIVE_FIELD_IS_BASECLASS,
- ARCHIVE_FIELD_IS_REFERENCING
+ ARCHIVE_FIELD_PTR,
+ ARCHIVE_FIELD_NULL,
+ ARCHIVE_FIELD_BASECLASS,
+ ARCHIVE_FIELD_REFERENCING
};
@@ -109,12 +112,11 @@
********************************************************************************/
struct fwd_ref
{
- int referencing;
- void **ptr;
- bool is_class;
- //bool add_ref_to_rcobject;
- char *class_name;
- bool to_add_ref;
+ int referencing;
+ void ** ptr;
+ bool is_class;
+ char * class_name;
+ bool to_add_ref;
};
@@ -259,7 +261,7 @@
const void* value,
const void* assoc_ptr,
int version,
- enum ArchiveFieldKind field_treat,
+ enum ArchiveFieldKind kind,
archive_field* refered,
int only_for_eval,
ENUM_ALLOW_DELAY allow_delay,
@@ -356,7 +358,7 @@
archive_field * current_compound_field;
- SimpleFieldMap * simple_hashout_fields;//for simple types
+ SimpleFieldMap * theSimpleFieldsMap;
hash64map<archive_field*> * hash_out_fields;//key is ptr, value is archive_field*, for non-simple types
std::vector<archive_field*> orphan_fields;
@@ -615,8 +617,8 @@
while (temp_field && (temp_field->theLevel >= lastlevel))
{
- if (temp_field->theKind == ARCHIVE_FIELD_IS_PTR ||
- temp_field->theKind == ARCHIVE_FIELD_IS_REFERENCING)
+ if (temp_field->theKind == ARCHIVE_FIELD_PTR ||
+ temp_field->theKind == ARCHIVE_FIELD_REFERENCING)
return false;
temp_field = temp_field->theParent;
=== modified file 'src/zorbaserialization/bin_archiver.cpp'
--- src/zorbaserialization/bin_archiver.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/bin_archiver.cpp 2012-04-04 09:34:21 +0000
@@ -172,11 +172,11 @@
write_xml_name(os, parent->theTypeName);
os << " n=\"" << parent->objects_saved << "\"";
os << " s=\"" << parent->thebytesSaved << "\"";
- if(parent->theKind == ARCHIVE_FIELD_IS_REFERENCING)
+ if(parent->theKind == ARCHIVE_FIELD_REFERENCING)
os << " t=\"ref\"";
- else if(parent->theKind == ARCHIVE_FIELD_IS_PTR)
+ else if(parent->theKind == ARCHIVE_FIELD_PTR)
os << " t=\"ptr\"";
- if((!parent->theIsSimple) && (parent->theKind != ARCHIVE_FIELD_IS_REFERENCING))
+ if((!parent->theIsSimple) && (parent->theKind != ARCHIVE_FIELD_REFERENCING))
{
os << ">" << std::endl;
archive_field *current_field = parent->first_child;
@@ -304,13 +304,13 @@
archive_field* current_field = parent_field->theFirstChild;
while (current_field)
{
- if(current_field->theKind != ARCHIVE_FIELD_IS_NULL)
+ if(current_field->theKind != ARCHIVE_FIELD_NULL)
{
#ifdef NDEBUG
- if(current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_IS_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_IS_REFERENCING)
+ if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
current_field->theValuePosInPool = add_to_string_pool(current_field->theValue);
}
@@ -318,7 +318,7 @@
if(!current_field->theIsSimple)
{
- if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
+ if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
collect_strings(current_field);
}
@@ -395,19 +395,19 @@
unsigned char small_treat = 0;
switch(current_field->theKind)
{
- case ARCHIVE_FIELD_IS_NULL: small_treat = 1;break;
- case ARCHIVE_FIELD_IS_REFERENCING: small_treat = 2;break;
- case ARCHIVE_FIELD_IS_BASECLASS: small_treat = 3;break;//??
+ case ARCHIVE_FIELD_NULL: small_treat = 1;break;
+ case ARCHIVE_FIELD_REFERENCING: small_treat = 2;break;
+ case ARCHIVE_FIELD_BASECLASS: small_treat = 3;break;//??
default: break;
}
write_bits(small_treat, 2);
#endif
- if(current_field->theKind != ARCHIVE_FIELD_IS_NULL)
+ if(current_field->theKind != ARCHIVE_FIELD_NULL)
{
#ifdef NDEBUG
- if (current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_IS_PTR))
+ if (current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_PTR))
#endif
{
if (!current_field->theTypeName)
@@ -420,7 +420,7 @@
last_id = current_field->theId;
- if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
+ if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
#ifndef NDEBUG
write_int(current_field->theClassVersion);
@@ -436,13 +436,13 @@
#ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
objects_saved++;
- if(current_field->theKind == ARCHIVE_FIELD_IS_PTR)
+ if(current_field->theKind == ARCHIVE_FIELD_PTR)
nr_ptrs++;
#endif
if (!current_field->theIsSimple)
{
- if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
+ if(current_field->theKind != ARCHIVE_FIELD_REFERENCING)
{
serialize_compound_fields(current_field);
#ifndef NDEBUG
@@ -844,17 +844,17 @@
switch(small_treat)
{
- case 1: *field_treat = ARCHIVE_FIELD_IS_NULL;break;
- case 2: *field_treat = ARCHIVE_FIELD_IS_REFERENCING;break;
- case 3: *field_treat = ARCHIVE_FIELD_IS_BASECLASS;break;//??
+ case 1: *field_treat = ARCHIVE_FIELD_NULL;break;
+ case 2: *field_treat = ARCHIVE_FIELD_REFERENCING;break;
+ case 3: *field_treat = ARCHIVE_FIELD_BASECLASS;break;//??
}
#endif
- assert(*field_treat <= ARCHIVE_FIELD_IS_REFERENCING);
+ assert(*field_treat <= ARCHIVE_FIELD_REFERENCING);
- if(*field_treat != ARCHIVE_FIELD_IS_NULL)
+ if(*field_treat != ARCHIVE_FIELD_NULL)
{
#ifdef NDEBUG
- if(*is_class && (*field_treat == ARCHIVE_FIELD_IS_PTR))
+ if(*is_class && (*field_treat == ARCHIVE_FIELD_PTR))
#endif
{
unsigned int field_type_pos;
@@ -867,7 +867,7 @@
}
*id = read_int_exp() + this->last_id;
this->last_id = *id;
- if(*field_treat != ARCHIVE_FIELD_IS_REFERENCING)
+ if(*field_treat != ARCHIVE_FIELD_REFERENCING)
{
#ifndef NDEBUG
*version = read_int();
=== modified file 'src/zorbaserialization/class_serializer.cpp'
--- src/zorbaserialization/class_serializer.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/class_serializer.cpp 2012-04-04 09:34:21 +0000
@@ -17,14 +17,12 @@
#include "zorbaserialization/class_serializer.h"
#include "zorbaserialization/archiver.h"
-#include "zorbaserialization/base64impl.h"
#include "zorbaserialization/mem_archiver.h"
#include "diagnostics/xquery_diagnostics.h"
+
#include "zorbautils/hashmap.h"
-#include "zorbatypes/floatimpl.h"
-
namespace zorba
{
@@ -204,725 +202,6 @@
harcoded_objects_archive = new MemArchiver(true, true);//simulate serialize out
}
-//////////////////////////////////////////////
-///////////////////////////////////////////Global serialization Operators
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, int &obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%d", obj);
-
- ar.add_simple_field("number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- sscanf(value.c_str(), "%d", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, uint32_t &obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%u", obj);
-
- ar.add_simple_field("unsigned number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "unsigned number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- sscanf(value.c_str(), "%u", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, long &obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%ld", obj);
-
- ar.add_simple_field("number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- sscanf(value.c_str(), "%ld", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, unsigned long &obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%lu", obj);
-
- ar.add_simple_field("unsigned number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "unsigned number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- sscanf(value.c_str(), "%lu", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, long long &obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%lld", obj);
-
- ar.add_simple_field("number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- sscanf(value.c_str(), "%lld", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, unsigned long long &obj)
-{
- if(ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%llu", obj);
-
- ar.add_simple_field("unsigned number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "unsigned number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- sscanf(value.c_str(), "%llu", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, short& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%hd", obj);
-
- ar.add_simple_field("number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "number",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- sscanf(value.c_str(), "%hd", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, unsigned short& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%hu", obj);
-
- ar.add_simple_field("unsigned number", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "unsigned number",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- sscanf(value.c_str(), "%hu", &obj);
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, char& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%d", (int)obj);
-
- ar.add_simple_field("char", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "char",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- int int_obj;
- sscanf(value.c_str(), "%d", &int_obj);
- obj = (char)int_obj;
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, signed char& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%d", (int)obj);
-
- ar.add_simple_field("char", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "char",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- int int_obj;
- sscanf(value.c_str(), "%d", &int_obj);
- obj = (signed char)int_obj;
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, unsigned char& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[30];
- sprintf(strtemp, "%u", (unsigned int)obj);
-
- ar.add_simple_field("unsigned char", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "unsigned char",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- unsigned int int_obj;
- sscanf(value.c_str(), "%u", &int_obj);
- obj = (unsigned char)int_obj;
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, float& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[100];
-
- FloatImpl<float> zorba_float(obj);
- zstring float_str = zorba_float.toString();
-
- if (isdigit(float_str.c_str()[0]))
- sprintf(strtemp, "%.7e", (double)obj);
- else
- strcpy(strtemp, float_str.c_str());
-
- ar.add_simple_field("float", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "float",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- FloatImpl<float> zorba_float(value.c_str());
- obj = zorba_float.getNumber();
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, double& obj)
-{
- if (ar.is_serializing_out())
- {
- char strtemp[100];
- FloatImpl<double> zorba_double(obj);
- zstring double_str = zorba_double.toString();
-
- if (isdigit(double_str.c_str()[0]))
- sprintf(strtemp, "%.16e", obj);
- else
- strcpy(strtemp, double_str.c_str());
-
- ar.add_simple_field("double", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "double",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- FloatImpl<double> zorba_double(value.c_str());
- obj = zorba_double.getNumber();
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, bool& obj)
-{
- if (ar.is_serializing_out())
- {
- ar.add_simple_field("bool", obj ? "true" : "false", &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "bool",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- if (value == "true")
- {
- obj = true;
- }
- else if (value == "false")
- {
- obj = false;
- }
- else
- {
- throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
- }
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver& ar, std::string& obj)
-{
- if(ar.is_serializing_out())
- {
- ar.add_simple_field("string", obj.c_str(), &obj, ARCHIVE_FIELD_NORMAL);
- }
- else
- {
- char* type;
- std::string value;
- int id;
- int version;
- 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, &version,
- &is_simple, &is_class, &field_treat, &referencing);
-
- if (!retval && ar.get_read_optional_field())
- return;
-
- ar.check_simple_field(retval, type, "string",
- is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
- obj = value;
-
- ar.register_reference(id, field_treat, &obj);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, std::string* &obj)
-{
- if(ar.is_serializing_out())
- {
- ar.add_simple_field("std::string*", obj ? obj->c_str() : NULL,
- obj,
- obj ? ARCHIVE_FIELD_IS_PTR : ARCHIVE_FIELD_IS_NULL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- bool is_simple = true;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "std::string*", is_simple, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_IS_NULL)
- {
- obj = NULL;
- return;
- }
- if((field_treat != ARCHIVE_FIELD_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- if(field_treat == ARCHIVE_FIELD_IS_PTR)
- {
- obj = new std::string(value);
- ar.register_reference(id, field_treat, obj);
- }
- else if((obj = (std::string*)ar.get_reference_value(referencing)) == NULL)// ARCHIVE_FIELD_IS_REFERENCING
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, NULL, referencing);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void operator&(Archiver &ar, char* &obj)//like char *p=strdup("io");
-{
- if(ar.is_serializing_out())
- {
- ar.add_simple_field("char*", obj, obj, obj ? ARCHIVE_FIELD_IS_PTR : ARCHIVE_FIELD_IS_NULL);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- bool is_simple = true;
- bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
- int referencing;
- bool retval;
- retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "char*", is_simple, field_treat, (ArchiveFieldKind)-1, id);
- if(field_treat == ARCHIVE_FIELD_IS_NULL)
- {
- obj = NULL;
- return;
- }
- if((field_treat != ARCHIVE_FIELD_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
- {
- throw ZORBA_EXCEPTION(
- zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
- );
- }
- if(field_treat == ARCHIVE_FIELD_IS_PTR)
- {
- obj = strdup(value.c_str());
- ar.register_reference(id, field_treat, obj);
- }
- else if((obj = (char*)ar.get_reference_value(referencing)) == NULL)// ARCHIVE_FIELD_IS_REFERENCING
- ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, NULL, referencing);
- }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void serialize_array(Archiver &ar, unsigned char *obj, int len)//like char p[20]
-{
- if(ar.is_serializing_out())
- {
- char *base64string;
- base64string = (char*)malloc(8*len/6 + 8 + 1);
- Base64Impl::Encode(obj, len, base64string);
- ar.add_simple_field("char[]", base64string, obj, ARCHIVE_FIELD_NORMAL);
- free(base64string);
- }
- else
- {
- char *type;
- std::string value;
- int id;
- int version;
- 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, &version, &is_simple, &is_class, &field_treat, &referencing);
- if(!retval && ar.get_read_optional_field())
- return;
- ar.check_simple_field(retval, type, "char[]", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-
- Base64Impl::Decode((const unsigned char*)value.c_str(), value.length(), obj);
- ar.register_reference(id, field_treat, &obj);
- }
-}
} // namespace serialization
} // namespace zorba
=== modified file 'src/zorbaserialization/class_serializer.h'
--- src/zorbaserialization/class_serializer.h 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/class_serializer.h 2012-04-04 09:34:21 +0000
@@ -46,8 +46,6 @@
#define BACKWARD_COMPATIBLE true
-#define ZORBA_VERSION_0_9_5 0x000905
-#define ZORBA_VERSION_1_0_0 0x010000
#define ZORBA_VERSION_1_5_0 0x010500
extern const unsigned long g_zorba_classes_version;
@@ -65,8 +63,7 @@
/*******************************************************************************
- derive all classes that need to be serialized from this base class
- that is: iterators, store items, static context and so on
+ Derive all classes that need to be serialized from this base class
********************************************************************************/
class ZORBA_DLL_PUBLIC SerializeBaseClass
{
@@ -95,9 +92,9 @@
// std::cout << "~class_deserializer" << std::endl;
}
- virtual SerializeBaseClass* create_new(Archiver &ar) = 0;
+ virtual SerializeBaseClass* create_new(Archiver& ar) = 0;
- virtual void cast_ptr(SerializeBaseClass* ptr, void **class_ptr) = 0;
+ virtual void cast_ptr(SerializeBaseClass* ptr, void** class_ptr) = 0;
};
@@ -105,14 +102,29 @@
/*******************************************************************************
stateless class, multithreading safe
- class_names : for each serializable class C, this vector stores the name of C
- and the static class_deserializer obj associated with C.
- class_names_count :
+ 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;
+private:
std::vector<std::pair<const char*, class_deserializer*> > class_names;
int class_names_count;
ClassFactoriesMap * class_factories;
@@ -120,6 +132,10 @@
MemArchiver * harcoded_objects_archive;
public:
+ clock_t t0;
+ clock_t t1;
+
+public:
static ClassSerializer* getInstance();
public:
@@ -129,14 +145,12 @@
void register_class_factory(const char *, class_deserializer *);
- class_deserializer *get_class_factory(const char *classname);
+ class_deserializer* get_class_factory(const char *classname);
Archiver* getArchiverForHardcodedObjects();
void destroyArchiverForHardcodedObjects();//called at shutdown
-public:
- clock_t t0, t1;
clock_t get_registration_time() { return t1-t0;}
};
@@ -181,30 +195,29 @@
/*******************************************************************************
********************************************************************************/
-#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 serialization::ClassVersion& get_classversion(int v) const \
-{ \
- return class_versions[v]; \
-} \
- \
-virtual int get_version_count() const \
-{ \
- return class_versions_count; \
-} \
- \
- \
+#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 serialization::ClassVersion& get_classversion(int v) const \
+{ \
+ return class_versions[v]; \
+} \
+ \
+virtual int get_version_count() const \
+{ \
+ return class_versions_count; \
+} \
+ \
virtual const char* get_class_name_str() const { return class_name_str; } \
- \
-static const char* get_class_name_str_static() {return class_name_str;}
+ \
+static const char* get_class_name_str_static() { return class_name_str; }
/*******************************************************************************
@@ -219,19 +232,18 @@
{ \
/*register this class into plan serializer*/ \
serialization::ClassSerializer::getInstance()-> \
- register_class_factory(T_serialized_class::get_class_name_str_static(), this); \
+ register_class_factory(T_serialized_class::get_class_name_str_static(), this); \
} \
\
- virtual serialization::SerializeBaseClass* create_new(serialization::Archiver &ar) \
+ virtual serialization::SerializeBaseClass* create_new(serialization::Archiver& ar) \
{ \
return creator; \
} \
\
- virtual void cast_ptr(serialization::SerializeBaseClass* ptr, void **class_ptr)\
+ virtual void cast_ptr(serialization::SerializeBaseClass* ptr, void** class_ptr)\
{ \
*class_ptr = (void*)dynamic_cast<T_serialized_class*>(ptr); \
} \
- \
};
@@ -239,7 +251,7 @@
********************************************************************************/
#define SERIALIZABLE_CLASS_NO_FACTORY(class_name) \
-virtual void serialize_internal(::zorba::serialization::Archiver &ar) \
+virtual void serialize_internal(::zorba::serialization::Archiver& ar) \
{ \
/*CHECK_CLASS_NAME(class_name)*/ \
if(ar.is_serialize_base_class()) \
@@ -258,9 +270,9 @@
return g_##class_name##_class_versions_count; \
} \
\
-virtual const char *get_class_name_str() const {return #class_name;} \
+virtual const char* get_class_name_str() const {return #class_name;} \
\
-static const char *get_class_name_str_static() {return #class_name;}
+static const char* get_class_name_str_static() {return #class_name;}
@@ -269,48 +281,88 @@
class.
********************************************************************************/
+//
+// Static members of non-template classes
+//
#define SERIALIZABLE_CLASS_VERSIONS(class_name) \
+ \
const char* class_name::class_name_str = #class_name; \
+ \
class_name::class_factory<class_name> class_name::g_class_factory; \
-const serialization::ClassVersion class_name::class_versions[] = {{ 1, ZORBA_VERSION_1_5_0, !BACKWARD_COMPATIBLE}
+ \
+const serialization::ClassVersion class_name::class_versions[] = \
+{{ 1, ZORBA_VERSION_1_5_0, !BACKWARD_COMPATIBLE}
#define CLASS_VERSION(class_version, zorba_version, compatibility, description) \
,{class_version, zorba_version, compatibility}
-#define END_SERIALIZABLE_CLASS_VERSIONS(class_name) \
-};\
-const int class_name::class_versions_count = sizeof(class_name::class_versions)/sizeof(struct serialization::ClassVersion);
-
-
-////////////////////
-//////////////////////define the template class versions
-
-#define SERIALIZABLE_TEMPLATE_VERSIONS(template_name) \
- extern const ::zorba::serialization::ClassVersion g_##template_name##_class_versions[] = {{ 1, ZORBA_VERSION_1_5_0, !BACKWARD_COMPATIBLE}
+#define END_SERIALIZABLE_CLASS_VERSIONS(class_name) \
+ }; \
+ const int class_name::class_versions_count = \
+ sizeof(class_name::class_versions)/sizeof(struct serialization::ClassVersion);
+
+
+//
+// Define the "versions" and "versions count" static data members of the template class
+//
+#define SERIALIZABLE_TEMPLATE_VERSIONS(template_name) \
+extern const ::zorba::serialization::ClassVersion g_##template_name##_class_versions[] = \
+{{ 1, ZORBA_VERSION_1_5_0, !BACKWARD_COMPATIBLE}
//add CLASS_VERSION here
-#define END_SERIALIZABLE_TEMPLATE_VERSIONS(template_name) \
- };\
- extern const int g_##template_name##_class_versions_count = sizeof(g_##template_name##_class_versions)/sizeof(struct ::zorba::serialization::ClassVersion);
-
-
-///////////////////
-/////////////////////define the versions dependency from template instance to template versions
-
-#define SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(template_name, instance_name, index) \
- instance_name::class_factory<instance_name> g_class_factory_##template_name##_##index;\
- template<> const ::zorba::serialization::ClassVersion *instance_name::class_versions = g_##template_name##_class_versions;\
- template<> const int instance_name::class_versions_count = g_##template_name##_class_versions_count;\
- template<> const char *instance_name::class_name_str = #instance_name;
-
+#define END_SERIALIZABLE_TEMPLATE_VERSIONS(template_name) \
+}; \
+extern const int g_##template_name##_class_versions_count = \
+sizeof(g_##template_name##_class_versions)/sizeof(struct ::zorba::serialization::ClassVersion);
+
+
+//
+// Define the versions dependency from template instance to template versions
+// Example:
+//
+// SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(
+// serializable_ItemPointerHashMap,
+// serializable_ItemPointerHashMap<StaticallyKnownCollection_t>,
+// 1)
+//
+#define SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(template_name, instance_name, index) \
+ \
+instance_name::class_factory<instance_name> g_class_factory_##template_name##_##index; \
+ \
+template<> const ::zorba::serialization::ClassVersion* instance_name::class_versions = \
+g_##template_name##_class_versions; \
+ \
+template<> const int instance_name::class_versions_count = \
+g_##template_name##_class_versions_count; \
+ \
+template<> const char* instance_name::class_name_str = #instance_name;
+
+//
+// If the template class has more than one template params, e.g. Foo<T1, T2>,
+// then we need this macro because we cannot pass Foo<T1, T2> as the instance_name
+// param of the SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS macro. This is because
+// the "," inside Foo<T1, T2> will make it appear as two params.
+// Example:
+//
+// SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(
+// serializable_HashEntry,
+// serializable_HashEntry<store::Item*,
+// StaticallyKnownCollection_t>,
+// 1)
+//
#define SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(template_name, instance_name, second_T, index) \
- instance_name,second_T::class_factory<instance_name,second_T> g_class_factory_##template_name##_##index;\
- template<> const ::zorba::serialization::ClassVersion *instance_name,second_T::class_versions = g_##template_name##_class_versions;\
- template<> const int instance_name,second_T::class_versions_count = g_##template_name##_class_versions_count;\
- template<> const char *instance_name,second_T::class_name_str = #instance_name "," #second_T;
+instance_name,second_T::class_factory<instance_name,second_T> g_class_factory_##template_name##_##index; \
+\
+template<> const ::zorba::serialization::ClassVersion *instance_name, second_T::class_versions = g_##template_name##_class_versions; \
+\
+template<> const int instance_name,second_T::class_versions_count = \
+g_##template_name##_class_versions_count; \
+\
+template<> const char *instance_name,second_T::class_name_str = #instance_name "," #second_T;
+
#define SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(template_name, instance_name, second_T, third_T, index) \
instance_name,second_T,third_T::class_factory<instance_name,second_T,third_T> g_class_factory_##template_name##_##index;\
@@ -326,21 +378,21 @@
********************************************************************************/
#define SERIALIZABLE_CLASS_CONSTRUCTOR(class_name) \
-class_name(::zorba::serialization::Archiver &ar) \
- : \
- ::zorba::serialization::SerializeBaseClass() \
-{ \
+class_name(::zorba::serialization::Archiver& ar) \
+ : \
+ ::zorba::serialization::SerializeBaseClass() \
+{ \
}
#define SERIALIZABLE_CLASS_CONSTRUCTOR2(class_name, base_class) \
-class_name(::zorba::serialization::Archiver &ar) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class(ar) \
{ \
}
#define SERIALIZABLE_CLASS_CONSTRUCTOR2_NULL_PARAM1(class_name, base_class, param1) \
-class_name(::zorba::serialization::Archiver &ar) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class(ar), \
param1(NULL) \
@@ -348,7 +400,7 @@
}
#define SERIALIZABLE_CLASS_CONSTRUCTOR2_NULL_PARAM2(class_name, base_class, param1, param2) \
-class_name(::zorba::serialization::Archiver &ar) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class(ar), \
param1(NULL), \
@@ -357,7 +409,7 @@
}
#define SERIALIZABLE_CLASS_CONSTRUCTOR2_NULL_PARAM3(class_name, base_class, param1, param2, param3) \
-class_name(::zorba::serialization::Archiver &ar) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class(ar), \
param1(NULL), \
@@ -367,7 +419,7 @@
}
#define SERIALIZABLE_CLASS_CONSTRUCTOR3(class_name, base_class1, base_class2) \
-class_name(::zorba::serialization::Archiver &ar) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class1(ar), \
base_class2(ar) \
@@ -375,14 +427,14 @@
}
#define SERIALIZABLE_CLASS_CONSTRUCTOR2T(class_name, base_class, templ2) \
-class_name(::zorba::serialization::Archiver &ar) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class , templ2(ar) \
{ \
}
-#define SERIALIZABLE_CLASS_CONSTRUCTOR3T(class_name, base_class, templ2, templ3) \
-class_name(::zorba::serialization::Archiver &ar) \
+#define SERIALIZABLE_CLASS_CONSTRUCTOR3T(class_name, base_class, templ2, templ3) \
+class_name(::zorba::serialization::Archiver& ar) \
: \
base_class , \
templ2, \
@@ -403,70 +455,6 @@
#endif
-
-///Public class serialization functions
-
-
- void operator&(Archiver &ar, int &obj);
-
- void operator&(Archiver &ar, uint32_t &obj);
-
- void operator&(Archiver &ar, long &obj);
-
- void operator&(Archiver &ar, unsigned long &obj);
-
- void operator&(Archiver &ar, long long &obj);
-
- void operator&(Archiver &ar, unsigned long long &obj);
-
- void operator&(Archiver &ar, short &obj);
-
- void operator&(Archiver &ar, unsigned short &obj);
-
- void operator&(Archiver &ar, char &obj);
-
- void operator&(Archiver &ar, signed char &obj);
-
- void operator&(Archiver &ar, unsigned char &obj);
-
- void operator&(Archiver &ar, float &obj);
-
- void operator&(Archiver &ar, double &obj);
-
- void operator&(Archiver &ar, bool &obj);
-
- void operator&(Archiver &ar, std::string &obj);
-
- void operator&(Archiver &ar, std::string* &obj);
-
- void operator&(Archiver &ar, char* &obj);//like char *p=strdup("io");
-
-// template<class T>
-// void operator&(Archiver &ar, std::list<T> &obj);
-//
-// template<class T>
-// void operator&(Archiver &ar, std::vector<T> &obj);
-//
-// template<class T>
-// void operator&(Archiver &ar, T &obj);
-//
-// template<class T>
-// void operator&(Archiver &ar, T *&obj);
-
-
-void serialize_array(Archiver &ar, unsigned char *obj, int len);//like char p[20]
-
-#define SERIALIZE_ENUM(enum_type, obj)\
- {\
- ar.set_is_temp_field_one_level(true);\
- int int_enum = (int)obj;\
- ar & int_enum;\
- if(!ar.is_serializing_out())\
- obj = (enum_type)int_enum;\
- ar.set_is_temp_field_one_level(false);\
- }
-
-
#define SERIALIZE_FUNCTION(f) ar & f;
=== modified file 'src/zorbaserialization/mem_archiver.cpp'
--- src/zorbaserialization/mem_archiver.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/mem_archiver.cpp 2012-04-04 09:34:21 +0000
@@ -58,7 +58,7 @@
is_after_last = false;
if(current_field->theFirstChild)
current_field = current_field->theFirstChild;
- else if(!*is_simple && ((*field_treat == ARCHIVE_FIELD_IS_BASECLASS) || (*field_treat == ARCHIVE_FIELD_IS_PTR)))
+ else if(!*is_simple && ((*field_treat == ARCHIVE_FIELD_BASECLASS) || (*field_treat == ARCHIVE_FIELD_PTR)))
{
//class without childs
temp_field.theParent = current_field;
=== modified file 'src/zorbaserialization/template_serializer.h'
--- src/zorbaserialization/template_serializer.h 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/template_serializer.h 2012-04-04 09:34:21 +0000
@@ -32,6 +32,7 @@
#include "archiver.h"
#include "class_serializer.h"
+#include "serialize_basic_types.h"
namespace zorba
{
@@ -48,7 +49,7 @@
template<class RepType>
-void operator&(Archiver &ar, zorba::rstring<RepType> &obj)
+void operator&(Archiver &ar, zorba::rstring<RepType>& obj)
{
bool is_normal_str = true;
if(ar.is_serializing_out())
@@ -86,7 +87,8 @@
}
}
else
- {//for strings which contain '\0' inside
+ {
+ //for strings which contain '\0' inside
if(ar.is_serializing_out())
{
const char *cstr = obj.c_str();
@@ -229,7 +231,7 @@
1 ,//class_version
!FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
char strtemp[20];
@@ -239,7 +241,7 @@
sprintf_s(strtemp, sizeof(strtemp), "%d", (int)obj->size());
#endif
bool is_ref;
- is_ref = ar.add_compound_field("std::vector<T>*", 0, !FIELD_IS_CLASS, strtemp, obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_IS_PTR);
+ is_ref = ar.add_compound_field("std::vector<T>*", 0, !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)
@@ -260,14 +262,14 @@
int version;
bool is_simple = false;
bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
obj = NULL;
ar.read_end_current_level();
@@ -276,7 +278,7 @@
if(ar.is_serialize_base_class())
ar.set_serialize_base_class(false);
void *new_obj;
- if(field_treat == ARCHIVE_FIELD_IS_PTR)
+ if(field_treat == ARCHIVE_FIELD_PTR)
{
obj = new std::vector<T>;
ar.register_reference(id, field_treat, obj);
@@ -291,7 +293,7 @@
}
ar.read_end_current_level();
}
- else if(field_treat == ARCHIVE_FIELD_IS_BASECLASS)
+ else if(field_treat == ARCHIVE_FIELD_BASECLASS)
{
int size;
sscanf(value.c_str(), "%d", &size);
@@ -303,7 +305,7 @@
}
ar.read_end_current_level();
}
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = (std::vector<T>*)new_obj;
if(!obj)
@@ -420,11 +422,11 @@
1 ,//class_version
!FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
bool is_ref;
- is_ref = ar.add_compound_field("std::pair<T1, T2>", 0, !FIELD_IS_CLASS, "", &obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_IS_PTR);
+ is_ref = ar.add_compound_field("std::pair<T1, T2>", 0, !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)
@@ -442,14 +444,14 @@
int version;
bool is_simple = false;
bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
obj = NULL;
ar.read_end_current_level();
@@ -459,7 +461,7 @@
ar.set_serialize_base_class(false);
void *new_obj;
- if(field_treat == ARCHIVE_FIELD_IS_PTR)
+ if(field_treat == ARCHIVE_FIELD_PTR)
{
obj = new std::pair<T1, T2>;
ar.register_reference(id, field_treat, &obj);
@@ -468,13 +470,13 @@
ar & obj->second;
ar.read_end_current_level();
}
- else if(field_treat == ARCHIVE_FIELD_IS_BASECLASS)
+ 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_IS_REFERENCING
+ else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = (std::pair<T1, T2>*)new_obj;
if(!obj)
@@ -500,11 +502,11 @@
1 ,//class_version
!FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
bool is_ref;
- is_ref = ar.add_compound_field("std::map<T1, T2>", 0, !FIELD_IS_CLASS, "", obj, ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_IS_PTR);
+ is_ref = ar.add_compound_field("std::map<T1, T2>", 0, !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)
@@ -533,14 +535,14 @@
int version;
bool is_simple = false;
bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
obj = NULL;
ar.read_end_current_level();
@@ -549,7 +551,7 @@
if(ar.is_serialize_base_class())
ar.set_serialize_base_class(false);
void *new_obj;
- if(field_treat == ARCHIVE_FIELD_IS_PTR)
+ if(field_treat == ARCHIVE_FIELD_PTR)
{
obj = new std::map<T1, T2>;
ar.register_reference(id, field_treat, obj);
@@ -568,7 +570,7 @@
ar.set_is_temp_field_one_level(false);
ar.read_end_current_level();
}
- else if(field_treat == ARCHIVE_FIELD_IS_BASECLASS)
+ else if(field_treat == ARCHIVE_FIELD_BASECLASS)
{
ar.set_is_temp_field_one_level(true);
int s;
@@ -584,7 +586,7 @@
ar.set_is_temp_field_one_level(false);
ar.read_end_current_level();
}
- else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ else if((new_obj = ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = (std::map<T1, T2>*)new_obj;
if(!obj)
@@ -671,7 +673,7 @@
T::class_versions[T::class_versions_count-1].class_version,
FIELD_IS_CLASS, "0",//strtemp,
(SerializeBaseClass*)&obj,
- //ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_NORMAL);
+ //ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_NORMAL);
ARCHIVE_FIELD_NORMAL);
if(!is_ref)
{
@@ -695,7 +697,7 @@
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,
- //ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_NORMAL,
+ //ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_NORMAL,
ARCHIVE_FIELD_NORMAL,
id);
ar.set_class_version(version);
@@ -759,7 +761,7 @@
1 ,//class_version
FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
bool is_ref;
@@ -772,7 +774,7 @@
obj->get_classversion(obj->get_version_count()-1).class_version),
FIELD_IS_CLASS, "0",//strtemp,
(SerializeBaseClass*)obj,
- ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_IS_PTR);
+ ar.is_serialize_base_class() ? ARCHIVE_FIELD_BASECLASS : ARCHIVE_FIELD_PTR);
if(!is_ref)
{
if(!ar.is_serialize_base_class())
@@ -795,14 +797,14 @@
int version;
bool is_simple = false;
bool is_class = true;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
assert(!ar.is_serialize_base_class());
obj = NULL;
@@ -823,7 +825,7 @@
);
}
#endif
- if(field_treat != ARCHIVE_FIELD_IS_BASECLASS)
+ if(field_treat != ARCHIVE_FIELD_BASECLASS)
{
throw ZORBA_EXCEPTION(
zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
@@ -832,7 +834,7 @@
}
else
{
- if((field_treat != ARCHIVE_FIELD_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
+ if((field_treat != ARCHIVE_FIELD_PTR) && (field_treat != ARCHIVE_FIELD_REFERENCING))
{
throw ZORBA_EXCEPTION(
zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
@@ -841,7 +843,7 @@
}
SerializeBaseClass *new_obj = NULL;
- if(field_treat == ARCHIVE_FIELD_IS_PTR)
+ if(field_treat == ARCHIVE_FIELD_PTR)
{
class_deserializer *cls_factory;
cls_factory = ClassSerializer::getInstance()->get_class_factory(type);
@@ -918,7 +920,7 @@
}
ar.read_end_current_level();
}
- else if(field_treat == ARCHIVE_FIELD_IS_BASECLASS)
+ else if(field_treat == ARCHIVE_FIELD_BASECLASS)
{
//check the version
#ifndef NDEBUG
@@ -965,7 +967,7 @@
obj->T::serialize_internal(ar);
ar.read_end_current_level();
}
- else if((new_obj = (SerializeBaseClass*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ else if((new_obj = (SerializeBaseClass*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
try{
obj = dynamic_cast<T*>(new_obj);
=== modified file 'src/zorbaserialization/xml_archiver.cpp'
--- src/zorbaserialization/xml_archiver.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/xml_archiver.cpp 2012-04-04 09:34:21 +0000
@@ -138,7 +138,7 @@
write_string("\" ");
if(current_field->theIsSimple ||
- (current_field->theKind == ARCHIVE_FIELD_IS_REFERENCING) ||
+ (current_field->theKind == ARCHIVE_FIELD_REFERENCING) ||
(current_field->theFirstChild == NULL))
{
write_string("/>\n");
@@ -185,10 +185,10 @@
switch(field_treat)
{
case ARCHIVE_FIELD_NORMAL : return "ARCHIVE_FIELD_NORMAL"; break;
- case ARCHIVE_FIELD_IS_PTR : return "ARCHIVE_FIELD_IS_PTR"; break;
- case ARCHIVE_FIELD_IS_NULL : return "ARCHIVE_FIELD_IS_NULL"; break;
- case ARCHIVE_FIELD_IS_BASECLASS : return "ARCHIVE_FIELD_IS_BASECLASS"; break;
- case ARCHIVE_FIELD_IS_REFERENCING : return "ARCHIVE_FIELD_IS_REFERENCING"; break;
+ case ARCHIVE_FIELD_PTR : return "ARCHIVE_FIELD_IS_PTR"; break;
+ case ARCHIVE_FIELD_NULL : return "ARCHIVE_FIELD_IS_NULL"; break;
+ case ARCHIVE_FIELD_BASECLASS : return "ARCHIVE_FIELD_IS_BASECLASS"; break;
+ case ARCHIVE_FIELD_REFERENCING : return "ARCHIVE_FIELD_IS_REFERENCING"; break;
}
return NULL;
}
@@ -314,13 +314,13 @@
if(!strcmp(attrib_value, "ARCHIVE_FIELD_NORMAL"))
*field_treat = ARCHIVE_FIELD_NORMAL;
else if(!strcmp(attrib_value, "ARCHIVE_FIELD_IS_PTR"))
- *field_treat = ARCHIVE_FIELD_IS_PTR;
+ *field_treat = ARCHIVE_FIELD_PTR;
else if(!strcmp(attrib_value, "ARCHIVE_FIELD_IS_NULL"))
- *field_treat = ARCHIVE_FIELD_IS_NULL;
+ *field_treat = ARCHIVE_FIELD_NULL;
else if(!strcmp(attrib_value, "ARCHIVE_FIELD_IS_BASECLASS"))
- *field_treat = ARCHIVE_FIELD_IS_BASECLASS;
+ *field_treat = ARCHIVE_FIELD_BASECLASS;
else if(!strcmp(attrib_value, "ARCHIVE_FIELD_IS_REFERENCING"))
- *field_treat = ARCHIVE_FIELD_IS_REFERENCING;
+ *field_treat = ARCHIVE_FIELD_REFERENCING;
else
{
return false;
@@ -380,7 +380,7 @@
is_compound_field_without_children = false;
if(!strcmp(attrib_name, "/"))//empty tag
{
- if(!*is_simple && (*field_treat != ARCHIVE_FIELD_IS_REFERENCING))
+ if(!*is_simple && (*field_treat != ARCHIVE_FIELD_REFERENCING))
is_compound_field_without_children = true;
}
else
=== modified file 'src/zorbaserialization/zorba_class_serializer.cpp'
--- src/zorbaserialization/zorba_class_serializer.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/zorba_class_serializer.cpp 2012-04-04 09:34:21 +0000
@@ -84,15 +84,16 @@
/*register this class into plan serializer*/
::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;
@@ -109,35 +110,39 @@
void operator&(Archiver &ar, XQPCollator*& obj)
{
- if(ar.is_serializing_out())
+ if (ar.is_serializing_out())
{
- if(obj == NULL)
+ if (obj == NULL)
{
ar.add_simple_field("XQPCollator*",
- "NULL",
- NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ "NULL",
+ NULL,//(SerializeBaseClass*)obj,
+ ARCHIVE_FIELD_NULL);
return;
}
- ar.add_simple_field("XQPCollator*", obj->getURI().c_str(), obj, ARCHIVE_FIELD_IS_PTR);
+ ar.add_simple_field("XQPCollator*", obj->getURI().c_str(), obj, ARCHIVE_FIELD_PTR);
}
else
{
- char *type;
+ char* type;
std::string value;
int id;
int version;
bool is_simple = true;
bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
+
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_PTR, id);
- if(field_treat == ARCHIVE_FIELD_IS_NULL)
+
+ ar.check_simple_field(retval, type, "XQPCollator*", is_simple, field_treat, ARCHIVE_FIELD_PTR, id);
+
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
obj = NULL;
return;
@@ -310,7 +315,7 @@
if(obj) \
obj->addReference(); \
ar.set_is_temp_field(false); \
- ar.register_reference(id, ARCHIVE_FIELD_IS_PTR, obj); \
+ ar.register_reference(id, ARCHIVE_FIELD_PTR, obj); \
ar.set_is_temp_field(true); \
}
@@ -325,7 +330,7 @@
int is_function = 0;
int id;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
if (ar.is_serializing_out())
@@ -336,7 +341,7 @@
1 ,//class_version
FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
@@ -360,7 +365,7 @@
FIELD_IS_CLASS,
strtemp,
obj,
- ARCHIVE_FIELD_IS_PTR);
+ ARCHIVE_FIELD_PTR);
if (is_node || is_function)
ar.set_is_temp_field(false);
@@ -377,20 +382,20 @@
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_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
obj = NULL;
ar.read_end_current_level();
return;
}
//ar.register_reference(id, &obj);
- if((field_treat != ARCHIVE_FIELD_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
+ 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_IS_REFERENCING);
+ is_ref = (field_treat == ARCHIVE_FIELD_REFERENCING);
if(!is_ref)
{
sscanf(value.c_str(), "n%da%dp%de%df%d",
@@ -766,7 +771,7 @@
obj = fitem;
if(obj)
obj->addReference();
- ar.register_reference(id, ARCHIVE_FIELD_IS_PTR, obj);
+ ar.register_reference(id, ARCHIVE_FIELD_PTR, obj);
}
ar.set_is_temp_field(true);
}
@@ -798,7 +803,7 @@
else
{
store::Item *new_obj = NULL;
- if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = dynamic_cast<store::Item*>(new_obj);
if(!obj)
@@ -844,7 +849,7 @@
ar.set_is_temp_field(false);
int id;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool is_ref;
if(ar.is_serializing_out())
@@ -855,11 +860,11 @@
1 ,//class_version
!FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
ar.set_is_temp_field(true);
return;
}
- is_ref = ar.add_compound_field("store::Item*", 0, FIELD_IS_CLASS, "", obj, ARCHIVE_FIELD_IS_PTR);
+ is_ref = ar.add_compound_field("store::Item*", 0, FIELD_IS_CLASS, "", obj, ARCHIVE_FIELD_PTR);
}
else
{
@@ -872,7 +877,7 @@
retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
if(!retval && ar.get_read_optional_field())
return;
- if(field_treat == ARCHIVE_FIELD_IS_NULL)
+ if(field_treat == ARCHIVE_FIELD_NULL)
{
obj = NULL;
ar.read_end_current_level();
@@ -881,13 +886,13 @@
}
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_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
+ 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_IS_REFERENCING);
+ is_ref = (field_treat == ARCHIVE_FIELD_REFERENCING);
}
ar.set_is_temp_field(true);
@@ -1009,7 +1014,7 @@
else
{
store::Item *new_obj = NULL;
- if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
+ if((new_obj = (store::Item*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_REFERENCING
{
obj = dynamic_cast<store::Item*>(new_obj);
if(!obj)
@@ -1045,7 +1050,7 @@
1 ,//class_version
!FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
bool is_ref;
@@ -1063,7 +1068,7 @@
1,
!FIELD_IS_CLASS, err_type,
obj,
- ARCHIVE_FIELD_IS_PTR);
+ ARCHIVE_FIELD_PTR);
if(!is_ref)
{
if(user_err)
@@ -1090,21 +1095,21 @@
int version;
bool is_simple = false;
bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_NULL)
+ 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_IS_PTR)
+ 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);
@@ -1152,7 +1157,7 @@
1 ,//class_version
!FIELD_IS_CLASS, "NULL",
NULL,//(SerializeBaseClass*)obj,
- ARCHIVE_FIELD_IS_NULL);
+ ARCHIVE_FIELD_NULL);
return;
}
bool is_ref;
@@ -1167,7 +1172,7 @@
1,
!FIELD_IS_CLASS, ex_type,
obj,
- ARCHIVE_FIELD_IS_PTR);
+ ARCHIVE_FIELD_PTR);
if(!is_ref)
{
ar & obj->diagnostic_;
@@ -1196,21 +1201,21 @@
int version;
bool is_simple = false;
bool is_class = false;
- enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
+ enum ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
int referencing;
bool retval;
retval = ar.read_next_field(&type, &value, &id, &version, &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_IS_NULL)
+ 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_IS_PTR)
+ if(field_treat == ARCHIVE_FIELD_PTR)
{
int is_user, is_xquery;
sscanf(value.c_str(), "u%dx%d", &is_user, &is_xquery);
=== modified file 'src/zorbaserialization/zorba_classes_version.cpp'
--- src/zorbaserialization/zorba_classes_version.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbaserialization/zorba_classes_version.cpp 2012-04-04 09:34:21 +0000
@@ -17,8 +17,10 @@
#include "zorbaserialization/class_serializer.h"
-namespace zorba{
- namespace serialization{
+namespace zorba
+{
+namespace serialization
+{
const unsigned long g_zorba_classes_version = 21;
=== modified file 'src/zorbatypes/datetime/duration.cpp'
--- src/zorbatypes/datetime/duration.cpp 2012-03-28 05:19:57 +0000
+++ src/zorbatypes/datetime/duration.cpp 2012-04-04 09:34:21 +0000
@@ -28,8 +28,12 @@
#include "util/ascii_util.h"
+#include "zorbaserialization/serialize_basic_types.h"
+
+
namespace zorba
{
+
SERIALIZABLE_CLASS_VERSIONS(Duration)
END_SERIALIZABLE_CLASS_VERSIONS(Duration)
Follow ups
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: noreply, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Markos Zaharioudakis, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Markos Zaharioudakis, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Markos Zaharioudakis, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/serializer into lp:zorba
From: Markos Zaharioudakis, 2012-04-04