⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.h

📁 FastDb是高效的内存数据库系统
💻 H
📖 第 1 页 / 共 3 页
字号:
    nat4 size; // number of elements in the array    int4 offs; // offset from the beginning of the record};/** * Database record for storing field descriptor */struct dbField {     enum FieldTypes {         tpBool,        tpInt1,        tpInt2,        tpInt4,        tpInt8,        tpReal4,         tpReal8,         tpString,        tpReference,        tpArray,        tpMethodBool,        tpMethodInt1,        tpMethodInt2,        tpMethodInt4,        tpMethodInt8,        tpMethodReal4,        tpMethodReal8,        tpMethodString,        tpMethodReference,        tpStructure,        tpRawBinary,         tpStdString,        tpRectangle,        tpUnknown    };            /**     * Full name of the field (for example "x.y.z")     */    dbVarying name;        /**     * Name of referenced table( only for references)     */    dbVarying tableName;     /**     * Name of inverse reference field (only for refereces)     */    dbVarying inverse;         /**     * Field type: one of <code>dbField::FieldTypes</code> constants     */#ifdef OLD_FIELD_DESCRIPTOR_FORMAT    int4      type;#else #if BYTE_ORDER == BIG_ENDIAN    int4      flags : 24;    int4      type  : 8;#else    int4      type  : 8;    int4      flags : 24;#endif#endif    /**     *  Offset of the field in the record     */    int4      offset;     /**     * Size of the field     */    nat4      size;    /**     * Hash table for hashed field     */    oid_t     hashTable;    /**     * T-Tree for field indexed by means of T-Ttree     */    oid_t     tTree;};     /** * Header of any database record */class dbRecord {   public:    /**     * Size of the record (including header     */    nat4   size;    /**     * Next record in the table (0 if it is last record)     */    oid_t  next;    /**     * Previous record in the table (0 if it is first record)     */    oid_t  prev;};/** * Database recod for storing table descriptor */class dbTable : public dbRecord {   public:    /**     * Name of the table     */    dbVarying name;        /**     * Array with field descriptors     */    dbVarying fields;    /**     * Size of fixed part of the record (without string and arrays bodies)     */    nat4      fixedSize;    /**     * Number of rows in the table     */    nat4      nRows;    /**     * Number of columns in the table     */    nat4      nColumns;        /**     * Identifier of first row in the table     */    oid_t     firstRow;    /**     * Identifier of last row in the table     */    oid_t     lastRow;#ifdef AUTOINCREMENT_SUPPORT    /**     * Autoincremented counter     */    nat4      count;#endif};inline dbFieldDescriptor* dbDescribeRawField(dbFieldDescriptor* fd, dbUDTComparator comparator){    fd->type = fd->appType = dbField::tpRawBinary;    fd->alignment = 1;    fd->comparator = comparator;    return fd;}template<class T>inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, T& x) {     fd->type = fd->appType = dbField::tpStructure;    fd->components = x.dbDescribeComponents(fd);    return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, int1&) {     fd->type = fd->appType = dbField::tpInt1;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, int2&) {     fd->type = fd->appType = dbField::tpInt2;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, int4&) {     fd->type = fd->appType = dbField::tpInt4;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, db_int8&) {     fd->type = fd->appType = dbField::tpInt8;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, nat1&) {     fd->type = fd->appType = dbField::tpInt1;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, nat2&) {     fd->type = fd->appType = dbField::tpInt2;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, nat4&) {     fd->type = fd->appType = dbField::tpInt4;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, nat8&) {     fd->type = fd->appType = dbField::tpInt8;     return fd;}#if SIZEOF_LONG != 8inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, long&){    fd->type = fd->appType = dbField::tpInt4;    return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, unsigned long&){    fd->type = fd->appType = dbField::tpInt4;    return fd;}#endifinline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, bool&) {     fd->type = fd->appType = dbField::tpBool;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, real4&) {     fd->type = fd->appType = dbField::tpReal4;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, real8&) {     fd->type = fd->appType = dbField::tpReal8;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, rectangle&){    fd->type = fd->appType = dbField::tpRectangle;    fd->alignment = sizeof(coord_t);    return fd;}#ifdef USE_STD_STRINGinline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, std::string&){    fd->type = dbField::tpString;    fd->appType = dbField::tpStdString;    fd->dbsSize = sizeof(dbVarying);    fd->alignment = 4;    fd->components = new dbFieldDescriptor("[]");    fd->components->type = fd->components->appType = dbField::tpInt1;    fd->components->dbsSize = fd->components->appSize = fd->components->alignment = 1;     return fd;}#endifinline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, char const*&) {     fd->type = fd->appType = dbField::tpString;     fd->dbsSize = sizeof(dbVarying);     fd->alignment = 4;    fd->components = new dbFieldDescriptor("[]");    fd->components->type = fd->components->appType = dbField::tpInt1;    fd->components->dbsSize = fd->components->appSize = 1;    fd->components->alignment = 1;     return fd;}inline dbFieldDescriptor* dbDescribeField(dbFieldDescriptor* fd, char*&) {     fd->type = fd->appType = dbField::tpString;     fd->dbsSize = sizeof(dbVarying);     fd->alignment = 4;    fd->components = new dbFieldDescriptor("[]");    fd->components->type = fd->components->appType = dbField::tpInt1;    fd->components->dbsSize = fd->components->appSize = 1;    fd->components->alignment = 1;     return fd;}/**  * Trampolinefor invocation of methods from SubSQL */class FASTDB_DLL_ENTRY dbAnyMethodTrampoline {   public:    dbFieldDescriptor* cls;    /**     * Invoke method     * @param data pointer to the record insode database     * @param result pointer to place result in      */    virtual void invoke(byte* data, void* result) = 0;    /**     * Get optimize trampoline. Optimized trampoline can be used for records     * which format in the database is the same as in application. In this case     * there is no need to fetch record and pointer insode database can be used intead     * @return optimized nethod trampoline     */    virtual dbAnyMethodTrampoline* optimize() = 0;    /**     * Method tramopile constructor     * @param fd method descriptor     */    dbAnyMethodTrampoline(dbFieldDescriptor* fd) { cls = fd; }        void* operator new(size_t size EXTRA_DEBUG_NEW_PARAMS);    void  operator delete(void* p EXTRA_DEBUG_NEW_PARAMS);    /**     * Trampoline desctructor     */    virtual~dbAnyMethodTrampoline();};    #if defined(__APPLE__) || defined(__VACPP_MULTI__) || defined(__IBMCPP__) || defined(__HP_aCC) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x520 && __SUNPRO_CC_COMPAT == 5)/** * Template for method trampoline implementation */template<class T, class R>class dbMethodTrampoline : public dbAnyMethodTrampoline {  public:    typedef R (T::*mfunc)();    mfunc              method;    dbFieldDescriptor* cls;    bool               optimized;    void invoke(byte* data, void* result) {        if (optimized) {             *(R*)result = (((T*)(data + this->cls->dbsOffs))->*method)();        } else {             T rec;            this->cls->components->fetchRecordFields((byte*)&rec, data);            *(R*)result = (rec.*method)();        }    }    dbAnyMethodTrampoline* optimize() {         optimized = true;        return this;    }    dbMethodTrampoline(dbFieldDescriptor* fd, mfunc f)    : dbAnyMethodTrampoline(fd)    {        this->method = f;        this->cls = fd;        this->optimized = false;    }};#else/** * Template for method trampoline implementation */template<class T, class R>class dbMethodTrampoline : public dbAnyMethodTrampoline {   public:    typedef R (T::*mfunc)();    mfunc method;    void invoke(byte* data, void* result) {        T rec;        this->cls->components->fetchRecordFields((byte*)&rec, data);        *(R*)result = (rec.*method)();    }    dbAnyMethodTrampoline* optimize();     dbMethodTrampoline(dbFieldDescriptor* fd, mfunc f)     : dbAnyMethodTrampoline(fd), method(f) {} };/** * Optimized method trampoline which doesn't fetch record from the database * and use direct pointer to the record inside database */template<class T, class R>class dbMethodFastTrampoline : public dbAnyMethodTrampoline {     typedef R (T::*mfunc)();    mfunc method;  public:    dbAnyMethodTrampoline* optimize() {         return this;    }    void invoke(byte* data, void* result) {        *(R*)result = (((T*)(data + this->cls->dbsOffs))->*method)();    }    dbMethodFastTrampoline(dbMethodTrampoline<T,R>* mt)     : dbAnyMethodTrampoline(mt->cls), method(mt->method) {        delete mt;    }};template<class T, class R>inline dbAnyMethodTrampoline* dbMethodTrampoline<T,R>::optimize() {     return new dbMethodFastTrampoline<T,R>(this);}    #endiftemplate<class T, class R>inline dbFieldDescriptor* dbDescribeMethod(dbFieldDescriptor* fd, R (T::*p)()) {     R ret;    dbDescribeField(fd, ret);    assert(fd->type <= dbField::tpReference);    fd->appType = fd->type += dbField::tpMethodBool;    fd->method = new dbMethodTrampoline<T,R>(fd, p);    return fd;}END_FASTDB_NAMESPACE#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -