#ifndef __ODB_STRUCT_H__ #define __ODB_STRUCT_H__ #ifndef _WINDOWS64 #include #endif #include #include #include #include #include "db_api/odb_define.h" #include "common_types.h" #include "db_com/rtdbkey_defs.h" //////////////////////////////////////////////////////// struct SCENARIO_PARA { std::string scenario; unsigned int scenario_id;//note: scenario_id is not used in comparasion, to avoid inconsistent with scenario unsigned int scenario_inst; std::string sub_scenario; unsigned int sub_scenario_id;//note: sub_scenario_id is not used in comparasion, to avoid inconsistent with sub_scenario unsigned int sub_scenario_inst; public: SCENARIO_PARA& operator=(const SCENARIO_PARA& _right); bool operator==(const SCENARIO_PARA& _right) const; bool operator<(const SCENARIO_PARA& _right) const; bool operator<=(const SCENARIO_PARA& _right) const; bool operator>(const SCENARIO_PARA& _right) const; bool operator>=(const SCENARIO_PARA& _right) const; std::string to_string() const; }; #ifndef _BIGENDIAN struct KEY_STRU { int key; short field_id; short table_no; }; struct KEY_STRU_AREA { int key:24; int area:8; short field_id; short table_no; }; #else struct KEY_STRU { short table_no; short field_id; int key; }; struct KEY_STRU_AREA { short table_no; short field_id; int area:8; int key:24; }; #endif struct SCENARIO_ID_INFO { unsigned int scenario_id; unsigned int scenario_inst; unsigned int sub_scenario_id; unsigned int sub_scenario_inst; public: //struct SCENARIO_ID_INFO():scenario_id(0),scenario_inst(0),sub_scenario_id(0),sub_scenario_inst(0){} //SCENARIO_PARA& operator=(const SCENARIO_ID_INFO& _right); bool operator==(const SCENARIO_ID_INFO& _right) const; bool operator<(const SCENARIO_ID_INFO& _right) const; bool operator<=(const SCENARIO_ID_INFO& _right) const; bool operator>(const SCENARIO_ID_INFO& _right) const; bool operator>=(const SCENARIO_ID_INFO& _right) const; bool operator!=(const SCENARIO_ID_INFO& _right) const; std::string to_string() const; std::string FormCommonSqlStringID() const; }; typedef cmnInt64 KEY_ID_STRU; typedef cmnUint32 TABLE_NO_T; typedef cmnUint32 COLUMN_NO_T; typedef cmnUint64 ARA_SER_NO_T; struct RTDB_KEY_STRU { cmnUint64 key_id1; //indicate table_id cmnUint64 key_id2; //indicate area_id_serial_no && column_no(4) //Constructor RTDB_KEY_STRU() : key_id1(0), key_id2(0) { } RTDB_KEY_STRU(const TABLE_NO_T table_no, const ARA_SER_NO_T area_serial_no, const COLUMN_NO_T column_no = 0); RTDB_KEY_STRU(const std::string &stringid); //creator //RTDB_KEY_STRU(){key_id1=0;key_id2=0;} inline void create_key(const TABLE_NO_T table_no, const ARA_SER_NO_T area_serial_no, const COLUMN_NO_T column_no = 0); void create_key(const std::string &stringid); //�漰�ַ����IJ��������ܲ���̫�ã����� //operator bool operator==(const RTDB_KEY_STRU &right) const; bool operator!=(const RTDB_KEY_STRU &right) const; bool operator>(const RTDB_KEY_STRU &right) const; bool operator<(const RTDB_KEY_STRU &right) const; bool operator<=(const RTDB_KEY_STRU &right) const; bool operator>=(const RTDB_KEY_STRU &right) const; RTDB_KEY_STRU& operator=(const RTDB_KEY_STRU &right); inline bool is_null() const { return key_id1 == 0 && key_id2 == 0;} inline void set_null() { key_id1 = 0; key_id2 = 0;} //Get Function inline TABLE_NO_T GetTableID() const; inline ARA_SER_NO_T GetAreaSerialNo() const; inline COLUMN_NO_T GetColumnNo() const; //Set Function void SetTableID(TABLE_NO_T table_no); void SetAreaSerialNo(ARA_SER_NO_T area_serial_no); void SetColumnNo(COLUMN_NO_T column_no); std::string FormStringID() const; std::string FormSgID() const; std::string FormCommonSqlStringID() const; int FormSqlStr(char* sql_value, const int length) const; }; struct APP_KEY_STRU { int app_id; RTDB_KEY_STRU key_id; bool operator>(const APP_KEY_STRU &kr) const; bool operator<(const APP_KEY_STRU &kr) const; bool operator==(const APP_KEY_STRU &kr) const; bool operator!=(const APP_KEY_STRU &kr) const; std::string FormCommonSqlStringID() const; int FormSqlStr(char* sql_value, const int length) const; }; struct SCN_ID_STRU { struct SCENARIO_ID_INFO scn_info; RTDB_KEY_STRU key_id; bool operator>(const SCN_ID_STRU &kr) const; bool operator<(const SCN_ID_STRU &kr) const; bool operator==(const SCN_ID_STRU &kr) const; bool operator!=(const SCN_ID_STRU &kr) const; std::string FormCommonSqlStringID() const; std::string FormStringID(); int FormSqlStr(char* sql_value, const int length) const; }; struct APP_ID_STRU { int app_id; RTDB_KEY_STRU key_id; bool operator>(const APP_ID_STRU &kr) const; bool operator<(const APP_ID_STRU &kr) const; bool operator==(const APP_ID_STRU &kr) const; bool operator!=(const APP_ID_STRU &kr) const; std::string FormCommonSqlStringID() const; int FormSqlStr(char* sql_value, const int length) const; }; #ifdef _BIGENDIAN struct COMM_KEY_STRU { short table_no; short column_id; int record_id; }; #else struct COMM_KEY_STRU { int record_id; short column_id; short table_no; }; #endif #ifdef _BIGENDIAN struct COMM_KEY_AREA_STRU { short table_no; short column_id; int area_id:8; int record_id:24; }; #else struct COMM_KEY_AREA_STRU { int record_id:24; int area_id:8; short column_id; short table_no; }; #endif struct _RTDB_KEY_STRU //as same as RTDB_KEY_STRU, to solve the problem that RTDB_KEY_STRU need constructor { cmnUint64 key_id1; cmnUint64 key_id2; bool operator==(const _RTDB_KEY_STRU &right) const; bool operator!=(const _RTDB_KEY_STRU &right) const; bool operator>(const _RTDB_KEY_STRU &right) const; bool operator<(const _RTDB_KEY_STRU &right) const; inline cmnUint32 GetTableID() const; inline cmnUint64 GetAreaSerialNo() const; inline cmnUint32 GetColumnNo() const; }; struct _SCN_ID_STRU { struct SCENARIO_ID_INFO scn_info; _RTDB_KEY_STRU key_id; bool operator>(const _SCN_ID_STRU &kr) const; bool operator<(const _SCN_ID_STRU &kr) const; bool operator==(const _SCN_ID_STRU &kr) const; bool operator!=(const _SCN_ID_STRU &kr) const; std::string FormCommonSqlStringID() const; int FormSqlStr(char* sql_value, const int length) const; }; struct _APP_KEY_STRU //as same as APP_KEY_STRU { int app_id; _RTDB_KEY_STRU key_id; bool operator>(const _APP_KEY_STRU &kr) const; bool operator<(const _APP_KEY_STRU &kr) const; bool operator==(const _APP_KEY_STRU &kr) const; bool operator!=(const _APP_KEY_STRU &kr) const; }; struct _APP_ID_STRU { int app_id; _RTDB_KEY_STRU key_id; bool operator>(const _APP_ID_STRU &kr) const; bool operator<(const _APP_ID_STRU &kr) const; bool operator==(const _APP_ID_STRU &kr) const; bool operator!=(const _APP_ID_STRU &kr) const; }; // //data define for record sort of real time db // union SORT_DATA_TYPE { char to_str[CHN_NAME_LEN]; int to_int; float to_float; double to_double; cmnInt64 to_long; unsigned int to_uint; //KEY_ID_STRU to_key; _APP_KEY_STRU to_appkey; _APP_ID_STRU to_appid; unsigned char to_uchar; _RTDB_KEY_STRU to_rtdbkey; _RTDB_KEY_STRU to_measrtdbkey; _SCN_ID_STRU to_scn_id; }; //lmj add 2004.0521 struct INT_VALUE_STATUS { int value; int status; }; struct FLOAT_VALUE_STATUS { float value; int status; }; struct CHAR_VALUE_STATUS { // char value[CHN_NAME_LEN]; unsigned char value; int status; }; struct LONG_VALUE_STATUS { cmnInt64 value; int status; }; struct UNION_VALUE_STATUS { SORT_DATA_TYPE value; int status; }; struct KEY_ID_STA_STRU { RTDB_KEY_STRU key_id_stru; int status_field; }; ////////////////// file mapping cache ////////////////////////// #define RDB_MAX_MAP_LEN 8000000000 #define RDB_FILE_NAME_LEN 256 typedef cmnInt64 MAP_FILE_KEY; struct MapItem { char *map_file_ptr; char file_name[RDB_FILE_NAME_LEN]; unsigned int map_size; int counter; MAP_FILE_KEY map_id; MapItem *p_next; MapItem *p_prev; MapItem() { map_file_ptr = NULL; map_size = 0; counter = 0; map_id = 0; memset(file_name, 0, RDB_FILE_NAME_LEN); p_next = NULL; p_prev = NULL; } }; struct CMmapList { struct MapItem *m_list; struct MapItem *m_ptail; //tail of list long m_length; unsigned int m_item_num; CMmapList() { m_list = NULL; m_ptail = NULL; m_length = 0; m_item_num = 0; } }; #define MAP_ID_SYSTEM 1 #if 0 struct MAP_FILE_KEY { #ifndef _BIGENDIAN int area_no:8; short table_no; int app_no; int ctx_no:8; #else int ctx_no:8; int app_no; short table_no; int area_no:8; #endif bool operator>(const MAP_FILE_KEY& kr) const { // return ( (this-> > kr.app_id) || // ((this->app_id == kr.app_id) && (this->key_id > kr.key_id)) ); return (*(cmnInt64*)this > (const cmnInt64&)kr); } bool operator<(const MAP_FILE_KEY& kr) const { // return ( (this->ctx_no < kr.ctx_no) || // ((this->ctx_no == kr.ctx_no) && (this->app_no < kr.app_no)) ); return (*(cmnInt64*)this < (const cmnInt64&)kr); } bool operator==(const MAP_FILE_KEY& kr) const { // return ( (this->ctx_no == kr.ctx_no) && (this->app_no == kr.app_no) // && (this->table_no == kr.table_no) && (this->area_no == kr.area_no)); return (*(cmnInt64*)this == (const cmnInt64&)kr); } bool operator!=(const MAP_FILE_KEY& kr) const { /* if(this->ctx_no != kr.ctx_no) return true; if(this->app_no != kr.app_no) return true; if(this->table_no != kr.table_no) return true; if(this->area_no != kr.area_no) return true; return false; */ return (*(cmnInt64*)this != (const cmnInt64&)kr); } }; #endif typedef struct map_file_value { char *map_file_ptr; char file_name[256]; unsigned int map_size; int counter; }RDB_MAP_FILE_VALUE; typedef std::map RDB_FILE_MAP; typedef struct map_file_struct { RDB_FILE_MAP map_file_list; cmnInt64 m_total_cache; }MMapInfoList; #endif