From 6b3f5d1364443c104674c2a6ec0add239c627dc4 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 30 Jul 2022 18:12:22 +0800 Subject: [PATCH] refactor database.cpp (1/2) --- Documents/DevDocument_ZH.md | 7 +- SuperScriptMaterializer.sln | 8 - .../SuperScriptMaterializer.vcxproj | 55 +- .../SuperScriptMaterializer.vcxproj.filters | 6 + SuperScriptMaterializer/data_export.h | 2 +- SuperScriptMaterializer/database.cpp | 905 +++++++++--------- SuperScriptMaterializer/database.h | 354 ++++--- SuperScriptMaterializer/env_export.cpp | 24 +- SuperScriptMaterializer/env_export.h | 12 +- SuperScriptMaterializer/script_export.cpp | 172 ++-- SuperScriptMaterializer/script_export.h | 32 +- SuperScriptMaterializer/shared_export.cpp | 12 +- SuperScriptMaterializer/shared_export.h | 18 +- SuperScriptMaterializer/stdafx.h | 4 +- SuperScriptMaterializer/string_helper.cpp | 0 SuperScriptMaterializer/string_helper.hpp | 1 + SuperScriptMaterializer/vt_menu.cpp | 28 +- SuperScriptMaterializer/vt_player.cpp | 10 +- 18 files changed, 786 insertions(+), 864 deletions(-) create mode 100644 SuperScriptMaterializer/string_helper.cpp create mode 100644 SuperScriptMaterializer/string_helper.hpp diff --git a/Documents/DevDocument_ZH.md b/Documents/DevDocument_ZH.md index a2e39d0..0f9fd16 100644 --- a/Documents/DevDocument_ZH.md +++ b/Documents/DevDocument_ZH.md @@ -39,8 +39,7 @@ SuperScriptMaterializer处理流程里会涉及很多不同的数据库文件,以下是这些数据库和其内表的格式。 其中这些是Materializer直接输出的基于文档的数据库: -* script.db -* data.db +* doc.db * env.db 这些数据库是上面数据库经过Decorator处理可以被Viewer接受的数据库: @@ -50,9 +49,9 @@ SuperScriptMaterializer处理流程里会涉及很多不同的数据库文件, * query.db * composition.db -## script.db 格式 +## doc.db 格式 -script.db导出的是当前Virtools文档内的脚本及其它重要数据。 +doc.db导出的是当前Virtools文档内的脚本及其它重要数据。 表列表: diff --git a/SuperScriptMaterializer.sln b/SuperScriptMaterializer.sln index 2e32779..159f48b 100644 --- a/SuperScriptMaterializer.sln +++ b/SuperScriptMaterializer.sln @@ -12,32 +12,24 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6D751BF5-87D6-4123-94B3-34721938CF04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6D751BF5-87D6-4123-94B3-34721938CF04}.Debug|x64.ActiveCfg = Debug|Any CPU {6D751BF5-87D6-4123-94B3-34721938CF04}.Debug|x86.ActiveCfg = Debug|Any CPU {6D751BF5-87D6-4123-94B3-34721938CF04}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6D751BF5-87D6-4123-94B3-34721938CF04}.Release|x64.ActiveCfg = Release|Any CPU {6D751BF5-87D6-4123-94B3-34721938CF04}.Release|x86.ActiveCfg = Release|Any CPU {4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x64.ActiveCfg = Debug|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x86.ActiveCfg = Debug|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x86.Build.0 = Debug|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|Any CPU.ActiveCfg = Release|Win32 - {4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x64.ActiveCfg = Release|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x86.ActiveCfg = Release|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x86.Build.0 = Release|Win32 {0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Debug|x64.ActiveCfg = Debug|Any CPU {0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Debug|x86.ActiveCfg = Debug|Any CPU {0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Release|x64.ActiveCfg = Release|Any CPU {0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution diff --git a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj index 0f48c8f..90405b8 100644 --- a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj +++ b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -15,7 +16,7 @@ SuperScriptMaterializer 10.0 - + v100 Dynamic @@ -30,18 +31,18 @@ Dynamic DynamicLibrary - + - + - + - + $(VIRTOOLS_OUTPUT_PATH) true @@ -107,31 +108,33 @@ - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + + + + - + - + \ No newline at end of file diff --git a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters index 672533e..f3f5364 100644 --- a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters +++ b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters @@ -42,6 +42,9 @@ 头文件 + + 头文件 + @@ -71,6 +74,9 @@ 源文件 + + 源文件 + diff --git a/SuperScriptMaterializer/data_export.h b/SuperScriptMaterializer/data_export.h index d1bbbb2..a876c96 100644 --- a/SuperScriptMaterializer/data_export.h +++ b/SuperScriptMaterializer/data_export.h @@ -4,6 +4,6 @@ #include "stdafx.h" #include "database.h" -void DigCKObjectData(CKObject* cko, scriptDatabase* db, db_shared_dictData* helper, EXPAND_CK_ID parents); +void DigCKObjectData(CKObject* cko, DocumentDatabase* mDb, dbdoc_data* helper, EXPAND_CK_ID parents); #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp index 3397fa9..ddf7bfd 100644 --- a/SuperScriptMaterializer/database.cpp +++ b/SuperScriptMaterializer/database.cpp @@ -1,671 +1,618 @@ #include "database.h" -#pragma region helper +#pragma region data struct helper -void dbScriptDataStructHelper::init(CKParameterManager* paramManager) { - _db_behavior = new db_script_behavior(); - _db_script = new db_script_script(); - _db_pTarget = new db_script_pTarget(); - _db_pIn = new db_script_pIn(); - _db_pOut = new db_script_pOut(); - _db_bIn = new db_script_bIn(); - _db_bOut = new db_script_bOut(); - _db_bLink = new db_script_bLink(); - _db_pLocal = new db_script_pLocal(); - _db_pAttr = new db_script_pAttr(); - _db_pLink = new db_script_pLink(); - _db_pData = new db_script_pData(); - _db_pOper = new db_script_pOper(); - _db_eLink = new db_script_eLink(); - - _parameterManager = paramManager; - _stringCache = (char*)malloc(STRINGCACHE_SIZE * sizeof(char)); - if (_stringCache == NULL) - throw new std::bad_alloc(); +DbDataStructHelper_Doc::DbDataStructHelper_Doc(CKParameterManager* paramManager) : + script(), script_behavior(), script_pOper(), + script_bIn(), script_bOut(), script_bLink(), + script_pIn(), script_pOut(), script_pLink(), script_eLink(), + script_pLocal(), script_pTarget(), script_pAttr(), + msg(), + _array(), array_header(), array_cell(), + data() { + param_manager = paramManager; } -void dbScriptDataStructHelper::dispose() { - delete _db_behavior; - delete _db_script; - delete _db_pTarget; - delete _db_pIn; - delete _db_pOut; - delete _db_bIn; - delete _db_bOut; - delete _db_bLink; - delete _db_pData; - delete _db_pLink; - delete _db_pLocal; - delete _db_pAttr; - delete _db_pOper; - delete _db_eLink; - - _parameterManager = NULL; - free(_stringCache); +DbDataStructHelper_Doc::~DbDataStructHelper_Doc() { + ; } -void dbDataDataStructHelper::init(CKParameterManager* paramManager) { - _db_obj = new db_data_obj(); - _db_objHeader = new db_data_objHeader(); - _db_objBody = new db_data_objBody(); - _db_objParam = new db_data_objParam(); - _db_msg = new db_data_msg(); - - _parameterManager = paramManager; - _stringCache = (char*)malloc(STRINGCACHE_SIZE * sizeof(char)); - if (_stringCache == NULL) - throw new std::bad_alloc(); +DbDataStructHelper_Env::DbDataStructHelper_Env() : + op(), param(), attr(), plugin(), variable() { + ; } -void dbDataDataStructHelper::dispose() { - delete _db_obj; - delete _db_objHeader; - delete _db_objBody; - delete _db_objParam; - delete _db_msg; - - _parameterManager = NULL; - free(_stringCache); -} - -void dbEnvDataStructHelper::init() { - _db_op = new db_env_op(); - _db_param = new db_env_param(); - _db_attr = new db_env_attr(); - _db_plugin = new db_env_plugin(); - _db_variable = new db_env_variable(); - - _stringCache = (char*)malloc(STRINGCACHE_SIZE * sizeof(char)); - if (_stringCache == NULL) - throw new std::bad_alloc(); -} - -void dbEnvDataStructHelper::dispose() { - delete _db_op; - delete _db_param; - delete _db_attr; - delete _db_plugin; - delete _db_variable; - - free(_stringCache); +DbDataStructHelper_Env::~DbDataStructHelper_Env() { + ; } #pragma endregion +#pragma region universal sqlite database init and free -#pragma region general func - -void database::open(const char* file) { - db = NULL; - stmtCache = new std::vector(); - - //open db +SSMaterializerDatabase::SSMaterializerDatabase(const char* file) : + mStmtCache(), mDb(NULL) { + // open mDb int result; - result = sqlite3_open(file, &db); + result = sqlite3_open(file, &mDb); if (result != SQLITE_OK) goto fail; // disable synchronous - result = sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); + result = sqlite3_exec(mDb, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); if (result != SQLITE_OK) goto fail; - // do some custom init - if (!init()) goto fail; + // do some custom Init + if (!Init()) goto fail; //start job - sqlite3_exec(db, "begin;", NULL, NULL, NULL); + sqlite3_exec(mDb, "begin;", NULL, NULL, NULL); return; fail: - db = NULL; + mDb = NULL; } -void database::close() { - if (db == NULL) return; +SSMaterializerDatabase::~SSMaterializerDatabase() { + if (mDb == NULL) return; - //stop job - for (auto it = stmtCache->begin(); it != stmtCache->end(); it++) { + //free all cached stmts and commit job + for (auto it = mStmtCache.begin(); it != mStmtCache.end(); it++) { if (*it != NULL) sqlite3_finalize(*it); } - sqlite3_exec(db, "commit;", NULL, NULL, NULL); + sqlite3_exec(mDb, "commit;", NULL, NULL, NULL); // do some custom job - finalJob(); + Finalize(); //release res - sqlite3_close(db); - db = NULL; - delete stmtCache; + sqlite3_close(mDb); + mDb = NULL; } -sqlite3_stmt* database::safeStmt(size_t index) { - if (index >= stmtCache->size()) { - // need resize - stmtCache->resize(index + 1, NULL); - } +sqlite3_stmt* SSMaterializerDatabase::CreateStmt(const char* str_stmt) { + int result; + sqlite3_stmt* stmt = NULL; + result = sqlite3_prepare_v2(mDb, str_stmt, -1, &stmt, NULL); + if (result != SQLITE_OK) return NULL; + + // append new one + mStmtCache.push_back(stmt); } -#define createTable(sql) result=sqlite3_exec(db,sql,NULL,NULL,NULL);if(result!=SQLITE_OK)return FALSE; +#pragma endregion -BOOL scriptDatabase::init() { - pAttrUniqueEnsurance = new std::set(); +#pragma region sub-database constructor and deconstructor +DocumentDatabase::DocumentDatabase(const char* file) : + SSMaterializerDatabase(file), m_pAttrUniqueEnsurance() { + ; +} + +DocumentDatabase::~DocumentDatabase() { + ; +} + +EnvironmentDatabase::EnvironmentDatabase(const char* file) : + SSMaterializerDatabase(file) { + ; +} + +EnvironmentDatabase::~EnvironmentDatabase() { + ; +} + +#pragma endregion + +#pragma region table, index creation functions + +#define SafeSqlExec(sql) result = sqlite3_exec(mDb, sql, NULL, NULL, NULL); \ +if (result != SQLITE_OK) { return FALSE; } + +BOOL DocumentDatabase::Init() { + int result; + + //Init table + SafeSqlExec("begin;"); + + SafeSqlExec("CREATE TABLE [script] ([thisobj] INTEGER, [name] TEXT, [index] INTEGER, [behavior] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_behavior] ([thisobj] INTEGER, [name] TEXT, [type] INTEGER, [proto_name] TEXT, [proto_guid] TEXT, [flags] INTEGER, [priority] INTEGER, [version] INTEGER, [pin_count] TEXT, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pTarget] ([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [parent] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pIn] ([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [parent] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pOut] ([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_bIn] ([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_bOut] ([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_bLink] ([input] INTEGER, [output] INTEGER, [delay] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_index] INETEGR, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pLocal] ([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [is_setting] INTEGER, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pLink] ([input] INTEGER, [output] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_is_bb] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_is_bb] INTEGER, [output_index] INETEGR, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pOper] ([thisobj] INTEGER, [op] TEXT, [op_guid] TEXT, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_eLink] ([export_obj] INTEGER, [internal_obj] INTEGER, [is_in] INTEGER, [index] INTEGER, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [script_pAttr] ([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT);"); + + SafeSqlExec("CREATE TABLE [msg] ([index] INTEGER, [name] TEXT);"); + + SafeSqlExec("CREATE TABLE [array] ([thisobj] INTEGER, [name] TEXT, [rows] INTEGER, [columns] INTEGER);"); + SafeSqlExec("CREATE TABLE [array_header] ([index] INTEGER, [name] TEXT, [type] INTEGER, [param_type] TEXT, [param_type_guid] TEXT, [parent] INTEGER);"); + SafeSqlExec("CREATE TABLE [array_cell] ([row] INTEGER, [column] INTEGER, [showcase] TEXT, [inner_param] INTEGER, [parent] INTEGER);"); + + SafeSqlExec("CREATE TABLE [data] ([field] TEXT, [data] TEXT, [parent] INTEGER);"); + + SafeSqlExec("commit;"); + + return TRUE; +} + +BOOL DocumentDatabase::Finalize() { + //create index for quick select in SuperScriptDecorator + int result; + + SafeSqlExec("begin;"); + SafeSqlExec("CREATE INDEX [quick_where1] ON [script_behavior] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where2] ON [script_pOper] ([parent], [thisobj])"); + SafeSqlExec("CREATE INDEX [quick_where3] ON [script_pTarget] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where4] ON [script_bIn] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where5] ON [script_bOut] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where6] ON [script_pIn] ([parent], [thisobj])"); + SafeSqlExec("CREATE INDEX [quick_where7] ON [script_pOut] ([parent], [thisobj])"); + SafeSqlExec("CREATE INDEX [quick_where8] ON [script_pLocal] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where9] ON [script_pLink] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where10] ON [script_bLink] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where11] ON [script_elink] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where12] ON [script_pAttr] ([thisobj])"); + SafeSqlExec("CREATE INDEX [quick_where13] ON [array_cell] ([parent])"); + SafeSqlExec("CREATE INDEX [quick_where14] ON [data] ([parent])"); + SafeSqlExec("commit;"); + + return TRUE; +} + +BOOL EnvironmentDatabase::Init() { int result; //init table - result = sqlite3_exec(db, "begin;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; + SafeSqlExec("begin;"); - createTable("CREATE TABLE script([thisobj] INTEGER, [name] TEXT, [index] INTEGER, [behavior] INTEGER);"); - createTable("CREATE TABLE behavior([thisobj] INTEGER, [name] TEXT, [type] INTEGER, [proto_name] TEXT, [proto_guid] TEXT, [flags] INTEGER, [priority] INTEGER, [version] INTEGER, [pin_count] TEXT, [parent] INTEGER);"); - createTable("CREATE TABLE pTarget([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);"); - createTable("CREATE TABLE pIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);"); - createTable("CREATE TABLE pOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE bIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE bOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE bLink([input] INTEGER, [output] INTEGER, [delay] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);"); - createTable("CREATE TABLE pLocal([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [is_setting] INTEGER, [belong_to] INTEGER);"); - createTable("CREATE TABLE pData([field] TEXT, [data] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE pLink([input] INTEGER, [output] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_is_bb] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_is_bb] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);"); - createTable("CREATE TABLE pOper([thisobj] INTEGER, [op] TEXT, [op_guid] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE eLink([export_obj] INTEGER, [internal_obj] INTEGER, [is_in] INTEGER, [index] INTEGER, [belong_to] INTEGER);"); - createTable("CREATE TABLE pAttr([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT);"); + SafeSqlExec("CREATE TABLE [op] ([funcptr] INTEGER, [in1_guid] TEXT, [in2_guid] TEXT, [out_guid] TEXT, [op_guid] TEXT, [op_name] TEXT, [op_code] INTEGER);"); + SafeSqlExec("CREATE TABLE [param] ([index] INTEGER, [guid] TEXT, [derived_from] TEXT, [type_name] TEXT, [default_size] INTEGER, [func_CreateDefault] INTEGER, [func_Delete] INTEGER, [func_SaveLoad] INTEGER, [func_Check] INTEGER, [func_Copy] INTEGER, [func_String] INTEGER, [func_UICreator] INTEGER, [creator_dll_index] INTEGER, [creator_plugin_index] INTEGER, [dw_param] INTEGER, [dw_flags] INTEGER, [cid] INTEGER, [saver_manager] TEXT);"); + SafeSqlExec("CREATE TABLE [attr] ([index] INTEGER, [name] TEXT, [category_index] INTEGER, [category_name] TEXT, [flags] INTEGER, [param_index] INTEGER, [compatible_classid] INTEGER, [default_value] TEXT);"); + SafeSqlExec("CREATE TABLE [plugin] ([dll_index] INTEGER, [dll_name] TEXT, [plugin_index] INTEGER, [category] TEXT, [active] INTEGER, [guid] TEXT, [desc] TEXT, [author] TEXT, [summary] TEXT, [version] INTEGER, [func_init] INTEGER, [func_exit] INTEGER);"); + SafeSqlExec("CREATE TABLE [variable] ([name] TEXT, [description] TEXT, [flags] INTEGER, [type] INTEGER, [representation] TEXT, [data] TEXT);"); - result = sqlite3_exec(db, "commit;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; + SafeSqlExec("commit;"); return TRUE; } -BOOL scriptDatabase::finalJob() { - //create index for quick select in following app - sqlite3_exec(db, "begin;", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where1] ON behavior ([parent])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where2] ON pOper ([belong_to], [thisobj])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where3] ON pTarget ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where4] ON bIn ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where5] ON bOut ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where6] ON pIn ([belong_to], [thisobj])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where7] ON pOut ([belong_to], [thisobj])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where8] ON pLocal ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where9] ON pLink ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where10] ON bLink ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where11] ON elink ([belong_to])", NULL, NULL, NULL); - sqlite3_exec(db, "CREATE INDEX [quick_where12] ON pAttr ([thisobj])", NULL, NULL, NULL); - sqlite3_exec(db, "commit;", NULL, NULL, NULL); - - delete pAttrUniqueEnsurance; +BOOL EnvironmentDatabase::Finalize() { return TRUE; } -BOOL dataDatabase::init() { - - int result; - - //init table - result = sqlite3_exec(db, "begin;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - - createTable("CREATE TABLE obj([thisObj] INTEGER, [name] TEXT, [type_classid] INTEGER, [type_guid] TEXT, [type_name] TEXT, [rows] INTEGER, [columns] INTEGER);"); - createTable("CREATE TABLE objHeader([index] INTEGER, [name] TEXT, [type] INTEGER, [param_type] TEXT, [param_type_guid] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE objBody([row] INTEGER, [column] INTEGER, [showcase] TEXT, [inner_object] INTEGER, [inner_param] INTEGER, [belong_to] INTEGER);"); - createTable("CREATE TABLE objParam([field] TEXT, [data] TEXT, [belong_to] INTEGER);"); - createTable("CREATE TABLE msg([index] INTEGER, [name] TEXT);"); - - result = sqlite3_exec(db, "commit;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - - return TRUE; -} - -BOOL dataDatabase::finalJob() { - return TRUE; -} - -BOOL envDatabase::init() { - - int result; - - //init table - result = sqlite3_exec(db, "begin;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - - createTable("CREATE TABLE op([funcptr] INTEGER, [in1_guid] TEXT, [in2_guid] TEXT, [out_guid] TEXT, [op_guid] TEXT, [op_name] TEXT, [op_code] INTEGER);"); - createTable("CREATE TABLE param([index] INTEGER, [guid] TEXT, [derived_from] TEXT, [type_name] TEXT, [default_size] INTEGER, [func_CreateDefault] INTEGER, [func_Delete] INTEGER, [func_SaveLoad] INTEGER, [func_Check] INTEGER, [func_Copy] INTEGER, [func_String] INTEGER, [func_UICreator] INTEGER, [creator_dll_index] INTEGER, [creator_plugin_index] INTEGER, [dw_param] INTEGER, [dw_flags] INTEGER, [cid] INTEGER, [saver_manager] TEXT);"); - createTable("CREATE TABLE attr([index] INTEGER, [name] TEXT, [category_index] INTEGER, [category_name] TEXT, [flags] INTEGER, [param_index] INTEGER, [compatible_classid] INTEGER, [default_value] TEXT);"); - createTable("CREATE TABLE plugin([dll_index] INTEGER, [dll_name] TEXT, [plugin_index] INTEGER, [category] TEXT, [active] INTEGER, [needed_by_file] INTEGER, [guid] TEXT, [desc] TEXT, [author] TEXT, [summary] TEXT, [version] INTEGER, [func_init] INTEGER, [func_exit] INTEGER);"); - createTable("CREATE TABLE [variable] ([name] TEXT, [description] TEXT, [flags] INTEGER, [type] INTEGER, [representation] TEXT, [data] TEXT);"); - - result = sqlite3_exec(db, "commit;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - - return TRUE; -} - -BOOL envDatabase::finalJob() { - return TRUE; -} - -#undef createTable +#undef SafeSqlExec #pragma endregion #pragma region write func -#define tryGetStmt(index,defaultStr) safeStmt(index);stmt=(*stmtCache)[index];if(stmt==NULL){sqlite3_prepare_v2(db,defaultStr,-1,&stmt,NULL);(*stmtCache)[index]=stmt;} +#define TryGetStmtCache(str_sql) static sqlite3_stmt* stmt = NULL; \ +if (stmt == NULL) { \ + stmt = CreateStmt(str_sql); \ + if (stmt == NULL) return; \ +} -void scriptDatabase::write_behavior(db_script_behavior* data) { - if (db == NULL) return; +void DocumentDatabase::write_script(dbdoc_script& data) { + if (mDb == NULL) return; - sqlite3_stmt* stmt = NULL; - tryGetStmt(0, "INSERT INTO behavior VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + TryGetStmtCache("INSERT INTO [script] VALUES (?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->type); - sqlite3_bind_text(stmt, 4, data->proto_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data->proto_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 6, data->flags); - sqlite3_bind_int(stmt, 7, data->priority); - sqlite3_bind_int(stmt, 8, data->version); - sqlite3_bind_text(stmt, 9, data->pin_count.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 10, data->parent); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_text(stmt, 2, data.host_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data.index); + sqlite3_bind_int(stmt, 4, data.behavior); sqlite3_step(stmt); } -void scriptDatabase::write_script(db_script_script* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_behavior(dbdoc_script_behavior& data) { + if (mDb == NULL) return; - sqlite3_stmt* stmt = NULL; - tryGetStmt(1, "INSERT INTO script VALUES (?, ?, ?, ?)"); + TryGetStmtCache("INSERT INTO [script_behavior] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->host_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->index); - sqlite3_bind_int(stmt, 4, data->behavior); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data.type); + sqlite3_bind_text(stmt, 4, data.proto_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, data.proto_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 6, data.flags); + sqlite3_bind_int(stmt, 7, data.priority); + sqlite3_bind_int(stmt, 8, data.version); + sqlite3_bind_text(stmt, 9, data.pin_count.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 10, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_pTarget(db_script_pTarget* data) { - if (db == NULL) return; + +void DocumentDatabase::write_script_pTarget(dbdoc_script_pTarget& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(2, "INSERT INTO pTarget VALUES (?, ?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(2, "INSERT INTO [script_pTarget] VALUES (?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, data->type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 5, data->belong_to); - sqlite3_bind_int(stmt, 6, data->direct_source); - sqlite3_bind_int(stmt, 7, data->shared_source); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, data.type.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 5, data.parent); + sqlite3_bind_int(stmt, 6, data.direct_source); + sqlite3_bind_int(stmt, 7, data.shared_source); sqlite3_step(stmt); } -void scriptDatabase::write_pIn(db_script_pIn* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_pIn(dbdoc_script_pIn& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(3, "INSERT INTO pIn VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(3, "INSERT INTO [script_pIn] VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_int(stmt, 2, data->index); - sqlite3_bind_text(stmt, 3, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 6, data->belong_to); - sqlite3_bind_int(stmt, 7, data->direct_source); - sqlite3_bind_int(stmt, 8, data->shared_source); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_int(stmt, 2, data.index); + sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.type.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 6, data.parent); + sqlite3_bind_int(stmt, 7, data.direct_source); + sqlite3_bind_int(stmt, 8, data.shared_source); sqlite3_step(stmt); } -void scriptDatabase::write_pOut(db_script_pOut* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_pOut(dbdoc_script_pOut& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(4, "INSERT INTO pOut VALUES (?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(4, "INSERT INTO [script_pOut] VALUES (?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_int(stmt, 2, data->index); - sqlite3_bind_text(stmt, 3, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 6, data->belong_to); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_int(stmt, 2, data.index); + sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.type.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 6, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_bIn(db_script_bIn* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_bIn(dbdoc_script_bIn& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(5, "INSERT INTO bIn VALUES (?, ?, ?, ?)"); + TryGetStmtCache(5, "INSERT INTO [script_bIn] VALUES (?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_int(stmt, 2, data->index); - sqlite3_bind_text(stmt, 3, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 4, data->belong_to); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_int(stmt, 2, data.index); + sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 4, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_bOut(db_script_bOut* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_bOut(dbdoc_script_bOut& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(6, "INSERT INTO bOut VALUES (?, ?, ?, ?)"); + TryGetStmtCache(6, "INSERT INTO [script_bOut] VALUES (?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_int(stmt, 2, data->index); - sqlite3_bind_text(stmt, 3, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 4, data->belong_to); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_int(stmt, 2, data.index); + sqlite3_bind_text(stmt, 3, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 4, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_bLink(db_script_bLink* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_bLink(dbdoc_script_bLink& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(7, "INSERT INTO bLink VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(7, "INSERT INTO [script_bLink] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->input); - sqlite3_bind_int(stmt, 2, data->output); - sqlite3_bind_int(stmt, 3, data->delay); - sqlite3_bind_int(stmt, 4, data->input_obj); - sqlite3_bind_int(stmt, 5, data->input_type); - sqlite3_bind_int(stmt, 6, data->input_index); - sqlite3_bind_int(stmt, 7, data->output_obj); - sqlite3_bind_int(stmt, 8, data->output_type); - sqlite3_bind_int(stmt, 9, data->output_index); - sqlite3_bind_int(stmt, 10, data->belong_to); + sqlite3_bind_int(stmt, 1, data.input); + sqlite3_bind_int(stmt, 2, data.output); + sqlite3_bind_int(stmt, 3, data.delay); + sqlite3_bind_int(stmt, 4, data.input_obj); + sqlite3_bind_int(stmt, 5, data.input_type); + sqlite3_bind_int(stmt, 6, data.input_index); + sqlite3_bind_int(stmt, 7, data.output_obj); + sqlite3_bind_int(stmt, 8, data.output_type); + sqlite3_bind_int(stmt, 9, data.output_index); + sqlite3_bind_int(stmt, 10, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_pLocal(db_script_pLocal* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_pLocal(dbdoc_script_pLocal& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(8, "INSERT INTO pLocal VALUES (?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(8, "INSERT INTO [script_pLocal] VALUES (?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, data->type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 5, data->is_setting); - sqlite3_bind_int(stmt, 6, data->belong_to); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, data.type.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 5, data.is_setting); + sqlite3_bind_int(stmt, 6, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_pLink(db_script_pLink* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_pLink(dbdoc_script_pLink& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(9, "INSERT INTO pLink VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(9, "INSERT INTO [script_pLink] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->input); - sqlite3_bind_int(stmt, 2, data->output); - sqlite3_bind_int(stmt, 3, data->input_obj); - sqlite3_bind_int(stmt, 4, data->input_type); - sqlite3_bind_int(stmt, 5, data->input_is_bb); - sqlite3_bind_int(stmt, 6, data->input_index); - sqlite3_bind_int(stmt, 7, data->output_obj); - sqlite3_bind_int(stmt, 8, data->output_type); - sqlite3_bind_int(stmt, 9, data->output_is_bb); - sqlite3_bind_int(stmt, 10, data->output_index); - sqlite3_bind_int(stmt, 11, data->belong_to); + sqlite3_bind_int(stmt, 1, data.input); + sqlite3_bind_int(stmt, 2, data.output); + sqlite3_bind_int(stmt, 3, data.input_obj); + sqlite3_bind_int(stmt, 4, data.input_type); + sqlite3_bind_int(stmt, 5, data.input_is_bb); + sqlite3_bind_int(stmt, 6, data.input_index); + sqlite3_bind_int(stmt, 7, data.output_obj); + sqlite3_bind_int(stmt, 8, data.output_type); + sqlite3_bind_int(stmt, 9, data.output_is_bb); + sqlite3_bind_int(stmt, 10, data.output_index); + sqlite3_bind_int(stmt, 11, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_pData(db_script_pData* data) { - if (db == NULL) return; +//void DocumentDatabase::write_pData(db_script_pData* data) { +// if (mDb == NULL) return; +// +// sqlite3_stmt* stmt = NULL; +// TryGetStmtCache(10, "INSERT INTO pData VALUES (?, ?, ?)"); +// sqlite3_reset(stmt); +// +// sqlite3_bind_text(stmt, 1, data.field.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_text(stmt, 2, data.data.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 3, data.parent); +// sqlite3_step(stmt); +//} + +void DocumentDatabase::write_script_pOper(dbdoc_script_pOper& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(10, "INSERT INTO pData VALUES (?, ?, ?)"); + TryGetStmtCache(11, "INSERT INTO [script_pOper] VALUES (?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_text(stmt, 1, data->field.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 2, data->data.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->belong_to); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_text(stmt, 2, data.op.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, data.op_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 4, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_pOper(db_script_pOper* data) { - if (db == NULL) return; +void DocumentDatabase::write_script_eLink(dbdoc_script_eLink& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(11, "INSERT INTO pOper VALUES (?, ?, ?, ?)"); + TryGetStmtCache(12, "INSERT INTO [script_eLink] VALUES (?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->op.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, data->op_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 4, data->belong_to); + sqlite3_bind_int(stmt, 1, data.export_obj); + sqlite3_bind_int(stmt, 2, data.internal_obj); + sqlite3_bind_int(stmt, 3, data.is_in); + sqlite3_bind_int(stmt, 4, data.index); + sqlite3_bind_int(stmt, 5, data.parent); sqlite3_step(stmt); } -void scriptDatabase::write_eLink(db_script_eLink* data) { - if (db == NULL) return; +BOOL DocumentDatabase::write_script_pAttr(dbdoc_script_pAttr& data) { + if (mDb == NULL) return TRUE; - sqlite3_stmt* stmt = NULL; - tryGetStmt(12, "INSERT INTO eLink VALUES (?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data->export_obj); - sqlite3_bind_int(stmt, 2, data->internal_obj); - sqlite3_bind_int(stmt, 3, data->is_in); - sqlite3_bind_int(stmt, 4, data->index); - sqlite3_bind_int(stmt, 5, data->belong_to); - sqlite3_step(stmt); -} - -BOOL scriptDatabase::write_pAttr(db_script_pAttr* data) { - if (db == NULL) return TRUE; - - if (pAttrUniqueEnsurance->find(data->thisobj) != pAttrUniqueEnsurance->end()) + if (m_pAttrUniqueEnsurance->find(data.thisobj) != m_pAttrUniqueEnsurance->end()) return FALSE; //existing item. skip it to make sure unique - pAttrUniqueEnsurance->insert(data->thisobj); //add this item + m_pAttrUniqueEnsurance->insert(data.thisobj); //add this item sqlite3_stmt* stmt = NULL; - tryGetStmt(13, "INSERT INTO pAttr VALUES (?, ?, ?, ?)"); + TryGetStmtCache(13, "INSERT INTO [script_pAttr] VALUES (?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, data->type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 1, data.thisobj); + sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, data.type.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); return TRUE; } +// +//void dataDatabase::write_obj(dbdoc_array* data) { +// if (mDb == NULL) return; +// +// sqlite3_stmt* stmt = NULL; +// TryGetStmtCache(0, "INSERT INTO objParam VALUES (?, ?, ?)"); +// sqlite3_reset(stmt); +// +// sqlite3_bind_int(stmt, 1, data.thisobj); +// sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 3, data.type_classid); +// sqlite3_bind_text(stmt, 4, data.type_guid.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_text(stmt, 5, data.type_name.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 6, data.rows); +// sqlite3_bind_int(stmt, 7, data.columns); +// sqlite3_step(stmt); +//} +// +//void dataDatabase::write_objHeader(dbdoc_array_header* data) { +// if (mDb == NULL) return; +// +// sqlite3_stmt* stmt = NULL; +// TryGetStmtCache(1, "INSERT INTO objParam VALUES (?, ?, ?)"); +// sqlite3_reset(stmt); +// +// sqlite3_bind_int(stmt, 1, data.index); +// sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 3, data->type); +// sqlite3_bind_text(stmt, 4, data->param_type.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_text(stmt, 5, data->param_type_guid.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 6, data->parent); +// sqlite3_step(stmt); +//} +// +//void dataDatabase::write_objBody(dbdoc_array_cell* data) { +// if (mDb == NULL) return; +// +// sqlite3_stmt* stmt = NULL; +// TryGetStmtCache(2, "INSERT INTO objParam VALUES (?, ?, ?)"); +// sqlite3_reset(stmt); +// +// sqlite3_bind_int(stmt, 1, data->row); +// sqlite3_bind_int(stmt, 2, data->column); +// sqlite3_bind_text(stmt, 3, data->showcase.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 4, data->inner_object); +// sqlite3_bind_int(stmt, 5, data->inner_param); +// sqlite3_bind_int(stmt, 6, data->parent); +// sqlite3_step(stmt); +//} +// +//void dataDatabase::write_objParam(db_data_objParam* data) { +// if (mDb == NULL) return; +// +// sqlite3_stmt* stmt = NULL; +// TryGetStmtCache(3, "INSERT INTO objParam VALUES (?, ?, ?)"); +// sqlite3_reset(stmt); +// +// sqlite3_bind_text(stmt, 1, data->field.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_text(stmt, 2, data->data.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_bind_int(stmt, 3, data->parent); +// sqlite3_step(stmt); +//} +// +//void dataDatabase::write_msg(dbdoc_msg* data) { +// if (mDb == NULL) return; +// +// sqlite3_stmt* stmt = NULL; +// TryGetStmtCache(4, "INSERT INTO msg VALUES (?, ?)"); +// sqlite3_reset(stmt); +// +// sqlite3_bind_int(stmt, 1, data->index); +// sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); +// sqlite3_step(stmt); +//} -void dataDatabase::write_obj(db_data_obj* data) { - if (db == NULL) return; + + +void EnvironmentDatabase::write_op(dbenv_op& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(0, "INSERT INTO objParam VALUES (?, ?, ?)"); + TryGetStmtCache(0, "INSERT INTO [op] VALUES (?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->thisobj); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->type_classid); - sqlite3_bind_text(stmt, 4, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data->type_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 6, data->rows); - sqlite3_bind_int(stmt, 7, data->columns); + sqlite3_bind_int(stmt, 1, (int)data.funcPtr); + sqlite3_bind_text(stmt, 2, data.in1_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, data.in2_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.out_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, data.op_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 6, data.op_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 7, data.op_code); sqlite3_step(stmt); } -void dataDatabase::write_objHeader(db_data_objHeader* data) { - if (db == NULL) return; +void EnvironmentDatabase::write_param(dbenv_param& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(1, "INSERT INTO objParam VALUES (?, ?, ?)"); + TryGetStmtCache(1, "INSERT INTO [param] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->index); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->type); - sqlite3_bind_text(stmt, 4, data->param_type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data->param_type_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 6, data->belong_to); + sqlite3_bind_int(stmt, 1, data.index); + sqlite3_bind_text(stmt, 2, data.guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, data.derived_from.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 4, data.type_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 5, data.default_size); + sqlite3_bind_int(stmt, 6, (int)data.func_CreateDefault); + sqlite3_bind_int(stmt, 7, (int)data.func_Delete); + sqlite3_bind_int(stmt, 8, (int)data.func_SaveLoad); + sqlite3_bind_int(stmt, 9, (int)data.func_Check); + sqlite3_bind_int(stmt, 10, (int)data.func_Copy); + sqlite3_bind_int(stmt, 11, (int)data.func_String); + sqlite3_bind_int(stmt, 12, (int)data.func_UICreator); + sqlite3_bind_int(stmt, 13, data.creator_dll_index); + sqlite3_bind_int(stmt, 14, data.creator_plugin_index); + sqlite3_bind_int(stmt, 15, data.dw_param); + sqlite3_bind_int(stmt, 16, data.dw_flags); + sqlite3_bind_int(stmt, 17, data.cid); + sqlite3_bind_text(stmt, 18, data.saver_manager.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); } -void dataDatabase::write_objBody(db_data_objBody* data) { - if (db == NULL) return; +void EnvironmentDatabase::write_attr(dbenv_attr& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(2, "INSERT INTO objParam VALUES (?, ?, ?)"); + TryGetStmtCache(2, "INSERT INTO [attr] VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_int(stmt, 1, data->row); - sqlite3_bind_int(stmt, 2, data->column); - sqlite3_bind_text(stmt, 3, data->showcase.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 4, data->inner_object); - sqlite3_bind_int(stmt, 5, data->inner_param); - sqlite3_bind_int(stmt, 6, data->belong_to); + sqlite3_bind_int(stmt, 1, data.index); + sqlite3_bind_text(stmt, 2, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data.category_index); + sqlite3_bind_text(stmt, 4, data.category_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 5, data.flags); + sqlite3_bind_int(stmt, 6, data.param_index); + sqlite3_bind_int(stmt, 7, data.compatible_classid); + sqlite3_bind_text(stmt, 8, data.default_value.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); } -void dataDatabase::write_objParam(db_data_objParam* data) { - if (db == NULL) return; +void EnvironmentDatabase::write_plugin(dbenv_plugin& data) { + if (mDb == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(3, "INSERT INTO objParam VALUES (?, ?, ?)"); + TryGetStmtCache(3, "INSERT INTO [plugin] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_text(stmt, 1, data->field.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 2, data->data.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->belong_to); + sqlite3_bind_int(stmt, 1, data.dll_index); + sqlite3_bind_text(stmt, 2, data.dll_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data.plugin_index); + sqlite3_bind_text(stmt, 4, data.category.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 5, data.active); + sqlite3_bind_int(stmt, 6, data.needed_by_file); + sqlite3_bind_text(stmt, 7, data.guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 8, data.desc.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 9, data.author.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 10, data.summary.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 11, data.version); + sqlite3_bind_int(stmt, 12, (int)data.func_init); + sqlite3_bind_int(stmt, 13, (int)data.func_exit); sqlite3_step(stmt); } -void dataDatabase::write_msg(db_data_msg* data) { - if (db == NULL) return; - - sqlite3_stmt* stmt = NULL; - tryGetStmt(4, "INSERT INTO msg VALUES (?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data->index); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_step(stmt); -} - - -void envDatabase::write_op(db_env_op* data) { - if (db == NULL) return; - - sqlite3_stmt* stmt = NULL; - tryGetStmt(0, "INSERT INTO op VALUES (?, ?, ?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, (int)data->funcPtr); - sqlite3_bind_text(stmt, 2, data->in1_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, data->in2_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->out_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, data->op_guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 6, data->op_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 7, data->op_code); - sqlite3_step(stmt); -} - -void envDatabase::write_param(db_env_param* data) { - if (db == NULL) return; - - sqlite3_stmt* stmt = NULL; - tryGetStmt(1, "INSERT INTO param VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data->index); - sqlite3_bind_text(stmt, 2, data->guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, data->derived_from.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 4, data->type_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 5, data->default_size); - sqlite3_bind_int(stmt, 6, (int)data->func_CreateDefault); - sqlite3_bind_int(stmt, 7, (int)data->func_Delete); - sqlite3_bind_int(stmt, 8, (int)data->func_SaveLoad); - sqlite3_bind_int(stmt, 9, (int)data->func_Check); - sqlite3_bind_int(stmt, 10, (int)data->func_Copy); - sqlite3_bind_int(stmt, 11, (int)data->func_String); - sqlite3_bind_int(stmt, 12, (int)data->func_UICreator); - sqlite3_bind_int(stmt, 13, data->creator_dll_index); - sqlite3_bind_int(stmt, 14, data->creator_plugin_index); - sqlite3_bind_int(stmt, 15, data->dw_param); - sqlite3_bind_int(stmt, 16, data->dw_flags); - sqlite3_bind_int(stmt, 17, data->cid); - sqlite3_bind_text(stmt, 18, data->saver_manager.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_step(stmt); -} - -void envDatabase::write_attr(db_env_attr* data) { - if (db == NULL) return; - - sqlite3_stmt* stmt = NULL; - tryGetStmt(2, "INSERT INTO attr VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data->index); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->category_index); - sqlite3_bind_text(stmt, 4, data->category_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 5, data->flags); - sqlite3_bind_int(stmt, 6, data->param_index); - sqlite3_bind_int(stmt, 7, data->compatible_classid); - sqlite3_bind_text(stmt, 8, data->default_value.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_step(stmt); -} - -void envDatabase::write_plugin(db_env_plugin* data) { - if (db == NULL) return; - - sqlite3_stmt* stmt = NULL; - tryGetStmt(3, "INSERT INTO plugin VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data->dll_index); - sqlite3_bind_text(stmt, 2, data->dll_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->plugin_index); - sqlite3_bind_text(stmt, 4, data->category.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 5, data->active); - sqlite3_bind_int(stmt, 6, data->needed_by_file); - sqlite3_bind_text(stmt, 7, data->guid.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 8, data->desc.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 9, data->author.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 10, data->summary.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 11, data->version); - sqlite3_bind_int(stmt, 12, (int)data->func_init); - sqlite3_bind_int(stmt, 13, (int)data->func_exit); - sqlite3_step(stmt); -} - -void envDatabase::write_variable(db_env_variable* data) { - if (db == NULL) return; +void EnvironmentDatabase::write_variable(dbenv_variable& data) { + if (mDb == NULL) return; #if !defined(VIRTOOLS_21) sqlite3_stmt* stmt = NULL; - tryGetStmt(4, "INSERT INTO [variable] VALUES (?, ?, ?, ?, ?, ?)"); + TryGetStmtCache(4, "INSERT INTO [variable] VALUES (?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); - sqlite3_bind_text(stmt, 1, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 2, data->desciption.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 3, data->flags); - sqlite3_bind_int(stmt, 4, data->type); - sqlite3_bind_text(stmt, 5, data->representation.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 6, data->data.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 1, data.name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 2, data.desciption.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data.flags); + sqlite3_bind_int(stmt, 4, data.type); + sqlite3_bind_text(stmt, 5, data.representation.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 6, data.data.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); #endif } -#undef tryGetStmt +#undef TryGetStmtCache #pragma endregion + + diff --git a/SuperScriptMaterializer/database.h b/SuperScriptMaterializer/database.h index bd27a98..d195fb3 100644 --- a/SuperScriptMaterializer/database.h +++ b/SuperScriptMaterializer/database.h @@ -6,9 +6,6 @@ #include #include #include -#include "virtools_compatible.h" - -#define STRINGCACHE_SIZE 25565 typedef long EXPAND_CK_ID; enum bLinkInputOutputType { @@ -25,9 +22,16 @@ enum pLinkInputOutputType { #pragma region data struct define -// =================== script db +// =================== doc mDb -typedef struct { +struct dbdoc_script { + EXPAND_CK_ID thisobj; + std::string host_name; + int index; + EXPAND_CK_ID behavior; +}; + +struct dbdoc_script_behavior { EXPAND_CK_ID thisobj; std::string name; CK_BEHAVIOR_TYPE type; @@ -39,59 +43,52 @@ typedef struct { //pTarget, pIn, pOut, bIn, bOut std::string pin_count; EXPAND_CK_ID parent; -}db_script_behavior; +}; -typedef struct { +struct dbdoc_script_bIO { EXPAND_CK_ID thisobj; - std::string host_name; int index; - EXPAND_CK_ID behavior; -}db_script_script; + std::string name; + EXPAND_CK_ID parent; +}; +typedef dbdoc_script_bIO dbdoc_script_bIn; +typedef dbdoc_script_bIO dbdoc_script_bOut; -typedef struct { +struct dbdoc_script_pTarget { EXPAND_CK_ID thisobj; std::string name; std::string type; std::string type_guid; - EXPAND_CK_ID belong_to; + EXPAND_CK_ID parent; EXPAND_CK_ID direct_source; EXPAND_CK_ID shared_source; -}db_script_pTarget; +}; -typedef struct { +struct dbdoc_script_pIn { EXPAND_CK_ID thisobj; int index; std::string name; std::string type; std::string type_guid; - EXPAND_CK_ID belong_to; + EXPAND_CK_ID parent; EXPAND_CK_ID direct_source; EXPAND_CK_ID shared_source; -}db_script_pIn; +}; -typedef struct { +struct dbdoc_script_pOut { EXPAND_CK_ID thisobj; int index; std::string name; std::string type; std::string type_guid; - EXPAND_CK_ID belong_to; -}db_script_pOut; + EXPAND_CK_ID parent; +}; -typedef struct { - EXPAND_CK_ID thisobj; - int index; - std::string name; - EXPAND_CK_ID belong_to; -}db_shared_bIO; -typedef db_shared_bIO db_script_bIn; -typedef db_shared_bIO db_script_bOut; - -typedef struct { +struct dbdoc_script_bLink { EXPAND_CK_ID input; EXPAND_CK_ID output; int delay; - EXPAND_CK_ID belong_to; + EXPAND_CK_ID parent; //additional field EXPAND_CK_ID input_obj; @@ -100,35 +97,28 @@ typedef struct { EXPAND_CK_ID output_obj; bLinkInputOutputType output_type; int output_index; -}db_script_bLink; +}; -typedef struct { +struct dbdoc_script_pLocal { EXPAND_CK_ID thisobj; std::string name; std::string type; std::string type_guid; BOOL is_setting; - EXPAND_CK_ID belong_to; -}db_script_pLocal; + EXPAND_CK_ID parent; +}; -typedef struct { +struct dbdoc_script_pAttr { EXPAND_CK_ID thisobj; std::string name; std::string type; std::string type_guid; -}db_script_pAttr; +}; -typedef struct { - std::string field; - std::string data; - EXPAND_CK_ID belong_to; -}db_shared_dictData; -typedef db_shared_dictData db_script_pData; - -typedef struct { +struct dbdoc_script_pLink { EXPAND_CK_ID input; EXPAND_CK_ID output; - EXPAND_CK_ID belong_to; + EXPAND_CK_ID parent; //additional field EXPAND_CK_ID input_obj; @@ -139,64 +129,61 @@ typedef struct { pLinkInputOutputType output_type; BOOL output_is_bb; int output_index; -}db_script_pLink; +}; -typedef struct { +struct dbdoc_script_pOper { EXPAND_CK_ID thisobj; std::string op; std::string op_guid; - EXPAND_CK_ID belong_to; -}db_script_pOper; + EXPAND_CK_ID parent; +}; -typedef struct { +struct dbdoc_script_eLink { EXPAND_CK_ID export_obj; EXPAND_CK_ID internal_obj; BOOL is_in; int index; - EXPAND_CK_ID belong_to; -}db_script_eLink; + EXPAND_CK_ID parent; +}; +struct dbdoc_msg { + CKMessageType index; + std::string name; +}; -// =================== data db - -typedef struct { +struct dbdoc_array { EXPAND_CK_ID thisobj; std::string name; - CK_CLASSID type_classid; - std::string type_guid; - std::string type_name; int rows; int columns; -}db_data_obj; +}; -typedef struct { +struct dbdoc_array_header { int index; std::string name; CK_ARRAYTYPE type; std::string param_type; std::string param_type_guid; - EXPAND_CK_ID belong_to; -}db_data_objHeader; + EXPAND_CK_ID parent; +}; -typedef struct { +struct dbdoc_array_cell { int row; int column; std::string showcase; - EXPAND_CK_ID inner_object; EXPAND_CK_ID inner_param; - EXPAND_CK_ID belong_to; -}db_data_objBody; + EXPAND_CK_ID parent; +}; -typedef db_shared_dictData db_data_objParam; +struct dbdoc_data { + std::string field; + std::string data; + EXPAND_CK_ID parent; +}; -typedef struct { - CKMessageType index; - std::string name; -}db_data_msg; +// =================== env mDb -// =================== env db - -typedef struct { +struct dbenv_op { CK_PARAMETEROPERATION funcPtr; std::string in1_guid; std::string in2_guid; @@ -204,9 +191,9 @@ typedef struct { std::string op_guid; std::string op_name; CKOperationType op_code; -}db_env_op; +}; -typedef struct { +struct dbenv_param { CKParameterType index; std::string guid; std::string derived_from; @@ -225,9 +212,9 @@ typedef struct { CKDWORD dw_flags; CKDWORD cid; std::string saver_manager; -}db_env_param; +}; -typedef struct { +struct dbenv_attr { CKAttributeType index; std::string name; CKAttributeCategory category_index; @@ -236,15 +223,14 @@ typedef struct { CKParameterType param_index; CK_CLASSID compatible_classid; std::string default_value; -}db_env_attr; +}; -typedef struct { +struct dbenv_plugin { int dll_index; std::string dll_name; int plugin_index; std::string category; CKBOOL active; - CKBOOL needed_by_file; std::string guid; std::string desc; std::string author; @@ -252,136 +238,124 @@ typedef struct { DWORD version; CK_INITINSTANCEFCT func_init; CK_EXITINSTANCEFCT func_exit; -}db_env_plugin; +}; -typedef struct { +struct dbenv_variable { std::string name; std::string desciption; XWORD flags; UNIVERSAL_VAR_TYPE type; std::string representation; std::string data; -}db_env_variable; +}; #pragma endregion -class dbScriptDataStructHelper { - public: - void init(CKParameterManager* paramManager); - void dispose(); - - char* _stringCache; - CKParameterManager* _parameterManager; - db_script_behavior* _db_behavior; - db_script_script* _db_script; - db_script_pTarget* _db_pTarget; - db_script_pIn* _db_pIn; - db_script_pOut* _db_pOut; - db_script_bIn* _db_bIn; - db_script_bOut* _db_bOut; - db_script_bLink* _db_bLink; - db_script_pLocal* _db_pLocal; - db_script_pAttr* _db_pAttr; - db_script_pLink* _db_pLink; - db_script_pData* _db_pData; - db_script_pOper* _db_pOper; - db_script_eLink* _db_eLink; -}; - -class dbDataDataStructHelper { +class DbDataStructHelper_Doc { public: - void init(CKParameterManager* paramManager); - void dispose(); + DbDataStructHelper_Doc(CKParameterManager* paramManager); + ~DbDataStructHelper_Doc(); - char* _stringCache; - CKParameterManager* _parameterManager; - db_data_obj* _db_obj; - db_data_objHeader* _db_objHeader; - db_data_objBody* _db_objBody; - db_data_objParam* _db_objParam; - db_data_msg* _db_msg; - + CKParameterManager* param_manager; + + dbdoc_script script; + dbdoc_script_behavior script_behavior; + dbdoc_script_bIn script_bIn; + dbdoc_script_bOut script_bOut; + dbdoc_script_pIn script_pIn; + dbdoc_script_pOut script_pOut; + dbdoc_script_bLink script_bLink; + dbdoc_script_pLocal script_pLocal; + dbdoc_script_pAttr script_pAttr; + dbdoc_script_pLink script_pLink; + dbdoc_script_pOper script_pOper; + dbdoc_script_eLink script_eLink; + dbdoc_script_pTarget script_pTarget; + + dbdoc_msg msg; + + dbdoc_array _array; + dbdoc_array_header array_header; + dbdoc_array_cell array_cell; + + dbdoc_data data; }; -class dbEnvDataStructHelper { - public: - void init(); - void dispose(); - - char* _stringCache; - db_env_op* _db_op; - db_env_param* _db_param; - //db_data_msg* _db_envMsg; - db_env_attr* _db_attr; - db_env_plugin* _db_plugin; - db_env_variable* _db_variable; -}; - - -class database { - public: - void open(const char* file); - void close(); - - protected: - sqlite3_stmt* safeStmt(size_t index); - virtual BOOL init() { return TRUE; } - virtual BOOL finalJob() { return TRUE; } - - sqlite3* db; - std::vector* stmtCache; -}; - -class scriptDatabase : public database { - public: - void write_behavior(db_script_behavior* data); - void write_script(db_script_script* data); - void write_pTarget(db_script_pTarget* data); - void write_pIn(db_script_pIn* data); - void write_pOut(db_script_pOut* data); - void write_bIn(db_script_bIn* data); - void write_bOut(db_script_bOut* data); - void write_bLink(db_script_bLink* data); - void write_pLocal(db_script_pLocal* data); - void write_pLink(db_script_pLink* data); - void write_pData(db_script_pData* data); - void write_pOper(db_script_pOper* data); - void write_eLink(db_script_eLink* data); - BOOL write_pAttr(db_script_pAttr* data); - - protected: - BOOL init(); - BOOL finalJob(); - - std::set* pAttrUniqueEnsurance; -}; - -class dataDatabase : public database { +class DbDataStructHelper_Env { public: - void write_obj(db_data_obj* data); - void write_objHeader(db_data_objHeader* data); - void write_objBody(db_data_objBody* data); - void write_objParam(db_data_objParam* data); - void write_msg(db_data_msg* data); + DbDataStructHelper_Env(); + ~DbDataStructHelper_Env(); + + dbenv_op op; + dbenv_param param; + dbenv_attr attr; + dbenv_plugin plugin; + dbenv_variable variable; +}; + + +class SSMaterializerDatabase { +public: + SSMaterializerDatabase(const char* file); + virtual ~SSMaterializerDatabase(); protected: - BOOL init(); - BOOL finalJob(); + sqlite3_stmt* CreateStmt(const char* stmt); + virtual BOOL Init() = 0; + virtual BOOL Finalize() = 0; + sqlite3* mDb; + std::vector mStmtCache; }; -class envDatabase : public database { - public: - void write_op(db_env_op* data); - void write_param(db_env_param* data); - //void write_msg(db_data_msg* data); - void write_attr(db_env_attr* data); - void write_plugin(db_env_plugin* data); - void write_variable(db_env_variable* data); +class DocumentDatabase : public SSMaterializerDatabase { +public: + DocumentDatabase(const char* file); + virtual ~DocumentDatabase(); - protected: - BOOL init(); - BOOL finalJob(); + void write_script(dbdoc_script& data); + void write_script_behavior(dbdoc_script_behavior& data); + void write_script_pTarget(dbdoc_script_pTarget& data); + void write_script_pIn(dbdoc_script_pIn& data); + void write_script_pOut(dbdoc_script_pOut& data); + void write_script_bIn(dbdoc_script_bIn& data); + void write_script_bOut(dbdoc_script_bOut& data); + void write_script_bLink(dbdoc_script_bLink& data); + void write_script_pLocal(dbdoc_script_pLocal& data); + void write_script_pLink(dbdoc_script_pLink& data); + void write_script_pOper(dbdoc_script_pOper& data); + void write_script_eLink(dbdoc_script_eLink& data); + BOOL write_script_pAttr(dbdoc_script_pAttr& data); + + void write_msg(dbdoc_msg& data); + + void write_array(dbdoc_array& data); + void write_array_header(dbdoc_array_header& data); + void write_array_cell(dbdoc_array_cell& data); + + void write_data(dbdoc_data& data); + +protected: + BOOL Init() override; + BOOL Finalize() override; + + std::set m_pAttrUniqueEnsurance; +}; + +class EnvironmentDatabase : public SSMaterializerDatabase { +public: + EnvironmentDatabase(const char* file); + virtual ~EnvironmentDatabase(); + + void write_op(dbenv_op& data); + void write_param(dbenv_param& data); + void write_attr(dbenv_attr& data); + void write_plugin(dbenv_plugin& data); + void write_variable(dbenv_variable& data); + +protected: + BOOL Init() override; + BOOL Finalize() override; }; #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/env_export.cpp b/SuperScriptMaterializer/env_export.cpp index 687ecc1..5b67d6e 100644 --- a/SuperScriptMaterializer/env_export.cpp +++ b/SuperScriptMaterializer/env_export.cpp @@ -5,7 +5,7 @@ #define copyGuid(guid,str) sprintf(helper->_stringCache,"%d,%d",guid.d1,guid.d2);str=helper->_stringCache; #define safeStringCopy(storage,str) storage=(str)?(str):""; -void IterateParameterOperation(CKParameterManager* parameterManager, envDatabase* db, dbEnvDataStructHelper* helper) { +void IterateParameterOperation(CKParameterManager* parameterManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper) { int count = parameterManager->GetParameterOperationCount(); CKOperationDesc* opList = NULL; int listCount = 0, cacheListCount = 0; @@ -32,14 +32,14 @@ void IterateParameterOperation(CKParameterManager* parameterManager, envDatabase copyGuid(opList[j].ResGuid, helper->_db_op->out_guid); helper->_db_op->funcPtr = opList[j].Fct; - db->write_op(helper->_db_op); + mDb->write_op(helper->_db_op); } } if (opList != NULL) free(opList); } -void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbEnvDataStructHelper* helper) { +void IterateParameter(CKParameterManager* parameterManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper) { int count = parameterManager->GetParameterTypesCount(); CKParameterTypeDesc* desc = NULL; for (int i = 0; i < count; i++) { @@ -70,21 +70,21 @@ void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbE helper->_db_param->cid = desc->Cid; copyGuid(desc->Saver_Manager, helper->_db_param->saver_manager); - db->write_param(helper->_db_param); + mDb->write_param(helper->_db_param); } } -void IterateMessage(CKMessageManager* msgManager, envDatabase* db, dbEnvDataStructHelper* helper) { +void IterateMessage(CKMessageManager* msgManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper) { int count = msgManager->GetMessageTypeCount(); for (int i = 0; i < count; i++) { helper->_db_envMsg->index = i; helper->_db_envMsg->name = msgManager->GetMessageTypeName(i); - db->write_msg(helper->_db_envMsg); + mDb->write_msg(helper->_db_envMsg); } } -void IterateAttribute(CKAttributeManager* attrManager, envDatabase* db, dbEnvDataStructHelper* helper) { +void IterateAttribute(CKAttributeManager* attrManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper) { int count = attrManager->GetAttributeCount(); for (int i = 0; i < count; i++) { helper->_db_attr->index = i; @@ -96,11 +96,11 @@ void IterateAttribute(CKAttributeManager* attrManager, envDatabase* db, dbEnvDat helper->_db_attr->compatible_classid = attrManager->GetAttributeCompatibleClassId(i); helper->_db_attr->default_value = attrManager->GetAttributeDefaultValue(i) != NULL ? attrManager->GetAttributeDefaultValue(i) : ""; - db->write_attr(helper->_db_attr); + mDb->write_attr(helper->_db_attr); } } -void IteratePlugin(CKPluginManager* plgManager, envDatabase* db, dbEnvDataStructHelper* helper) { +void IteratePlugin(CKPluginManager* plgManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper) { for (int i = 0; i <= 7; i++) { int catCount = plgManager->GetPluginCount(i); helper->_db_plugin->category = plgManager->GetCategoryName(i); @@ -121,13 +121,13 @@ void IteratePlugin(CKPluginManager* plgManager, envDatabase* db, dbEnvDataStruct helper->_db_plugin->func_init = plgInfo->m_InitInstanceFct; helper->_db_plugin->func_exit = plgInfo->m_ExitInstanceFct; - db->write_plugin(helper->_db_plugin); + mDb->write_plugin(helper->_db_plugin); } } } #if !defined(VIRTOOLS_21) -void IterateVariable(CKVariableManager* varManager, envDatabase* db, dbEnvDataStructHelper* helper) { +void IterateVariable(CKVariableManager* varManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper) { CKVariableManager::Iterator it = varManager->GetVariableIterator(); CKVariableManager::Variable* varobj = NULL; XString dataCopyCache; @@ -141,7 +141,7 @@ void IterateVariable(CKVariableManager* varManager, envDatabase* db, dbEnvDataSt varobj->GetStringValue(dataCopyCache); helper->_db_variable->data = dataCopyCache.CStr(); - db->write_variable(helper->_db_variable); + mDb->write_variable(helper->_db_variable); } } #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/env_export.h b/SuperScriptMaterializer/env_export.h index 9d31b0c..e3a1fcd 100644 --- a/SuperScriptMaterializer/env_export.h +++ b/SuperScriptMaterializer/env_export.h @@ -4,11 +4,11 @@ #include "stdafx.h" #include "database.h" -void IterateParameterOperation(CKParameterManager* parameterManager, envDatabase* db, dbEnvDataStructHelper* helper); -void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbEnvDataStructHelper* helper); -void IterateMessage(CKMessageManager* msgManager, envDatabase* db, dbEnvDataStructHelper* helper); -void IterateAttribute(CKAttributeManager* attrManager, envDatabase* db, dbEnvDataStructHelper* helper); -void IteratePlugin(CKPluginManager* plgManager, envDatabase* db, dbEnvDataStructHelper* helper); -void IterateVariable(CKVariableManager* varManager, envDatabase* db, dbEnvDataStructHelper* helper); +void IterateParameterOperation(CKParameterManager* parameterManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper); +void IterateParameter(CKParameterManager* parameterManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper); +void IterateMessage(CKMessageManager* msgManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper); +void IterateAttribute(CKAttributeManager* attrManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper); +void IteratePlugin(CKPluginManager* plgManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper); +void IterateVariable(CKVariableManager* varManager, EnvironmentDatabase* mDb, dbEnvDataStructHelper* helper); #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/script_export.cpp b/SuperScriptMaterializer/script_export.cpp index 8123595..4156ebd 100644 --- a/SuperScriptMaterializer/script_export.cpp +++ b/SuperScriptMaterializer/script_export.cpp @@ -11,7 +11,7 @@ #pragma region inline func -void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget) { +void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget) { //WARNING: i only choose one between [DirectSource] and [SharedSource] bucause i don't find any pIn both have these two field CKParameter* directSource = NULL; CKObject* ds_Owner = NULL; @@ -48,7 +48,7 @@ void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* helper->_db_pLink->input_type = pLinkInputOutputType_PATTR; helper->_db_pLink->input_is_bb = FALSE; helper->_db_pLink->input_index = -1; - proc_pAttr(ctx, db, helper, directSource); + proc_pAttr(ctx, mDb, helper, directSource); break; default: //normal object, see as virtual bb pLocal shortcut @@ -56,7 +56,7 @@ void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* helper->_db_pLink->input_type = pLinkInputOutputType_PATTR; helper->_db_pLink->input_is_bb = FALSE; helper->_db_pLink->input_index = -1; - proc_pAttr(ctx, db, helper, directSource); + proc_pAttr(ctx, mDb, helper, directSource); break; } } @@ -91,11 +91,11 @@ void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* helper->_db_pLink->output_index = index; helper->_db_pLink->belong_to = grandparents; - db->write_pLink(helper->_db_pLink); + mDb->write_script_pLink(helper->_db_pLink); } } -void proc_pTarget(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents) { +void proc_pTarget(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents) { helper->_db_pTarget->thisobj = cache->GetID(); helper->_db_pTarget->name = cache->GetName(); helper->_db_pTarget->type = helper->_parameterManager->ParameterTypeToName(cache->GetType()); @@ -104,9 +104,9 @@ void proc_pTarget(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbSc helper->_db_pTarget->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1; helper->_db_pTarget->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1; - db->write_pTarget(helper->_db_pTarget); + mDb->write_script_pTarget(helper->_db_pTarget); - //judge whether expoer parameter and write database + //judge whether expoer parameter and write SSMaterializerDatabase if (((CKBehavior*)ctx->GetObject(grandparents))->GetInputParameterPosition(cache) != -1) { helper->_db_eLink->export_obj = cache->GetID(); helper->_db_eLink->internal_obj = parents; @@ -114,15 +114,15 @@ void proc_pTarget(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbSc helper->_db_eLink->index = -1; helper->_db_eLink->belong_to = grandparents; - db->write_eLink(helper->_db_eLink); + mDb->write_script_eLink(helper->_db_eLink); return; } //=========try generate pLink - generate_pLink_in_pIn(ctx, cache, db, helper, parents, grandparents, -1, TRUE, TRUE); + generate_pLink_in_pIn(ctx, cache, mDb, helper, parents, grandparents, -1, TRUE, TRUE); } -void proc_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { +void proc_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { helper->_db_pIn->thisobj = cache->GetID(); helper->_db_pIn->index = index; helper->_db_pIn->name = cache->GetName(); @@ -134,9 +134,9 @@ void proc_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScript helper->_db_pIn->direct_source = cache->GetDirectSource() ? cache->GetDirectSource()->GetID() : -1; helper->_db_pIn->shared_source = cache->GetSharedSource() ? cache->GetSharedSource()->GetID() : -1; - db->write_pIn(helper->_db_pIn); + mDb->write_script_pIn(helper->_db_pIn); - //judge whether expoer parameter and write database + //judge whether expoer parameter and write SSMaterializerDatabase if (((CKBehavior*)ctx->GetObject(grandparents))->GetInputParameterPosition(cache) != -1) { helper->_db_eLink->export_obj = cache->GetID(); helper->_db_eLink->internal_obj = parents; @@ -144,16 +144,16 @@ void proc_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScript helper->_db_eLink->index = index; helper->_db_eLink->belong_to = grandparents; - db->write_eLink(helper->_db_eLink); + mDb->write_script_eLink(helper->_db_eLink); return; } //=========try generate pLink - generate_pLink_in_pIn(ctx, cache, db, helper, parents, grandparents, index, executedFromBB, FALSE); + generate_pLink_in_pIn(ctx, cache, mDb, helper, parents, grandparents, index, executedFromBB, FALSE); } -void proc_pOut(CKContext* ctx, CKParameterOut* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { +void proc_pOut(CKContext* ctx, CKParameterOut* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB) { helper->_db_pOut->thisobj = cache->GetID(); helper->_db_pOut->index = index; helper->_db_pOut->name = cache->GetName(); @@ -163,9 +163,9 @@ void proc_pOut(CKContext* ctx, CKParameterOut* cache, scriptDatabase* db, dbScri copyGuid(cache->GetGUID(), helper->_db_pOut->type_guid); helper->_db_pOut->belong_to = parents; - db->write_pOut(helper->_db_pOut); + mDb->write_script_pOut(helper->_db_pOut); - //judge whether expoer parameter and write database + //judge whether expoer parameter and write SSMaterializerDatabase if (((CKBehavior*)ctx->GetObject(grandparents))->GetOutputParameterPosition(cache) != -1) { helper->_db_eLink->export_obj = cache->GetID(); helper->_db_eLink->internal_obj = parents; @@ -173,7 +173,7 @@ void proc_pOut(CKContext* ctx, CKParameterOut* cache, scriptDatabase* db, dbScri helper->_db_eLink->index = index; helper->_db_eLink->belong_to = grandparents; - db->write_eLink(helper->_db_eLink); + mDb->write_script_eLink(helper->_db_eLink); return; } @@ -210,29 +210,29 @@ void proc_pOut(CKContext* ctx, CKParameterOut* cache, scriptDatabase* db, dbScri helper->_db_pLink->belong_to = grandparents; - db->write_pLink(helper->_db_pLink); + mDb->write_script_pLink(helper->_db_pLink); } } -void proc_bIn(CKBehaviorIO* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, int index) { +void proc_bIn(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index) { helper->_db_bIn->thisobj = cache->GetID(); helper->_db_bIn->index = index; helper->_db_bIn->name = cache->GetName(); helper->_db_bIn->belong_to = parents; - db->write_bIn(helper->_db_bIn); + mDb->write_script_bIn(helper->_db_bIn); } -void proc_bOut(CKBehaviorIO* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, int index) { +void proc_bOut(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index) { helper->_db_bOut->thisobj = cache->GetID(); helper->_db_bOut->index = index; helper->_db_bOut->name = cache->GetName(); helper->_db_bOut->belong_to = parents; - db->write_bOut(helper->_db_bOut); + mDb->write_script_bOut(helper->_db_bOut); } -void proc_bLink(CKBehaviorLink* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void proc_bLink(CKBehaviorLink* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { CKBehaviorIO* io = cache->GetInBehaviorIO(); CKBehavior* beh = io->GetOwner(); helper->_db_bLink->input = io->GetID(); @@ -249,10 +249,10 @@ void proc_bLink(CKBehaviorLink* cache, scriptDatabase* db, dbScriptDataStructHel helper->_db_bLink->delay = cache->GetActivationDelay(); helper->_db_bLink->belong_to = parents; - db->write_bLink(helper->_db_bLink); + mDb->write_script_bLink(helper->_db_bLink); } -void proc_pLocal(CKParameterLocal* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting) { +void proc_pLocal(CKParameterLocal* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting) { helper->_db_pLocal->thisobj = cache->GetID(); helper->_db_pLocal->name = cache->GetName() ? cache->GetName() : ""; CKParameterType vaildTypeChecker = cache->GetType(); @@ -262,27 +262,27 @@ void proc_pLocal(CKParameterLocal* cache, scriptDatabase* db, dbScriptDataStruct helper->_db_pLocal->is_setting = is_setting; helper->_db_pLocal->belong_to = parents; - db->write_pLocal(helper->_db_pLocal); + mDb->write_script_pLocal(helper->_db_pLocal); //export plocal metadata - DigParameterData(cache, db, helper, cache->GetID()); + DigParameterData(cache, mDb, helper, cache->GetID()); } -void proc_pOper(CKContext* ctx, CKParameterOperation* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void proc_pOper(CKContext* ctx, CKParameterOperation* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { helper->_db_pOper->thisobj = cache->GetID(); helper->_db_pOper->op = helper->_parameterManager->OperationGuidToName(cache->GetOperationGuid()); copyGuid(cache->GetOperationGuid(), helper->_db_pOper->op_guid); helper->_db_pOper->belong_to = parents; - db->write_pOper(helper->_db_pOper); + mDb->write_script_pOper(helper->_db_pOper); //export 2 input param and 1 output param - proc_pIn(ctx, cache->GetInParameter1(), db, helper, cache->GetID(), parents, 0, FALSE); - proc_pIn(ctx, cache->GetInParameter2(), db, helper, cache->GetID(), parents, 1, FALSE); - proc_pOut(ctx, cache->GetOutParameter(), db, helper, cache->GetID(), parents, 0, FALSE); + proc_pIn(ctx, cache->GetInParameter1(), mDb, helper, cache->GetID(), parents, 0, FALSE); + proc_pIn(ctx, cache->GetInParameter2(), mDb, helper, cache->GetID(), parents, 1, FALSE); + proc_pOut(ctx, cache->GetOutParameter(), mDb, helper, cache->GetID(), parents, 0, FALSE); } -void proc_pAttr(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* helper, CKParameter* cache) { +void proc_pAttr(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper, CKParameter* cache) { //write self first to detect conflict helper->_db_pAttr->thisobj = cache->GetID(); safeStringCopy(helper->_db_pAttr->name, cache->GetName()); @@ -291,32 +291,32 @@ void proc_pAttr(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* he else helper->_db_pAttr->type = "!!UNKNOW TYPE!!"; //unknow type copyGuid(cache->GetGUID(), helper->_db_pAttr->type_guid); - if (!db->write_pAttr(helper->_db_pAttr)) + if (!mDb->write_script_pAttr(helper->_db_pAttr)) return; //not duplicated, continue write property CKObject* host = cache->GetOwner(); - helper_pDataExport("attr.host_id", (long)host->GetID(), db, helper, cache->GetID()); - helper_pDataExport("attr.host_name", host->GetName(), db, helper, cache->GetID()); + helper_pDataExport("attr.host_id", (long)host->GetID(), mDb, helper, cache->GetID()); + helper_pDataExport("attr.host_name", host->GetName(), mDb, helper, cache->GetID()); } //============================helper for pLocal data export -void helper_pDataExport(const char* field, const char* data, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void helper_pDataExport(const char* field, const char* data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { helper->_db_pData->field = field; helper->_db_pData->data = data; helper->_db_pData->belong_to = parents; - db->write_pData(helper->_db_pData); + mDb->write_pData(helper->_db_pData); } -void helper_pDataExport(const char* field, float data, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void helper_pDataExport(const char* field, float data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { char str[32]; sprintf(str, "%f", data); - helper_pDataExport(field, str, db, helper, parents); + helper_pDataExport(field, str, mDb, helper, parents); } -void helper_pDataExport(const char* field, long data, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void helper_pDataExport(const char* field, long data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { char str[32]; ltoa(data, str, 10); - helper_pDataExport(field, str, db, helper, parents); + helper_pDataExport(field, str, mDb, helper, parents); } @@ -325,7 +325,7 @@ void helper_pDataExport(const char* field, long data, scriptDatabase* db, dbScri #pragma region normal func -void IterateScript(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* helper) { +void IterateScript(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper) { CKBeObject* beobj = NULL; CKBehavior* beh = NULL; XObjectPointerArray objArray = ctx->GetObjectListByType(CKCID_BEOBJECT, TRUE); @@ -342,15 +342,15 @@ void IterateScript(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* helper->_db_script->host_name = beobj->GetName(); helper->_db_script->index = j; helper->_db_script->behavior = beh->GetID(); - db->write_script(helper->_db_script); + mDb->write_script(helper->_db_script); //iterate script - IterateBehavior(ctx, beh, db, helper, -1); + IterateBehavior(ctx, beh, mDb, helper, -1); } } } -void IterateBehavior(CKContext* ctx, CKBehavior* bhv, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void IterateBehavior(CKContext* ctx, CKBehavior* bhv, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { //write self data helper->_db_behavior->thisobj = bhv->GetID(); helper->_db_behavior->name = bhv->GetName(); @@ -368,42 +368,42 @@ void IterateBehavior(CKContext* ctx, CKBehavior* bhv, scriptDatabase* db, dbScri bhv->GetInputCount(), bhv->GetOutputCount()); helper->_db_behavior->pin_count = helper->_stringCache; - db->write_behavior(helper->_db_behavior); + mDb->write_script_behavior(helper->_db_behavior); //write target if (bhv->IsUsingTarget()) - proc_pTarget(ctx, bhv->GetTargetParameter(), db, helper, bhv->GetID(), parents); + proc_pTarget(ctx, bhv->GetTargetParameter(), mDb, helper, bhv->GetID(), parents); int count = 0, i = 0; //pIn for (i = 0, count = bhv->GetInputParameterCount(); i < count; i++) - proc_pIn(ctx, bhv->GetInputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE); + proc_pIn(ctx, bhv->GetInputParameter(i), mDb, helper, bhv->GetID(), parents, i, TRUE); //pOut for (i = 0, count = bhv->GetOutputParameterCount(); i < count; i++) - proc_pOut(ctx, bhv->GetOutputParameter(i), db, helper, bhv->GetID(), parents, i, TRUE); + proc_pOut(ctx, bhv->GetOutputParameter(i), mDb, helper, bhv->GetID(), parents, i, TRUE); //bIn for (i = 0, count = bhv->GetInputCount(); i < count; i++) - proc_bIn(bhv->GetInput(i), db, helper, bhv->GetID(), i); + proc_bIn(bhv->GetInput(i), mDb, helper, bhv->GetID(), i); //bOut for (i = 0, count = bhv->GetOutputCount(); i < count; i++) - proc_bOut(bhv->GetOutput(i), db, helper, bhv->GetID(), i); + proc_bOut(bhv->GetOutput(i), mDb, helper, bhv->GetID(), i); //bLink for (i = 0, count = bhv->GetSubBehaviorLinkCount(); i < count; i++) - proc_bLink(bhv->GetSubBehaviorLink(i), db, helper, bhv->GetID()); + proc_bLink(bhv->GetSubBehaviorLink(i), mDb, helper, bhv->GetID()); //pLocal for (i = 0, count = bhv->GetLocalParameterCount(); i < count; i++) - proc_pLocal(bhv->GetLocalParameter(i), db, helper, bhv->GetID(), + proc_pLocal(bhv->GetLocalParameter(i), mDb, helper, bhv->GetID(), bhv->IsLocalParameterSetting(i)); //pOper for (i = 0, count = bhv->GetParameterOperationCount(); i < count; i++) - proc_pOper(ctx, bhv->GetParameterOperation(i), db, helper, bhv->GetID()); + proc_pOper(ctx, bhv->GetParameterOperation(i), mDb, helper, bhv->GetID()); //iterate sub bb for (i = 0, count = bhv->GetSubBehaviorCount(); i < count; i++) - IterateBehavior(ctx, bhv->GetSubBehavior(i), db, helper, bhv->GetID()); + IterateBehavior(ctx, bhv->GetSubBehavior(i), mDb, helper, bhv->GetID()); } -void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void DigParameterData(CKParameterLocal* p, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { CKGUID t = p->GetGUID(); BOOL unknowType = FALSE; @@ -412,12 +412,12 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc //nothing if (t == CKPGUID_NONE) return; if (p->GetParameterClassID() && p->GetValueObject(false)) { - helper_pDataExport("id", (long)p->GetValueObject(false)->GetID(), db, helper, parents); - helper_pDataExport("name", p->GetValueObject(false)->GetName(), db, helper, parents); + helper_pDataExport("id", (long)p->GetValueObject(false)->GetID(), mDb, helper, parents); + helper_pDataExport("name", p->GetValueObject(false)->GetName(), mDb, helper, parents); CK_CLASSID none_classid = p->GetValueObject(false)->GetClassID(); CKParameterType none_type = helper->_parameterManager->ClassIDToType(none_classid); - helper_pDataExport("type",helper->_parameterManager->ParameterTypeToName(none_type), db, helper, parents); + helper_pDataExport("type",helper->_parameterManager->ParameterTypeToName(none_type), mDb, helper, parents); return; } //float @@ -426,7 +426,7 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc || t == CKPGUID_FLOATSLIDER #endif ) { - helper_pDataExport("float-data", *(float*)(p->GetReadDataPtr(false)), db, helper, parents); + helper_pDataExport("float-data", *(float*)(p->GetReadDataPtr(false)), mDb, helper, parents); return; } //int @@ -437,22 +437,22 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc || t == CKPGUID_LIGHTTYPE || t == CKPGUID_SPRITEALIGN || t == CKPGUID_DIRECTION || t == CKPGUID_LAYERTYPE || t == CKPGUID_COMPOPERATOR || t == CKPGUID_BINARYOPERATOR || t == CKPGUID_SETOPERATOR || t == CKPGUID_OBSTACLEPRECISION || t == CKPGUID_OBSTACLEPRECISIONBEH) { - helper_pDataExport("int-data", (long)(*(int*)(p->GetReadDataPtr(false))), db, helper, parents); + helper_pDataExport("int-data", (long)(*(int*)(p->GetReadDataPtr(false))), mDb, helper, parents); return; } if (t == CKPGUID_VECTOR) { VxVector vec; memcpy(&vec, p->GetReadDataPtr(false), sizeof(vec)); - helper_pDataExport("vector.x", vec.x, db, helper, parents); - helper_pDataExport("vector.y", vec.y, db, helper, parents); - helper_pDataExport("vector.z", vec.z, db, helper, parents); + helper_pDataExport("vector.x", vec.x, mDb, helper, parents); + helper_pDataExport("vector.y", vec.y, mDb, helper, parents); + helper_pDataExport("vector.z", vec.z, mDb, helper, parents); return; } if (t == CKPGUID_2DVECTOR) { Vx2DVector vec; memcpy(&vec, p->GetReadDataPtr(false), sizeof(vec)); - helper_pDataExport("2dvector.x", vec.x, db, helper, parents); - helper_pDataExport("2dvector.y", vec.y, db, helper, parents); + helper_pDataExport("2dvector.x", vec.x, mDb, helper, parents); + helper_pDataExport("2dvector.y", vec.y, mDb, helper, parents); return; } if (t == CKPGUID_MATRIX) { @@ -463,7 +463,7 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { sprintf(position, "matrix[%d][%d]", i, j); - helper_pDataExport(position, mat[i][j], db, helper, parents); + helper_pDataExport(position, mat[i][j], mDb, helper, parents); } } return; @@ -471,10 +471,10 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc if (t == CKPGUID_COLOR) { VxColor col; memcpy(&col, p->GetReadDataPtr(false), sizeof(col)); - helper_pDataExport("color.r", col.r, db, helper, parents); - helper_pDataExport("color.g", col.g, db, helper, parents); - helper_pDataExport("color.b", col.b, db, helper, parents); - helper_pDataExport("color.a", col.a, db, helper, parents); + helper_pDataExport("color.r", col.r, mDb, helper, parents); + helper_pDataExport("color.g", col.g, mDb, helper, parents); + helper_pDataExport("color.b", col.b, mDb, helper, parents); + helper_pDataExport("color.a", col.a, mDb, helper, parents); return; } if (t == CKPGUID_2DCURVE) { @@ -488,27 +488,27 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc endIndex = strlen(prefix); changeSuffix(".pos.x"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetPosition().x, db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetPosition().x, mDb, helper, parents); changeSuffix(".pos.y"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetPosition().y, db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetPosition().y, mDb, helper, parents); changeSuffix(".islinear"); - helper_pDataExport(prefix, (long)c->GetControlPoint(i)->IsLinear(), db, helper, parents); + helper_pDataExport(prefix, (long)c->GetControlPoint(i)->IsLinear(), mDb, helper, parents); if (c->GetControlPoint(i)->IsTCB()) { changeSuffix(".bias"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetBias(), db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetBias(), mDb, helper, parents); changeSuffix(".continuity"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetContinuity(), db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetContinuity(), mDb, helper, parents); changeSuffix(".tension"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetTension(), db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetTension(), mDb, helper, parents); } else { changeSuffix(".intangent.x"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetInTangent().x, db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetInTangent().x, mDb, helper, parents); changeSuffix(".intangent.y"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetInTangent().y, db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetInTangent().y, mDb, helper, parents); changeSuffix(".outtangent.x"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetOutTangent().x, db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetOutTangent().x, mDb, helper, parents); changeSuffix(".outtangent.y"); - helper_pDataExport(prefix, c->GetControlPoint(i)->GetOutTangent().y, db, helper, parents); + helper_pDataExport(prefix, c->GetControlPoint(i)->GetOutTangent().y, mDb, helper, parents); } } return; @@ -521,7 +521,7 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc helper->_db_pData->data.insert(0, cptr, 0, cc); helper->_db_pData->field = "str"; helper->_db_pData->belong_to = p->GetID(); - db->write_pData(helper->_db_pData); + mDb->write_pData(helper->_db_pData); return; } @@ -554,10 +554,10 @@ void DigParameterData(CKParameterLocal* p, scriptDatabase* db, dbScriptDataStruc else helper->_db_pData->field = "dump.partial_data"; helper->_db_pData->belong_to = p->GetID(); - db->write_pData(helper->_db_pData); + mDb->write_pData(helper->_db_pData); //dump data length - helper_pDataExport("dump.length", (long)cc, db, helper, parents); + helper_pDataExport("dump.length", (long)cc, mDb, helper, parents); return; } } diff --git a/SuperScriptMaterializer/script_export.h b/SuperScriptMaterializer/script_export.h index 780d310..eb92b71 100644 --- a/SuperScriptMaterializer/script_export.h +++ b/SuperScriptMaterializer/script_export.h @@ -4,23 +4,23 @@ #include "stdafx.h" #include "database.h" -void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget); -void proc_pTarget(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents); -void proc_pIn(CKContext* ctx, CKParameterIn* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB); -void proc_pOut(CKContext* ctx, CKParameterOut* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB); -void proc_bIn(CKBehaviorIO* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, int index); -void proc_bOut(CKBehaviorIO* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, int index); -void proc_bLink(CKBehaviorLink* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); -void proc_pLocal(CKParameterLocal* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting); -void proc_pOper(CKContext* ctx, CKParameterOperation* cache, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); -void proc_pAttr(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* helper, CKParameter* cache); +void generate_pLink_in_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB, BOOL isTarget); +void proc_pTarget(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents); +void proc_pIn(CKContext* ctx, CKParameterIn* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB); +void proc_pOut(CKContext* ctx, CKParameterOut* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, EXPAND_CK_ID grandparents, int index, BOOL executedFromBB); +void proc_bIn(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index); +void proc_bOut(CKBehaviorIO* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, int index); +void proc_bLink(CKBehaviorLink* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); +void proc_pLocal(CKParameterLocal* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents, BOOL is_setting); +void proc_pOper(CKContext* ctx, CKParameterOperation* cache, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); +void proc_pAttr(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper, CKParameter* cache); -void helper_pDataExport(const char* field, long data, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); -void helper_pDataExport(const char* field, float data, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); -void helper_pDataExport(const char* field, const char* data, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); +void helper_pDataExport(const char* field, long data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); +void helper_pDataExport(const char* field, float data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); +void helper_pDataExport(const char* field, const char* data, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); -void IterateBehavior(CKContext* ctx, CKBehavior* bhv, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); -void IterateScript(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* helper); -void DigParameterData(CKParameterLocal* pl, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); +void IterateBehavior(CKContext* ctx, CKBehavior* bhv, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); +void IterateScript(CKContext* ctx, DocumentDatabase* mDb, dbDocDataStructHelper* helper); +void DigParameterData(CKParameterLocal* pl, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/shared_export.cpp b/SuperScriptMaterializer/shared_export.cpp index cb4267d..4d0c76e 100644 --- a/SuperScriptMaterializer/shared_export.cpp +++ b/SuperScriptMaterializer/shared_export.cpp @@ -8,7 +8,7 @@ combined_database::combined_database() : ; } -db_shared_dictData* combined_database::get_struct() { +dbdoc_data* combined_database::get_struct() { if (helper_script != NULL) return helper_script->_db_pData; if (helper_data != NULL) return helper_data->_db_objParam; return NULL; @@ -20,22 +20,22 @@ char* combined_database::get_string_cache() { return NULL; } -void combined_database::write_dict(db_shared_dictData* data) { +void combined_database::write_dict(dbdoc_data* data) { if (db_script != NULL) db_script->write_pData(data); if (db_data != NULL) db_data->write_objParam(data); } -void DigParameterData(CKParameter* p, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { +void DigParameterData(CKParameter* p, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents) { combined_database cdb; - cdb.db_script = db; + cdb.db_script = mDb; cdb.helper_script = helper; DigParameterData(p, &cdb, parents); } -void DigParameterData(CKParameter* p, dataDatabase* db, dbDataDataStructHelper* helper, EXPAND_CK_ID parents) { +void DigParameterData(CKParameter* p, dataDatabase* mDb, dbDataDataStructHelper* helper, EXPAND_CK_ID parents) { combined_database cdb; - cdb.db_data = db; + cdb.db_data = mDb; cdb.helper_data = helper; DigParameterData(p, &cdb, parents); diff --git a/SuperScriptMaterializer/shared_export.h b/SuperScriptMaterializer/shared_export.h index d8272d3..0b20d20 100644 --- a/SuperScriptMaterializer/shared_export.h +++ b/SuperScriptMaterializer/shared_export.h @@ -7,12 +7,12 @@ class combined_database { public: combined_database(); - db_shared_dictData* get_struct(); + dbdoc_data* get_struct(); char* get_string_cache(); - void write_dict(db_shared_dictData* data); + void write_dict(dbdoc_data* data); - scriptDatabase* db_script; - dbScriptDataStructHelper* helper_script; + DocumentDatabase* db_script; + dbDocDataStructHelper* helper_script; dataDatabase* db_data; dbDataDataStructHelper* helper_data; }; @@ -21,11 +21,11 @@ public: #define safeStringCopy(storage,str) storage=(str)?(str):""; void DigParameterData(CKParameter* p, combined_database* helper, EXPAND_CK_ID parents); -void DigParameterData(CKParameter* p, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); -void DigParameterData(CKParameter* p, dataDatabase* db, dbDataDataStructHelper* helper, EXPAND_CK_ID parents); +void DigParameterData(CKParameter* p, DocumentDatabase* mDb, dbDocDataStructHelper* helper, EXPAND_CK_ID parents); +void DigParameterData(CKParameter* p, dataDatabase* mDb, dbDataDataStructHelper* helper, EXPAND_CK_ID parents); -void helper_FillStruct(const char* field, long data, db_shared_dictData* helper); -void helper_FillStruct(const char* field, float data, db_shared_dictData* helper); -void helper_FillStruct(const char* field, const char* data, db_shared_dictData* helper); +void helper_FillStruct(const char* field, long data, dbdoc_data* helper); +void helper_FillStruct(const char* field, float data, dbdoc_data* helper); +void helper_FillStruct(const char* field, const char* data, dbdoc_data* helper); #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/stdafx.h b/SuperScriptMaterializer/stdafx.h index f355fc1..c2e5d17 100644 --- a/SuperScriptMaterializer/stdafx.h +++ b/SuperScriptMaterializer/stdafx.h @@ -17,11 +17,11 @@ #ifndef _AFX_NO_DB_SUPPORT -#include // MFC ODBC database classes +#include // MFC ODBC SSMaterializerDatabase classes #endif // _AFX_NO_DB_SUPPORT #ifndef _AFX_NO_DAO_SUPPORT -#include // MFC DAO database classes +#include // MFC DAO SSMaterializerDatabase classes #endif // _AFX_NO_DAO_SUPPORT #include // MFC support for Internet Explorer 4 Common Controls diff --git a/SuperScriptMaterializer/string_helper.cpp b/SuperScriptMaterializer/string_helper.cpp new file mode 100644 index 0000000..e69de29 diff --git a/SuperScriptMaterializer/string_helper.hpp b/SuperScriptMaterializer/string_helper.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/SuperScriptMaterializer/string_helper.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/SuperScriptMaterializer/vt_menu.cpp b/SuperScriptMaterializer/vt_menu.cpp index 94cbea6..4e2cacf 100644 --- a/SuperScriptMaterializer/vt_menu.cpp +++ b/SuperScriptMaterializer/vt_menu.cpp @@ -80,25 +80,25 @@ void PluginMenuCallback(int commandID) { switch (commandID) { case 0: { - //init file + //Init file std::string file; OpenFileDialog(&file); if (file.empty()) break; DeleteFile(file.c_str()); - //init resources - scriptDatabase* _db = new scriptDatabase(); - dbScriptDataStructHelper* _helper = new dbScriptDataStructHelper(); - _db->open(file.c_str()); - _helper->init(ctx->GetParameterManager()); + //Init resources + DocumentDatabase* _db = new DocumentDatabase(); + dbDocDataStructHelper* _helper = new dbDocDataStructHelper(); + _db->Open(file.c_str()); + _helper->Init(ctx->GetParameterManager()); //iterate item IterateScript(ctx, _db, _helper); - //close all resources + //Close all resources _helper->dispose(); - _db->close(); + _db->Close(); delete _helper; delete _db; @@ -107,18 +107,18 @@ void PluginMenuCallback(int commandID) { break; case 1: { - //init file + //Init file std::string file; OpenFileDialog(&file); if (file.empty()) break; DeleteFile(file.c_str()); - //init - envDatabase* _db = new envDatabase(); + //Init + EnvironmentDatabase* _db = new EnvironmentDatabase(); dbEnvDataStructHelper* _helper = new dbEnvDataStructHelper(); - _db->open(file.c_str()); - _helper->init(); + _db->Open(file.c_str()); + _helper->Init(); //iterate parameter operation/param IterateParameterOperation(ctx->GetParameterManager(), _db, _helper); @@ -132,7 +132,7 @@ void PluginMenuCallback(int commandID) { //release all _helper->dispose(); - _db->close(); + _db->Close(); delete _helper; delete _db; diff --git a/SuperScriptMaterializer/vt_player.cpp b/SuperScriptMaterializer/vt_player.cpp index 22a28cc..aece227 100644 --- a/SuperScriptMaterializer/vt_player.cpp +++ b/SuperScriptMaterializer/vt_player.cpp @@ -9,7 +9,7 @@ void PlayerMain(const char* virtools_composition, const char* script_db_path, co printf("Homepage: https://github.com/yyc12345/SuperScriptMaterializer\n"); printf("Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues\n"); - // ====================== init ck2 engine + // ====================== Init ck2 engine #if defined(VIRTOOLS_21) CommonAssert(LoadLibrary("CK2.dll") != NULL, "Error loading CK2.dll"); #endif @@ -34,8 +34,8 @@ void PlayerMain(const char* virtools_composition, const char* script_db_path, co #endif printf("Parsing %s...\n", virtools_composition); - // ====================== do database export - // define and init + // ====================== do SSMaterializerDatabase export + // define and Init scriptDatabase* _script_db = new scriptDatabase(); dbScriptDataStructHelper* _script_helper = new dbScriptDataStructHelper(); envDatabase* _env_db = new envDatabase(); @@ -88,13 +88,13 @@ void PlayerMain(const char* virtools_composition, const char* script_db_path, co context->ClearAll(); // todo: Virtools 4.0 standalone version throw exception in there, but i don't knwo why - // but it doesn't affect database export, perhaps + // but it doesn't affect SSMaterializerDatabase export, perhaps CKCloseContext(context); CKShutdown(); // todo: Virtools 2.5 standalone version throw exception in there, but i don't knwo why - // but it doesn't affect database export, perhaps + // but it doesn't affect SSMaterializerDatabase export, perhaps } void CommonAssert(BOOL condition, const char* desc) {