Basic.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 #include "AttrNative.h"
00027 #include "CollectionBE.h"
00028 #include <assert.h>
00029 
00030 //#define E_XDR_TRACE
00031 
00032 namespace eyedb {
00033 
00034 enum {
00035   CharClass_Code = 10,
00036   ByteClass_Code,
00037   OidPClass_Code,
00038   Int16Class_Code,
00039   Int32Class_Code,
00040   Int64Class_Code,
00041   FloatClass_Code
00042 };
00043 
00044 const char char_class_name[]  = "char";
00045 const char byte_class_name[]  = "byte";
00046 const char oid_class_name[]   = "oid";
00047 const char int16_class_name[] = "int16";
00048 const char int32_class_name[] = "int32";
00049 const char int64_class_name[] = "int64";
00050 const char float_class_name[] = "float";
00051 
00052 CharClass    *Char_Class;
00053 ByteClass    *Byte_Class;
00054 OidClass    *OidP_Class;
00055 Int16Class   *Int16_Class;
00056 Int32Class   *Int32_Class;
00057 Int64Class   *Int64_Class;
00058 FloatClass   *Float_Class;
00059 
00060 static void
00061 fprint_float(FILE *fd, double d);
00062 
00063 static int
00064 increment(int n, int dim[], const TypeModifier *tmod)
00065 {
00066   if (n < tmod->ndims)
00067     {
00068       if (dim[n] == tmod->dims[n]-1)
00069         {
00070           dim[n] = 0;
00071           return increment(n-1, dim, tmod) + 1;
00072         }
00073 
00074       dim[n]++;
00075       return 0;
00076     }
00077 }
00078 
00079 static int
00080 increment(int dim[], const TypeModifier *tmod)
00081 {
00082   return increment(tmod->ndims-1, dim, tmod);
00083 }
00084 
00085 static const char *mk_indent(int indent, int n)
00086 {
00087 #define INCR 4
00088 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
00089   static char *indstr;
00090   static int size;
00091 
00092   int q = indent + INCR * n;
00093   if (!indstr || size < q)
00094     {
00095       size = MAX(128, q);
00096       if (indstr)
00097         free(indstr);
00098       indstr = (char *)malloc(size);
00099       memset(indstr, ' ', size-1);
00100       indstr[size-1] = 0;
00101     }
00102 
00103   return &indstr[size-q-1];
00104 }
00105 
00106 static void
00107 traceData(FILE *fd, int indent, Data inidata,
00108           Data data, TypeModifier *tmod, int size,
00109           void (*print_data)(FILE *fd, Data data))
00110 {
00111   int i, j, k;
00112 
00113   int *dim = (int *)malloc(tmod->ndims * sizeof(int));
00114   for (j = 0; j < tmod->ndims; j++)
00115     {
00116       dim[j] = 0;
00117       fprintf(fd, "%s{\n", (j ? mk_indent(indent, j) : ""));
00118     }
00119 
00120   dim[tmod->ndims-1] = -1;
00121   for (i = 0; i < tmod->pdims; i++)
00122     {
00123       int r = increment(dim, tmod);
00124       for (k = r-1; k >= 0; k--)
00125         fprintf(fd, "\n%s}", mk_indent(indent, tmod->ndims - r + k));
00126       if (i)
00127         fprintf(fd, ",%s", (r ? "" : "\n"));
00128       for (k = 0; k < r; k++)
00129         fprintf(fd, "\n%s{", mk_indent(indent, tmod->ndims - r + k));
00130                   
00131       fprintf(fd, "%s%s  ", (r ? "\n" : ""),
00132               mk_indent(indent, tmod->ndims-1));
00133 
00134       for (j = 0; j < tmod->ndims; j++)
00135         fprintf(fd, "[%d]", dim[j]);
00136       
00137       fprintf(fd, " = ");
00138       if (Attribute::isNull(inidata, 1, i))
00139         fprintf(fd, "%s", NullString);
00140       else
00141         print_data(fd, data);
00142 
00143       data += size;
00144     }
00145 
00146   for (j = tmod->ndims-1; j >= 0; j--)
00147     fprintf(fd, "\n%s}", mk_indent(indent - INDENT_INC, j));
00148   free(dim);
00149 }
00150 
00151 static void
00152 print_int32_data(FILE *fd, Data data)
00153 {
00154   eyedblib::int32 n;
00155 #ifdef E_XDR
00156   x2h_32_cpy(&n, data);
00157 #else
00158   memcpy(&n, data, sizeof(eyedblib::int32));
00159 #endif
00160   fprintf(fd, "%d", n);
00161 }
00162 
00163 static void
00164 print_int16_data(FILE *fd, Data data)
00165 {
00166   eyedblib::int16 n;
00167 #ifdef E_XDR
00168   x2h_16_cpy(&n, data);
00169 #else
00170   memcpy(&n, data, sizeof(eyedblib::int16));
00171 #endif
00172   fprintf(fd, "%d", n);
00173 }
00174 
00175 static void
00176 print_int64_data(FILE *fd, Data data)
00177 {
00178   eyedblib::int64 n;
00179 #ifdef E_XDR
00180   x2h_64_cpy(&n, data);
00181 #else
00182   memcpy(&n, data, sizeof(eyedblib::int64));
00183 #endif
00184   fprintf(fd, "%lld", n);
00185 }
00186 
00187 static void
00188 print_xdr_float_data(FILE *fd, Data data)
00189 {
00190   double d;
00191 #ifdef E_XDR
00192   x2h_f64_cpy(&d, data);
00193 #else
00194   memcpy(&d, data, sizeof(double));
00195 #endif
00196   fprint_float(fd, d);
00197 }
00198 
00199 static void
00200 print_xdr_oid_data(FILE *fd, Data data)
00201 {
00202   Oid oid;
00203 #ifdef E_XDR
00204   eyedbsm::x2h_oid(oid.getOid(), data);
00205 #else
00206   memcpy(oid.getOid(), data, sizeof(Oid));
00207 #endif
00208   fprintf(fd, "%s", oid.getString());
00209 }
00210 
00211 #define MAXPRES 80
00212 #define MINPRES  6
00213 
00214 static void
00215 fprint_float(FILE *fd, double d)
00216 {
00217   double od = 0;
00218   char tok[128], fmt[32];
00219 
00220   for (int i = MINPRES; i < MAXPRES; i += 4)
00221     {
00222       sprintf(fmt, "%%.%dg", i);
00223       sprintf(tok, fmt, d);
00224       double cd = atof(tok);
00225       if (cd == d || (i != MINPRES && od != cd))
00226         {
00227           fprintf(fd, tok);
00228           return;
00229         }
00230 
00231       od = cd;
00232     }
00233 
00234   sprintf(fmt, "%%.%dg", MAXPRES);
00235   sprintf(tok, fmt, d);
00236   fprintf(fd, tok);
00237 }
00238 
00239 static void
00240 print_float_data(FILE *fd, Data data)
00241 {
00242   double d;
00243   memcpy(&d, data, sizeof(double));
00244   fprint_float(fd, d);
00245 }
00246 
00247 static void
00248 print_byte_data(FILE *fd, Data data)
00249 {
00250   fprintf(fd, "'\\%03o'", *data);
00251 }
00252 
00253 static void
00254 print_oid_data(FILE *fd, Data data)
00255 {
00256   Oid oid;
00257   memcpy(&oid, data, sizeof(Oid));
00258   fprintf(fd, oid.getString());
00259 }
00260 
00261 static void
00262 print_char_data(FILE *fd, Data data)
00263 {
00264   fprintf(fd, "'%c'", *(char *)data);
00265 }
00266 
00267 //
00268 // BasicClass
00269 //
00270 
00271 BasicClass::BasicClass(const char *s) : Class(s)
00272 {
00273   parent = Class_Class;
00274   type = _BasicClass_Type;
00275   *Cname = 0;
00276 
00277   AttrNative::copy(ClassITEMS, items, items_cnt, this);
00278 }
00279 
00280 BasicClass::BasicClass(Database *_db, const char *s) :
00281 Class(_db, s)
00282 {
00283   parent = Class_Class;
00284   type = _BasicClass_Type;
00285   *Cname = 0;
00286 
00287   AttrNative::copy(ClassITEMS, items, items_cnt, this);
00288 }
00289 
00290 void
00291 BasicClass::copy_realize(const BasicClass &cl)
00292 {
00293   code = cl.code;
00294   strcpy(Cname, cl.Cname);
00295 }
00296 
00297 BasicClass::BasicClass(const BasicClass &cl)
00298   : Class(cl)
00299 {
00300   *Cname = 0;
00301   copy_realize(cl);
00302 }
00303 
00304 Status
00305 BasicClass::loadComplete(const Class *cl)
00306 {
00307   assert(cl->asBasicClass());
00308   Status s = Class::loadComplete(cl);
00309   if (s) return s;
00310   copy_realize(*cl->asBasicClass());
00311   return Success;
00312 }
00313 
00314 BasicClass &BasicClass::operator=(const BasicClass &cl)
00315 {
00316   this->Class::operator=(cl);
00317   copy_realize(cl);
00318   return *this;
00319 }
00320 
00321 Status BasicClass::attrsComplete()
00322 {
00323   //  return Success;
00324   return Class::attrsComplete();
00325 }
00326 
00327 const char *
00328 BasicClass::getCName(Bool useAsRef) const
00329 {
00330   if (useAsRef) {
00331       static const char prefix[] = "eyedb::";
00332       static const int prefix_len = strlen(prefix);
00333       strcpy(const_cast<BasicClass *>(this)->Cname, prefix);
00334       const_cast<BasicClass *>(this)->Cname[prefix_len] = *name + 'A' - 'a';
00335       const_cast<BasicClass *>(this)->Cname[prefix_len+1] = 0;
00336       strcat(const_cast<BasicClass *>(this)->Cname, name+1);
00337   }
00338   else {
00339     strcpy(const_cast<BasicClass *>(this)->Cname, "eyedblib::");
00340     strcat(const_cast<BasicClass *>(this)->Cname, name);
00341   }
00342   return Cname;
00343 }
00344 
00345 int BasicClass::getCode() const
00346 {
00347   return code;
00348 }
00349 
00350 Status BasicClass::trace(FILE *fd, unsigned int flags, const RecMode *rcm) const
00351 {
00352   fprintf(fd, "%s ", oid.getString());
00353   return ObjectPeer::trace_realize(this, fd, INDENT_INC, flags, rcm);
00354 }
00355 
00356 Status BasicClass::create()
00357 {
00358   if (oid.isValid())
00359     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating basic_class '%s'",
00360                          name);
00361 
00362   IDB_CHECK_WRITE(db);
00363 
00364   RPCStatus rpc_status;
00365   eyedblib::int16 kk;
00366   Size alloc_size;
00367   Offset offset;
00368   Size size;
00369   Status status;
00370 
00371   alloc_size = 0;
00372   //idr->idr = 0;
00373   idr->setIDR((Size)0);
00374   Data data = 0;
00375 
00376   /*
00377   offset = IDB_CLASS_MAG_ORDER;
00378   int32_code (&data, &offset, &alloc_size, (eyedblib::int32 *)&mag_order);
00379   */
00380   offset = IDB_CLASS_IMPL_TYPE;
00381   status = IndexImpl::code(data, offset, alloc_size, *idximpl);
00382   if (status) return status;
00383 
00384   offset = IDB_CLASS_MTYPE;
00385   eyedblib::int32 mt = m_type;
00386   int32_code (&data, &offset, &alloc_size, &mt);
00387 
00388   offset = IDB_CLASS_DSPID;
00389   eyedblib::int16 dspid = get_instdspid();
00390   int16_code (&data, &offset, &alloc_size, &dspid);
00391 
00392   offset = IDB_CLASS_HEAD_SIZE;
00393       
00394   status = class_name_code(db->getDbHandle(), getDataspaceID(), &data,
00395                                &offset, &alloc_size, name);
00396   if (status) return status;
00397 
00398   int16_code  (&data, &offset, &alloc_size, &code);
00399 
00400   size = offset;
00401   idr->setIDR(size, data);
00402   headerCode(_BasicClass_Type, size);
00403 
00404   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(),
00405                                 data, oid.getOid());
00406 
00407   return StatusMake(rpc_status);
00408 }
00409 
00410 Status BasicClass::update()
00411 {
00412   return Success;
00413 }
00414 
00415 Status BasicClass::remove(const RecMode*)
00416 {
00417   return Success;
00418 }
00419 
00420 Status BasicClass::setValue(Data)
00421 {
00422   return Success;
00423 }
00424 
00425 Status BasicClass::getValue(Data*) const
00426 {
00427   return Success;
00428 }
00429 
00430 Status
00431 basicClassMake(Database *db, const Oid *oid, Object **o,
00432                   const RecMode *rcm, const ObjectHeader *hdr,
00433                   Data idr, LockMode lockmode, const Class*)
00434 {
00435   RPCStatus rpc_status;
00436   Data temp;
00437 
00438   if (!idr)
00439     {
00440       temp = (unsigned char *)malloc(hdr->size);
00441       object_header_code_head(temp, hdr);
00442       rpc_status = objectRead(db->getDbHandle(), temp, 0, 0, oid->getOid(),
00443                                   0, lockmode, 0);
00444     }
00445   else
00446     {
00447       temp = idr;
00448       rpc_status = RPCSuccess;
00449     }
00450 
00451   if (rpc_status == RPCSuccess)
00452     {
00453       eyedblib::int16 code;
00454       Offset offset;
00455       char *s;
00456 
00457       /*
00458       eyedblib::int32 mag_order;
00459       offset = IDB_CLASS_MAG_ORDER;
00460       int32_decode (temp, &offset, &mag_order);
00461       */
00462 
00463       IndexImpl *idximpl;
00464       offset = IDB_CLASS_IMPL_TYPE;
00465       Status status = IndexImpl::decode(db, temp, offset, idximpl);
00466       if (status) return status;
00467 
00468       int mt;
00469       offset = IDB_CLASS_MTYPE;
00470       int32_decode (temp, &offset, &mt);
00471 
00472       eyedblib::int16 dspid;
00473       offset = IDB_CLASS_DSPID;
00474       int16_decode (temp, &offset, &dspid);
00475 
00476       offset = IDB_CLASS_HEAD_SIZE;
00477       status = class_name_decode(db->getDbHandle(), temp, &offset, &s);
00478       if (status) return status;
00479       int16_decode(temp, &offset, &code);
00480 
00481       *o = db->getSchema()->getClass(s);
00482       free(s); s = 0;
00483       (*o)->asClass()->setExtentImplementation(idximpl, True);
00484       if (idximpl)
00485         idximpl->release();
00486       (*o)->asClass()->setInstanceDspid(dspid);
00487 
00488       ClassPeer::setMType((Class *)*o, (Class::MType)mt);
00489 
00490       status = ClassPeer::makeColls(db, (Class *)*o, temp);
00491 
00492       if (status)
00493         {
00494           if (!idr)
00495             delete temp;
00496           return status;
00497         }
00498     }
00499 
00500   if (!idr)
00501     {
00502       if (!rpc_status)
00503         ObjectPeer::setIDR(*o, temp, hdr->size);
00504     }
00505   return StatusMake(rpc_status);
00506 }
00507 
00508 //
00509 // Basic
00510 // 
00511 
00512 Status Basic::create()
00513 {
00514   abort();
00515   return Success;
00516 }
00517 
00518 Status Basic::update()
00519 {
00520   return Success;
00521 }
00522 
00523 Status Basic::remove(const RecMode*)
00524 {
00525   return Success;
00526 }
00527 
00528 Basic::Basic(Database *_db, const Dataspace *_dataspace) :
00529   Instance(_db, _dataspace)
00530 {
00531 }
00532 
00533 Basic::Basic(const Basic *o) : Instance(o)
00534 {
00535 }
00536 
00537 Basic::Basic(const Basic &o) : Instance(o)
00538 {
00539 }
00540 
00541 void Basic::init(void)
00542 {
00543   ObjectPeer::setUnrealizable(Char_Class, True);
00544   ObjectPeer::setUnrealizable(Byte_Class, True);
00545   ObjectPeer::setUnrealizable(OidP_Class, True);
00546   ObjectPeer::setUnrealizable(Int16_Class, True);
00547   ObjectPeer::setUnrealizable(Int32_Class, True);
00548   ObjectPeer::setUnrealizable(Int64_Class, True);
00549   ObjectPeer::setUnrealizable(Float_Class, True);
00550 }
00551 
00552 void Basic::_release(void)
00553 {
00554   Char_Class->release();
00555   Byte_Class->release();
00556   OidP_Class->release();
00557   Int16_Class->release();
00558   Int32_Class->release();
00559   Int64_Class->release();
00560   Float_Class->release();
00561   Bool_Class->release();
00562 }
00563 
00564 Status
00565 basicMake(Database *db, const Oid *oid, Object **o,
00566               const RecMode *rcm, const ObjectHeader *hdr,
00567               Data idr, LockMode lockmode, const Class *_class)
00568 {
00569   RPCStatus rpc_status;
00570   BasicClass *cls = (BasicClass *)_class;
00571 
00572   if (!cls)
00573     cls = (BasicClass *)db->getSchema()->getClass(hdr->oid_cl);
00574 
00575   if (!cls)
00576     return Exception::make(IDB_CLASS_NOT_FOUND, "basic class '%s'",
00577                          OidGetString(&hdr->oid_cl));
00578 
00579   if (idr && !ObjectPeer::isRemoved(*hdr))
00580     *o = cls->newObj(idr + IDB_OBJ_HEAD_SIZE, False);
00581   else
00582     *o = cls->newObj();
00583 
00584   Status status = (*o)->setDatabase(db);
00585 
00586   if (status)
00587     return status;
00588 
00589   if (idr)
00590     rpc_status = RPCSuccess;
00591   else
00592     rpc_status = objectRead(db->getDbHandle(), (*o)->getIDR(), 0, 0,
00593                                 oid->getOid(), 0, lockmode, 0);
00594 
00595   return StatusMake(rpc_status);
00596 }
00597 
00598 Status
00599 basic_class_trace(FILE *fd, int indent, unsigned int flags, const char *name,
00600                     const char *oid_str)
00601 {
00602   char *indent_str = make_indent(indent);
00603   fprintf(fd, "%s %s : basic_class : class : object {\n", oid_str, name);
00604   fprintf(fd, "%s<abstract class>;\n};\n", indent_str);
00605   delete_indent(indent_str);
00606   return Success;
00607 }
00608 
00609 //
00610 // CharClass
00611 //
00612 
00613 Status CharClass::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
00614 {
00615   return Class::trace_realize(fd, indent, flags, rcm);
00616 }
00617 
00618 CharClass::CharClass(const CharClass &cl)
00619   : BasicClass(cl)
00620 {
00621 }
00622 
00623 CharClass &CharClass::operator=(const CharClass &cl)
00624 {
00625   this->BasicClass::operator=(cl);
00626   return *this;
00627 }
00628 
00629 Status CharClass::traceData(FILE *fd, int indent, Data inidata,
00630                                   Data data, TypeModifier *tmod) const
00631 {
00632   int i;
00633   if (data)
00634     {
00635       if (tmod)
00636         {
00637           if (tmod->ndims == 1)
00638             fprintf(fd, "\"%s\"", (char *)data);
00639           else if (tmod->ndims > 1) {
00640             eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(char),
00641                         print_char_data);
00642           }
00643           else
00644             fprintf(fd, "'%c'",  *(char *)data);
00645         }
00646       else
00647         fprintf(fd, "'%c'",  *(char *)data);
00648     }
00649   else
00650     fprintf(fd, "''");
00651 
00652   return Success;
00653 }
00654 #define MetaB
00655 CharClass::CharClass(Database *_db) : BasicClass(_db, char_class_name)
00656 {
00657   code = CharClass_Code;
00658 #ifdef MetaB
00659   setClass(BasicClass_Class);
00660   parent = Basic_Class;
00661 #else
00662   setClass(Basic_Class);
00663   parent = Basic_Class;
00664 #endif
00665 
00666   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(char);
00667   idr_psize = idr_objsz;
00668   idr_vsize = 0;
00669 }
00670 
00671 Object *CharClass::newObj(Database *_db) const
00672 {
00673   Object *o = new Char(_db);
00674   ObjectPeer::setClass(o, this);
00675   return o;
00676 }
00677 
00678 Object *CharClass::newObj(Data data, Bool) const
00679 {
00680   return new Char(* (char *)data);
00681 }
00682 
00683 void
00684 CharClass::decode(void * hdata, // to
00685                      const void * xdata, // from
00686                      Size incsize, // temporarely necessary 
00687                      unsigned int nb) const
00688 {
00689   Class::decode(hdata, xdata, incsize, nb);
00690 }
00691 
00692 
00693 void
00694 CharClass::encode(void * xdata, // to
00695                      const void * hdata, // from
00696                      Size incsize, // temporarely necessary 
00697                      unsigned int nb) const
00698 {
00699   Class::encode(xdata, hdata, incsize, nb);
00700 }
00701 
00702 int
00703 CharClass::cmp(const void * xdata,
00704                   const void * hdata,
00705                   Size incsize, // temporarely necessary 
00706                   unsigned int nb) const
00707 {
00708   return Class::cmp(hdata, xdata, incsize, nb);
00709 }
00710 
00711 //
00712 // Int16Class
00713 //
00714 
00715 Int16Class::Int16Class(Database *_db) : BasicClass(_db, int16_class_name)
00716 {
00717   setAliasName("short");
00718   code = Int16Class_Code;
00719 #ifdef MetaB
00720   setClass(BasicClass_Class);
00721   parent = Basic_Class;
00722 #else
00723   setClass(Basic_Class);
00724   parent = Basic_Class;
00725 #endif
00726   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(eyedblib::int16);
00727   idr_psize = idr_objsz;
00728   idr_vsize = 0;
00729 }
00730 
00731 Int16Class::Int16Class(const Int16Class &cl)
00732   : BasicClass(cl)
00733 {
00734 }
00735 
00736 Int16Class &Int16Class::operator=(const Int16Class &cl)
00737 {
00738   this->BasicClass::operator=(cl);
00739   return *this;
00740 }
00741 
00742 Object *Int16Class::newObj(Database *_db) const
00743 {
00744   return new Int16(_db);
00745 }
00746 
00747 Object *Int16Class::newObj(Data data, Bool) const
00748 {
00749 #ifdef E_XDR
00750   eyedblib::int16 l;
00751   x2h_16_cpy(&l, data);
00752   //Offset offset = 0;
00753   //  xdr_int16_decode(data, &offset, &l);
00754   return new Int16(l);
00755 #else
00756   return new Int16(* (eyedblib::int16 *)data);
00757 #endif
00758 }
00759 
00760 Status Int16Class::traceData(FILE *fd, int indent, Data inidata,
00761                                    Data data, TypeModifier *tmod) const
00762 {
00763   int i;
00764   if (data)
00765     {
00766       eyedblib::int16 j;
00767       if (tmod)
00768         {
00769           if (tmod->pdims > 1)
00770             {
00771               eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(eyedblib::int16),
00772                           print_int16_data);
00773             }
00774           else
00775             {
00776               /*
00777               memcpy(&j, data, sizeof(eyedblib::int16));
00778               fprintf(fd, "%d", j);
00779               */
00780               print_int16_data(fd, data);
00781             }
00782         }
00783       else
00784         {
00785           /*
00786           memcpy(&j, data, sizeof(eyedblib::int16));
00787           fprintf(fd, "%d", j);
00788           */
00789           print_int16_data(fd, data);
00790         }
00791     }
00792   else
00793     fprintf(fd, "''");
00794 
00795   return Success;
00796 }
00797 
00798 Status Int16Class::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
00799 {
00800   return Class::trace_realize(fd, indent, flags, rcm);
00801 }
00802 
00803 void
00804 Int16Class::decode(void * hdata, // to
00805                       const void * xdata, // from
00806                       Size incsize, // temporarely necessary 
00807                       unsigned int nb) const
00808 {
00809 #ifdef E_XDR_TRACE
00810   std::cout << "Int16Class::decode " << name << std::endl;
00811 #endif
00812   CHECK_INCSIZE("decode", incsize, sizeof(eyedblib::int16));
00813 
00814   if (nb == 1) {
00815     x2h_16_cpy(hdata, xdata);
00816     return;
00817   }
00818 
00819   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int16))
00820     x2h_16_cpy((char *)hdata + inc, (char *)xdata + inc);
00821 }
00822 
00823 
00824 void
00825 Int16Class::encode(void * xdata, // to
00826                       const void * hdata, // from
00827                       Size incsize, // temporarely necessary 
00828                       unsigned int nb) const
00829 {
00830 #ifdef E_XDR_TRACE
00831   std::cout << "Int16Class::encode " << name << std::endl;
00832 #endif
00833   CHECK_INCSIZE("encode", incsize, sizeof(eyedblib::int16));
00834 
00835   if (nb == 1) {
00836     h2x_16_cpy(xdata, hdata);
00837     return;
00838   }
00839 
00840   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int16))
00841     h2x_16_cpy((char *)xdata + inc, (char *)hdata + inc);
00842 }
00843 
00844 int
00845 Int16Class::cmp(const void * xdata,
00846                    const void * hdata,
00847                    Size incsize, // temporarely necessary 
00848                    unsigned int nb) const
00849 {
00850 #ifdef E_XDR_TRACE
00851   std::cout << "Int16Class::cmp " << name;
00852 #endif
00853   CHECK_INCSIZE("cmp", incsize, sizeof(eyedblib::int16));
00854 
00855   if (nb == 1) {
00856     eyedblib::int16 l;
00857     x2h_16_cpy(&l, xdata);
00858     int r = memcmp(&l, hdata, sizeof(eyedblib::int16));
00859 #ifdef E_XDR_TRACE
00860     std::cout << " -> " << r << std::endl;
00861 #endif
00862     return r;
00863   }
00864 
00865   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int16)) {
00866     eyedblib::int16 l;
00867     x2h_16_cpy(&l, (char *)xdata + inc);
00868     int r = memcmp(&l, (char *)hdata + inc, sizeof(eyedblib::int16));
00869     if (r)
00870       return r;
00871   }
00872 
00873   return 0;
00874 }
00875 
00876 //
00877 // Int32Class
00878 //
00879 
00880 Int32Class::Int32Class(Database *_db) : BasicClass(_db, int32_class_name)
00881 {
00882   setAliasName("int");
00883   code = Int32Class_Code;
00884 #ifdef MetaB
00885   setClass(BasicClass_Class);
00886   parent = Basic_Class;
00887 #else
00888   setClass(Basic_Class);
00889   parent = Basic_Class;
00890 #endif
00891   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(eyedblib::int32);
00892   idr_psize = idr_objsz;
00893   idr_vsize = 0;
00894 }
00895 
00896 Int32Class::Int32Class(const Int32Class &cl)
00897   : BasicClass(cl)
00898 {
00899 }
00900 
00901 Int32Class &Int32Class::operator=(const Int32Class &cl)
00902 {
00903   this->BasicClass::operator=(cl);
00904   return *this;
00905 }
00906 
00907 Object *Int32Class::newObj(Database *_db) const
00908 {
00909   return new Int32(_db);
00910 }
00911 
00912 Object *Int32Class::newObj(Data data, Bool) const
00913 {
00914 #ifdef E_XDR
00915   eyedblib::int32 l;
00916   x2h_32_cpy(&l, data);
00917   //Offset offset = 0;
00918   //  xdr_int32_decode(data, &offset, &l);
00919   return new Int32(l);
00920 #else
00921   return new Int32(* (eyedblib::int32 *)data);
00922 #endif
00923 }
00924 
00925 Status Int32Class::traceData(FILE *fd, int indent, Data inidata,
00926                                    Data data, TypeModifier *tmod) const
00927 {
00928   int i, j, k;
00929   if (data)
00930     {
00931       eyedblib::int32 n;
00932       if (tmod)
00933         {
00934           if (tmod->pdims > 1)
00935             {
00936               eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(eyedblib::int32),
00937                           print_int32_data);
00938             }
00939           else
00940             {
00941               /*
00942               memcpy(&n, data, sizeof(eyedblib::int32));
00943               fprintf(fd, "%d", n);
00944               */
00945               print_int32_data(fd, data);
00946             }
00947         }
00948       else
00949         {
00950           /*
00951           memcpy(&n, data, sizeof(eyedblib::int32));
00952           fprintf(fd, "%d", n);
00953           */
00954           print_int16_data(fd, data);
00955         }
00956     }
00957   else
00958     fprintf(fd, "''");
00959 
00960   return Success;
00961 }
00962 
00963 Status Int32Class::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
00964 {
00965   return Class::trace_realize(fd, indent, flags, rcm);
00966 }
00967 
00968 void
00969 Int32Class::decode(void * hdata, // to
00970                       const void * xdata, // from
00971                       Size incsize, // temporarely necessary 
00972                       unsigned int nb) const
00973 {
00974 #ifdef E_XDR_TRACE
00975   std::cout << "Int32Class::decode " << name << std::endl;
00976 #endif
00977   CHECK_INCSIZE("decode", incsize, sizeof(eyedblib::int32));
00978 
00979   if (nb == 1) {
00980     x2h_32_cpy(hdata, xdata);
00981     return;
00982   }
00983 
00984   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int32))
00985     x2h_32_cpy((char *)hdata + inc, (char *)xdata + inc);
00986 }
00987 
00988 
00989 void
00990 Int32Class::encode(void * xdata, // to
00991                       const void * hdata, // from
00992                       Size incsize, // temporarely necessary 
00993                       unsigned int nb) const
00994 {
00995 #ifdef E_XDR_TRACE
00996   std::cout << "Int32Class::encode " << name << std::endl;
00997 #endif
00998   CHECK_INCSIZE("encode", incsize, sizeof(eyedblib::int32));
00999 
01000   if (nb == 1) {
01001     h2x_32_cpy(xdata, hdata);
01002     return;
01003   }
01004 
01005   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int32))
01006     h2x_32_cpy((char *)xdata + inc, (char *)hdata + inc);
01007 }
01008 
01009 int
01010 Int32Class::cmp(const void * xdata,
01011                    const void * hdata,
01012                    Size incsize, // temporarely necessary 
01013                    unsigned int nb) const
01014 {
01015 #ifdef E_XDR_TRACE
01016   std::cout << "Int32Class::cmp " << name;
01017 #endif
01018   CHECK_INCSIZE("cmp", incsize, sizeof(eyedblib::int32));
01019 
01020   if (nb == 1) {
01021     eyedblib::int32 l;
01022     x2h_32_cpy(&l, xdata);
01023     int r = memcmp(&l, hdata, sizeof(eyedblib::int32));
01024 #ifdef E_XDR_TRACE
01025     std::cout << " -> " << r << std::endl;
01026 #endif
01027     return r;
01028   }
01029 
01030   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int32)) {
01031     eyedblib::int32 l;
01032     x2h_32_cpy(&l, (char *)xdata + inc);
01033     int r = memcmp(&l, (char *)hdata + inc, sizeof(eyedblib::int32));
01034     if (r)
01035       return r;
01036   }
01037 
01038   return 0;
01039 }
01040 
01041 //
01042 // Int64Class
01043 //
01044 
01045 Int64Class::Int64Class(Database *_db) : BasicClass(_db, int64_class_name)
01046 {
01047   setAliasName("long");
01048 
01049   code = Int64Class_Code;
01050 #ifdef MetaB
01051   setClass(BasicClass_Class);
01052   parent = Basic_Class;
01053 #else
01054   setClass(Basic_Class);
01055   parent = Basic_Class;
01056 #endif
01057   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(eyedblib::int64);
01058   idr_psize = idr_objsz;
01059   idr_vsize = 0;
01060 }
01061 
01062 Int64Class::Int64Class(const Int64Class &cl)
01063   : BasicClass(cl)
01064 {
01065 }
01066 
01067 Int64Class &Int64Class::operator=(const Int64Class &cl)
01068 {
01069   this->BasicClass::operator=(cl);
01070   return *this;
01071 }
01072 
01073 Object *Int64Class::newObj(Database *_db) const
01074 {
01075   return new Int64(_db);
01076 }
01077 
01078 Object *Int64Class::newObj(Data data, Bool) const
01079 {
01080 #ifdef E_XDR
01081   eyedblib::int64 l;
01082   // called when loaded from DB, eyedboql:
01083   // i := new int64(123);
01084   // \p (i.e. loading)
01085   // i->toString(); (i.e. loading)
01086 
01087   x2h_64_cpy(&l, data);
01088   //Offset offset = 0;
01089   //xdr_int64_decode(pdata, &offset, &l);
01090   return new Int64(l);
01091 #else
01092   return new Int64(* (eyedblib::int64 *)data);
01093 #endif
01094 }
01095 
01096 Status Int64Class::traceData(FILE *fd, int indent, Data inidata,
01097                                    Data data, TypeModifier *tmod) const
01098 {
01099   int i, j, k;
01100   if (data)
01101     {
01102       eyedblib::int64 n;
01103       if (tmod)
01104         {
01105           if (tmod->pdims > 1) {
01106             eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(eyedblib::int64),
01107                         print_int64_data);
01108           }
01109           else {
01110             /*
01111             memcpy(&n, data, sizeof(eyedblib::int64));
01112             fprintf(fd, "%lld", n);
01113             */
01114             print_int64_data(fd, data);
01115           }
01116         }
01117       else {
01118         /*
01119         memcpy(&n, data, sizeof(eyedblib::int64));
01120         fprintf(fd, "%lld", n);
01121         */
01122         print_int64_data(fd, data);
01123       }
01124     }
01125   else
01126     fprintf(fd, "''");
01127 
01128   return Success;
01129 }
01130 
01131 Status Int64Class::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
01132 {
01133   return Class::trace_realize(fd, indent, flags, rcm);
01134 }
01135 
01136 void
01137 Int64Class::decode(void * hdata, // to
01138                       const void * xdata, // from
01139                       Size incsize, // temporarely necessary 
01140                       unsigned int nb) const
01141 {
01142 #ifdef E_XDR_TRACE
01143   std::cout << "Int64Class::decode " << name << std::endl;
01144 #endif
01145   CHECK_INCSIZE("decode", incsize, sizeof(eyedblib::int64));
01146 
01147   if (nb == 1) {
01148     x2h_64_cpy(hdata, xdata);
01149     return;
01150   }
01151 
01152   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int64))
01153     x2h_64_cpy((char *)hdata + inc, (char *)xdata + inc);
01154 }
01155 
01156 
01157 void
01158 Int64Class::encode(void * xdata, // to
01159                       const void * hdata, // from
01160                       Size incsize, // temporarely necessary 
01161                       unsigned int nb) const
01162 {
01163 #ifdef E_XDR_TRACE
01164   std::cout << "Int64Class::encode " << name << std::endl;
01165 #endif
01166   CHECK_INCSIZE("encode", incsize, sizeof(eyedblib::int64));
01167 
01168   if (nb == 1) {
01169     h2x_64_cpy(xdata, hdata);
01170     return;
01171   }
01172 
01173   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int64))
01174     h2x_64_cpy((char *)xdata + inc, (char *)hdata + inc);
01175 }
01176 
01177 int
01178 Int64Class::cmp(const void * xdata,
01179                    const void * hdata,
01180                    Size incsize, // temporarely necessary 
01181                    unsigned int nb) const
01182 {
01183 #ifdef E_XDR_TRACE
01184   std::cout << "Int64Class::cmp " << name;
01185 #endif
01186   CHECK_INCSIZE("cmp", incsize, sizeof(eyedblib::int64));
01187 
01188   if (nb == 1) {
01189     eyedblib::int64 l;
01190     x2h_64_cpy(&l, xdata);
01191     int r = memcmp(&l, hdata, sizeof(eyedblib::int64));
01192 #ifdef E_XDR_TRACE
01193     std::cout << " -> " << r << std::endl;
01194 #endif
01195     return r;
01196   }
01197 
01198   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::int64)) {
01199     eyedblib::int64 l;
01200     x2h_64_cpy(&l, (char *)xdata + inc);
01201     int r = memcmp(&l, (char *)hdata + inc, sizeof(eyedblib::int64));
01202     if (r)
01203       return r;
01204   }
01205 
01206   return 0;
01207 }
01208 
01209 //
01210 // ByteClass
01211 //
01212 
01213 ByteClass::ByteClass(Database *_db) : BasicClass(_db, "byte")
01214 {
01215   code = ByteClass_Code;
01216 #ifdef MetaB
01217   setClass(BasicClass_Class);
01218   parent = Basic_Class;
01219 #else
01220   setClass(Basic_Class);
01221   parent = Basic_Class;
01222 #endif
01223   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(unsigned char);
01224   idr_psize = idr_objsz;
01225   idr_vsize = 0;
01226 }
01227 
01228 Object *ByteClass::newObj(Database *_db) const
01229 {
01230   return new Byte(_db);
01231 }
01232 
01233 Object *ByteClass::newObj(Data data, Bool) const
01234 {
01235   return new Byte(* (unsigned char *)data);
01236 }
01237 
01238 ByteClass::ByteClass(const ByteClass &cl)
01239   : BasicClass(cl)
01240 {
01241 }
01242 
01243 ByteClass &ByteClass::operator=(const ByteClass &cl)
01244 {
01245   this->BasicClass::operator=(cl);
01246   return *this;
01247 }
01248 
01249 Status ByteClass::traceData(FILE *fd, int indent, Data inidata,
01250                                   Data data, TypeModifier *tmod) const
01251 {
01252   int i;
01253   if (data)
01254     {
01255       unsigned char j;
01256       if (tmod)
01257         {
01258           if (tmod->pdims > 1)
01259             {
01260               eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(unsigned char),
01261                           print_byte_data);
01262             }
01263           else
01264             {
01265               memcpy(&j, data, sizeof(unsigned char));
01266               fprintf(fd, "\\%03o", j);
01267             }
01268         }
01269       else
01270         {
01271           memcpy(&j, data, sizeof(unsigned char));
01272           fprintf(fd, "\\%03o", j);
01273         }
01274     }
01275   else
01276     fprintf(fd, "''");
01277 
01278   return Success;
01279 }
01280 
01281 Status ByteClass::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
01282 {
01283   return Class::trace_realize(fd, indent, flags, rcm);
01284 }
01285 
01286 void
01287 ByteClass::decode(void * hdata, // to
01288                      const void * xdata, // from
01289                      Size incsize, // temporarely necessary 
01290                      unsigned int nb) const
01291 {
01292   Class::decode(hdata, xdata, incsize, nb);
01293 }
01294 
01295 
01296 void
01297 ByteClass::encode(void * xdata, // to
01298                      const void * hdata, // from
01299                      Size incsize, // temporarely necessary 
01300                      unsigned int nb) const
01301 {
01302   Class::encode(xdata, hdata, incsize, nb);
01303 }
01304 
01305 int
01306 ByteClass::cmp(const void * xdata,
01307                   const void * hdata,
01308                   Size incsize, // temporarely necessary 
01309                   unsigned int nb) const
01310 {
01311   return Class::cmp(hdata, xdata, incsize, nb);
01312 }
01313 
01314 //
01315 // FloatClass
01316 //
01317 
01318 FloatClass::FloatClass(Database *_db) : BasicClass(_db, "float")
01319 {
01320   code = FloatClass_Code;
01321 #ifdef MetaB
01322   setClass(BasicClass_Class);
01323   parent = Basic_Class;
01324 #else
01325   setClass(Basic_Class);
01326   parent = Basic_Class;
01327 #endif
01328   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(double);
01329   idr_psize = idr_objsz;
01330   idr_vsize = 0;
01331 }
01332 
01333 FloatClass::FloatClass(const FloatClass &cl)
01334   : BasicClass(cl)
01335 {
01336 }
01337 
01338 FloatClass &FloatClass::operator=(const FloatClass &cl)
01339 {
01340   this->BasicClass::operator=(cl);
01341   return *this;
01342 }
01343 
01344 Object *FloatClass::newObj(Database *_db) const
01345 {
01346   return new Float(_db);
01347 }
01348 
01349 Object *FloatClass::newObj(Data data, Bool) const
01350 {
01351 #ifdef E_XDR
01352   double d;
01353   x2h_f64_cpy(&d, data);
01354   //Offset offset = 0;
01355   //xdr_double_decode(data, &offset, &d);
01356   return new Float(d);
01357 #else
01358   double d;
01359   memcpy(&d, data, sizeof(double));
01360   return new Float(d);
01361 #endif
01362 }
01363 
01364 Status FloatClass::traceData(FILE *fd, int indent, Data inidata,
01365                                    Data data, TypeModifier *tmod) const
01366 {
01367   int i;
01368   if (data)
01369     {
01370       double j;
01371       if (tmod)
01372         {
01373           if (tmod->pdims > 1)
01374             {
01375               eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(double),
01376                           print_float_data);
01377             }
01378           else
01379             {
01380               /*
01381               memcpy(&j, data, sizeof(double));
01382               fprint_float(fd, j);
01383               */
01384               print_xdr_float_data(fd, data);
01385             }
01386         }
01387       else {
01388         /*
01389           memcpy(&j, data, sizeof(double));
01390           fprint_float(fd, j);
01391         */
01392         print_xdr_float_data(fd, data);
01393       }
01394     }
01395   else
01396     fprintf(fd, "''");
01397 
01398   return Success;
01399 }
01400 
01401 Status FloatClass::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
01402 {
01403   return Class::trace_realize(fd, indent, flags, rcm);
01404 }
01405 
01406 void
01407 FloatClass::decode(void * hdata, // to
01408                       const void * xdata, // from
01409                       Size incsize, // temporarely necessary 
01410                       unsigned int nb) const
01411 {
01412 #ifdef E_XDR_TRACE
01413   std::cout << "FloatClass::decode " << name << std::endl;
01414 #endif
01415   CHECK_INCSIZE("decode", incsize, sizeof(eyedblib::float64));
01416 
01417   if (nb == 1) {
01418     x2h_f64_cpy(hdata, xdata);
01419     return;
01420   }
01421 
01422   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::float64))
01423     x2h_f64_cpy((char *)hdata + inc, (char *)xdata + inc);
01424 }
01425 
01426 
01427 void
01428 FloatClass::encode(void * xdata, // to
01429                       const void * hdata, // from
01430                       Size incsize, // temporarely necessary 
01431                       unsigned int nb) const
01432 {
01433 #ifdef E_XDR_TRACE
01434   std::cout << "FloatClass::encode " << name << std::endl;
01435 #endif
01436   CHECK_INCSIZE("encode", incsize, sizeof(eyedblib::float64));
01437 
01438   if (nb == 1) {
01439     h2x_f64_cpy(xdata, hdata);
01440     return;
01441   }
01442 
01443   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::float64))
01444     h2x_f64_cpy((char *)xdata + inc, (char *)hdata + inc);
01445 }
01446 
01447 int
01448 FloatClass::cmp(const void * xdata,
01449                    const void * hdata,
01450                    Size incsize, // temporarely necessary 
01451                    unsigned int nb) const
01452 {
01453 #ifdef E_XDR_TRACE
01454   std::cout << "FloatClass::cmp " << name;
01455 #endif
01456   CHECK_INCSIZE("cmp", incsize, sizeof(eyedblib::float64));
01457 
01458   if (nb == 1) {
01459     eyedblib::float64 l;
01460     x2h_f64_cpy(&l, xdata);
01461     int r = memcmp(&l, hdata, sizeof(eyedblib::float64));
01462 #ifdef E_XDR_TRACE
01463     std::cout << " -> " << r << std::endl;
01464 #endif
01465     return r;
01466   }
01467 
01468   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedblib::float64)) {
01469     eyedblib::float64 l;
01470     x2h_f64_cpy(&l, (char *)xdata + inc);
01471     int r = memcmp(&l, (char *)hdata + inc, sizeof(eyedblib::float64));
01472     if (r)
01473       return r;
01474   }
01475 
01476   return 0;
01477 }
01478 
01479 //
01480 // OidClass
01481 //
01482 
01483 OidClass::OidClass(Database *_db) : BasicClass(_db, "oid")
01484 {
01485   code = OidPClass_Code;
01486 #ifdef MetaB
01487   setClass(BasicClass_Class);
01488   parent = Basic_Class;
01489 #else
01490   setClass(Basic_Class);
01491   parent = Basic_Class;
01492 #endif
01493   idr_objsz = IDB_OBJ_HEAD_SIZE + sizeof(Oid);
01494   idr_psize = idr_objsz;
01495   idr_vsize = 0;
01496 }
01497 
01498 OidClass::OidClass(const OidClass &cl)
01499   : BasicClass(cl)
01500 {
01501 }
01502 
01503 OidClass &OidClass::operator=(const OidClass &cl)
01504 {
01505   this->BasicClass::operator=(cl);
01506   return *this;
01507 }
01508 
01509 Object *OidClass::newObj(Database *_db) const
01510 {
01511   return new OidP(_db);
01512 }
01513 
01514 Object *OidClass::newObj(Data data, Bool) const
01515 {
01516 #ifdef E_XDR
01517   Oid _oid;
01518   eyedbsm::x2h_oid(_oid.getOid(), data);
01519   //Offset offset = 0;
01520   //xdr_oid_decode(data, &offset, _oid.getOid());
01521   return new OidP(&_oid);
01522 #else
01523   Oid _oid;
01524   memcpy(&_oid, data, sizeof(Oid));
01525   return new OidP(&_oid);
01526 #endif
01527 }
01528 
01529 Status OidClass::traceData(FILE *fd, int indent, Data inidata,
01530                                   Data data, TypeModifier *tmod) const
01531 {
01532   int i;
01533   if (data)
01534     {
01535       Oid j;
01536       if (tmod)
01537         {
01538           if (tmod->pdims > 1)
01539             {
01540               eyedb::traceData(fd, indent, inidata, data, tmod, sizeof(Oid),
01541                           print_oid_data);
01542             }
01543           else
01544             {
01545               /*
01546               memcpy(&j, data, sizeof(Oid));
01547               fprintf(fd, "%s", j.getString());
01548               */
01549               print_xdr_oid_data(fd, data);
01550             }
01551         }
01552       else
01553         {
01554           /*
01555           memcpy(&j, data, sizeof(Oid));
01556           fprintf(fd, "%s", j.getString());
01557           */
01558           print_xdr_oid_data(fd, data);
01559         }
01560     }
01561   else
01562     fprintf(fd, "''");
01563 
01564   return Success;
01565 }
01566 
01567 Status OidClass::trace_realize(FILE *fd, int indent, unsigned int flags, const RecMode *rcm) const
01568 {
01569   return Class::trace_realize(fd, indent, flags, rcm);
01570 }
01571 
01572 void
01573 OidClass::decode(void * hdata, // to
01574                     const void * xdata, // from
01575                     Size incsize, // temporarely necessary 
01576                     unsigned int nb) const
01577 {
01578 #ifdef E_XDR_TRACE
01579   std::cout << "OidClass::decode " << name << std::endl;
01580 #endif
01581   CHECK_INCSIZE("decode", incsize, sizeof(Oid));
01582 
01583   if (nb == 1) {
01584     eyedbsm::Oid hoid;
01585     eyedbsm::x2h_oid(&hoid, xdata);
01586     memcpy(hdata, &hoid, sizeof(hoid));
01587     return;
01588   }
01589 
01590   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(Oid)) {
01591     eyedbsm::Oid hoid;
01592     eyedbsm::x2h_oid(&hoid, (char *)xdata + inc);
01593     memcpy((char *)hdata + inc, &hoid, sizeof(hoid));
01594   }
01595 }
01596 
01597 
01598 void
01599 OidClass::encode(void * xdata, // to
01600                       const void * hdata, // from
01601                       Size incsize, // temporarely necessary 
01602                       unsigned int nb) const
01603 {
01604 #ifdef E_XDR_TRACE
01605   std::cout << "OidClass::encode " << name << std::endl;
01606 #endif
01607   CHECK_INCSIZE("encode", incsize, sizeof(Oid));
01608 
01609   if (nb == 1) {
01610     eyedbsm::Oid hoid;
01611     memcpy(&hoid, hdata, sizeof(hoid));
01612     eyedbsm::h2x_oid(xdata, &hoid);
01613     return;
01614   }
01615 
01616   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(Oid)) {
01617     eyedbsm::Oid hoid;
01618     memcpy(&hoid, (char *)hdata + inc, sizeof(hoid));
01619     eyedbsm::h2x_oid((char *)xdata + inc, &hoid);
01620   }
01621 }
01622 
01623 int
01624 OidClass::cmp(const void * xdata,
01625                  const void * hdata,
01626                  Size incsize, // temporarely necessary 
01627                  unsigned int nb) const
01628 {
01629 #ifdef E_XDR_TRACE
01630   std::cout << "OidClass::cmp " << name;
01631 #endif
01632   CHECK_INCSIZE("cmp", incsize, sizeof(Oid));
01633 
01634   if (nb == 1) {
01635     eyedbsm::Oid xoid;
01636     eyedbsm::x2h_oid(&xoid, xdata);
01637     int r = memcmp(&xoid, hdata, sizeof(xoid));
01638 #ifdef E_XDR_TRACE
01639     std::cout << " -> " << r << std::endl;
01640 #endif
01641     return r;
01642   }
01643 
01644   for (int n = 0, inc = 0; n < nb; n++, inc += sizeof(eyedbsm::Oid)) {
01645     eyedbsm::Oid xoid;
01646     eyedbsm::x2h_oid(&xoid, (char *)xdata + inc);
01647     int r = memcmp(&xoid, (char *)hdata + inc, sizeof(eyedbsm::Oid));
01648     if (r)
01649       return r;
01650   }
01651 
01652   return 0;
01653 }
01654 
01655 //
01656 // Char
01657 //
01658 
01659 Char::Char(char c) : Basic()
01660 {
01661   setClass(Char_Class);
01662   val = c;
01663 
01664   /*
01665   idr->idr_sz = cls->getIDRObjectSize();
01666   idr->idr = (unsigned char *)malloc(idr->idr_sz);
01667   */
01668   type = Basic_Type;
01669   idr->setIDR(getClass()->getIDRObjectSize());
01670 
01671   headerCode(_Basic_Type, idr->getSize());
01672 }
01673 
01674 Char::Char(Database *_db, char c, const Dataspace *_dataspace) : Basic(_db, _dataspace)
01675 {
01676   setClass(Char_Class);
01677   val = c;
01678 
01679   /*
01680   idr->idr_sz = cls->getIDRObjectSize();
01681   idr->idr = (unsigned char *)malloc(idr->idr_sz);
01682   */
01683   idr->setIDR(getClass()->getIDRObjectSize());
01684   type = Basic_Type;
01685 
01686   headerCode(_Basic_Type, idr->getSize());
01687 }
01688 
01689 Char::Char(const Char *o) : Basic(o)
01690 {
01691   val = (o ? o->val : 0);
01692 }
01693 
01694 Char::Char(const Char &o) : Basic(o)
01695 {
01696   val = o.val;
01697 }
01698 
01699 Char& Char::operator=(const Char& o)
01700 {
01701   if (&o == this)
01702     return *this;
01703 
01704   *(Basic *)this = Basic::operator=((const Basic &)o);
01705 
01706   val = o.val;
01707   return *this;
01708 }
01709 
01710 Status Char::setValue(Data data)
01711 {
01712   val = *(char *)data;
01713   return Success;
01714 }
01715 
01716 Status Char::getValue(Data* data) const
01717 {
01718   *data = (Data)&val;
01719   return Success;
01720 }
01721 
01722 Status Char::create()
01723 {
01724   if (oid.isValid())
01725     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating char");
01726 
01727   IDB_CHECK_WRITE(db);
01728 
01729   RPCStatus rpc_status;
01730   
01731   Offset offset;
01732   Size alloc_size;
01733 
01734   alloc_size = idr->getSize();
01735   offset = IDB_OBJ_HEAD_SIZE;
01736 
01737   Data data = idr->getIDR();
01738   char_code(&data, &offset, &alloc_size, &val);
01739 
01740   classOidCode();
01741   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(),
01742                                 data, oid.getOid());
01743 
01744   return StatusMake(rpc_status);
01745 }
01746 
01747 Status Char::update()
01748 {
01749   if (!oid.isValid()) /* && modify */
01750     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating char");
01751 
01752   IDB_CHECK_WRITE(db);
01753   RPCStatus rpc_status;
01754   
01755   Offset offset;
01756   Size alloc_size;
01757 
01758   alloc_size = idr->getSize();
01759   offset = IDB_OBJ_HEAD_SIZE;
01760 
01761   Data data = idr->getIDR();
01762   char_code(&data, &offset, &alloc_size, &val);
01763 
01764   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
01765 
01766   return Success;
01767 }
01768 
01769 Status Char::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
01770 {
01771   fprintf(fd, "%s char = ", oid.getString());
01772   return trace_realize(fd, INDENT_INC, flags, rcm);
01773 }
01774 
01775 Status Char::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
01776 {
01777   fprintf(fd, "'%c';\n", val);
01778   return Success;
01779 }
01780 
01781 //
01782 // Byte
01783 //
01784 
01785 Byte::Byte(unsigned char c) : Basic()
01786 {
01787   setClass(Byte_Class);
01788   val = c;
01789 
01790   /*
01791   idr->idr_sz = getClass()->getIDRObjectSize();
01792   idr->idr = (unsigned char *)malloc(idr->idr_sz);
01793   */
01794   idr->setIDR(getClass()->getIDRObjectSize());
01795   type = Basic_Type;
01796 
01797   headerCode(_Basic_Type, idr->getSize());
01798 }
01799 
01800 Byte::Byte(Database *_db, unsigned char c, const Dataspace *_dataspace) : Basic(_db, _dataspace)
01801 {
01802   setClass(Byte_Class);
01803   val = c;
01804 
01805   /*
01806   idr->idr_sz = getClass()->getIDRObjectSize();
01807   idr->idr = (unsigned char *)malloc(idr->idr_sz);
01808   */
01809   idr->setIDR(getClass()->getIDRObjectSize());
01810   type = Basic_Type;
01811 
01812   headerCode(_Basic_Type, idr->getSize());
01813 }
01814 
01815 Byte::Byte(const Byte *o) : Basic(o)
01816 {
01817   val = (o ? o->val : 0);
01818 }
01819 
01820 Byte::Byte(const Byte &o) : Basic(o)
01821 {
01822   val = o.val;
01823 }
01824 
01825 Byte& Byte::operator=(const Byte& o)
01826 {
01827   if (&o == this)
01828     return *this;
01829 
01830   *(Basic *)this = Basic::operator=((const Basic &)o);
01831 
01832   val = o.val;
01833   return *this;
01834 }
01835 
01836 Status Byte::setValue(Data data)
01837 {
01838   val = *(unsigned char *)data;
01839   return Success;
01840 }
01841 
01842 Status Byte::getValue(Data* data) const
01843 {
01844   *data = (Data)&val;
01845   return Success;
01846 }
01847 
01848 Status Byte::create()
01849 {
01850   if (oid.isValid())
01851     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating Byte");
01852 
01853   IDB_CHECK_WRITE(db);
01854 
01855   RPCStatus rpc_status;
01856   
01857   Offset offset;
01858   Size alloc_size;
01859 
01860   alloc_size = idr->getSize();
01861   offset = IDB_OBJ_HEAD_SIZE;
01862   Data data = idr->getIDR();
01863   char_code(&data, &offset, &alloc_size, (char *)&val);
01864 
01865   classOidCode();
01866   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(),
01867                                 data, oid.getOid());
01868 
01869   return StatusMake(rpc_status);
01870 }
01871 
01872 Status Byte::update()
01873 {
01874   if (!oid.isValid()) /* && modify */
01875     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating byte");
01876 
01877   IDB_CHECK_WRITE(db);
01878   RPCStatus rpc_status;
01879   
01880   Offset offset;
01881   Size alloc_size;
01882 
01883   alloc_size = idr->getSize();
01884   offset = IDB_OBJ_HEAD_SIZE;
01885 
01886   Data data = idr->getIDR();
01887   char_code(&data, &offset, &alloc_size, (char *)&val);
01888 
01889   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
01890 
01891   return Success;
01892 }
01893 
01894 Status Byte::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
01895 {
01896   fprintf(fd, "%s byte = ", oid.getString());
01897   return trace_realize(fd, INDENT_INC, flags, rcm);
01898 }
01899 
01900 Status Byte::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
01901 {
01902   fprintf(fd, "'\\%03o';\n", val);
01903   return Success;
01904 }
01905 
01906 //
01907 // Int16
01908 //
01909 
01910 Int16::Int16(eyedblib::int16 i) : Basic()
01911 {
01912   setClass(Int16_Class);
01913   val = i;
01914 
01915   /*
01916   idr->idr_sz = getClass()->getIDRObjectSize();
01917   idr->idr = (unsigned char *)malloc(idr->idr_sz);
01918   */
01919   idr->setIDR(getClass()->getIDRObjectSize());
01920 
01921   type = Basic_Type;
01922 
01923   headerCode(_Basic_Type, idr->getSize());
01924 }
01925 
01926 Int16::Int16(Database *_db, eyedblib::int16 i, const Dataspace *_dataspace) : Basic(_db, _dataspace)
01927 {
01928   setClass(Int16_Class);
01929   val = i;
01930 
01931   /*
01932   idr->idr_sz = getClass()->getIDRObjectSize();
01933   idr->idr = (unsigned char *)malloc(idr->idr_sz);
01934   */
01935   idr->setIDR(getClass()->getIDRObjectSize());
01936 
01937   type = Basic_Type;
01938 
01939   headerCode(_Basic_Type, idr->getSize());
01940 }
01941 
01942 Int16::Int16(const Int16 *o) : Basic(o)
01943 {
01944   val = (o ? o->val : 0);
01945 }
01946 
01947 Int16::Int16(const Int16 &o) : Basic(o)
01948 {
01949   val = o.val;
01950 }
01951 
01952 Int16& Int16::operator=(const Int16& o)
01953 {
01954   if (&o == this)
01955     return *this;
01956 
01957   *(Basic *)this = Basic::operator=((const Basic &)o);
01958 
01959   val = o.val;
01960   return *this;
01961 }
01962 
01963 Status Int16::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
01964 {
01965   fprintf(fd, "%s int16 = ", oid.getString());
01966   return trace_realize(fd, INDENT_INC, flags, rcm);
01967 }
01968 
01969 Status Int16::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
01970 {
01971   fprintf(fd, "%d;\n", val);
01972   return Success;
01973 }
01974 
01975 Status Int16::create()
01976 {
01977   if (oid.isValid())
01978     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating eyedblib::int16");
01979 
01980   IDB_CHECK_WRITE(db);
01981 
01982   RPCStatus rpc_status;
01983   
01984   Offset offset;
01985   Size alloc_size;
01986 
01987   alloc_size = idr->getSize();
01988   offset = IDB_OBJ_HEAD_SIZE;
01989 
01990   Data data = idr->getIDR();
01991   xdr_int16_code(&data, &offset, &alloc_size, &val);
01992 
01993   classOidCode();
01994   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(),
01995                                 data, oid.getOid());
01996 
01997   return StatusMake(rpc_status);
01998 }
01999 
02000 Status Int16::update()
02001 {
02002   if (!oid.isValid()) /* && modify */
02003     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating eyedblib::int16");
02004 
02005   IDB_CHECK_WRITE(db);
02006   RPCStatus rpc_status;
02007   
02008   Offset offset;
02009   Size alloc_size;
02010 
02011   alloc_size = idr->getSize();
02012   offset = IDB_OBJ_HEAD_SIZE;
02013 
02014   Data data = idr->getIDR();
02015   xdr_int16_code(&data, &offset, &alloc_size, &val);
02016 
02017   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
02018 
02019   return Success;
02020 }
02021 
02022 Status Int16::setValue(Data data)
02023 {
02024   memcpy(&val, data, sizeof(eyedblib::int16));
02025   return Success;
02026 }
02027 
02028 Status Int16::getValue(Data* data) const
02029 {
02030   *data = (Data)&val;
02031   return Success;
02032 }
02033 
02034 //
02035 // OidP
02036 //
02037 
02038 OidP::OidP(const Oid *_oid) : Basic()
02039 {
02040   setClass(OidP_Class);
02041 
02042   if (_oid)
02043     val = *_oid;
02044 
02045   /*
02046   idr->idr_sz = getClass()->getIDRObjectSize();
02047   idr->idr = (unsigned char *)malloc(idr->idr_sz);
02048   */
02049   idr->setIDR(getClass()->getIDRObjectSize());
02050 
02051   type = Basic_Type;
02052 
02053   headerCode(_Basic_Type, idr->getSize());
02054 }
02055 
02056 OidP::OidP(Database *_db, const Oid *_oid, const Dataspace *_dataspace) : Basic(_db, _dataspace)
02057 {
02058   setClass(OidP_Class);
02059 
02060   if (_oid)
02061     val = *_oid;
02062 
02063   /*
02064   idr->idr_sz = getClass()->getIDRObjectSize();
02065   idr->idr = (unsigned char *)malloc(idr->idr_sz);
02066   */
02067   idr->setIDR(getClass()->getIDRObjectSize());
02068 
02069   type = Basic_Type;
02070 
02071   headerCode(_Basic_Type, idr->getSize());
02072 }
02073 
02074 OidP::OidP(const OidP *o) : Basic(o)
02075 {
02076   if (o)
02077     val = o->val;
02078 }
02079 
02080 OidP::OidP(const OidP &o) : Basic(o)
02081 {
02082   val = o.val;
02083 }
02084 
02085 OidP& OidP::operator=(const OidP& o)
02086 {
02087   if (&o == this)
02088     return *this;
02089 
02090   *(Basic *)this = Basic::operator=((const Basic &)o);
02091 
02092   val = o.val;
02093   return *this;
02094 }
02095 
02096 Status OidP::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
02097 {
02098   fprintf(fd, "%s oid = ", oid.getString());
02099   return trace_realize(fd, INDENT_INC, flags, rcm);
02100 }
02101 
02102 Status OidP::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
02103 {
02104   fprintf(fd, "%s;\n", val.getString());
02105   return Success;
02106 }
02107 
02108 Status OidP::create()
02109 {
02110   if (oid.isValid())
02111     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating OidP");
02112 
02113   IDB_CHECK_WRITE(db);
02114   RPCStatus rpc_status;
02115   
02116   Offset offset;
02117   Size alloc_size;
02118 
02119   alloc_size = idr->getSize();
02120   offset = IDB_OBJ_HEAD_SIZE;
02121 
02122   Data data = idr->getIDR();
02123   xdr_oid_code(&data, &offset, &alloc_size, val.getOid());
02124 
02125   classOidCode();
02126   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(), data, oid.getOid());
02127 
02128   return StatusMake(rpc_status);
02129 }
02130 
02131 Status OidP::update()
02132 {
02133   if (!oid.isValid()) /* && modify */
02134     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating OidP");
02135 
02136   IDB_CHECK_WRITE(db);
02137   RPCStatus rpc_status;
02138   
02139   Offset offset;
02140   Size alloc_size;
02141 
02142   alloc_size = idr->getSize();
02143   offset = IDB_OBJ_HEAD_SIZE;
02144 
02145   Data data = idr->getIDR();
02146   xdr_oid_code(&data, &offset, &alloc_size, val.getOid());
02147 
02148   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
02149 
02150   return Success;
02151 }
02152 
02153 Status OidP::setValue(Data data)
02154 {
02155   memcpy(&val, data, sizeof(Oid));
02156   return Success;
02157 }
02158 
02159 Status OidP::getValue(Data* data) const
02160 {
02161   memcpy(data, &val, sizeof(Oid));
02162   return Success;
02163 }
02164 
02165 //
02166 // Int32
02167 //
02168 
02169 Int32::Int32(eyedblib::int32 i) : Basic()
02170 {
02171   setClass(Int32_Class);
02172   val = i;
02173 
02174   /*
02175   idr->idr_sz = getClass()->getIDRObjectSize();
02176   idr->idr = (unsigned char *)malloc(idr->idr_sz);
02177   */
02178   idr->setIDR(getClass()->getIDRObjectSize());
02179 
02180   type = Basic_Type;
02181 
02182   headerCode(_Basic_Type, idr->getSize());
02183 }
02184 
02185 Int32::Int32(Database *_db, eyedblib::int32 i, const Dataspace *_dataspace) : Basic(_db, _dataspace)
02186 {
02187   setClass(Int32_Class);
02188   val = i;
02189 
02190   /*
02191   idr->idr_sz = getClass()->getIDRObjectSize();
02192   idr->idr = (unsigned char *)malloc(idr->idr_sz);
02193   */
02194   idr->setIDR(getClass()->getIDRObjectSize());
02195 
02196   type = Basic_Type;
02197 
02198   headerCode(_Basic_Type, idr->getSize());
02199 }
02200 
02201 Int32::Int32(const Int32 *o) : Basic(o)
02202 {
02203   val = (o ? o->val : 0);
02204 }
02205 
02206 Int32::Int32(const Int32 &o) : Basic(o)
02207 {
02208   val = o.val;
02209 }
02210 
02211 Int32& Int32::operator=(const Int32& o)
02212 {
02213   if (&o == this)
02214     return *this;
02215 
02216   *(Basic *)this = Basic::operator=((const Basic &)o);
02217 
02218   val = o.val;
02219   return *this;
02220 }
02221 
02222 Status Int32::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
02223 {
02224   fprintf(fd, "%s int32 = ", oid.getString());
02225   return trace_realize(fd, INDENT_INC, flags, rcm);
02226 }
02227 
02228 Status Int32::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
02229 {
02230   fprintf(fd, "%d;\n", val);
02231   return Success;
02232 }
02233 
02234 Status Int32::create()
02235 {
02236   if (oid.isValid())
02237     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating eyedblib::int32");
02238 
02239   IDB_CHECK_WRITE(db);
02240 
02241   RPCStatus rpc_status;
02242   
02243   Offset offset;
02244   Size alloc_size;
02245 
02246   alloc_size = idr->getSize();
02247   offset = IDB_OBJ_HEAD_SIZE;
02248 
02249   Data data = idr->getIDR();
02250   xdr_int32_code(&data, &offset, &alloc_size, &val);
02251 
02252   classOidCode();
02253   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(), data, oid.getOid());
02254 
02255   return StatusMake(rpc_status);
02256 }
02257 
02258 Status Int32::update()
02259 {
02260   if (!oid.isValid()) /* && modify */
02261     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating eyedblib::int32");
02262 
02263   IDB_CHECK_WRITE(db);
02264   RPCStatus rpc_status;
02265   
02266   Offset offset;
02267   Size alloc_size;
02268 
02269   alloc_size = idr->getSize();
02270   offset = IDB_OBJ_HEAD_SIZE;
02271 
02272   Data data = idr->getIDR();
02273   xdr_int32_code(&data, &offset, &alloc_size, &val);
02274 
02275   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
02276 
02277   return Success;
02278 }
02279 
02280 Status Int32::setValue(Data data)
02281 {
02282   val = *(eyedblib::int32 *)data;
02283   return Success;
02284 }
02285 
02286 Status Int32::getValue(Data* data) const
02287 {
02288   *data = (Data)&val;
02289   return Success;
02290 }
02291 
02292 //
02293 // Int64
02294 //
02295 
02296 Int64::Int64(eyedblib::int64 i) : Basic()
02297 {
02298   setClass(Int64_Class);
02299   val = i;
02300 
02301   idr->setIDR(getClass()->getIDRObjectSize());
02302 
02303   type = Basic_Type;
02304 
02305   headerCode(_Basic_Type, idr->getSize());
02306 }
02307 
02308 Int64::Int64(Database *_db, eyedblib::int64 i, const Dataspace *_dataspace) : Basic(_db, _dataspace)
02309 {
02310   setClass(Int64_Class);
02311   val = i;
02312 
02313   idr->setIDR(getClass()->getIDRObjectSize());
02314 
02315   type = Basic_Type;
02316 
02317   headerCode(_Basic_Type, idr->getSize());
02318 }
02319 
02320 Int64::Int64(const Int64 *o) : Basic(o)
02321 {
02322   val = (o ? o->val : 0);
02323 }
02324 
02325 Int64::Int64(const Int64 &o) : Basic(o)
02326 {
02327   val = o.val;
02328 }
02329 
02330 Int64& Int64::operator=(const Int64& o)
02331 {
02332   if (&o == this)
02333     return *this;
02334 
02335   *(Basic *)this = Basic::operator=((const Basic &)o);
02336 
02337   val = o.val;
02338   return *this;
02339 }
02340 
02341 Status Int64::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
02342 {
02343   fprintf(fd, "%s int64 = ", oid.getString());
02344   return trace_realize(fd, INDENT_INC, flags, rcm);
02345 }
02346 
02347 Status Int64::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
02348 {
02349   fprintf(fd, "%lld;\n", val);
02350   return Success;
02351 }
02352 
02353 Status Int64::create()
02354 {
02355   if (oid.isValid())
02356     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating eyedblib::int64");
02357 
02358   IDB_CHECK_WRITE(db);
02359   RPCStatus rpc_status;
02360   
02361   Offset offset;
02362   Size alloc_size;
02363 
02364   alloc_size = idr->getSize();
02365   offset = IDB_OBJ_HEAD_SIZE;
02366 
02367   Data data = idr->getIDR();
02368 #ifdef E_XDR
02369   xdr_int64_code(&data, &offset, &alloc_size, &val);
02370 #endif
02371 
02372   classOidCode();
02373   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(), data, oid.getOid());
02374 
02375   return StatusMake(rpc_status);
02376 }
02377 
02378 Status Int64::update()
02379 {
02380   if (!oid.isValid()) /* && modify */
02381     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating eyedblib::int64");
02382 
02383   IDB_CHECK_WRITE(db);
02384 
02385   RPCStatus rpc_status;
02386   
02387   Offset offset;
02388   Size alloc_size;
02389 
02390   alloc_size = idr->getSize();
02391   offset = IDB_OBJ_HEAD_SIZE;
02392 
02393   Data data = idr->getIDR();
02394 #ifdef E_XDR
02395   xdr_int64_code(&data, &offset, &alloc_size, &val);
02396 #endif
02397 
02398   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
02399 
02400   return Success;
02401 }
02402 
02403 Status Int64::setValue(Data data)
02404 {
02405   val = *(eyedblib::int64 *)data;
02406   return Success;
02407 }
02408 
02409 Status Int64::getValue(Data* data) const
02410 {
02411   *data = (Data)&val;
02412   return Success;
02413 }
02414 
02415 //
02416 // Float
02417 //
02418 
02419 Float::Float(double d) : Basic()
02420 {
02421   setClass(Float_Class);
02422   val = d;
02423 
02424   /*
02425   idr->idr_sz = getClass()->getIDRObjectSize();
02426   idr->idr = (unsigned char *)malloc(idr->idr_sz);
02427   */
02428   idr->setIDR(getClass()->getIDRObjectSize());
02429 
02430   type = Basic_Type;
02431 
02432   headerCode(_Basic_Type, idr->getSize());
02433 }
02434 
02435 Float::Float(Database *_db, double d, const Dataspace *_dataspace) : Basic(_db, _dataspace)
02436 {
02437   setClass(Float_Class);
02438   val = d;
02439 
02440   /*
02441   idr->idr_sz = getClass()->getIDRObjectSize();
02442   idr->idr = (unsigned char *)malloc(idr->idr_sz);
02443   */
02444   idr->setIDR(getClass()->getIDRObjectSize());
02445 
02446   type = Basic_Type;
02447 
02448   headerCode(_Basic_Type, idr->getSize());
02449 }
02450 
02451 Float::Float(const Float *o) : Basic(o)
02452 {
02453   val = (o ? o->val : 0.);
02454 }
02455 
02456 Float::Float(const Float &o) : Basic(o)
02457 {
02458   val = o.val;
02459 }
02460 
02461 Float& Float::operator=(const Float& o)
02462 {
02463   if (&o == this)
02464     return *this;
02465 
02466   *(Basic *)this = Basic::operator=((const Basic &)o);
02467 
02468   val = o.val;
02469   return *this;
02470 }
02471 
02472 Status Float::trace(FILE* fd, unsigned int flags, const RecMode *rcm) const
02473 {
02474   fprintf(fd, "%s float = ", oid.getString());
02475   return trace_realize(fd, INDENT_INC, flags, rcm);
02476 }
02477 
02478 Status Float::trace_realize(FILE* fd, int indent, unsigned int flags, const RecMode *rcm) const
02479 {
02480   fprint_float(fd, val);
02481   fprintf(fd, ";\n");
02482   return Success;
02483 }
02484 
02485 Status Float::create()
02486 {
02487   if (oid.isValid())
02488     return Exception::make(IDB_OBJECT_ALREADY_CREATED, "creating float");
02489 
02490   IDB_CHECK_WRITE(db);
02491 
02492   RPCStatus rpc_status;
02493   
02494   Offset offset;
02495   Size alloc_size;
02496 
02497   alloc_size = idr->getSize();
02498   offset = IDB_OBJ_HEAD_SIZE;
02499 
02500   Data data = idr->getIDR();
02501   xdr_double_code(&data, &offset, &alloc_size, &val);
02502 
02503   classOidCode();
02504   rpc_status = objectCreate(db->getDbHandle(), getDataspaceID(), data, oid.getOid());
02505 
02506   return StatusMake(rpc_status);
02507 }
02508 
02509 Status Float::update()
02510 {
02511   if (!oid.isValid()) /* && modify */
02512     return Exception::make(IDB_OBJECT_NOT_CREATED, "updating float");
02513 
02514   IDB_CHECK_WRITE(db);
02515   RPCStatus rpc_status;
02516   
02517   Offset offset;
02518   Size alloc_size;
02519 
02520   alloc_size = idr->getSize();
02521   offset = IDB_OBJ_HEAD_SIZE;
02522 
02523   Data data = idr->getIDR();
02524   xdr_double_code(&data, &offset, &alloc_size, &val);
02525 
02526   rpc_status = objectWrite(db->getDbHandle(), data, oid.getOid());
02527 
02528   return Success;
02529 }
02530 
02531 Status Float::setValue(Data data)
02532 {
02533   memcpy(&val, data, sizeof(double));
02534   return Success;
02535 }
02536 
02537 Status Float::getValue(Data* data) const
02538 {
02539   memcpy(data, &val, sizeof(double));
02540   return Success;
02541 }
02542 
02543 }

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