SchemaInfo.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #include "eyedb_p.h"
00026 
00027 namespace eyedb {
00028 
00029   void
00030   decode_sch_info(Data data, void *xschinfo)
00031   {
00032     Offset offset = 0;
00033     eyedblib::int32 cnt;
00034     int32_decode(data, &offset, &cnt);
00035     SchemaInfo *schinfo = new SchemaInfo(cnt);
00036 
00037     for (int i = 0; i < cnt; i++)
00038       {
00039         eyedbsm::Oid *xoid = schinfo->class_oid[i].getOid();
00040         oid_decode(data, &offset, xoid);
00041       }
00042 
00043     *((SchemaInfo **)xschinfo) = schinfo;
00044   }
00045 
00046   void
00047   code_sch_info(void *xschinfo, Data *data, int *size)
00048   {
00049     Offset offset = 0;
00050     Size alloc_size = 0;
00051     SchemaInfo *schinfo = (SchemaInfo *)xschinfo;
00052 
00053     int cnt = schinfo->class_cnt;
00054     int32_code(data, &offset, &alloc_size, &cnt);
00055 
00056     for (int i = 0; i < cnt; i++)
00057       oid_code(data, &offset, &alloc_size, schinfo->class_oid[i].getOid());
00058 
00059     *size = offset;
00060   }
00061 
00062   SchemaInfo::SchemaInfo(int cnt)
00063   {
00064     class_cnt = cnt;
00065     //  class_oid = (class_cnt ? new Oid[class_cnt] : NULL);
00066     class_oid = (class_cnt ? (Oid *)calloc(sizeof(Oid) * class_cnt, 1)
00067                  : NULL);
00068   }
00069 
00070   SchemaInfo::SchemaInfo(LinkedList *cl_list)
00071   {
00072     class_cnt = cl_list->getCount();
00073     class_oid = (class_cnt ? (Oid *)calloc(sizeof(Oid) * class_cnt, 1)
00074                  : NULL);
00075 
00076     if (class_cnt)
00077       {
00078         int n = 0;
00079         LinkedListCursor c(cl_list);
00080         Class *cls;
00081 
00082         while (cl_list->getNextObject(&c, (void *&)cls))
00083           class_oid[n++] = cls->getOid();
00084       }      
00085   }
00086 
00087   SchemaInfo::~SchemaInfo()
00088   {
00089     free(class_oid);
00090 
00091     class_oid = NULL;
00092     class_cnt = 0;
00093   }
00094 
00095 }
00096 
00097   

Generated on Mon Dec 22 18:16:07 2008 for eyedb by  doxygen 1.5.3