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 #include "stdafx.h" 17 18 #include "zorbaserialization/class_serializer.h" 19 #include "zorbaserialization/archiver.h" 20 #include "zorbaserialization/mem_archiver.h" 21 22 #include "diagnostics/xquery_diagnostics.h" 23 #include "diagnostics/assert.h" 24 25 #include "zorbautils/hashmap.h" 26 27 namespace zorba 28 { 29 30 namespace serialization 31 { 32 33 34 /******************************************************************************* 35 36 ********************************************************************************/ 37 const unsigned long ClassSerializer::g_zorba_classes_version = 25; 38 39 40 /******************************************************************************* 41 42 ********************************************************************************/ ClassSerializer()43ClassSerializer::ClassSerializer() 44 { 45 theClassFactories.resize(TYPE_LAST); 46 47 t0 = clock(); 48 49 harcoded_objects_archive = new MemArchiver(true, true); 50 } 51 52 53 /******************************************************************************* 54 55 ********************************************************************************/ ~ClassSerializer()56ClassSerializer::~ClassSerializer() 57 { 58 delete harcoded_objects_archive; 59 } 60 61 62 /******************************************************************************* 63 64 ********************************************************************************/ getInstance()65ClassSerializer* ClassSerializer::getInstance() 66 { 67 static ClassSerializer theInstance; 68 return &theInstance; 69 } 70 71 72 /******************************************************************************* 73 74 ********************************************************************************/ register_class_factory(TypeCode code,ClassDeserializer * class_factory)75void ClassSerializer::register_class_factory( 76 TypeCode code, 77 ClassDeserializer* class_factory) 78 { 79 assert(code < TYPE_LAST); 80 theClassFactories[code] = class_factory; 81 82 t1 = clock(); 83 } 84 85 86 /******************************************************************************* 87 88 ********************************************************************************/ get_class_factory(TypeCode code)89ClassDeserializer* ClassSerializer::get_class_factory(TypeCode code) 90 { 91 assert(code < TYPE_LAST); 92 return theClassFactories[code]; 93 } 94 95 96 /******************************************************************************* 97 98 ********************************************************************************/ getArchiverForHardcodedObjects()99Archiver* ClassSerializer::getArchiverForHardcodedObjects() 100 { 101 return harcoded_objects_archive; 102 } 103 104 105 /******************************************************************************* 106 called at shutdown 107 ********************************************************************************/ destroyArchiverForHardcodedObjects()108void ClassSerializer::destroyArchiverForHardcodedObjects() 109 { 110 delete harcoded_objects_archive; 111 harcoded_objects_archive = NULL; 112 harcoded_objects_archive = new MemArchiver(true, true); 113 } 114 115 116 } // namespace serialization 117 } // namespace zorba 118 /* vim:set et sw=2 ts=2: */ 119