1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #ifndef ZORBA_BINARY_SERIALIZATION_ARCHIVER_FIELD 18 #define ZORBA_BINARY_SERIALIZATION_ARCHIVER_FIELD 19 20 #include "zorbaserialization/plan_settings.h" 21 #include "zorbaserialization/archiver_consts.h" 22 23 #include "store/api/shared_types.h" 24 25 namespace zorba 26 { 27 28 namespace serialization 29 { 30 31 class SerializeBaseClass; 32 33 /******************************************************************************* 34 35 Archiver is working with fields. During serialization, an intermediate tree of 36 fields is constructed in memory to represent all the objects that need to be 37 serialized. Then, the fields are written to disk in depth-first order, creating 38 an archive. During deserialization, the fields in the archive are read and the 39 associated objects recreated directly in memory, without going through the 40 intermediate representation of the fields-tree. 41 42 Notice that in the context of the serializer, an "object" is defined as any 43 address in memory that contains information to be serialized. For example, 44 it can be a C++ class object, an std::vector<> or a C++ integer. The object 45 can be heap-allocated, or on the stack. 46 47 Fileds can be "simple" or "compound". Simple fields represent values of simple 48 types; they always appear as leaves in the fields-tree. Compound fields represent 49 C++-class objects and other structured types like vectors, maps, etc. They 50 typically contain subtrees of other fields. 51 52 Each field has a unique id. 53 54 ********************************************************************************/ 55 56 57 /******************************************************************************* 58 theId : 59 ------- 60 Fields that may be referenced by other fields are assigned a unique id so that 61 the referring field can use this id as a "pointer" to the referred field. For 62 field that cannot be referenced by other fields, theId is 0. Note: only fields 63 of kind ARCHIVE_FIELD_NORMAL and ARCHIVE_FIELD_PTR may have ids. 64 65 theIsSimple: 66 ------------ 67 Whether this field represents a "simple" obj or a "compound" obj. 68 69 theIsClass: 70 ----------- 71 Whether this field represents a class obj or not. Class objs are always 72 considered as "compound", so if theIsClass is true, theIsSimple is false. 73 However, the reverse is not true: a non-class obj may be simple or compound. 74 For example, an std::vector<> is a compound, non-class obj. 75 76 theKind: 77 -------- 78 The kind of the field. See ArchiveFieldKind enum in archiver_consts.h. 79 80 theType: 81 -------- 82 An enum value signifying the data type of the obj. 83 84 85 theValue: 86 --------- 87 88 theValuePosInPool: 89 ------------------ 90 The position of theValue string within the string pool. The string pool 91 is created after the fields tree has been fully built and just before we 92 start actually writting stuff out to "disk". theValue string is copied 93 into the string pool only if theKind is PTR or NORMAL. 94 95 thePtr : 96 -------- 97 Pointer to the obj represented by this field. NULL for FIELD_REFERENCING and 98 FIELD_NULL fields. 99 100 theReferredField: 101 ----------------- 102 103 theOrder: 104 --------- 105 Order in the tree. Not initialized by constructor. 106 107 theLevel: 108 --------- 109 The level of this field, i.e., the nuber of fields in the path from this 110 field to the root. The root is at level 0. 111 112 theNextSibling: 113 --------------- 114 The right sibling of this field (if any). 115 116 theFirstChild: 117 -------------- 118 The 1st child of this field (if any). 119 120 theLastChild: 121 ------------- 122 The last child of this field (if any). 123 124 theParent: 125 ---------- 126 The parent field in the fields tree. 127 128 theOnlyForEval: 129 --------------- 130 131 theAllowDelay2: 132 --------------- 133 134 theBytesSaved: 135 -------------- 136 137 theObjectsSaved: 138 ---------------- 139 140 The following data members are serialized: 141 142 1. theType : only if theKind is PTR and theIsClass is true. 143 2. theValue : except if theKind is REFERENCING or NULL 144 3. theReferedId : only if theKind is REFERENCING 145 4. theKind 146 5. theId : 147 ********************************************************************************/ 148 class archive_field 149 { 150 public: 151 unsigned int theId; 152 153 bool theIsSimple; 154 bool theIsClass; 155 156 ArchiveFieldKind theKind; 157 158 TypeCode theType; 159 160 SimpleValue theValue; 161 zstring theStringValue; 162 csize theValuePosInPool; 163 164 const void * theObjPtr; 165 166 archive_field * theReferredField; 167 168 unsigned int theOrder; 169 170 unsigned int theLevel; 171 172 class archive_field * theNextSibling; 173 class archive_field * theFirstChild; 174 class archive_field * theLastChild; 175 class archive_field * theParent; 176 177 int theOnlyForEval; 178 179 ENUM_ALLOW_DELAY theAllowDelay2; 180 181 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS 182 unsigned int theBytesSaved; 183 unsigned int theObjectsSaved; 184 #endif 185 186 public: 187 archive_field( 188 TypeCode type, 189 bool is_simple, 190 bool is_class, 191 const void* ptr, 192 ArchiveFieldKind kind, 193 archive_field* refered, 194 int only_for_eval, 195 ENUM_ALLOW_DELAY allow_delay, 196 unsigned int level); 197 198 archive_field( 199 TypeCode type, 200 const void* ptr, 201 ArchiveFieldKind kind, 202 int only_for_eval, 203 ENUM_ALLOW_DELAY allow_delay, 204 unsigned int level); 205 206 ~archive_field(); 207 }; 208 209 210 211 } 212 } 213 #endif 214 /* vim:set et sw=2 ts=2: */ 215