AttrNative.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 <assert.h>
00027 #include "Attribute_p.h"
00028 
00029 #define ADD_PROT
00030 
00031 namespace eyedb {
00032 
00033   struct AttrNativeItems {
00034     Attribute **items;
00035     int items_cnt;
00036   };
00037 
00038   AttrNativeItems nat_items[idbITEMS_COUNT];
00039 
00040   static Oid
00041   get_class_oid(const Object *refo, const Class *cls)
00042   {
00043     if (cls->getOid().isValid())
00044       return cls->getOid();
00045 
00046     if (!refo->getDatabase())
00047       return Oid::nullOid;
00048 
00049     cls = const_cast<Schema *>(refo->getDatabase()->getSchema())->getClass(cls->getName());
00050 
00051     if (!cls)
00052       return Oid::nullOid;
00053 
00054     return cls->getOid();
00055   }
00056 
00057   static Status
00058   getv_class(const Object *o, Data *data, int nb, int from,
00059              Bool *isnull, Bool isGetTValue, Size *rnb)
00060   {
00061     if (isnull)
00062       *isnull = False;
00063 
00064     const Class *cls = o->getClass();
00065 
00066     if (isGetTValue) {
00067       Oid xoid = get_class_oid(o, cls);
00068       memcpy(data, &xoid, sizeof(Oid));
00069       return Success;
00070     }
00071 
00072     memcpy(data, &cls, sizeof(Object *));
00073     return Success;
00074   }
00075 
00076   static Status
00077   geto_class(const Object *o, Oid *oid, int nb, int from)
00078   {
00079     Oid xoid = get_class_oid(o, o->getClass());
00080     memcpy(oid, &xoid, sizeof(Oid));
00081     return Success;
00082   }
00083 
00084   static Status
00085   getv_protection(const Object *o, Data *data, int nb, int from,
00086                   Bool *isnull, Bool isGetTValue, Size *rnb)
00087   {
00088     if (isnull)
00089       *isnull = False;
00090     Oid prot_oid;
00091     Status s = o->getProtection(prot_oid);
00092     if (s) return s;
00093 
00094     if (isGetTValue)
00095       {
00096         memcpy(data, &prot_oid, sizeof(Oid));
00097         return Success;
00098       }
00099 
00100     if (prot_oid.isValid())
00101       return ((Object *)o)->getDatabase()->loadObject(&prot_oid, (Object **)data);
00102     memset(data, 0, sizeof(Object *));
00103     return Success;
00104   }
00105 
00106   static Status
00107   geto_protection(const Object *o, Oid *oid, int nb, int from)
00108   {
00109     return o->getProtection(*oid);
00110   }
00111 
00112   static Status
00113   setv_protection(Object *o, Data data, int nb, int from)
00114   {
00115     const Class *cls = o->getClass();
00116     memcpy(data, &cls, sizeof(Object *));
00117     return Success;
00118   }
00119 
00120   static Status
00121   seto_protection(Object *o, const Oid *oid, int nb, int from, Bool)
00122   {
00123     return o->setProtection(*oid);
00124   }
00125 
00126   static Status
00127   getv_parent(const Object *o, Data *data, int nb, int from,
00128               Bool *isnull, Bool isGetTValue, Size *rnb)
00129   {
00130     if (isnull)
00131       *isnull = False;
00132 
00133     Class *parent;
00134     Status s = const_cast<Class *>(o->asClass())->getParent(const_cast<Database *>(o->getDatabase()), parent);
00135     if (s) return s;
00136 
00137     if (isGetTValue)
00138       {
00139         if (parent) {
00140           Oid xoid = get_class_oid(o, parent);
00141           memcpy(data, &xoid, sizeof(Oid));
00142         }
00143         else
00144           memcpy(data, &Oid::nullOid, sizeof(Oid));
00145         return Success;
00146       }
00147 
00148     if (parent)
00149       memcpy(data, &parent, sizeof(Object *));
00150     else
00151       memset(data, 0, sizeof(Object *));
00152     return Success;
00153   }
00154 
00155   static Status
00156   geto_parent(const Object *o, Oid *oid, int nb, int from)
00157   {
00158     Class *parent;
00159     Status s = const_cast<Class *>(o->asClass())->getParent(const_cast<Database *>(o->getDatabase()), parent);
00160     if (s) return s;
00161 
00162     if (parent) {
00163       Oid xoid = get_class_oid(o, parent);
00164       memcpy(oid, &xoid, sizeof(Oid));
00165     }
00166     else
00167       oid->invalidate();
00168     return Success;
00169   }
00170 
00171   static Status
00172   getv_name(const Object *o, Data *data, int nb, int from, Bool *isnull,
00173             Bool isGetTValue, Size *rnb)
00174   {
00175     if (isnull)
00176       *isnull = False;
00177 
00178     const char *name = ((Class *)o)->getName();
00179     if (isGetTValue)
00180       {
00181         if (nb == Attribute::wholeData)
00182           *data = (Data)strdup(name);
00183         else
00184           memcpy(data, name, strlen(name)+1);
00185 
00186         if (rnb) *rnb = strlen(name) + 1;
00187         return Success;
00188       }
00189 
00190     if (nb == Attribute::directAccess)
00191       *data = (Data)name;
00192     else
00193       memcpy(data, name, strlen(name)+1);
00194     return Success;
00195   }
00196 
00197   static Status
00198   getv_mtype(const Object *o, Data *data, int nb, int from,
00199              Bool *isnull, Bool isGetTValue, Size *rnb)
00200   {
00201     if (isnull)
00202       *isnull = False;
00203 
00204     const char *str = (((Class *)o)->isSystem() ? "system" : "user");
00205 
00206     if (isGetTValue)
00207       {
00208         if (nb == Attribute::wholeData)
00209           *data = (Data)strdup(str);
00210         else
00211           memcpy(data, str, strlen(str)+1);
00212 
00213         if (rnb) *rnb = strlen(str) + 1;
00214         return Success;
00215       }
00216 
00217     if (nb == Attribute::directAccess)
00218       *data = (Data)str;
00219     else
00220       memcpy(data, str, strlen(str)+1);
00221 
00222     return Success;
00223   }
00224 
00225   static Status
00226   getv_components(const Object *o, Data *data, int nb, int from,
00227                   Bool *isnull, Bool isGetTValue, Size *rnb)
00228   {
00229     if (isnull)
00230       *isnull = False;
00231     Collection *coll;
00232     Status status = o->asClass()->getComponents(coll);
00233     if (status) return status;
00234 
00235     if (isGetTValue)
00236       {
00237         memcpy(data, &coll->getOid(), sizeof(Oid));
00238         return Success;
00239       }
00240 
00241     memcpy(data, &coll, sizeof(Object *));
00242     return Success;
00243   }
00244 
00245   static Status
00246   geto_components(const Object *o, Oid *oid, int nb, int from)
00247   {
00248     Collection *coll;
00249     Status status = o->asClass()->getComponents(coll);
00250     if (status) return status;
00251 
00252     if (coll) {
00253       memcpy(oid, &coll->getOid(), sizeof(Oid));
00254     }
00255     else
00256       oid->invalidate();
00257 
00258     return Success;
00259   }
00260 
00261   static Status
00262   getv_extent(const Object *o, Data *data, int nb, int from,
00263               Bool *isnull, Bool isGetTValue, Size *rnb)
00264   {
00265     if (isnull)
00266       *isnull = False;
00267     Collection *coll;
00268     Status status = o->asClass()->getExtent(coll);
00269     if (status) return status;
00270 
00271     if (isGetTValue)
00272       {
00273         memcpy(data, &coll->getOid(), sizeof(Oid));
00274         return Success;
00275       }
00276 
00277     memcpy(data, &coll, sizeof(Object *));
00278     return Success;
00279   }
00280 
00281   static Status
00282   geto_extent(const Object *o, Oid *oid, int nb, int from)
00283   {
00284     Collection *coll;
00285     Status status = o->asClass()->getExtent(coll);
00286     if (status) return status;
00287 
00288     if (coll)
00289       memcpy(oid, &coll->getOid(), sizeof(Oid));
00290     else
00291       oid->invalidate();
00292 
00293     return Success;
00294   }
00295 
00296   static Status
00297   getv_collcls(const Object *o, Data *data, int nb, int from,
00298                Bool *isnull, Bool isGetTValue, Size *rnb)
00299   {
00300     if (isnull)
00301       *isnull = False;
00302     const Class *cl = ((CollectionClass *)(o->getClass()))->getCollClass();
00303 
00304     if (isGetTValue)
00305       {
00306         Oid xoid = get_class_oid(o, cl);
00307         memcpy(data, &xoid, sizeof(Oid));
00308         return Success;
00309       }
00310 
00311     memcpy(data, &cl, sizeof(Object *));
00312     return Success;
00313   }
00314 
00315   static Status
00316   geto_collcls(const Object *o, Oid *oid, int nb, int from)
00317   {
00318     Oid xoid = get_class_oid(o, ((CollectionClass *)(o->getClass()))->getCollClass());
00319 
00320     memcpy(oid, &xoid, sizeof(Oid));
00321     return Success;
00322   }
00323 
00324 
00325   static Status
00326   getv_isref(const Object *o, Data *data, int nb, int from,
00327              Bool *isnull, Bool, Size *rnb)
00328   {
00329     if (isnull)
00330       *isnull = False;
00331 
00332     Bool isref;
00333     (void)((CollectionClass *)(o->getClass()))->getCollClass(&isref);
00334     eyedblib::int32 i = isref;
00335     memcpy(data, &i, sizeof(i));
00336     return Success;
00337   }
00338 
00339   static Status
00340   getv_cname(const Object *o, Data *data, int nb, int from,
00341              Bool *isnull, Bool isGetTValue, Size *rnb)
00342   {
00343     if (isnull)
00344       *isnull = False;
00345 
00346     const char *name = ((Collection *)o)->getName();
00347     if (isGetTValue)
00348       {
00349         if (nb == Attribute::wholeData)
00350           *data = (Data)strdup(name);
00351         else
00352           memcpy(data, name, strlen(name)+1);
00353         if (rnb) *rnb = strlen(name) + 1;
00354         return Success;
00355       }
00356 
00357     if (nb == Attribute::directAccess)
00358       *data = (Data)name;
00359     else
00360       memcpy(data, name, strlen(name)+1);
00361     return Success;
00362   }
00363 
00364   static Status
00365   getv_dim(const Object *o, Data *data, int nb, int from,
00366            Bool *isnull, Bool, Size *rnb)
00367   {
00368     if (isnull)
00369       *isnull = False;
00370 
00371     eyedblib::int16 dim;
00372     (void)((CollectionClass *)(o->getClass()))->getCollClass(0, &dim);
00373     eyedblib::int32 i = dim;
00374     memcpy(data, &i, sizeof(i));
00375     return Success;
00376   }
00377 
00378   static Status
00379   getv_magorder(const Object *o, Data *data, int nb, int from,
00380                 Bool *isnull, Bool, Size *rnb)
00381   {
00382     if (isnull)
00383       *isnull = False;
00384 
00385     //int mgo = ((CollectionClass *)(o->getClass()))->getMagOrder();
00386     int mgo = 0;
00387     memcpy(data, &mgo, sizeof(mgo));
00388     return Success;
00389   }
00390 
00391   static Status
00392   getv_count(const Object *o, Data *data, int nb, int from,
00393              Bool *isnull, Bool, Size *rnb)
00394   {
00395     if (isnull)
00396       *isnull = False;
00397 
00398     int count = ((Collection *)o)->getCount();
00399     memcpy(data, &count, sizeof(count));
00400     return Success;
00401   }
00402 
00403 
00404   static inline void make_items(int type, AttrNative **items, int items_cnt)
00405   {
00406     class_info[type].items = items;
00407     class_info[type].items_cnt = items_cnt;
00408   }
00409 
00410   enum {
00411     classITEM = 0,
00412 #ifdef ADD_PROT
00413     protITEM,
00414 #endif
00415     mtypeITEM,
00416     nameITEM,
00417     parentITEM,
00418     componentsITEM,
00419     extentITEM,
00420     collclsITEM,
00421     isrefITEM,
00422     dimITEM,
00423     magorderITEM,
00424     cnameITEM,
00425     countITEM,
00426     ITEMS_CNT
00427   };
00428 
00429   static void
00430   make_tmpitems(AttrNative *tmpitems[], CollectionClass **pcollsetobjs)
00431   {
00432     tmpitems[classITEM] = new AttrNative(Class_Class,
00433                                          Object_Class,
00434                                          "class", True,
00435                                          getv_class, 0,
00436                                          geto_class, 0);
00437 
00438     tmpitems[protITEM] = new AttrNative(Object_Class,
00439                                         Object_Class,
00440                                         "protection", True,
00441                                         getv_protection, setv_protection,
00442                                         geto_protection, seto_protection);
00443 
00444     tmpitems[nameITEM] = new AttrNative(Char_Class,
00445                                         Class_Class,
00446                                         "name", 128,
00447                                         getv_name, 0, 0, 0);
00448 
00449 
00450     tmpitems[mtypeITEM] = new AttrNative(Char_Class,
00451                                          Class_Class,
00452                                          "type", 16,
00453                                          getv_mtype, 0, 0, 0);
00454 
00455     tmpitems[parentITEM] = new AttrNative(Class_Class,
00456                                           Class_Class,
00457                                           "parent", True,
00458                                           getv_parent, 0,
00459                                           geto_parent, 0);
00460 
00461     (*pcollsetobjs) = new CollSetClass(Object_Class, True);
00462 
00463     // "components" has been changed to "components" 
00464     tmpitems[componentsITEM] = new AttrNative(*pcollsetobjs,
00465                                               Class_Class,
00466                                               "components", True,
00467                                               getv_components, 0,
00468                                               geto_components, 0);
00469 
00470     // "extent" has been changed to "extent" 
00471     tmpitems[extentITEM] = new AttrNative(*pcollsetobjs,
00472                                           Class_Class,
00473                                           "extent", True,
00474                                           getv_extent, 0,
00475                                           geto_extent, 0);
00476 
00477     tmpitems[collclsITEM] = new AttrNative(*pcollsetobjs,
00478                                            Collection_Class,
00479                                            "collcls", True,
00480                                            getv_collcls, 0,
00481                                            geto_collcls, 0);
00482 
00483     tmpitems[isrefITEM] = new AttrNative(Int32_Class,
00484                                          Collection_Class,
00485                                          "isref", 0,
00486                                          getv_isref, 0, 0, 0);
00487 
00488     tmpitems[dimITEM] = new AttrNative(Int32_Class,
00489                                        Collection_Class,
00490                                        "dim", 0,
00491                                        getv_dim, 0, 0, 0);
00492 
00493     tmpitems[cnameITEM] = new AttrNative(Char_Class,
00494                                          Collection_Class,
00495                                          "name", 128,
00496                                          getv_cname, 0, 0, 0);
00497 
00498     tmpitems[countITEM] = new AttrNative(Int32_Class,
00499                                          Collection_Class,
00500                                          "count", 0,
00501                                          getv_count, 0, 0, 0);
00502 
00503     tmpitems[magorderITEM] = new AttrNative(Int32_Class,
00504                                             Collection_Class,
00505                                             "magorder", 0,
00506                                             getv_magorder, 0, 0, 0);
00507   }
00508 
00509 #ifdef ADD_PROT
00510   const int
00511   objitemsCOUNT    = 2,
00512     m_clitemsCOUNT   = 7,
00513     collitemsCOUNT   = 8;
00514 #else
00515   const int
00516   objitemsCOUNT    = 1,
00517     m_clitemsCOUNT   = 6,
00518     collitemsCOUNT   = 7;
00519 #endif
00520 
00521   static inline AttrNative **
00522   make(int count)
00523   {
00524     AttrNative **x = (AttrNative **)malloc(count * sizeof(AttrNative *));
00525     memset(x, 0, count * sizeof(AttrNative *));
00526     return x;
00527   }
00528 
00529   static AttrNative *tmpitems[ITEMS_CNT];
00530   static AttrNative **m_clitems, **objitems, **collitems;
00531   static  CollectionClass *collsetobjs;
00532 
00533   void AttrNative::init()
00534   {
00535     make_tmpitems(tmpitems, &collsetobjs);
00536 
00537     int n;
00538 
00539     objitems    = make(objitemsCOUNT);
00540     collitems   = make(collitemsCOUNT);
00541     m_clitems   = make(m_clitemsCOUNT);
00542 
00543     n = 0;
00544     objitems[n++]    = tmpitems[classITEM];
00545 #ifdef ADD_PROT
00546     objitems[n++]    = tmpitems[protITEM];
00547 #endif
00548 
00549     n = 0;
00550     m_clitems[n++]   = tmpitems[classITEM];
00551 #ifdef ADD_PROT
00552     m_clitems[n++]   = tmpitems[protITEM];
00553 #endif
00554     m_clitems[n++]   = tmpitems[mtypeITEM];
00555     m_clitems[n++]   = tmpitems[nameITEM];
00556     m_clitems[n++]   = tmpitems[parentITEM];
00557     m_clitems[n++]   = tmpitems[extentITEM];
00558     m_clitems[n++]   = tmpitems[componentsITEM];
00559 
00560     n = 0;
00561     collitems[n++]   = tmpitems[classITEM];
00562 #ifdef ADD_PROT
00563     collitems[n++]   = tmpitems[protITEM];
00564 #endif
00565     collitems[n++]   = tmpitems[cnameITEM];
00566     collitems[n++]   = tmpitems[countITEM];
00567     collitems[n++]   = tmpitems[collclsITEM];
00568     collitems[n++]   = tmpitems[isrefITEM];
00569     collitems[n++]   = tmpitems[dimITEM];
00570     collitems[n++]   = tmpitems[magorderITEM];
00571 
00572 #if 0
00573     make_items(Object_Type, m_clitems, m_clitemsCOUNT);
00574 #else
00575     make_items(Object_Type, objitems, objitemsCOUNT);
00576 #endif
00577 
00578     make_items(Class_Type,   m_clitems, m_clitemsCOUNT);
00579     make_items(BasicClass_Type,   m_clitems, m_clitemsCOUNT);
00580     make_items(EnumClass_Type,    m_clitems, m_clitemsCOUNT);
00581     make_items(AgregatClass_Type, m_clitems, m_clitemsCOUNT);
00582     make_items(StructClass_Type,  m_clitems, m_clitemsCOUNT);
00583     make_items(UnionClass_Type,   m_clitems, m_clitemsCOUNT);
00584 
00585     make_items(Instance_Type,      objitems, objitemsCOUNT);
00586     make_items(Basic_Type,      objitems, objitemsCOUNT);
00587     make_items(Enum_Type,       objitems, objitemsCOUNT);
00588     make_items(Agregat_Type,    objitems, objitemsCOUNT);
00589     make_items(Struct_Type,     objitems, objitemsCOUNT);
00590     make_items(Union_Type,      objitems, objitemsCOUNT);
00591     make_items(Schema_Type, objitems, objitemsCOUNT);
00592   
00593     make_items(CollectionClass_Type, m_clitems, m_clitemsCOUNT);
00594     make_items(CollSetClass_Type,    m_clitems, m_clitemsCOUNT);
00595     make_items(CollBagClass_Type,    m_clitems, m_clitemsCOUNT);
00596     make_items(CollListClass_Type,   m_clitems, m_clitemsCOUNT);
00597     make_items(CollArrayClass_Type,  m_clitems, m_clitemsCOUNT);
00598 
00599     make_items(Collection_Type, collitems, collitemsCOUNT);
00600     make_items(CollSet_Type,    collitems, collitemsCOUNT);
00601     make_items(CollBag_Type,    collitems, collitemsCOUNT);
00602     make_items(CollList_Type,   collitems, collitemsCOUNT);
00603     make_items(CollArray_Type,  collitems, collitemsCOUNT);
00604 
00605     nat_items[ObjectITEMS].items           = (Attribute **)objitems;
00606     nat_items[ObjectITEMS].items_cnt       = objitemsCOUNT;
00607     nat_items[ClassITEMS].items       = (Attribute **)m_clitems;
00608     nat_items[ClassITEMS].items_cnt   = m_clitemsCOUNT;
00609     nat_items[CollectionITEMS].items       = (Attribute **)collitems;
00610     nat_items[CollectionITEMS].items_cnt   = collitemsCOUNT;
00611     nat_items[CollectionClassITEMS].items  = (Attribute **)m_clitems;
00612     nat_items[CollectionClassITEMS].items_cnt = m_clitemsCOUNT;
00613 
00614     collsetobjs->setAttributes((Attribute **)collitems, collitemsCOUNT);
00615   }
00616 
00617   void AttrNative::_release()
00618   {
00619     for (int i = 0; i < ITEMS_CNT; i++)
00620       delete tmpitems[i];
00621 
00622     free(objitems);
00623     free(collitems);
00624     free(m_clitems);
00625 
00626     //collsetobjs->setAttributes(NULL, 0);
00627     collsetobjs->release();
00628   }
00629 
00630 
00631   //
00632   // AttrNative methods
00633   //
00634 
00635   AttrNative::AttrNative
00636   (Class *cl, Class *cl_own, const char *s, Bool isRef,
00637    Status (*_getv)(const Object *, Data *, int, int, Bool *, Bool, Size *),
00638    Status (*_setv)(Object *, Data, int, int),
00639    Status (*_geto)(const Object *, Oid *oid, int nb, int from),
00640    Status (*_seto)(Object *, const Oid *, int, int, Bool)) :
00641     Attribute(cl, s, isRef)
00642   {
00643     code = AttrNative_Code;
00644     class_owner = cl_own;
00645     _getvalue = _getv;
00646     _setvalue = _setv;
00647     _getoid = _geto;
00648     _setoid = _seto;
00649     idr_item_psize = sizeof(Oid);
00650     idr_psize = idr_item_psize;
00651     idr_poff = 0;
00652     idr_voff = 0;
00653     idr_inisize = 0;
00654   }
00655 
00656   AttrNative::AttrNative
00657   (Class *cl, Class *cl_own, const char *s, int dim,
00658    Status (*_getv)(const Object *, Data *, int, int, Bool *, Bool, Size *),
00659    Status (*_setv)(Object *, Data, int, int),
00660    Status (*_geto)(const Object *, Oid *oid, int nb, int from),
00661    Status (*_seto)(Object *, const Oid *, int, int, Bool))
00662     : Attribute(cl, s, dim)
00663   {
00664     code = AttrNative_Code;
00665     class_owner = cl_own;
00666     _getvalue = _getv;
00667     _setvalue = _setv;
00668     _getoid = _geto;
00669     _setoid = _seto;
00670 
00671     cl->getIDRObjectSize(&idr_item_psize);
00672     idr_item_psize -= IDB_OBJ_HEAD_SIZE;
00673     idr_psize = dim * idr_item_psize;
00674     idr_poff = 0;
00675     idr_voff = 0;
00676     idr_inisize = 0;
00677   }
00678 
00679   void
00680   AttrNative::reportAttrCompSetOid(Offset *offset, Data idr) const
00681   {
00682   }
00683 
00684   Status
00685   AttrNative::cannot(const char *msg) const
00686   {
00687     return Exception::make(IDB_ATTRIBUTE_ERROR, "cannot %s for %s::%s",
00688                            msg, class_owner->getName(), name);
00689   }
00690 
00691   Status AttrNative::setOid(Object *o, const Oid *oid, int nb , int from, Bool check_class) const
00692   {
00693     if (_setoid)
00694       return (*_setoid)(o, oid, nb, from, check_class);
00695     return cannot("set oid");
00696   }
00697 
00698   Status AttrNative::getOid(const Object *o, Oid *oid, int nb, int from) const
00699   {
00700     if (_getoid)
00701       return (*_getoid)(o, oid, nb, from);
00702     return cannot("get oid");
00703   }
00704 
00705   Status AttrNative::setValue(Object *o, Data data,
00706                               int nb, int from, Bool) const
00707   {
00708     if (_setvalue)
00709       return (*_setvalue)(o, data, nb, from);
00710 
00711     return cannot("set value");
00712   }
00713 
00714   Status AttrNative::getValue(const Object *o, Data *data, int nb, int from, Bool *isnull) const
00715   {
00716     if (_getvalue)
00717       return (*_getvalue)(o, data, nb, from, isnull, False, 0);
00718     return cannot("get value");
00719   }
00720 
00721   Status AttrNative::getTValue(Database *db, const Oid &objoid,
00722                                Data *data, int nb, int from,
00723                                Bool *isnull, Size *rnb, Offset poffset) const
00724   {
00725     if (_getvalue)
00726       {
00727         if (rnb) *rnb = nb;
00728         Object *o;
00729         Status s = db->loadObject(objoid, o);
00730         if (s) return s;
00731         s = (*_getvalue)(o, data, nb, from, isnull, True, rnb);
00732         o->release();
00733         return s;
00734       }
00735 
00736     return cannot("get value");
00737   }
00738 
00739   Status AttrNative::trace(const Object *o, FILE *fd, int *indent, unsigned int flags, const RecMode *rcm) const
00740   {
00741     char *indent_str = make_indent(*indent);
00742     char prefix[64];
00743     Status status = Success;
00744 
00745     get_prefix(o, class_owner, prefix, sizeof(prefix));
00746 
00747     unsigned char data[128];
00748     status = getValue(o, (Data *)data, 1, 0, 0);
00749 
00750     if (status) return status;
00751 
00752     fprintf(fd, "%snative attribute ", indent_str);
00753     if (isString())
00754       fprintf(fd, "string ");
00755     else
00756       fprintf(fd, "%s ", cls->getName());
00757 
00758     fprintf(fd, "%s%s = ", (isIndirect() ? "*" : ""), name);
00759 
00760     if (is_basic_enum)
00761       {
00762         int len = strlen(indent_str) + strlen(prefix) + strlen(name) + 3;
00763 
00764         if (cls->asBasicClass())
00765           status = ((BasicClass *)cls)->traceData(fd, len, data, data, (TypeModifier *)&typmod);
00766 
00767         fprintf(fd, ";\n");
00768       }
00769     else
00770       {
00771         Object *oo;
00772         memcpy(&oo, data, sizeof(Object *));
00773         if (oo)
00774           {
00775             if (rcm->isAgregRecurs(this, 0, oo))
00776               status = ObjectPeer::trace_realize(oo, fd, *indent + INDENT_INC, flags, rcm);
00777             else
00778               fprintf(fd, "{%s};\n", oo->getOid().getString());
00779           }
00780         else
00781           fprintf(fd, "%s;\n", NullString);
00782       }
00783 
00784     delete_indent(indent_str);
00785     return status;
00786   }
00787 
00788   AttrNative::AttrNative(const AttrNative *agr,
00789                          const Class *_cls,
00790                          const Class *_class_owner, 
00791                          const Class *_dyn_class_owner, 
00792                          int n) :
00793     Attribute(agr, _cls, _class_owner, _dyn_class_owner, n)
00794   {
00795     _getvalue = agr->_getvalue;
00796     _setvalue = agr->_setvalue;
00797     _getoid   = agr->_getoid;
00798     _setoid   = agr->_setoid;
00799 
00800     idr_item_psize = agr->idr_item_psize;
00801     idr_psize      = agr->idr_psize;
00802     idr_poff       = agr->idr_poff;
00803     idr_voff       = agr->idr_voff;
00804     idr_inisize    = agr->idr_inisize;
00805   }
00806 
00807   void AttrNative::copy(int w, Attribute ** &items, unsigned int &items_cnt,
00808                         Class *cls)
00809   {
00810     items_cnt = nat_items[w].items_cnt;
00811     items = (Attribute **)malloc(sizeof(Attribute *) * items_cnt);
00812 
00813     for (int i = 0; i < items_cnt; i++)
00814       items[i] =
00815         new AttrNative((AttrNative *)nat_items[w].items[i], 0, cls, cls, i);
00816   }
00817 }

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