ObjectPeer.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 //  static void make(Object *, Class *, Data, Size, Type);
00027   
00028 namespace eyedb {
00029 
00030 void ObjectPeer::incrRefCount(Object *o)
00031 {
00032   o->incrRefCount();
00033 }
00034 
00035 void ObjectPeer::decrRefCount(Object *o)
00036 {
00037   o->decrRefCount();
00038 }
00039 
00040 void ObjectPeer::setUnrealizable(Object *o, Bool unreal)
00041 {
00042   o->setUnrealizable(unreal);
00043 }
00044 
00045 void ObjectPeer::setOid(Object *o, const Oid& oid)
00046 {
00047   o->setOid(oid);
00048 }
00049 
00050 void ObjectPeer::setProtOid(Object *o, const Oid& prot_oid)
00051 {
00052   o->oid_prot = prot_oid;
00053 }
00054 
00055 void ObjectPeer::setTimes(Object *o, const ObjectHeader &hdr)
00056 {
00057   if (hdr.ctime)
00058     o->c_time = hdr.ctime;
00059   else
00060     o->c_time = hdr.mtime;
00061 
00062   o->m_time = hdr.mtime;
00063 }
00064 
00065 void ObjectPeer::make(Object *o, const Class *cls,
00066                          Data data, Type type, Size idr_objsz,
00067                          Size idr_psize, Size idr_vsize, Bool _copy)
00068 {
00069   Object::IDR *idr = o->idr;
00070   o->cls = (Class *)cls;
00071   o->type   = type;
00072 
00073   if (_copy)
00074     {
00075       idr->setIDR(idr_objsz);
00076       /*
00077       idr->idr = (unsigned char *)malloc(idr_objsz);
00078       idr->idr_sz = idr_objsz;
00079       */
00080 
00081       if (data)
00082         {
00083           memcpy(idr->getIDR() + IDB_OBJ_HEAD_SIZE, data,
00084                  idr_psize - IDB_OBJ_HEAD_SIZE);
00085           memset(idr->getIDR() + idr_psize, 0, idr_vsize);
00086         }
00087       else
00088         memset(idr->getIDR() + IDB_OBJ_HEAD_SIZE, 0,
00089                idr->getSize() - IDB_OBJ_HEAD_SIZE);
00090     }
00091   else
00092     {
00093       //idr->idr_sz = idr_objsz;
00094 
00095       if (data)
00096         {
00097           idr->setIDR(idr_objsz, data - IDB_OBJ_HEAD_SIZE);
00098           //idr->idr = data - IDB_OBJ_HEAD_SIZE;
00099         }
00100       else
00101         {
00102           //idr->idr = (unsigned char *)malloc(idr_objsz);
00103           idr->setIDR(idr_objsz);
00104           memset(idr->getIDR() + IDB_OBJ_HEAD_SIZE, 0,
00105                  idr->getSize() - IDB_OBJ_HEAD_SIZE);
00106         }
00107     }
00108 
00109   o->headerCode(type, idr_psize, IDB_XINFO_LOCAL_OBJ);
00110 }
00111 
00112 void ObjectPeer::setIDR(Object *o, Data idr, Size idr_sz)
00113 {
00114   o->idr->setIDR(idr_sz, idr);
00115   /*
00116   if (o->idr->idr)
00117     free(o->idr->idr);
00118   o->idr->idr = idr;
00119   o->idr->idr_sz = idr_sz;
00120   */
00121 }
00122 
00123 Status ObjectPeer::trace_realize(const Object *o, FILE *fd, int indent, unsigned int flags, const RecMode *rcm)
00124 {
00125   return o->trace_realize(fd, indent, flags, rcm);
00126 }
00127 
00128 void ObjectPeer::setModify(Object *o, Bool b)
00129 {
00130   o->modify = b;
00131 }
00132 
00133 void ObjectPeer::setClass(Object *o, const Class *cls)
00134 {
00135   o->setClass(cls);
00136 }
00137 
00138 Bool ObjectPeer::isRemoved(const ObjectHeader &hdr)
00139 {
00140   return (hdr.xinfo & IDB_XINFO_REMOVED) ? True : False;
00141 }
00142 
00143 void ObjectPeer::setRemoved(Object *o)
00144 {
00145   o->removed = True;
00146 }
00147 
00148 void
00149 ObjectPeer::loadEpilogue(Object *o, const Oid &oid,
00150                          const ObjectHeader &hdr, Data o_idr)
00151 {
00152   //o->setOid(oid);;
00153   o->oid = oid;
00154   o->modify = False;
00155   setTimes(o, hdr);
00156   o->oid_prot = hdr.oid_prot;
00157 
00158   if (isRemoved(hdr))
00159     o->removed = True;
00160 
00161   if (!o->idr->getIDR())
00162     setIDR(o, o_idr, hdr.size);
00163   else if (o->idr->getIDR() != o_idr)
00164     free(o_idr);
00165 }
00166 }

Generated on Mon Dec 22 18:15:59 2008 for eyedb by  doxygen 1.5.3