From 5849478fe501ad7226cb371e7b31f7552fd054a6 Mon Sep 17 00:00:00 2001 From: zonble Date: Wed, 2 Feb 2022 18:07:41 +0800 Subject: [PATCH] Removes the dependency on OpenVanilla. --- McBopomofo.xcodeproj/project.pbxproj | 72 -- Source/Engine/OpenVanilla/OVAroundFilter.h | 49 -- Source/Engine/OpenVanilla/OVBase.h | 46 - Source/Engine/OpenVanilla/OVBenchmark.h | 102 --- Source/Engine/OpenVanilla/OVCINDataTable.h | 806 ------------------ .../Engine/OpenVanilla/OVCINDatabaseService.h | 189 ---- .../OpenVanilla/OVCINToSQLiteConvertor.h | 125 --- .../Engine/OpenVanilla/OVCandidateService.h | 208 ----- Source/Engine/OpenVanilla/OVDatabaseService.h | 101 --- Source/Engine/OpenVanilla/OVDateTimeHelper.h | 149 ---- Source/Engine/OpenVanilla/OVEncodingService.h | 72 -- .../OpenVanilla/OVEventHandlingContext.h | 102 --- Source/Engine/OpenVanilla/OVException.h | 46 - Source/Engine/OpenVanilla/OVFileHelper.h | 627 -------------- Source/Engine/OpenVanilla/OVFrameworkInfo.h | 92 -- Source/Engine/OpenVanilla/OVInputMethod.h | 49 -- Source/Engine/OpenVanilla/OVKey.h | 303 ------- Source/Engine/OpenVanilla/OVKeyPreprocessor.h | 49 -- Source/Engine/OpenVanilla/OVKeyValueMap.h | 175 ---- Source/Engine/OpenVanilla/OVLoaderBase.h | 50 -- Source/Engine/OpenVanilla/OVLoaderService.h | 120 --- Source/Engine/OpenVanilla/OVLocalization.h | 136 --- Source/Engine/OpenVanilla/OVModule.h | 146 ---- Source/Engine/OpenVanilla/OVModulePackage.h | 100 --- Source/Engine/OpenVanilla/OVOutputFilter.h | 49 -- Source/Engine/OpenVanilla/OVPathInfo.h | 63 -- .../OpenVanilla/OVSQLiteDatabaseService.h | 249 ------ Source/Engine/OpenVanilla/OVSQLiteWrapper.h | 278 ------ Source/Engine/OpenVanilla/OVStringHelper.h | 218 ----- Source/Engine/OpenVanilla/OVTextBuffer.h | 102 --- Source/Engine/OpenVanilla/OVUTF8Helper.h | 194 ----- Source/Engine/OpenVanilla/OVWildcard.h | 248 ------ Source/Engine/OpenVanilla/OpenVanilla.h | 97 --- Source/KeyHandler.mm | 1 - 34 files changed, 5413 deletions(-) delete mode 100644 Source/Engine/OpenVanilla/OVAroundFilter.h delete mode 100644 Source/Engine/OpenVanilla/OVBase.h delete mode 100644 Source/Engine/OpenVanilla/OVBenchmark.h delete mode 100644 Source/Engine/OpenVanilla/OVCINDataTable.h delete mode 100644 Source/Engine/OpenVanilla/OVCINDatabaseService.h delete mode 100644 Source/Engine/OpenVanilla/OVCINToSQLiteConvertor.h delete mode 100644 Source/Engine/OpenVanilla/OVCandidateService.h delete mode 100644 Source/Engine/OpenVanilla/OVDatabaseService.h delete mode 100644 Source/Engine/OpenVanilla/OVDateTimeHelper.h delete mode 100644 Source/Engine/OpenVanilla/OVEncodingService.h delete mode 100644 Source/Engine/OpenVanilla/OVEventHandlingContext.h delete mode 100644 Source/Engine/OpenVanilla/OVException.h delete mode 100644 Source/Engine/OpenVanilla/OVFileHelper.h delete mode 100644 Source/Engine/OpenVanilla/OVFrameworkInfo.h delete mode 100644 Source/Engine/OpenVanilla/OVInputMethod.h delete mode 100644 Source/Engine/OpenVanilla/OVKey.h delete mode 100644 Source/Engine/OpenVanilla/OVKeyPreprocessor.h delete mode 100644 Source/Engine/OpenVanilla/OVKeyValueMap.h delete mode 100644 Source/Engine/OpenVanilla/OVLoaderBase.h delete mode 100644 Source/Engine/OpenVanilla/OVLoaderService.h delete mode 100644 Source/Engine/OpenVanilla/OVLocalization.h delete mode 100644 Source/Engine/OpenVanilla/OVModule.h delete mode 100644 Source/Engine/OpenVanilla/OVModulePackage.h delete mode 100644 Source/Engine/OpenVanilla/OVOutputFilter.h delete mode 100644 Source/Engine/OpenVanilla/OVPathInfo.h delete mode 100644 Source/Engine/OpenVanilla/OVSQLiteDatabaseService.h delete mode 100644 Source/Engine/OpenVanilla/OVSQLiteWrapper.h delete mode 100644 Source/Engine/OpenVanilla/OVStringHelper.h delete mode 100644 Source/Engine/OpenVanilla/OVTextBuffer.h delete mode 100644 Source/Engine/OpenVanilla/OVUTF8Helper.h delete mode 100644 Source/Engine/OpenVanilla/OVWildcard.h delete mode 100644 Source/Engine/OpenVanilla/OpenVanilla.h diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index 5f4ba050..69c0636d 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -114,38 +114,6 @@ 6A0D4F1E15FC0EB100ABF4B3 /* Walker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Walker.h; sourceTree = ""; }; 6A0D4F2015FC0EB100ABF4B3 /* Mandarin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Mandarin.cpp; sourceTree = ""; }; 6A0D4F2115FC0EB100ABF4B3 /* Mandarin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mandarin.h; sourceTree = ""; }; - 6A0D4F2315FC0EB100ABF4B3 /* OpenVanilla.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenVanilla.h; sourceTree = ""; }; - 6A0D4F2415FC0EB100ABF4B3 /* OVAroundFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVAroundFilter.h; sourceTree = ""; }; - 6A0D4F2515FC0EB100ABF4B3 /* OVBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVBase.h; sourceTree = ""; }; - 6A0D4F2615FC0EB100ABF4B3 /* OVBenchmark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVBenchmark.h; sourceTree = ""; }; - 6A0D4F2715FC0EB100ABF4B3 /* OVCandidateService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVCandidateService.h; sourceTree = ""; }; - 6A0D4F2815FC0EB100ABF4B3 /* OVCINDatabaseService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVCINDatabaseService.h; sourceTree = ""; }; - 6A0D4F2915FC0EB100ABF4B3 /* OVCINDataTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVCINDataTable.h; sourceTree = ""; }; - 6A0D4F2A15FC0EB100ABF4B3 /* OVCINToSQLiteConvertor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVCINToSQLiteConvertor.h; sourceTree = ""; }; - 6A0D4F2B15FC0EB100ABF4B3 /* OVDatabaseService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVDatabaseService.h; sourceTree = ""; }; - 6A0D4F2C15FC0EB100ABF4B3 /* OVDateTimeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVDateTimeHelper.h; sourceTree = ""; }; - 6A0D4F2D15FC0EB100ABF4B3 /* OVEncodingService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVEncodingService.h; sourceTree = ""; }; - 6A0D4F2E15FC0EB100ABF4B3 /* OVEventHandlingContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVEventHandlingContext.h; sourceTree = ""; }; - 6A0D4F2F15FC0EB100ABF4B3 /* OVException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVException.h; sourceTree = ""; }; - 6A0D4F3015FC0EB100ABF4B3 /* OVFileHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVFileHelper.h; sourceTree = ""; }; - 6A0D4F3115FC0EB100ABF4B3 /* OVFrameworkInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVFrameworkInfo.h; sourceTree = ""; }; - 6A0D4F3215FC0EB100ABF4B3 /* OVInputMethod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVInputMethod.h; sourceTree = ""; }; - 6A0D4F3315FC0EB100ABF4B3 /* OVKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVKey.h; sourceTree = ""; }; - 6A0D4F3415FC0EB100ABF4B3 /* OVKeyPreprocessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVKeyPreprocessor.h; sourceTree = ""; }; - 6A0D4F3515FC0EB100ABF4B3 /* OVKeyValueMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVKeyValueMap.h; sourceTree = ""; }; - 6A0D4F3615FC0EB100ABF4B3 /* OVLoaderBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVLoaderBase.h; sourceTree = ""; }; - 6A0D4F3715FC0EB100ABF4B3 /* OVLoaderService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVLoaderService.h; sourceTree = ""; }; - 6A0D4F3815FC0EB100ABF4B3 /* OVLocalization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVLocalization.h; sourceTree = ""; }; - 6A0D4F3915FC0EB100ABF4B3 /* OVModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVModule.h; sourceTree = ""; }; - 6A0D4F3A15FC0EB100ABF4B3 /* OVModulePackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVModulePackage.h; sourceTree = ""; }; - 6A0D4F3B15FC0EB100ABF4B3 /* OVOutputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVOutputFilter.h; sourceTree = ""; }; - 6A0D4F3C15FC0EB100ABF4B3 /* OVPathInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVPathInfo.h; sourceTree = ""; }; - 6A0D4F3D15FC0EB100ABF4B3 /* OVSQLiteDatabaseService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVSQLiteDatabaseService.h; sourceTree = ""; }; - 6A0D4F3E15FC0EB100ABF4B3 /* OVSQLiteWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVSQLiteWrapper.h; sourceTree = ""; }; - 6A0D4F3F15FC0EB100ABF4B3 /* OVStringHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVStringHelper.h; sourceTree = ""; }; - 6A0D4F4015FC0EB100ABF4B3 /* OVTextBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVTextBuffer.h; sourceTree = ""; }; - 6A0D4F4115FC0EB100ABF4B3 /* OVUTF8Helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVUTF8Helper.h; sourceTree = ""; }; - 6A0D4F4215FC0EB100ABF4B3 /* OVWildcard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVWildcard.h; sourceTree = ""; }; 6A0D4F5615FC0EF900ABF4B3 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hant"; path = "Source/zh-Hant.lproj/preferences.xib"; sourceTree = ""; }; 6A15B32421A51F2300B92CD3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 6A15B32521A51F2300B92CD3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; @@ -333,7 +301,6 @@ children = ( 6A0D4F1315FC0EB100ABF4B3 /* Gramambular */, 6A0D4F1F15FC0EB100ABF4B3 /* Mandarin */, - 6A0D4F2215FC0EB100ABF4B3 /* OpenVanilla */, 6ACC3D3E27914F2400F1B140 /* KeyValueBlobReader.cpp */, 6ACC3D3C27914AAB00F1B140 /* KeyValueBlobReader.h */, D41355DC278EA3ED005E5CBD /* UserPhrasesLM.cpp */, @@ -381,45 +348,6 @@ path = Mandarin; sourceTree = ""; }; - 6A0D4F2215FC0EB100ABF4B3 /* OpenVanilla */ = { - isa = PBXGroup; - children = ( - 6A0D4F2315FC0EB100ABF4B3 /* OpenVanilla.h */, - 6A0D4F2415FC0EB100ABF4B3 /* OVAroundFilter.h */, - 6A0D4F2515FC0EB100ABF4B3 /* OVBase.h */, - 6A0D4F2615FC0EB100ABF4B3 /* OVBenchmark.h */, - 6A0D4F2715FC0EB100ABF4B3 /* OVCandidateService.h */, - 6A0D4F2815FC0EB100ABF4B3 /* OVCINDatabaseService.h */, - 6A0D4F2915FC0EB100ABF4B3 /* OVCINDataTable.h */, - 6A0D4F2A15FC0EB100ABF4B3 /* OVCINToSQLiteConvertor.h */, - 6A0D4F2B15FC0EB100ABF4B3 /* OVDatabaseService.h */, - 6A0D4F2C15FC0EB100ABF4B3 /* OVDateTimeHelper.h */, - 6A0D4F2D15FC0EB100ABF4B3 /* OVEncodingService.h */, - 6A0D4F2E15FC0EB100ABF4B3 /* OVEventHandlingContext.h */, - 6A0D4F2F15FC0EB100ABF4B3 /* OVException.h */, - 6A0D4F3015FC0EB100ABF4B3 /* OVFileHelper.h */, - 6A0D4F3115FC0EB100ABF4B3 /* OVFrameworkInfo.h */, - 6A0D4F3215FC0EB100ABF4B3 /* OVInputMethod.h */, - 6A0D4F3315FC0EB100ABF4B3 /* OVKey.h */, - 6A0D4F3415FC0EB100ABF4B3 /* OVKeyPreprocessor.h */, - 6A0D4F3515FC0EB100ABF4B3 /* OVKeyValueMap.h */, - 6A0D4F3615FC0EB100ABF4B3 /* OVLoaderBase.h */, - 6A0D4F3715FC0EB100ABF4B3 /* OVLoaderService.h */, - 6A0D4F3815FC0EB100ABF4B3 /* OVLocalization.h */, - 6A0D4F3915FC0EB100ABF4B3 /* OVModule.h */, - 6A0D4F3A15FC0EB100ABF4B3 /* OVModulePackage.h */, - 6A0D4F3B15FC0EB100ABF4B3 /* OVOutputFilter.h */, - 6A0D4F3C15FC0EB100ABF4B3 /* OVPathInfo.h */, - 6A0D4F3D15FC0EB100ABF4B3 /* OVSQLiteDatabaseService.h */, - 6A0D4F3E15FC0EB100ABF4B3 /* OVSQLiteWrapper.h */, - 6A0D4F3F15FC0EB100ABF4B3 /* OVStringHelper.h */, - 6A0D4F4015FC0EB100ABF4B3 /* OVTextBuffer.h */, - 6A0D4F4115FC0EB100ABF4B3 /* OVUTF8Helper.h */, - 6A0D4F4215FC0EB100ABF4B3 /* OVWildcard.h */, - ); - path = OpenVanilla; - sourceTree = ""; - }; 6A0D4F4715FC0EB900ABF4B3 /* Resources */ = { isa = PBXGroup; children = ( diff --git a/Source/Engine/OpenVanilla/OVAroundFilter.h b/Source/Engine/OpenVanilla/OVAroundFilter.h deleted file mode 100644 index dc024f30..00000000 --- a/Source/Engine/OpenVanilla/OVAroundFilter.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// OVAroundFilter.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVAroundFilter_h -#define OVAroundFilter_h - -#if defined(__APPLE__) - #include -#else - #include "OVModule.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVAroundFilter : public OVModule { - public: - virtual bool isAroundFilter() const - { - return true; - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVBase.h b/Source/Engine/OpenVanilla/OVBase.h deleted file mode 100644 index aa4c9a39..00000000 --- a/Source/Engine/OpenVanilla/OVBase.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// OVBase.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVBase_h -#define OVBase_h - -#include -#include -#include - -namespace OpenVanilla { - using namespace std; - - class OVBase { - public: - virtual ~OVBase() - { - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVBenchmark.h b/Source/Engine/OpenVanilla/OVBenchmark.h deleted file mode 100644 index f37f625a..00000000 --- a/Source/Engine/OpenVanilla/OVBenchmark.h +++ /dev/null @@ -1,102 +0,0 @@ -// -// OVBenchmark.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVBenchmark_h -#define OVBenchmark_h - -#include - -namespace OpenVanilla { - using namespace std; - - class OVBenchmark - { - public: - OVBenchmark() - : m_used(false) - , m_running(false) - , m_start(0) - , m_elapsedTicks(0) - , m_elapsedSeconds(0.0) - { - } - - void start() - { - m_used = true; - m_running = true; - m_elapsedSeconds = 0.0; - m_elapsedTicks = 0; - m_start = clock(); - } - - void stop() - { - if (m_running) { - update(); - m_running = false; - } - } - - clock_t elapsedTicks() - { - if (!m_used) - return 0; - - if (m_running) - update(); - - return m_elapsedTicks; - } - - double elapsedSeconds() - { - if (!m_used) - return 0; - - if (m_running) - update(); - - return m_elapsedSeconds; - } - - protected: - void update() - { - m_elapsedTicks = clock() - m_start; - m_elapsedSeconds = static_cast(m_elapsedTicks) / CLOCKS_PER_SEC; - } - - bool m_used; - bool m_running; - clock_t m_start; - clock_t m_elapsedTicks; - double m_elapsedSeconds; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVCINDataTable.h b/Source/Engine/OpenVanilla/OVCINDataTable.h deleted file mode 100644 index 3638b768..00000000 --- a/Source/Engine/OpenVanilla/OVCINDataTable.h +++ /dev/null @@ -1,806 +0,0 @@ -// -// OVCINDataTable.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVCINDataTable_h -#define OVCINDataTable_h - -#include -#include -#include -#include -#include - -#include "OVFileHelper.h" -#include "OVUTF8Helper.h" -#include "OVWildcard.h" - -#include - -namespace OpenVanilla { - using namespace std; - - // CIN := (COMMENT | PROPERTY | KEYNAME | CHARDEF)* - // EOL := \n|\r - // COMMENT := ^#.*(EOL) - // KEY := \w+ - // VALUE := \w([\w\s]*\w)* - // PROPERTY: ^%(KEY)\s+(VALUE)(EOL) - // KEYNAME := - // ^%keyname\s+begin(EOL) - // ^(KEY)\s+(VALUE)(EOL) - // ^%keyname\s+end(EOL) - // CHARDEF: - // ^%chardef\s+begin(EOL) - // ^(KEY)\s+(VALUE)(EOL) - // ^%chardef\s+end(EOL) - - class OVCINDataTableParser; - - class OVFastKeyValuePairMap { - public: - ~OVFastKeyValuePairMap() - { - free(m_data); - } - - size_t size() - { - return m_index; - } - - pair keyValuePairAtIndex(size_t index) - { - if (index >= m_index) - return pair(); - - KVPair* entry = m_data + index; - return pair(entry->key, entry->value); - } - - vector > findPairsWithKey(const char* key) - { - return fetchValuesFromIndex(findFirstOccuranceOfKey(key), key); - } - - vector > findPairsWithWildcard(const OVWildcard& pWildcard) - { - const OVWildcard* ptrWildcard = &pWildcard; - - if (pWildcard.isCaseSensitive() != m_caseSensitive) { - OVWildcard newWildcard(pWildcard.expression(), pWildcard.matchOneChar(), pWildcard.matchZeroOrMoreChar(), m_caseSensitive); - ptrWildcard = &newWildcard; - } - - const OVWildcard& wildcard = *ptrWildcard; - - string headString = wildcard.longestHeadMatchString(); - insensitivizeString(headString); - size_t hSLength = headString.length(); - - size_t start = findFirstOccuranceOfKey(headString.c_str(), true); - vector > result; - - for (size_t index = start; index < m_index; index++) { - KVPair* entry = m_data + index; - string keyString = entry->key; - - // if no more head matchZeroOrMoreChar - string keySubstr = keyString.substr(0, hSLength); - insensitivizeString(keySubstr); - if (keySubstr > headString) - break; - - if (wildcard.match(keyString)) - result.push_back(pair(keyString, entry->value)); - } - - return result; - } - protected: - friend class OVCINDataTableParser; - - OVFastKeyValuePairMap(size_t initSize, size_t growSize, bool caseSensitive = false) - : m_index(0) - , m_size(initSize ? initSize : 1) - , m_growSize(growSize) - , m_caseSensitive(caseSensitive) - { - m_data = (KVPair*)calloc(1, sizeof(KVPair) * m_size); - } - - - void add(char* key, char* value) - { - KVPair* entry = m_data + m_index; - entry->key = key; - entry->value = value; - - m_index++; - if (m_index == m_size) - grow(); - } - - void sortAndFreeze() - { - m_size = m_index; - - if (m_caseSensitive) - qsort(m_data, m_index, sizeof(KVPair), OVFastKeyValuePairMap::qsortCompareCaseSensitive); - else - qsort(m_data, m_index, sizeof(KVPair), OVFastKeyValuePairMap::qsortCompare); - } - - void insensitivizeString(string& str) - { - if (m_caseSensitive) - return; - - for (string::iterator iter = str.begin() ; iter != str.end() ; ++iter) - *iter = tolower(*iter); - } - - protected: - vector > fetchValuesFromIndex(size_t start, const char* key) - { - vector > result; - for (size_t index = start ; index < m_index; index++) { - KVPair* entry = m_data + index; - - if (compareString(entry->key, key) <= 0) { - result.push_back(pair(entry->key, entry->value)); - } - else { - break; - } - } - - return result; - } - - size_t findFirstOccuranceOfKey(const char* key, bool closest = false) - { - if (!m_index) - return m_index; - - size_t mid, low = 0, high = m_index - 1; - - while (low <= high) { - mid = (low + high) / 2; - - char* entryKey = (m_data + mid)->key; - int cmp = compareString(key, entryKey); - - if (!cmp) { - if (!mid) - return mid; - - size_t oneUp = mid - 1; - if (!compareString(key, (m_data + oneUp)->key)) - high = oneUp; - else - return mid; - } - else { - if (closest) { - if (mid > 0) { - if (compareString(key, (m_data + mid - 1)->key) > 0 && compareString(key, entryKey) <= 0) - return mid; - } - } - - if (cmp < 0) { - if (!mid) { - if (closest) - return 0; - - return m_index; - } - - high = mid - 1; - } - else { - if (low + 1 >= m_index) - return m_index; - - low = mid + 1; - } - } - } - - return m_index; - } - - int compareString(const char* a, const char* b) - { - #ifndef WIN32 - return m_caseSensitive ? strcmp(a, b) : strcasecmp(a, b); - #else - return m_caseSensitive ? strcmp(a, b) : _stricmp(a, b); - #endif - } - - static int qsortCompare(const void* a, const void* b) - { - int cmp; - char* aa = ((const KVPair*)a)->key; - char* bb = ((const KVPair*)b)->key; - - #ifndef WIN32 - if (!(cmp = strcasecmp(aa, bb))) - #else - if (!(cmp = _stricmp(aa, bb))) - #endif - return aa == bb ? 0 : (aa > bb ? 1 : -1); - else - return cmp; - } - - static int qsortCompareCaseSensitive(const void* a, const void* b) - { - int cmp; - char* aa = ((const KVPair*)a)->key; - char* bb = ((const KVPair*)b)->key; - - if (!(cmp = strcmp(aa, bb))) - return aa == bb ? 0 : (aa > bb ? 1 : -1); - else - return cmp; - } - - - void grow() - { - size_t growSize = m_growSize ? m_growSize : m_size; - KVPair* newData = (KVPair*)malloc(sizeof(KVPair) * (m_size + growSize)); - memcpy(newData, m_data, sizeof(KVPair) * m_size); - memset(newData + m_size, 0, sizeof(KVPair) * growSize); - - KVPair* tmp = m_data; - m_data = newData; - free(tmp); - - m_size += growSize; - } - - protected: - struct KVPair { - char* key; - char* value; - }; - - bool m_caseSensitive; - size_t m_growSize; - size_t m_size; - size_t m_index; - KVPair* m_data; - }; - - class OVCINDataTable { - public: - ~OVCINDataTable() - { - if (m_propertyMap) - delete m_propertyMap; - if (m_keynameMap) - delete m_keynameMap; - if (m_chardefMap) - delete m_chardefMap; - if (m_data) - free (m_data); - } - - string findProperty(const string& key) - { - vector > result = m_propertyMap->findPairsWithKey(key.c_str()); - if (result.size()) return result[0].second; - return string(); - } - - string findKeyname(const string& key) - { - vector > result = m_keynameMap->findPairsWithKey(key.c_str()); - if (result.size()) return result[0].second; - return string(); - } - - vector findChardef(const string& key) - { - vector > ret = m_chardefMap->findPairsWithKey(key.c_str()); - vector result; - vector >::iterator iter= ret.begin(); - - for ( ; iter != ret.end(); iter++) - result.push_back((*iter).second); - - return result; - } - - vector > findChardefWithWildcard(const OVWildcard& wildcard) - { - return m_chardefMap->findPairsWithWildcard(wildcard); - } - - OVFastKeyValuePairMap* propertyMap() - { - return m_propertyMap; - } - - OVFastKeyValuePairMap* keynameMap() - { - return m_keynameMap; - } - - OVFastKeyValuePairMap* chardefMap() - { - return m_chardefMap; - } - - protected: - friend class OVCINDataTableParser; - OVCINDataTable(char* data, OVFastKeyValuePairMap* propertyMap, OVFastKeyValuePairMap* keynameMap, OVFastKeyValuePairMap* chardefMap) - : m_data(data) - , m_propertyMap(propertyMap) - , m_keynameMap(keynameMap) - , m_chardefMap(chardefMap) - { - } - - char* m_data; - OVFastKeyValuePairMap* m_propertyMap; - OVFastKeyValuePairMap* m_keynameMap; - OVFastKeyValuePairMap* m_chardefMap; - }; - - - - class OVCINDataTableParser { - public: - enum { - NoFileError, - SeekError, - EmptyFileError, - MemoryAllocationError, - ReadError, - NoDataError = EmptyFileError - }; - - OVCINDataTableParser() - : m_data(0) - , m_lastError(0) - { - } - - ~OVCINDataTableParser() - { - if (m_data) - free(m_data); - } - - int lastError() - { - return m_lastError; - } - - OVCINDataTable* CINDataTableFromFileName(const string& filename, bool caseSensitive = false) - { - if (m_data) { - free(m_data); - m_data = 0; - } - - FILE* f = OVFileHelper::OpenStream(filename); - if (!f) { - m_lastError = NoFileError; - return 0; - } - - OVCINDataTable* table; - OVCINDataTableParser parser; - table = parser.CINDataTableFromFileStream(f, caseSensitive); - fclose(f); - return table; - } - - OVCINDataTable* CINDataTableFromString(const char* string, bool caseSensitive = false) - { - if (m_data) { - free(m_data); - m_data = 0; - } - - size_t len = strlen(string); - if (!len) { - m_lastError = NoDataError; - return 0; - } - - m_data = (char*)calloc(1, len + 1); - if (!m_data) { - m_lastError = MemoryAllocationError; - return 0; - } - - memcpy(m_data, string, len); - - return CINDataTableFromRetainedData(caseSensitive); - } - - - OVCINDataTable* CINDataTableFromFileStream(FILE* stream, bool caseSensitive = false) - { - if (m_data) { - free(m_data); - m_data = 0; - } - - if (!stream) { - m_lastError = NoFileError; - return 0; - } - - if (fseek(stream, 0, SEEK_END) == -1) { - m_lastError = SeekError; - return 0; - } - - size_t size; - if (!(size = ftell(stream))) { - m_lastError = EmptyFileError; - return 0; - } - - if (fseek(stream, 0, SEEK_SET) == -1) { - m_lastError = SeekError; - return 0; - } - - m_data = (char*)calloc(1, size + 1); - if (!m_data) { - m_lastError = MemoryAllocationError; - return 0; - } - - if (fread(m_data, 1, size, stream) != size) { - m_lastError = ReadError; - return 0; - } - - return CINDataTableFromRetainedData(caseSensitive); - } - - protected: - OVCINDataTable* CINDataTableFromRetainedData(bool caseSensitive) - { - OVFastKeyValuePairMap* propertyMap = new OVFastKeyValuePairMap(16, 0, caseSensitive); - if (!propertyMap) { - free(m_data); - m_lastError = MemoryAllocationError; - return 0; - } - - OVFastKeyValuePairMap* keynameMap = new OVFastKeyValuePairMap(64, 0, caseSensitive); - if (!keynameMap) { - free(m_data); - delete propertyMap; - m_lastError = MemoryAllocationError; - return 0; - } - - OVFastKeyValuePairMap* chardefMap = new OVFastKeyValuePairMap(1024, 0, caseSensitive); - if (!chardefMap) { - free(m_data); - delete propertyMap; - delete keynameMap; - m_lastError = MemoryAllocationError; - return 0; - } - - m_scanner = m_data; - - char first; - int blockMode = 0; - - while (first = *m_scanner) { - if (blockMode) { - if (first == '\r' || first == '\n') { - m_scanner++; - continue; - } - - char* key = m_scanner; - char* value = const_cast(""); - char endingChar = skipToSpaceCharOrLineEndAndMarkAndForward(); - - if (endingChar == '\r' || endingChar == '\n') { - ; - } - else { - endingChar = skipUntilNonSpaceChar(); - if (endingChar == '\r' || endingChar == '\n') { - ; - } - else { - value = m_scanner; - skipToLineEndAndMarkAndForwardWithoutTrailingSpace(); - } - } - - if (blockMode == 1) { - if (!strcmp(key, "%keyname") && !strcmp(value, "end")) { - blockMode = 0; - } - else { - if (!caseSensitive) - makeLowerCase(key); - - keynameMap->add(key, value); - } - } - else if (blockMode == 2) { - if (!strcmp(key, "%chardef") && !strcmp(value, "end")) { - blockMode = 0; - } - - else { - if (!caseSensitive) - makeLowerCase(key); - - chardefMap->add(key, value); - } - } - - continue; - } - - - if (first == '#') { - skipUntilNextLine(); - continue; - } - - if (first == '%') { - m_scanner++; - - char* key; - char* value = const_cast(""); - - if (*(key = m_scanner)) { - char endingChar = skipToSpaceCharOrLineEndAndMarkAndForward(); - - if (endingChar == '\r' || endingChar == '\n') { - ; - } - else { - endingChar = skipUntilNonSpaceChar(); - if (endingChar == '\r' || endingChar == '\n') { - ; - } - else { - value = m_scanner; - skipToLineEndAndMarkAndForwardWithoutTrailingSpace(); - } - } - - if (!strcmp(key, "keyname") && !strcmp(value, "begin")) { - blockMode = 1; - } - else if (!strcmp(key, "chardef") && !strcmp(value, "begin")) { - blockMode = 2; - } - else { - propertyMap->add(key, value); - } - } - - continue; - } - - m_scanner++; - } - - propertyMap->sortAndFreeze(); - keynameMap->sortAndFreeze(); - chardefMap->sortAndFreeze(); - - OVCINDataTable* table = new OVCINDataTable(m_data, propertyMap, keynameMap, chardefMap); - - if (!table) { - free(m_data); - delete propertyMap; - delete keynameMap; - delete chardefMap; - m_lastError = MemoryAllocationError; - return 0; - } - else { - m_data = 0; - } - - return table; - } - - void skipUntilNextLine() - { - skipUntilEitherCRLF(); - skipUntilNeitherCRLF(); - } - - void skipUntilEitherCRLF() - { - char nextChar; - while (nextChar = *m_scanner) { - if (nextChar == '\r' || nextChar == '\n') break; - m_scanner++; - } - } - - void skipUntilNeitherCRLF() - { - char nextChar; - while (nextChar = *m_scanner) { - if (!(nextChar == '\r' || nextChar == '\n')) break; - m_scanner++; - } - } - - void skipToLineEndAndMarkAndForwardWithoutTrailingSpace() - { - char nextChar; - while (nextChar = *m_scanner) { - if (nextChar == ' ' || nextChar == '\t') { - char* begin = m_scanner; - - m_scanner++; - while (nextChar = *m_scanner) { - if (!(nextChar == ' ' || nextChar == '\t')) break; - m_scanner++; - } - - if (nextChar == '\n' || nextChar == '\r') { - *begin = 0; - m_scanner++; - return; - } - else { - m_scanner++; - continue; - } - } - - if (nextChar == '\n' || nextChar == '\r') { - *m_scanner = 0; - m_scanner++; - return; - } - - m_scanner++; - } - } - - char skipToSpaceCharOrLineEndAndMarkAndForward() - { - char nextChar; - while (nextChar = *m_scanner) { - if (nextChar == ' ' || nextChar == '\t' || nextChar == '\n' || nextChar == '\r') { - *m_scanner = 0; - m_scanner++; - return nextChar; - } - - m_scanner++; - } - - return 0; - } - - char skipUntilNonSpaceChar() - { - char nextChar; - while (nextChar = *m_scanner) { - if (!(nextChar == ' ' || nextChar == '\t')) - return nextChar; - - m_scanner++; - } - - return 0; - } - - void makeLowerCase(char* ptr) - { - while (*ptr) { - *ptr = tolower(*ptr); - ptr++; - } - } - - protected: - char* m_data; - char* m_scanner; - int m_lastError; - - public: - static const map QuickParseProperty(const string& filename) - { - map properties; - FILE* stream = OVFileHelper::OpenStream(filename); - - if (!stream) - return properties; - - while (!feof(stream)) { - char buffer[256]; - fgets(buffer, sizeof(buffer) - 1, stream); - - if (!*buffer) - continue; - - if (*buffer == '#') - continue; - - pair pv = SplitPropertyString(buffer + 1); - if (pv.first == "keyname") - break; - - properties[pv.first] = pv.second; - } - - fclose(stream); - return properties; - } - - static pair SplitPropertyString(const char* str) - { - const char* scanner = str; - while (*scanner) { - if (*scanner == ' ' || *scanner == '\t' || *scanner == '\r' || *scanner == '\n') - break; - scanner++; - } - - string property = string(str, (size_t)(scanner - str)); - - while (*scanner) { - if (*scanner != ' ' && *scanner != '\t') - break; - scanner++; - } - - const char* begin = scanner; - while (*scanner) { - if (*scanner == '\r' || *scanner == '\n') - break; - scanner++; - } - - string value = string(begin, (size_t)(scanner - begin)); - return pair(property, value); - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVCINDatabaseService.h b/Source/Engine/OpenVanilla/OVCINDatabaseService.h deleted file mode 100644 index 8ff666cb..00000000 --- a/Source/Engine/OpenVanilla/OVCINDatabaseService.h +++ /dev/null @@ -1,189 +0,0 @@ -// -// OVCINDatabaseService.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVCINDatabaseService_h -#define OVCINDatabaseService_h - -#if defined(__APPLE__) - #include - #include -#else - #include "OVCINDataTable.h" - #include "OVDatabaseService.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVCINDatabaseService; - - class OVCINKeyValueDataTable : public OVKeyValueDataTableInterface - { - public: - ~OVCINKeyValueDataTable() - { - delete m_table; - } - - virtual const vector valuesForKey(const string& key) - { - return m_table->findChardef(key); - } - - virtual const vector > valuesForKey(const OVWildcard& expression) - { - return m_table->findChardefWithWildcard(expression); - } - - virtual const string valueForProperty(const string& property) - { - if (OVKeynamePropertyHelper::IsPropertyKeyname(property)) - return m_table->findKeyname(OVKeynamePropertyHelper::KeynameFromProperty(property)); - else - return m_table->findProperty(property); - } - - protected: - OVCINDataTable* m_table; - - friend class OVCINDatabaseService; - - OVCINKeyValueDataTable(OVCINDataTable* table) - : m_table(table) - { - } - }; - - - class OVCINDatabaseService : public OVDatabaseService { - public: - OVCINDatabaseService() - { - } - - OVCINDatabaseService(const string& pathToScan, const string& includePattern = "*.cin", const string& excludePattern = "", size_t depth = 1) - { - addDirectory(pathToScan, includePattern, excludePattern, depth); - } - - // note addDirectory overwrites the table data, so scan user directory after scan the systems if you want to give precedence to user' tables - void addDirectory(const string& pathToScan, const string& includePattern = "*.cin", const string& excludePattern = "", size_t depth = 1) - { - string pathPrefix = OVPathHelper::NormalizeByExpandingTilde(pathToScan) + OVPathHelper::Separator(); - size_t prefixLength = pathPrefix.length(); - - vector tables = OVDirectoryHelper::Glob(pathPrefix, includePattern, excludePattern, depth); - - vector::iterator iter = tables.begin(); - for ( ; iter != tables.end(); ++iter) { - const string& path = *iter; - string shortPath = *iter; - shortPath.erase(0, prefixLength); - - string tableName = OVCINDatabaseService::TableNameFromPath(shortPath); - m_tables[tableName] = path; - } - } - - virtual const vector tables(const OVWildcard& filter = string("*")) - { - vector result; - - for (map::iterator iter = m_tables.begin() ; iter != m_tables.end(); ++iter) { - if (filter.match((*iter).first)) - result.push_back((*iter).first); - } - - return result; - } - - virtual bool tableSupportsValueToKeyLookup(const string &tableName) - { - return false; - } - - virtual OVKeyValueDataTableInterface* createKeyValueDataTableInterface(const string& name, bool suggestedCaseSensitivity = false) - { - map::iterator iter = m_tables.find(name); - if (iter == m_tables.end()) - return 0; - - OVCINDataTableParser parser; - OVCINDataTable* table = parser.CINDataTableFromFileName((*iter).second, suggestedCaseSensitivity); - - if (!table) - return 0; - - return new OVCINKeyValueDataTable(table); - } - - - virtual const string valueForPropertyInTable(const string& property, const string& name) - { - map::iterator iter; - - if (name != m_cachedTableName) - { - iter = m_tables.find(name); - if (iter == m_tables.end()) - return string(); - - m_cachedProperties = OVCINDataTableParser::QuickParseProperty((*iter).second); - m_cachedTableName = name; - } - - iter = m_cachedProperties.find(property); - if (iter != m_cachedProperties.end()) - return (*iter).second; - - return string(); - } - - protected: - map m_tables; - map m_cachedProperties; - string m_cachedTableName; - - public: - static const string TableNameFromPath(const string& path) - { - string result; - char separator = OVPathHelper::Separator(); - - string::const_iterator iter = path.begin(); - for ( ; iter != path.end(); ++iter) - if (*iter == separator || *iter == '.') - result += '-'; - else - result += *iter; - - return result; - } - }; -}; - -#endif \ No newline at end of file diff --git a/Source/Engine/OpenVanilla/OVCINToSQLiteConvertor.h b/Source/Engine/OpenVanilla/OVCINToSQLiteConvertor.h deleted file mode 100644 index 4a73d6b3..00000000 --- a/Source/Engine/OpenVanilla/OVCINToSQLiteConvertor.h +++ /dev/null @@ -1,125 +0,0 @@ -// -// OVCINToSQLiteConvertor.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVCINToSQLiteConvertor_h -#define OVCINToSQLiteConvertor_h - -#if defined(__APPLE__) - #include - #include -#else - #include "OVCINDataTable.h" - #include "OVSQLiteWrapper.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVCINToSQLiteConvertor { - protected: - static bool InsertKeyValue(OVFastKeyValuePairMap* map, OVSQLiteStatement* statement, const char* prefix = 0) - { - string prefixString = prefix ? prefix : ""; - - size_t size = map->size(); - - for (size_t index = 0; index < size; index++) { - pair kvpair = map->keyValuePairAtIndex(index); - - const string& key = prefix ? prefixString + kvpair.first : kvpair.first; - - statement->bindTextToColumn(key, 1); - statement->bindTextToColumn(kvpair.second, 2); - - if (statement->step() != SQLITE_DONE) - return false; - - statement->reset(); - } - - return true; - } - - public: - static bool Convert(OVCINDataTable* table, OVSQLiteConnection* connection, const string& tableName, bool overwriteTable = true) - { - const char* nameStr = tableName.c_str(); - // query if the table exists - OVSQLiteStatement* statement; - - statement = connection->prepare("SELECT name FROM sqlite_master WHERE name = %Q", nameStr); - - if (!statement) - return false; - - if (statement->step() == SQLITE_ROW && overwriteTable) - { - delete statement; - - if (connection->execute("DROP TABLE %Q", nameStr) != SQLITE_OK) { - delete statement; - return false; - } - } - else - delete statement; - - if (connection->execute("CREATE TABLE %Q (key, value)", nameStr) != SQLITE_OK) - return false; - - string indexName = tableName + "_index"; - if (connection->execute("CREATE INDEX %Q on %Q (key)", indexName.c_str(), nameStr) != SQLITE_OK) - return false; - - statement = connection->prepare("INSERT INTO %Q VALUES (?, ?)", nameStr); - if (!statement) { - return false; - } - - if (connection->execute("BEGIN") != SQLITE_OK) { - return false; - } - - string keynameProperty = string(OVPropertyStringInternalPrefix) + string(OVCINKeynameString); - - if (InsertKeyValue(table->propertyMap(), statement, OVPropertyStringInternalPrefix)) - if (InsertKeyValue(table->keynameMap(), statement, keynameProperty.c_str())) - InsertKeyValue(table->chardefMap(), statement); - - delete statement; - - if (connection->execute("COMMIT") != SQLITE_OK) { - return false; - } - - return true; - } - - }; -}; - -#endif \ No newline at end of file diff --git a/Source/Engine/OpenVanilla/OVCandidateService.h b/Source/Engine/OpenVanilla/OVCandidateService.h deleted file mode 100644 index ecaff8c9..00000000 --- a/Source/Engine/OpenVanilla/OVCandidateService.h +++ /dev/null @@ -1,208 +0,0 @@ -// -// OVCandidateService.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVCandidateService_h -#define OVCandidateService_h - -#if defined(__APPLE__) - #include - #include - #include -#else - #include "OVBase.h" - #include "OVKey.h" - #include "OVLoaderService.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVCandidateList : public OVBase { - public: - virtual void clear() = 0; - virtual size_t size() const = 0; - virtual string candidateAtIndex(size_t index) const = 0; - virtual void setCandidate(size_t index, const string& candidate) = 0; - virtual void setCandidates(const vector& candidates) = 0; - virtual void addCandidate(const string& candidate) = 0; - virtual void addCandidates(const vector& candidates) = 0; - }; - - class OVCandidatePanel; - class OVOneDimensionalCandidatePanel; - // class OVTwoDimensionalCandidatePanel; - class OVFreeContentPanel; - class OVPlainTextCandidatePanel; - class OVHTMLCandidatePanel; - - class OVCandidatePanel : public OVBase { - public: - virtual bool isOneDimensionalPanel() const - { - return false; - } - - virtual bool isTwoDimensionalPanel() const - { - return false; - } - - virtual bool isPlainTextPanelPanel() const - { - return false; - } - - virtual bool isHTMLPanel() const - { - return false; - } - - virtual void hide() = 0; - virtual void show() = 0; - virtual void updateDisplay() = 0; - virtual bool isVisible() = 0; - - virtual void setPrompt(const string& prompt) = 0; - virtual string prompt() = 0; - - virtual bool yieldToCandidateEventHandler() = 0; - virtual void cancelEventHandler() = 0; - - virtual void reset() = 0; - }; - - class OVOneDimensionalCandidatePanel : public OVCandidatePanel { - public: - virtual bool isOneDimensionalPanel() const - { - return true; - } - - virtual bool isHorizontal() const = 0; - virtual bool isVertical() const = 0; - - virtual OVCandidateList* candidateList() = 0; - - virtual size_t candidatesPerPage() const = 0; - virtual void setCandidatesPerPage(size_t number) = 0; - virtual size_t pageCount() const = 0; - virtual size_t currentPage() const = 0; - virtual size_t currentPageCandidateCount() const = 0; - virtual bool allowsPageWrapping() const = 0; - virtual void setAllowsPageWrapping(bool allowsPageWrapping) = 0; - - virtual size_t currentHightlightIndex() const = 0; - virtual void setHighlightIndex(size_t index) = 0; - virtual size_t currentHightlightIndexInCandidateList() const = 0; - - virtual size_t goToNextPage() = 0; - virtual size_t goToPreviousPage() = 0; - virtual size_t goToPage(size_t page) = 0; - - virtual const OVKey candidateKeyAtIndex(size_t index) = 0; - virtual void setCandidateKeys(const string& asciiKeys, OVLoaderService* loaderService) - { - OVKeyVector keys; - for (size_t index = 0; index < asciiKeys.length(); index++) { - keys.push_back(loaderService->makeOVKey(asciiKeys[index])); - } - - setCandidateKeys(keys); - setCandidatesPerPage(asciiKeys.length()); - } - - virtual void setCandidateKeys(const OVKeyVector& keys) = 0; - virtual void setNextPageKeys(const OVKeyVector& keys) = 0; - virtual void setPreviousPageKeys(const OVKeyVector& keys) = 0; - virtual void setNextCandidateKeys(const OVKeyVector& keys) = 0; - virtual void setPreviousCandidateKeys(const OVKeyVector& keys) = 0; - virtual void setCancelKeys(const OVKeyVector& keys) = 0; - virtual void setChooseHighlightedCandidateKeys(const OVKeyVector& keys) = 0; - - virtual const OVKeyVector defaultCandidateKeys() const = 0; - virtual const OVKeyVector defaultNextPageKeys() const = 0; - virtual const OVKeyVector defaultNextCandidateKeys() const = 0; - virtual const OVKeyVector defaultPreviousPageKeys() const = 0; - virtual const OVKeyVector defaultPreviousCandidateKeys() const = 0; - virtual const OVKeyVector defaultCancelKeys() const = 0; - virtual const OVKeyVector defaultChooseHighlightedCandidateKeys() const = 0; - }; - - class OVFreeContentStorage : public OVBase { - public: - virtual void clear() = 0; - virtual void setContent(const string& content) = 0; - virtual void appendContent(const string& content) = 0; - }; - - class OVPlainTextCandidatePanel : public OVCandidatePanel { - public: - virtual bool isPlainTextPanelPanel() - { - return true; - } - - virtual OVFreeContentStorage* textStorage() = 0; - }; - - class OVHTMLCandidatePanel : public OVCandidatePanel { - public: - virtual OVFreeContentStorage* HTMLSourceStorage() = 0; - }; - - class OVCandidateService : public OVBase { - public: - virtual OVOneDimensionalCandidatePanel* useHorizontalCandidatePanel() - { - return 0; - } - - virtual OVOneDimensionalCandidatePanel* useVerticalCandidatePanel() - { - return 0; - } - - virtual OVOneDimensionalCandidatePanel* useOneDimensionalCandidatePanel() - { - return useVerticalCandidatePanel(); - } - - // virtual OVTwoDimensionalCandidatePanel* twoDimensionalCandidatePanel(); - - virtual OVPlainTextCandidatePanel* usePlainTextCandidatePanel() - { - return 0; - } - - virtual OVHTMLCandidatePanel* useHTMLCandidatePanel() - { - return 0; - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVDatabaseService.h b/Source/Engine/OpenVanilla/OVDatabaseService.h deleted file mode 100644 index 6baf5e05..00000000 --- a/Source/Engine/OpenVanilla/OVDatabaseService.h +++ /dev/null @@ -1,101 +0,0 @@ -// -// OVDatabaseService.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVDatabaseService_h -#define OVDatabaseService_h - -#if defined(__APPLE__) - #include - #include - #include - #include -#else - #include "OVBase.h" - #include "OVCINDataTable.h" - #include "OVFileHelper.h" - #include "OVWildcard.h" -#endif - -#include - -namespace OpenVanilla { - using namespace std; - - // database-backed table uses this prefix to store properties ina key-value data table - #define OVPropertyStringInternalPrefix "__property_" - - #define OVCINKeynameString "keyname-" - #define OVCINKeynameStringLength 8 - - // keyname is defined in the .cin format, not to be confused with the key in key-value pairs - class OVKeynamePropertyHelper : public OVBase { - public: - static bool IsPropertyKeyname(const string& property) - { - return (property.substr(0, OVCINKeynameStringLength) == OVCINKeynameString); - } - - // passes property and gets back the keyname - static const string KeynameFromProperty(const string& property) - { - return IsPropertyKeyname(property) ? property.substr(OVCINKeynameStringLength, property.length() - OVCINKeynameStringLength) : string(); - } - - // passes keyname and gets the combined property - static const string KeynameToProperty(const string& keyname) - { - return string(OVCINKeynameString) + keyname; - } - }; - - class OVKeyValueDataTableInterface : public OVBase { - public: - virtual const vector valuesForKey(const string& key) = 0; - virtual const vector > valuesForKey(const OVWildcard& expression) = 0; - virtual const string valueForProperty(const string& property) = 0; - - // only supported by database services that support value-to-key lookup, the default implementation is an empty vector - virtual const vector keysForValue(const string& value) - { - return vector(); - } - }; - - class OVDatabaseService : public OVBase { - public: - virtual const vector tables(const OVWildcard& filter = string("*")) = 0; - virtual bool tableSupportsValueToKeyLookup(const string &tableName) = 0; - - virtual OVKeyValueDataTableInterface* createKeyValueDataTableInterface(const string& name, bool suggestedCaseSensitivity = false) = 0; - - // this is needed so that modules like OVIMGeneric can know table localized names in advance, without really loading them - virtual const string valueForPropertyInTable(const string& property, const string& name) = 0; - }; - -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVDateTimeHelper.h b/Source/Engine/OpenVanilla/OVDateTimeHelper.h deleted file mode 100644 index 117800ea..00000000 --- a/Source/Engine/OpenVanilla/OVDateTimeHelper.h +++ /dev/null @@ -1,149 +0,0 @@ -// -// OVDateTimeHelper.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVDateTimeHelper_h -#define OVDateTimeHelper_h - -#include -#include -#include - -namespace OpenVanilla { - using namespace std; - - class OVDateTimeHelper - { - public: - static time_t GetTimeIntervalSince1970() - { - return time(NULL); - } - - static time_t GetTimeIntervalSince1970FromString(const string& s) - { - stringstream sst; - sst << s; - time_t t; - sst >> t; - return t; - } - - static const string GetTimeIntervalSince1970AsString() - { - stringstream sst; - sst << time(NULL); - return sst.str(); - } - - static time_t GetTimeIntervalSince1970AtBeginningOfTodayLocalTime() - { - time_t t = time(NULL); - - #ifdef WIN32 - struct tm tdata; - struct tm* td = &tdata; - if (localtime_s(td, &t)) - return 0; - #else - struct tm* td; - td = localtime(&t); - #endif - - td->tm_hour = 0; - td->tm_min = 0; - td->tm_sec = 0; - - return mktime(td); - } - - static const string LocalTimeString() - { - time_t t = time(NULL); - - #ifdef WIN32 - struct tm tdata; - struct tm* td = &tdata; - if (localtime_s(td, &t)) - return string(); - #else - struct tm* td; - td = localtime(&t); - #endif - - ostringstream sstr; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_hour << ":"; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_min << ":"; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_sec; - return sstr.str(); - } - - static const string LocalDateTimeString() - { - time_t t = time(NULL); - - #ifdef WIN32 - struct tm tdata; - struct tm* td = &tdata; - if (localtime_s(td, &t)) - return string(); - #else - struct tm* td; - td = localtime(&t); - #endif - - ostringstream sstr; - sstr.width(4); - sstr << td->tm_year + 1900 << "-"; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_mon + 1 << "-"; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_mday << " "; - - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_hour << ":"; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_min << ":"; - sstr.width(2); - sstr.fill('0'); - sstr << td->tm_sec; - return sstr.str(); - } - }; - -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVEncodingService.h b/Source/Engine/OpenVanilla/OVEncodingService.h deleted file mode 100644 index 4afd0e4b..00000000 --- a/Source/Engine/OpenVanilla/OVEncodingService.h +++ /dev/null @@ -1,72 +0,0 @@ -// -// OVEncodingService.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVEncodingService_h -#define OVEncodingService_h - -#if defined(__APPLE__) - #include -#else - #include "OVUTF8Helper.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVEncodingService : public OVBase { - public: - virtual bool stringSupportedByEncoding(const string& text, const string& encoding) - { - vector svec = OVUTF8Helper::SplitStringByCodePoint(text); - for (vector::iterator iter = svec.begin() ; iter != svec.end() ; ++iter) - if (!codepointSupportedByEncoding(*iter, encoding)) - return false; - - return true; - } - - virtual bool stringSupportedBySystem(const string& text) - { - vector svec = OVUTF8Helper::SplitStringByCodePoint(text); - for (vector::iterator iter = svec.begin() ; iter != svec.end() ; ++iter) - if (!codepointSupportedBySystem(*iter)) - return false; - - return true; - } - - virtual bool codepointSupportedByEncoding(const string& codepoint, const string& encoding) = 0; - virtual bool codepointSupportedBySystem(const string& codepoint) = 0; - virtual const vector supportedEncodings() = 0; - virtual bool isEncodingSupported(const string& encoding) = 0; - - virtual bool isEncodingConversionSupported(const string& fromEncoding, const string& toEncoding) = 0; - virtual const pair convertEncoding(const string& fromEncoding, const string& toEncoding, const string& text) = 0; - }; -}; - -#endif \ No newline at end of file diff --git a/Source/Engine/OpenVanilla/OVEventHandlingContext.h b/Source/Engine/OpenVanilla/OVEventHandlingContext.h deleted file mode 100644 index 51c12c8b..00000000 --- a/Source/Engine/OpenVanilla/OVEventHandlingContext.h +++ /dev/null @@ -1,102 +0,0 @@ -// -// OVEventHandlingContext.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVEventHandlingContext_h -#define OVEventHandlingContext_h - -#if defined(__APPLE__) - #include - #include - #include - #include - #include - #include -#else - #include "OVBase.h" - #include "OVCandidateService.h" - #include "OVStringHelper.h" - #include "OVTextBuffer.h" - #include "OVKey.h" - #include "OVLoaderService.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVEventHandlingContext : public OVBase { - public: - virtual void startSession(OVLoaderService* loaderService) - { - } - - virtual void stopSession(OVLoaderService* loaderService) - { - } - - virtual void clear(OVLoaderService* loaderService) - { - stopSession(loaderService); - startSession(loaderService); - } - - virtual bool handleKey(OVKey* key, OVTextBuffer* readingText, OVTextBuffer* composingText, OVCandidateService* candidateService, OVLoaderService* loaderService) - { - return false; - } - - virtual bool handleDirectText(const vector& segments, OVTextBuffer* readingText, OVTextBuffer* composingText, OVCandidateService* candidateService, OVLoaderService* loaderService) - { - return handleDirectText(OVStringHelper::Join(segments), readingText, composingText, candidateService, loaderService); - } - - virtual bool handleDirectText(const string&, OVTextBuffer* readingText, OVTextBuffer* composingText, OVCandidateService* candidateService, OVLoaderService* loaderService) - { - return false; - } - - virtual void candidateCanceled(OVCandidateService* candidateService, OVTextBuffer* readingText, OVTextBuffer* composingText, OVLoaderService* loaderService) - { - } - - virtual bool candidateSelected(OVCandidateService* candidateService, const string& text, size_t index, OVTextBuffer* readingText, OVTextBuffer* composingText, OVLoaderService* loaderService) - { - return true; - } - - virtual bool candidateNonPanelKeyReceived(OVCandidateService* candidateService, const OVKey* key, OVTextBuffer* readingText, OVTextBuffer* composingText, OVLoaderService* loaderService) - { - return false; - } - - virtual const string filterText(const string& inputText, OVLoaderService* loaderService) - { - return inputText; - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVException.h b/Source/Engine/OpenVanilla/OVException.h deleted file mode 100644 index 27b9fb73..00000000 --- a/Source/Engine/OpenVanilla/OVException.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// OVException.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVException_h -#define OVException_h - -#if defined(__APPLE__) - #include -#else - #include "OVBase.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVException { - public: - class OverflowException {}; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVFileHelper.h b/Source/Engine/OpenVanilla/OVFileHelper.h deleted file mode 100644 index 3899674a..00000000 --- a/Source/Engine/OpenVanilla/OVFileHelper.h +++ /dev/null @@ -1,627 +0,0 @@ -// -// OVFileHelper.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVFileHelper_h -#define OVFileHelper_h - -#if defined(__APPLE__) - #include - #include -#else - #include - #include - #include -#endif - -#include - -#include -#include -#include -#include "OVWildcard.h" -#include "OVUTF8Helper.h" - -namespace OpenVanilla { - using namespace std; - - class OVFileHelper { - public: - static FILE* OpenStream(const string& filename, const string& mode = "rb") - { - #ifndef WIN32 - return fopen(filename.c_str(), mode.c_str()); - #else - FILE* stream = NULL; - errno_t err = _wfopen_s(&stream, OVUTF16::FromUTF8(filename).c_str(), OVUTF16::FromUTF8(mode).c_str()); - return err ? 0 : stream; - #endif - } - - static void OpenOFStream(ofstream& stream, const string& filename, ios_base::openmode openMode) - { - #ifndef WIN32 - stream.open(filename.c_str(), openMode); - #else - stream.open(OVUTF16::FromUTF8(filename).c_str(), openMode); - #endif - } - - static void OpenIFStream(ifstream& stream, const string& filename, ios_base::openmode openMode) - { - #ifndef WIN32 - stream.open(filename.c_str(), openMode); - #else - stream.open(OVUTF16::FromUTF8(filename).c_str(), openMode); - #endif - } - - // use free(), not delete[], to free the block allocated - static pair SlurpFile(const string& filename, bool addOneByteOfStringTerminationPadding = false) - { - FILE* stream = OpenStream(filename); - char* buf = 0; - size_t size = 0; - if (stream) { - if (!fseek(stream, 0, SEEK_END)) { - long lsize = ftell(stream); - if (lsize) { - size = (size_t)lsize; - if (!fseek(stream, 0, SEEK_SET)) { - buf = (char*)calloc(1, (size_t)size + (addOneByteOfStringTerminationPadding ? 1 : 0)); - if (buf) { - if (fread(buf, size, 1, stream) != 1) { - free(buf); - buf = 0; - size = 0; - } - } - else { - size = 0; - } - } - else { - size = 0; - } - } - } - - fclose(stream); - } - - return pair(buf, size); - } - }; - - class OVFileTimestamp { - public: - #if defined(__APPLE__) - OVFileTimestamp(__darwin_time_t timestamp = 0, long subtimestamp = 0) - #elif defined(WIN32) - OVFileTimestamp(time_t timestamp = 0, time_t subtimestamp = 0) - #else - #error We don't know about Linux yet, sorry. - #endif - : m_timestamp(timestamp) - , m_subtimestamp(subtimestamp) - { - } - - OVFileTimestamp(const OVFileTimestamp& timestamp) - : m_timestamp(timestamp.m_timestamp) - , m_subtimestamp(timestamp.m_subtimestamp) - { - } - - OVFileTimestamp& operator=(const OVFileTimestamp& timestamp) - { - m_timestamp = timestamp.m_timestamp; - m_subtimestamp = timestamp.m_subtimestamp; - return *this; - } - - - bool operator==(OVFileTimestamp& another) - { - return (m_timestamp == another.m_timestamp) && (m_subtimestamp == another.m_subtimestamp); - } - - bool operator!=(OVFileTimestamp& another) - { - return (m_timestamp != another.m_timestamp) || (m_subtimestamp != another.m_subtimestamp); - } - - bool operator<(OVFileTimestamp& another) - { - return (m_timestamp < another.m_timestamp) || ((m_timestamp == another.m_timestamp) && m_subtimestamp < another.m_subtimestamp); - } - - bool operator>(OVFileTimestamp& another) - { - return (m_timestamp > another.m_timestamp) || ((m_timestamp == another.m_timestamp) && m_subtimestamp > another.m_subtimestamp); - } - - - protected: - #if defined(__APPLE__) - __darwin_time_t m_timestamp; - long m_subtimestamp; - #elif defined(WIN32) - time_t m_timestamp; - time_t m_subtimestamp; - #else - #error We don't know about Linux yet, sorry. - #endif - }; - - - class OVPathHelper { - public: - static char Separator() - { - #ifndef WIN32 - return '/'; - #else - return '\\'; - #endif - } - - - static const string DirectoryFromPath(const string& path) - { - string realPath = OVPathHelper::NormalizeByExpandingTilde(path); - if (OVPathHelper::PathExists(realPath) && OVPathHelper::IsDirectory(realPath)) - return realPath; - - char separator = OVPathHelper::Separator(); - - if (!realPath.length()) - return string("."); - - for (size_t index = realPath.length() - 1; index >= 0 ; index--) { - if (realPath[index] == separator) { - if (index) { - // reserve the \\ on Windows - if (realPath[index-1] == '\\') - return realPath.substr(0, index + 1); - else - return realPath.substr(0, index); - } - else - return realPath.substr(0, 1); - } - - // if we run into : (like C:) on Windows - if (realPath[index] == ':') - return realPath.substr(0, index + 1) + Separator(); - - if (!index) break; - } - - return string("."); - } - - static const string FilenameWithoutPath(const string &path) - { - char separator = OVPathHelper::Separator(); - - if (!path.length()) - return string(); - - for (size_t index = path.length() - 1; index >= 0 ; index--) { - if (path[index] == separator) - return path.substr(index + 1, path.length() - (index + 1)); - - if (!index) break; - } - - return path; - } - - static const string FilenameWithoutExtension(const string &path) - { - char separator = OVPathHelper::Separator(); - if (!path.length()) - return string(); - - for (size_t index = path.length() - 1; index >= 0 ; index--) { - if (path[index] == separator) - break; - - if (path[index] == '.') - return path.substr(0, index); - - if (!index) break; - } - - return path; - } - - static const string ChopTrailingSeparator(const string& path) - { - if (path.length() == 1 && path[0] == Separator()) - return path; - - string result; - - if (path.length()) { - if (path[path.length() - 1] == Separator()) - result = path.substr(0, path.length() - 1); - else - result = path; - } - - return result; - } - - static const string ChopLeadingSeparator(const string& path) - { - if (path.length() == 1 && path[0] == Separator()) - return path; - - string result; - if (path.length()) { - if (path[0] == Separator()) { - result = path.substr(1, path.length() - 1); - } - else { - result = path; - } - } - return result; - } - - static const string PathCat(const string& s1, const string& s2) - { - if (s2.length()) - return ChopTrailingSeparator(s1) + Separator() + ChopLeadingSeparator(s2); - else - return s1; - } - - static const string Normalize(const string& path) - { - string newPath; - size_t length = path.length(); - for (size_t index = 0; index < length; index++) { - if (path[index] == '/' || path[index] == '\\') { - if (index < length - 1) { - if (path[index+1] == '/' || path[index+1] == '\\') - index++; - } - - newPath += Separator(); - } - else - newPath += path[index]; - } - - return ChopTrailingSeparator(newPath); - } - - static const bool PathExists(const string& path) - { - #ifndef WIN32 - struct stat buf; - return !stat(path.c_str(), &buf); - #else - struct _stat buf; - wstring wpath = OVUTF16::FromUTF8(path); - return !_wstat(wpath.c_str(), &buf); - #endif - } - - static const bool IsDirectory(const string& path) - { - #ifndef WIN32 - struct stat buf; - if (!stat(path.c_str(), &buf)) - { - if (buf.st_mode & S_IFDIR) - return true; - } - #else - struct _stat buf; - wstring wpath = OVUTF16::FromUTF8(path); - if (!_wstat(wpath.c_str(), &buf)) - { - if (buf.st_mode & S_IFDIR) - return true; - } - #endif - return false; - } - - static const OVFileTimestamp TimestampForPath(const string& path) - { - OVFileTimestamp timestamp; - #if defined(__APPLE__) - struct stat buf; - if (!stat(path.c_str(), &buf)) - { - timestamp = OVFileTimestamp(buf.st_mtimespec.tv_sec, buf.st_mtimespec.tv_nsec); - } - #elif defined(WIN32) - struct _stat buf; - wstring wpath = OVUTF16::FromUTF8(path); - if (!_wstat(wpath.c_str(), &buf)) - { - timestamp = OVFileTimestamp(buf.st_mtime); - } - #else - #error Sorry, no idea for Linux yet. - #endif - return timestamp; - } - - static bool RemoveEverythingAtPath(const string& path); - static const string NormalizeByExpandingTilde(const string& path); - }; - - class OVDirectoryHelper { - public: - static bool MakeDirectory(const string& path) - { - #ifndef WIN32 - return !mkdir(path.c_str(), S_IRWXU); - #else - wstring wpath = OVUTF16::FromUTF8(path); - return CreateDirectoryW(wpath.c_str(), NULL) == TRUE; - #endif - } - - static bool MakeDirectoryWithImmediates(const string& path) - { - string realPath = OVPathHelper::NormalizeByExpandingTilde(path); - - if (OVPathHelper::PathExists(realPath) && OVPathHelper::IsDirectory(realPath)) { - return true; - } - - string lastPart = OVPathHelper::DirectoryFromPath(realPath); - - if (lastPart != realPath && !OVPathHelper::PathExists(lastPart)) { - if (!MakeDirectoryWithImmediates(lastPart)) - return false; - } - - return MakeDirectory(realPath); - } - - static bool CheckDirectory(const string& path) - { - string realPath = OVPathHelper::NormalizeByExpandingTilde(path); - if (OVPathHelper::PathExists(realPath)) - return OVPathHelper::IsDirectory(realPath); - - return MakeDirectoryWithImmediates(realPath); - } - - static const vector Glob(const string& directory, const string& pattern = "*", const string& excludePattern = "", size_t depth = 1) - { - string sanitizedDirectory = OVPathHelper::NormalizeByExpandingTilde(directory); - - OVWildcard expression(pattern); - OVWildcard negativeExpression(excludePattern); - vector dirResult; - vector fileResult; - struct dirent** namelist = NULL; - - #ifndef WIN32 - int count = scandir(sanitizedDirectory.c_str(), &namelist, NULL, NULL); - for (int index = 0; index < count; index++) { - struct dirent* entry = namelist[index]; - bool isDir = entry->d_type == DT_DIR; - string name = entry->d_name; - #else - vector > foundFiles; - WIN32_FIND_DATAW findData; - HANDLE findHandle = FindFirstFileW(OVUTF16::FromUTF8(OVPathHelper::PathCat(sanitizedDirectory, "*.*")).c_str(), &findData); - if (findHandle != INVALID_HANDLE_VALUE) { - foundFiles.push_back(pair(OVUTF8::FromUTF16(findData.cFileName), (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)); - - while (FindNextFileW(findHandle, &findData)) - { - foundFiles.push_back(pair(OVUTF8::FromUTF16(findData.cFileName), (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)); - } - FindClose(findHandle); - } - - size_t count = foundFiles.size(); - for (size_t index = 0; index < count; index++) { - string name = foundFiles[index].first; - bool isDir = foundFiles[index].second; - #endif - - if ((!depth || depth > 1) && isDir && name != "." && name != "..") { - vector subResult = Glob(OVPathHelper::PathCat(sanitizedDirectory, name), pattern, excludePattern, depth ? depth - 1 : 0); - vector::iterator iter = subResult.begin(); - for ( ; iter != subResult.end() ; iter++) - dirResult.push_back(*iter); - } - - if (name != "." && name != ".." && expression.match(name) && !negativeExpression.match(name)) { - fileResult.push_back(OVPathHelper::PathCat(sanitizedDirectory, name)); - } - - #ifndef WIN32 - free(entry); - #endif - } - - #ifndef WIN32 - if (count != -1) - free(namelist); - #endif - - sort(dirResult.begin(), dirResult.end()); - sort(fileResult.begin(), fileResult.end()); - for (vector::iterator iter = dirResult.begin() ; iter != dirResult.end(); iter++) - fileResult.push_back(*iter); - - return fileResult; - } - - static const string TempDirectory() - { - #ifndef WIN32 - return string("/tmp"); - #else - WCHAR path[MAX_PATH + 1]; - GetTempPathW(MAX_PATH, path); - return OVUTF8::FromUTF16(path); - #endif - } - - static const string GenerateTempFilename(const string& prefix = "temp") - { - string pattern = OVPathHelper::PathCat(TempDirectory(), prefix + "-" + "XXXXXXXX"); - #ifndef WIN32 - char *p = (char*)calloc(1, pattern.length() + 1); - strcpy(p, pattern.c_str()); - char *r = mktemp(p); - if (!r) { - free(p); - return string(); - } - string result = r; - free(p); - return result; - #else - wstring wp = OVUTF16::FromUTF8(pattern); - size_t length = wp.length() + 1; - wchar_t* p = (wchar_t*)calloc(1, length * sizeof(wchar_t)); - wcscpy_s(p, length, wp.c_str()); - errno_t err = _wmktemp_s(p, length); - if (err != 0) { - free(p); - return string(); - } - - string result = OVUTF8::FromUTF16(p); - free(p); - return result; - - #endif - } - - static const string UserHomeDirectory() - { - #ifndef WIN32 - const char* homePath = getenv("HOME"); - if (homePath) - return string(homePath); - return TempDirectory(); - #else - WCHAR path[MAX_PATH + 1]; - HRESULT error = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path); - if (!error) { - return OVUTF8::FromUTF16(path); - } - return TempDirectory(); - #endif - } - - static const string UserApplicationDataDirectory(const string& applicationName) - { - #if defined(__APPLE__) - return OVPathHelper::PathCat(UserHomeDirectory(), OVPathHelper::PathCat("/Library/", applicationName)); - #elif defined(WIN32) - WCHAR path[MAX_PATH + 1]; - HRESULT error = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path); - if (!error) { - return OVPathHelper::PathCat(OVUTF8::FromUTF16(path), applicationName); - } - return OVPathHelper::PathCat(TempDirectory(), applicationName); - #else - return OVPathHelper::PathCat(UserHomeDirectory(), string(".") + applicationName); - #endif - } - - static const string UserApplicationSupportDataDirectory(const string& applicationName) - { - #ifdef __APPLE__ - return OVPathHelper::PathCat(UserHomeDirectory(), OVPathHelper::PathCat("/Library/Application Support", applicationName)); - #else - return UserApplicationDataDirectory(applicationName); - #endif - } - - static const string UserPreferencesDirectory(const string& applicationName) - { - #ifdef __APPLE__ - return OVPathHelper::NormalizeByExpandingTilde("~/Library/Preferences"); - #else - return UserApplicationDataDirectory(applicationName); - #endif - } - - }; - - inline const string OVPathHelper::NormalizeByExpandingTilde(const string& path) - { - string newPath = Normalize(path); - - if (newPath.length()) { - if (newPath[0] == '~') { - newPath = OVPathHelper::PathCat(OVDirectoryHelper::UserHomeDirectory(), newPath.substr(1, newPath.length())); - } - } - - return newPath; - } - - inline bool OVPathHelper::RemoveEverythingAtPath(const string& path) - { - if (!PathExists(path)) return false; - - if (IsDirectory(path)) { - vector files = OVDirectoryHelper::Glob(path, "*", "", 0); - vector::iterator iter = files.begin(); - for ( ; iter != files.end(); iter++) { - if (!RemoveEverythingAtPath(*iter)) - return false; - } - - #ifndef WIN32 - return !rmdir(path.c_str()); - #else - wstring wpath = OVUTF16::FromUTF8(path); - return RemoveDirectoryW(wpath.c_str()) == TRUE; - #endif - } - else { - #ifndef WIN32 - return !unlink(path.c_str()); - #else - wstring wpath = OVUTF16::FromUTF8(path); - return DeleteFileW(wpath.c_str()) == TRUE; - #endif - } - } -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVFrameworkInfo.h b/Source/Engine/OpenVanilla/OVFrameworkInfo.h deleted file mode 100644 index 70070635..00000000 --- a/Source/Engine/OpenVanilla/OVFrameworkInfo.h +++ /dev/null @@ -1,92 +0,0 @@ -// -// OVFrameworkInfo.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVFrameworkVersion_h -#define OVFrameworkVersion_h - -#if defined(__APPLE__) - #include -#else - #include "OVBase.h" -#endif - -#include - -namespace OpenVanilla { - using namespace std; - - class OVFrameworkInfo { - public: - static unsigned int MajorVersion() - { - return c_MajorVersion; - } - - static unsigned int MinorVersion() - { - return c_MinorVersion; - } - - static unsigned int TinyVersion() - { - return c_TinyVersion; - } - - static unsigned int Version() - { - return ((c_MajorVersion & 0xff) << 24) | ((c_MinorVersion & 0xff)<< 16) | (c_TinyVersion & 0xffff); - } - - static unsigned int BuildNumber() - { - return c_FrameworkBuildNumber; - } - - static const string VersionString(bool withBuildNumber = false) - { - stringstream s; - s << c_MajorVersion << "." << c_MinorVersion << "." << c_TinyVersion; - if (withBuildNumber) - s << "." << c_FrameworkBuildNumber; - - return s.str(); - } - - static const string VersionStringWithBuildNumber() - { - return VersionString(true); - } - - protected: - static const unsigned int c_MajorVersion; - static const unsigned int c_MinorVersion; - static const unsigned int c_TinyVersion; - static const unsigned int c_FrameworkBuildNumber; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVInputMethod.h b/Source/Engine/OpenVanilla/OVInputMethod.h deleted file mode 100644 index 0f4c68e6..00000000 --- a/Source/Engine/OpenVanilla/OVInputMethod.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// OVInputMethod.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVInputMethod_h -#define OVInputMethod_h - -#if defined(__APPLE__) - #include -#else - #include "OVModule.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVInputMethod : public OVModule { - public: - virtual bool isInputMethod() const - { - return true; - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVKey.h b/Source/Engine/OpenVanilla/OVKey.h deleted file mode 100644 index 22234470..00000000 --- a/Source/Engine/OpenVanilla/OVKey.h +++ /dev/null @@ -1,303 +0,0 @@ -// -// OVKey.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu and Weizhong Yang -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVKey_h -#define OVKey_h - -namespace OpenVanilla { - using namespace std; - - // keyCode() is 0 if receivedString() is a non-ASCII glyph/string - class OVKeyInterface : public OVBase { - public: - virtual const string receivedString() const = 0; - virtual unsigned int keyCode() const = 0; - virtual bool isAltPressed() const = 0; - virtual bool isOptPressed() const = 0; - virtual bool isCtrlPressed() const = 0; - virtual bool isShiftPressed() const = 0; - virtual bool isCommandPressed() const = 0; - virtual bool isNumLockOn() const = 0; - virtual bool isCapsLockOn() const = 0; - - // a direct text key carries a composed glyph (or a string) that semantically differs from the intended keystroke - // (i.e. a half-width char stroke but with a composed, full-width char output) - virtual bool isDirectTextKey() const = 0; - }; - - class OVKeyImpl : public OVKeyInterface { - public: - virtual bool shouldDelete() const = 0; - virtual OVKeyImpl* copy() = 0; - }; - - class OVKey : public OVKeyInterface { - public: - OVKey(OVKeyImpl* keyImpl = 0) - : m_keyImpl(keyImpl) - { - } - - OVKey(const OVKey& aKey) - { - m_keyImpl = aKey.m_keyImpl ? aKey.m_keyImpl->copy() : 0; - } - - ~OVKey() - { - if (m_keyImpl) { - if (m_keyImpl->shouldDelete()) { - delete m_keyImpl; - } - } - } - - OVKey& operator=(const OVKey& aKey) - { - if (m_keyImpl) { - if (m_keyImpl->shouldDelete()) { - delete m_keyImpl; - } - - m_keyImpl = 0; - } - - m_keyImpl = aKey.m_keyImpl ? aKey.m_keyImpl->copy() : 0; - return *this; - } - - virtual bool operator==(const OVKey& key) const - { - if (isAltPressed() == key.isAltPressed() && isOptPressed() == key.isOptPressed() && isCtrlPressed() == key.isCtrlPressed() && isShiftPressed() == key.isShiftPressed() && isCommandPressed() == key.isCommandPressed()) - if (!keyCode() && !key.keyCode()) - return receivedString() == key.receivedString(); - else - return keyCode() == key.keyCode(); - - return false; - } - - virtual bool operator<(const OVKey& key) const - { - if (keyCode() < key.keyCode()) return true; - if (keyCode() > key.keyCode()) return false; - - if (!keyCode() && !key.keyCode()) { - if (receivedString() < key.receivedString()) return true; - if (receivedString() > key.receivedString()) return false; - } - - if (isAltPressed() != key.isAltPressed()) { - if (key.isAltPressed()) return true; - if (isAltPressed()) return false; - } - - if (isOptPressed() != key.isOptPressed()) { - if (key.isOptPressed()) return true; - if (isOptPressed()) return false; - } - - if (isCtrlPressed() != key.isCtrlPressed()) { - if (key.isCtrlPressed()) return true; - if (isCtrlPressed()) return false; - } - - if (isShiftPressed() != key.isShiftPressed()) { - if (key.isShiftPressed()) return true; - if (isShiftPressed()) return false; - } - - if (isCommandPressed() != key.isCommandPressed()) { - if (key.isCommandPressed()) return true; - if (isCommandPressed()) return false; - } - - if (isNumLockOn() != key.isNumLockOn()) { - if (key.isNumLockOn()) return true; - if (isNumLockOn()) return false; - } - - if (isCapsLockOn() != key.isCapsLockOn()) { - if (key.isCapsLockOn()) return true; - if (isCapsLockOn()) return false; - } - - return false; - } - - public: - virtual const string receivedString() const - { - return m_keyImpl ? m_keyImpl->receivedString() : string(); - } - - virtual unsigned int keyCode() const - { - return m_keyImpl ? m_keyImpl->keyCode() : 0; - } - - virtual bool isAltPressed() const - { - return m_keyImpl ? m_keyImpl->isAltPressed() : false; - } - - virtual bool isOptPressed() const - { - return m_keyImpl ? m_keyImpl->isOptPressed() : false; - } - - virtual bool isCtrlPressed() const - { - return m_keyImpl ? m_keyImpl->isCtrlPressed() : false; - } - - virtual bool isShiftPressed() const - { - return m_keyImpl ? m_keyImpl->isShiftPressed() : false; - } - - virtual bool isCommandPressed() const - { - return m_keyImpl ? m_keyImpl->isCommandPressed() : false; - } - - virtual bool isNumLockOn() const - { - return m_keyImpl ? m_keyImpl->isNumLockOn() : false; - } - - virtual bool isCapsLockOn() const - { - return m_keyImpl ? m_keyImpl->isCapsLockOn() : false; - } - - virtual bool isDirectTextKey() const - { - return m_keyImpl ? m_keyImpl->isDirectTextKey() : false; - } - - virtual bool isKeyCodePrintable() const - { - if (keyCode() >= 32 && keyCode() <= 126) - return true; - - return false; - } - - virtual bool isKeyCodeNumeric() const - { - if (keyCode() >= '0' && keyCode() <= '9') - return true; - - return false; - } - - virtual bool isKeyCodeAlpha() const - { - if (keyCode() >= 'A' && keyCode() <= 'Z' || keyCode() >= 'a' && keyCode() <= 'z') - return true; - - return false; - } - - virtual bool isCombinedFunctionKey() const - { - return isCtrlPressed() || isAltPressed() || isOptPressed() || isCommandPressed(); - } - - virtual bool isPrintable() const - { - size_t rssize = receivedString().size(); - unsigned int code = keyCode(); - - if (!rssize) - return false; - - if (rssize > 1) - return true; - - return ((code < 128 && isprint((char)code)) || code > 128); - } - - protected: - OVKeyImpl* m_keyImpl; - }; - - typedef vector OVKeyVector; - - class OVKeyCode { - public: - enum { - Delete = 127, - Backspace = 8, - Up = 30, - Down = 31, - Left = 28, - Right = 29, - Home = 1, - End = 4, - PageUp = 11, - PageDown = 12, - Tab = 9, - Esc = 27, - Space = 32, - Return = 13, - Enter = Return, - LeftShift = 0x10001, - RightShift = 0x10002, - CapsLock = 0x10010, - MacEnter = 0x10020, - F1 = 0x11001, - F2 = 0x11002, - F3 = 0x11003, - F4 = 0x11004, - F5 = 0x11005, - F6 = 0x11006, - F7 = 0x11007, - F8 = 0x11008, - F9 = 0x11009, - F10 = 0x11010, - }; - }; - - class OVKeyMask { - public: - enum { - Alt = 0x0001, - Opt = 0x0002, - AltOpt = 0x0003, - Ctrl = 0x0004, - Shift = 0x008, - Command = 0x0010, - NumLock = 0x0020, - CapsLock = 0x0040, - DirectText = 0x0080 - }; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVKeyPreprocessor.h b/Source/Engine/OpenVanilla/OVKeyPreprocessor.h deleted file mode 100644 index e82e3d2c..00000000 --- a/Source/Engine/OpenVanilla/OVKeyPreprocessor.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// OVKeyPreprocessor.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVKeyPreprocessor_h -#define OVKeyPreprocessor_h - -#if defined(__APPLE__) - #include -#else - #include "OVModule.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVKeyPreprocessor : public OVModule { - public: - virtual bool isPreprocessor() const - { - return true; - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVKeyValueMap.h b/Source/Engine/OpenVanilla/OVKeyValueMap.h deleted file mode 100644 index 2d18f220..00000000 --- a/Source/Engine/OpenVanilla/OVKeyValueMap.h +++ /dev/null @@ -1,175 +0,0 @@ -// -// OVKeyValueMap.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVKeyValueMap_h -#define OVKeyValueMap_h - -#if defined(__APPLE__) - #include -#else - #include "OVBase.h" -#endif - -#include - -namespace OpenVanilla { - using namespace std; - - class OVKeyValueMapInterface : public OVBase { - public: - virtual bool isReadOnly() = 0; - virtual bool setKeyStringValue(const string& key, const string& value) = 0; - virtual bool hasKey(const string& key) = 0; - virtual const string stringValueForKey(const string& key) = 0; - - virtual bool setKeyIntValue(const string& key, int value) - { - stringstream sstr; - sstr << value; - return setKeyStringValue(key, sstr.str()); - } - - virtual bool setKeyBoolValue(const string& key, bool value) - { - if (value) - return setKeyStringValue(key, "true"); - - return setKeyStringValue(key, "false"); - } - - virtual int intValueForKey(const string& key) - { - string value = stringValueForKey(key); - return atoi(value.c_str()); - } - - virtual const string stringValueForKeyWithDefault(const string& key, const string& defaultValue = "", bool setIfNotFound = true) - { - if (hasKey(key)) - return stringValueForKey(key); - - if (setIfNotFound) - setKeyStringValue(key, defaultValue); - - return defaultValue; - } - - virtual const string operator[](const string& key) - { - return stringValueForKey(key); - } - - virtual bool isKeyTrue(const string& key) - { - if (!hasKey(key)) - return false; - - string value = stringValueForKey(key); - - if (atoi(value.c_str()) > 0) - return true; - - if (value == "true") - return true; - - return false; - } - }; - - class OVKeyValueMapImpl : public OVKeyValueMapInterface { - public: - virtual bool shouldDelete() = 0; - virtual OVKeyValueMapImpl* copy() = 0; - }; - - class OVKeyValueMap : public OVKeyValueMapInterface { - public: - OVKeyValueMap(OVKeyValueMapImpl* keyValueMapImpl = 0) - : m_keyValueMapImpl(keyValueMapImpl) - { - } - - OVKeyValueMap(const OVKeyValueMap& aKeyValueMap) - { - m_keyValueMapImpl = aKeyValueMap.m_keyValueMapImpl ? aKeyValueMap.m_keyValueMapImpl->copy() : 0; - } - - ~OVKeyValueMap() - { - if (m_keyValueMapImpl) { - if (m_keyValueMapImpl->shouldDelete()) { - delete m_keyValueMapImpl; - } - } - } - - OVKeyValueMap& operator=(const OVKeyValueMap& aKeyValueMap) - { - if (m_keyValueMapImpl) { - if (m_keyValueMapImpl->shouldDelete()) { - delete m_keyValueMapImpl; - } - - m_keyValueMapImpl = 0; - } - - m_keyValueMapImpl = aKeyValueMap.m_keyValueMapImpl ? aKeyValueMap.m_keyValueMapImpl->copy() : 0; - return *this; - } - - public: - virtual bool isReadOnly() - { - return m_keyValueMapImpl ? m_keyValueMapImpl->isReadOnly() : true; - } - - virtual bool setKeyStringValue(const string& key, const string& value) - { - return m_keyValueMapImpl ? m_keyValueMapImpl->setKeyStringValue(key, value) : false; - } - - virtual bool hasKey(const string& key) - { - return m_keyValueMapImpl ? m_keyValueMapImpl->hasKey(key) : false; - } - - virtual const string stringValueForKey(const string& key) - { - return m_keyValueMapImpl ? m_keyValueMapImpl->stringValueForKey(key) : string(); - } - - virtual const string stringValueForKeyWithDefault(const string& key, const string& defaultValue = "", bool setIfNotFound = true) - { - return m_keyValueMapImpl ? m_keyValueMapImpl->stringValueForKeyWithDefault(key, defaultValue, setIfNotFound) : string(); - } - - protected: - OVKeyValueMapImpl* m_keyValueMapImpl; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVLoaderBase.h b/Source/Engine/OpenVanilla/OVLoaderBase.h deleted file mode 100644 index fdaef0a0..00000000 --- a/Source/Engine/OpenVanilla/OVLoaderBase.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// OVLoaderBase.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVLoaderBase_h -#define OVLoaderBase_h - -#if defined(__APPLE__) - #include -#else - #include "OVModule.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVLoader : public OVBase { - public: - virtual OVLoaderService* loaderService() = 0; - virtual OVModule* moduleForIdentifier(const string& identifier) = 0; - virtual vector moduleIdentifiers() = 0; - virtual vector moduleIdentifiersForConditions(bool preprocessor, bool inputMethod, bool outputFilter) = 0; - }; - -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVLoaderService.h b/Source/Engine/OpenVanilla/OVLoaderService.h deleted file mode 100644 index c0994e0a..00000000 --- a/Source/Engine/OpenVanilla/OVLoaderService.h +++ /dev/null @@ -1,120 +0,0 @@ -// -// OVLoaderService.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVLoaderService_h -#define OVLoaderService_h - -#if defined(__APPLE__) - #include - #include - #include - #include -#else - #include "OVBase.h" - #include "OVDatabaseService.h" - #include "OVEncodingService.h" - #include "OVKey.h" -#endif - -#include -#include - -namespace OpenVanilla { - using namespace std; - - class OVLogEmitter : public OVBase { - public: - virtual const string sectionName() const = 0; - virtual void setSectionName(const string& sectionName) = 0; - virtual void emitLog(const string& logEntry) = 0; - }; - - class OVLogStringBuffer : public stringbuf { - public: - OVLogStringBuffer(OVLogEmitter* logEmitter = 0) - : m_logEmitter(logEmitter) - { - } - - virtual int sync() { - if (str().length()) { - if (m_logEmitter) - m_logEmitter->emitLog(str()); - else - cerr << "Log: " << str(); - - str(string()); - } - - // clear the buffer - return 0; - } - - virtual OVLogEmitter* logEmitter() const - { - return m_logEmitter; - } - - virtual void setLogEmitter(OVLogEmitter* logEmitter) - { - m_logEmitter = logEmitter; - } - - protected: - OVLogEmitter* m_logEmitter; - }; - - class OVLoaderService : public OVBase { - public: - virtual void beep() = 0; - virtual void notify(const string& message) = 0; - virtual void HTMLNotify(const string& content) = 0; - - virtual const string locale() const = 0; - virtual const OVKey makeOVKey(int characterCode, bool alt = false, bool opt = false, bool ctrl = false, bool shift = false, bool command = false, bool capsLock = false, bool numLock = false) = 0; - virtual const OVKey makeOVKey(const string& receivedString, bool alt = false, bool opt = false, bool ctrl = false, bool shift = false, bool command = false, bool capsLock = false, bool numLock = false) = 0; - - virtual ostream& logger(const string& sectionName = "") = 0; - - virtual OVDatabaseService* defaultDatabaseService() = 0; - virtual OVDatabaseService* CINDatabaseService() = 0; - virtual OVDatabaseService* SQLiteDatabaseService() = 0; - - virtual OVEncodingService* encodingService() = 0; - - virtual void __reserved1(const string&) = 0; - virtual void __reserved2(const string&) = 0; - virtual void __reserved3(const string&) = 0; - virtual void __reserved4(const string&) = 0; - virtual const string __reserved5() const = 0; - virtual void __reserved6(const string&) = 0; - virtual void __reserved7(const string&, const string &) = 0; - virtual void* __reserved8(const string&) = 0; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVLocalization.h b/Source/Engine/OpenVanilla/OVLocalization.h deleted file mode 100644 index e02bb08d..00000000 --- a/Source/Engine/OpenVanilla/OVLocalization.h +++ /dev/null @@ -1,136 +0,0 @@ -// -// OVLocalization.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVLocalization_h -#define OVLocalization_h - -#include -#include -#include "OVStringHelper.h" -#include "OVWildcard.h" - -namespace OpenVanilla { - using namespace std; - - class OVLocale { - public: - static const string POSIXLocaleID(const string& locale) - { - string n = OVStringHelper::StringByReplacingOccurrencesOfStringWithString(locale, "-", "_"); - - if (OVWildcard::Match(n, "zh_Hant")) { - return "zh_TW"; - } - - if (OVWildcard::Match(n, "zh_Hans")) { - return "zh_CN"; - } - - if (OVWildcard::Match(n, "zh_HK")) { - return "zh_TW"; - } - - if (OVWildcard::Match(n, "zh_SG")) { - return "zh_CN"; - } - - if (OVWildcard::Match(n, "en_*")) { - return "en"; - } - - return locale; - } - }; - - - template class OVLocalization { - public: - static const void SetDefaultLocale(const string& locale) - { - SharedInstance()->m_defaultLocale = locale.length() ? OVLocale::POSIXLocaleID(locale) : string("en"); - } - - static const string S(const string& locale, const string& text) - { - return SharedInstance()->m_table(locale, text); - } - - static const string S(const string& text) - { - return SharedInstance()->m_table(SharedInstance()->m_defaultLocale, text); - } - - protected: - static OVLocalization* SharedInstance() - { - static OVLocalization* instance = 0; - if (!instance) { - instance = new OVLocalization; - } - - return instance; - } - - OVLocalization() - : m_defaultLocale("en") - { - } - - T m_table; - string m_defaultLocale; - }; - - class OVLocalizationStringTable { - public: - const string operator()(const string& locale, const string& text) const - { - // maybe we'll have fallback logic later here - map >::const_iterator i = m_table.find(locale); - if (i == m_table.end()) { - return text; - } - - map::const_iterator j = (*i).second.find(text); - if (j == (*i).second.end()) { - return text; - } - - return (*j).second; - } - - - protected: - void add(const string& locale, const string& original, const string& localized) - { - m_table[locale][original] = localized; - } - - map > m_table; - }; -}; - -#endif \ No newline at end of file diff --git a/Source/Engine/OpenVanilla/OVModule.h b/Source/Engine/OpenVanilla/OVModule.h deleted file mode 100644 index 4694aee9..00000000 --- a/Source/Engine/OpenVanilla/OVModule.h +++ /dev/null @@ -1,146 +0,0 @@ -// -// OVModule.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVModule_h -#define OVModule_h - -#if defined(__APPLE__) - #include - #include - #include -#else - #include "OVEventHandlingContext.h" - #include "OVKeyValueMap.h" - #include "OVPathInfo.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVModule : public OVBase { - public: - OVModule() - : m_initialized(false) - , m_usable(false) - { - } - - virtual bool isInitialized() const - { - return m_initialized; - } - - virtual bool isUsable() const - { - return m_usable; - } - - virtual bool isPreprocessor() const - { - return false; - } - - virtual bool isInputMethod() const - { - return false; - } - - virtual bool isOutputFilter() const - { - return false; - } - - virtual bool isAroundFilter() const - { - return false; - } - - // the smaller it gets, the closer the the filter gets to the commit event - virtual int suggestedOrder() const - { - return 0; - } - - virtual OVEventHandlingContext* createContext() - { - return 0; - } - - virtual const string identifier() const = 0; - - virtual const string localizedName(const string& locale) - { - return identifier(); - - } - - virtual bool moduleInitialize(OVPathInfo* pathInfo, OVLoaderService* loaderService) - { - if (m_initialized) - return false; - - m_usable = initialize(pathInfo, loaderService); - m_initialized = true; - return m_usable; - } - - virtual bool initialize(OVPathInfo* pathInfo, OVLoaderService* loaderService) - { - return true; - } - - virtual void finalize() - { - } - - virtual void loadConfig(OVKeyValueMap* moduleConfig, OVLoaderService* loaderService) - { - } - - virtual void saveConfig(OVKeyValueMap* moduleConfig, OVLoaderService* loaderService) - { - } - - enum AroundFilterDisplayOption { - ShownAsPreprocessor, - ShownAsOutputFilter, - ShownAsBoth - }; - - // around filter modules need to tell loader how it wishes to be placed in the menu - virtual AroundFilterDisplayOption aroundFilterPreferredDisplayOption() - { - return ShownAsBoth; - } - - protected: - bool m_initialized; - bool m_usable; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVModulePackage.h b/Source/Engine/OpenVanilla/OVModulePackage.h deleted file mode 100644 index 21c98080..00000000 --- a/Source/Engine/OpenVanilla/OVModulePackage.h +++ /dev/null @@ -1,100 +0,0 @@ -// -// OVModulePackage.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVModulePackage_h -#define OVModulePackage_h - -#if defined(__APPLE__) - #include - #include -#else - #include "OVFrameworkInfo.h" - #include "OVModule.h" -#endif - -#ifdef WIN32 - #define OVEXPORT __declspec(dllexport) -#else - #define OVEXPORT -#endif - -namespace OpenVanilla { - using namespace std; - - class OVModuleClassWrapperBase : public OVBase { - public: - virtual OVModule* newModule() - { - // this member function can't be abstract, or vector wouldn't instantiate under VC++ 2005 - return 0; - } - }; - - template class OVModuleClassWrapper : public OVModuleClassWrapperBase { - public: - virtual OVModule* newModule() - { - return new T; - } - }; - - // we encourage people to do the real initialization in initialize - class OVModulePackage : OVBase { - public: - ~OVModulePackage() - { - vector::iterator iter = m_moduleVector.begin(); - for ( ; iter != m_moduleVector.end(); ++iter) - delete *iter; - } - virtual bool initialize(OVPathInfo* , OVLoaderService* loaderService) - { - // in your derived class, add class wrappers to m_moduleVector - return true; - } - - virtual void finalize() - { - } - - virtual size_t numberOfModules(OVLoaderService*) - { - return m_moduleVector.size(); - } - - virtual OVModule* moduleAtIndex(size_t index, OVLoaderService*) - { - if (index > m_moduleVector.size()) return 0; - return m_moduleVector[index]->newModule(); - } - - protected: - vector m_moduleVector; - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVOutputFilter.h b/Source/Engine/OpenVanilla/OVOutputFilter.h deleted file mode 100644 index 5477b9dc..00000000 --- a/Source/Engine/OpenVanilla/OVOutputFilter.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// OVOutputFilter.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVOutputFilter_h -#define OVOutputFilter_h - -#if defined(__APPLE__) - #include -#else - #include "OVModule.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVOutputFilter : public OVModule { - public: - virtual bool isOutputFilter() const - { - return true; - } - }; -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVPathInfo.h b/Source/Engine/OpenVanilla/OVPathInfo.h deleted file mode 100644 index 70eab573..00000000 --- a/Source/Engine/OpenVanilla/OVPathInfo.h +++ /dev/null @@ -1,63 +0,0 @@ -// -// OVPathInfo.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVPathInfo_h -#define OVPathInfo_h - -#if defined(__APPLE__) - #include -#else - #include "OVFileHelper.h" -#endif - -namespace OpenVanilla { - using namespace std; - - struct OVPathInfo { - string loadedPath; - string resourcePath; - string writablePath; - - static const OVPathInfo DefaultPathInfo() { - string tmpdir = OVDirectoryHelper::TempDirectory(); - OVPathInfo pathInfo; - - pathInfo.loadedPath = tmpdir; - pathInfo.resourcePath = tmpdir; - pathInfo.writablePath = tmpdir; - return pathInfo; - } - }; - - inline ostream& operator<<(ostream& stream, const OVPathInfo& info) - { - stream << "OVPathInfo = (loaded path = " << info.loadedPath << ", resource path = " << info.resourcePath << ", writable path = " << info.writablePath << ")"; - return stream; - } -}; - -#endif diff --git a/Source/Engine/OpenVanilla/OVSQLiteDatabaseService.h b/Source/Engine/OpenVanilla/OVSQLiteDatabaseService.h deleted file mode 100644 index a5b2333c..00000000 --- a/Source/Engine/OpenVanilla/OVSQLiteDatabaseService.h +++ /dev/null @@ -1,249 +0,0 @@ -// -// OVSQLiteDatabaseService.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVSQLiteDatabaseService_h -#define OVSQLiteDatabaseService_h - -#if defined(__APPLE__) - #include - #include - #include -#else - #include "OVDatabaseService.h" - #include "OVSQLiteWrapper.h" - #include "OVWildcard.h" -#endif - -namespace OpenVanilla { - using namespace std; - - class OVSQLiteHelper { - public: - static const pair SQLiteStringFromWildcard(const OVWildcard& wildcard) - { - const string& expression = wildcard.expression(); - string sqlstr; - - char mOC = wildcard.matchOneChar(); - char mZOMC = wildcard.matchZeroOrMoreChar(); - char escChar = mZOMC ? mZOMC : mOC; - - for (string::const_iterator iter = expression.begin() ; iter != expression.end() ; ++iter) { - if (*iter == mOC) { - sqlstr += '_'; - } - else if (*iter == mZOMC) { - sqlstr += '%'; - } - else if (*iter == '_') { - sqlstr += escChar; - sqlstr += '_'; - } - else if (*iter == '%') { - sqlstr += escChar; - sqlstr += '%'; - } - else { - sqlstr += *iter; - } - } - - return pair(sqlstr, string(1, escChar)); - } - }; - - class OVSQLiteDatabaseService; - - class OVSQLiteKeyValueDataTable : public OVKeyValueDataTableInterface { - public: - virtual const vector valuesForKey(const string& key); - virtual const vector > valuesForKey(const OVWildcard& expression); - virtual const string valueForProperty(const string& property); - virtual const vector keysForValue(const string& value); - - protected: - OVSQLiteDatabaseService* m_source; - string m_tableName; - - friend class OVSQLiteDatabaseService; - OVSQLiteKeyValueDataTable(OVSQLiteDatabaseService* source, const string& tableName) - : m_source(source) - , m_tableName(tableName) - { - } - }; - - class OVSQLiteDatabaseService : public OVDatabaseService { - public: - ~OVSQLiteDatabaseService() - { - if (m_ownsConnection) - delete m_connection; - } - - virtual const vector tables(const OVWildcard& filter = string("*")) - { - pair exp = OVSQLiteHelper::SQLiteStringFromWildcard(filter); - - vector result; - OVSQLiteStatement* statement = m_connection->prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE %Q ESCAPE %Q ORDER BY name", exp.first.c_str(), exp.second.c_str()); - if (statement) { - while (statement->step() == SQLITE_ROW) { - result.push_back(statement->textOfColumn(0)); - } - - delete statement; - } - - return result; - } - - virtual bool tableSupportsValueToKeyLookup(const string &tableName) - { - return true; - } - - virtual OVKeyValueDataTableInterface* createKeyValueDataTableInterface(const string& name, bool suggestedCaseSensitivity = false) - { - return new OVSQLiteKeyValueDataTable(this, name); - } - - virtual const string valueForPropertyInTable(const string& property, const string& name) - { - OVSQLiteStatement* statement = m_connection->prepare("SELECT VALUE FROM %Q WHERE KEY = ?", name.c_str()); - string result; - - if (statement) { - statement->bindTextToColumn(string(OVPropertyStringInternalPrefix) + property, 1); - - if (statement->step() == SQLITE_ROW) { - result = statement->textOfColumn(0); - while (statement->step() == SQLITE_ROW) ; - } - - delete statement; - } - - return result; - } - - virtual const string filename() - { - return m_connection->filename(); - } - - static OVSQLiteDatabaseService* Create(const string& filename = ":memory:") - { - OVSQLiteConnection* connection = OVSQLiteConnection::Open(filename); - if (!connection) - return 0; - - return new OVSQLiteDatabaseService(connection, true); - } - - static OVSQLiteDatabaseService* ServiceWithExistingConnection(OVSQLiteConnection* connection, bool ownsConnection = false) - { - return new OVSQLiteDatabaseService(connection, ownsConnection); - } - - OVSQLiteConnection* connection() - { - return m_connection; - } - - protected: - friend class OVSQLiteKeyValueDataTable; - - OVSQLiteDatabaseService(OVSQLiteConnection* connection, bool ownsConnection = false) - : m_connection(connection) - , m_ownsConnection(ownsConnection) - { - } - - OVSQLiteConnection* m_connection; - bool m_ownsConnection; - }; - - inline const vector OVSQLiteKeyValueDataTable::valuesForKey(const string& key) - { - vector result; - OVSQLiteStatement* statement = m_source->connection()->prepare("SELECT value FROM %Q WHERE key = %Q", m_tableName.c_str(), key.c_str()); - if (statement) { - while (statement->step() == SQLITE_ROW) { - result.push_back(statement->textOfColumn(0)); - } - - delete statement; - } - - return result; - } - - inline const vector OVSQLiteKeyValueDataTable::keysForValue(const string& value) - { - vector result; - OVSQLiteStatement* statement = m_source->connection()->prepare("SELECT key FROM %Q WHERE value = %Q", m_tableName.c_str(), value.c_str()); - if (statement) { - while (statement->step() == SQLITE_ROW) { - string key = statement->textOfColumn(0); - - // we don't want property get into it - if (!OVWildcard::Match(key, OVPropertyStringInternalPrefix "*")) { - result.push_back(key); - } - } - - delete statement; - } - - return result; - } - - inline const vector > OVSQLiteKeyValueDataTable::valuesForKey(const OVWildcard& expression) - { - pair exp = OVSQLiteHelper::SQLiteStringFromWildcard(expression); - - vector > result; - OVSQLiteStatement* statement = m_source->connection()->prepare("SELECT key, value FROM %Q WHERE key like %Q escape %Q", m_tableName.c_str(), exp.first.c_str(), exp.second.c_str()); - if (statement) { - while (statement->step() == SQLITE_ROW) { - result.push_back(pair(statement->textOfColumn(0), statement->textOfColumn(1))); - } - - delete statement; - } - - return result; - } - - inline const string OVSQLiteKeyValueDataTable::valueForProperty(const string& property) - { - return m_source->valueForPropertyInTable(property, m_tableName); - } -}; - -#endif \ No newline at end of file diff --git a/Source/Engine/OpenVanilla/OVSQLiteWrapper.h b/Source/Engine/OpenVanilla/OVSQLiteWrapper.h deleted file mode 100644 index 1e056f92..00000000 --- a/Source/Engine/OpenVanilla/OVSQLiteWrapper.h +++ /dev/null @@ -1,278 +0,0 @@ -// -// OVSQLiteWrapper.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVSQLite3Wrapper -#define OVSQLite3Wrapper - -#include - -#if defined(__APPLE__) - #include -#else - #include "OpenVanilla.h" -#endif - -// For status codes (SQLITE_OK, SQLITE_ERROR, etc.), please refer to sqlite3.h - -namespace OpenVanilla { - using namespace std; - - class OVSQLiteStatement; - - class OVSQLiteConnection { - public: - // remember to manage the object returned by this class member function - static OVSQLiteConnection* Open(const string& filename = ":memory:"); - ~OVSQLiteConnection(); - - int lastError(); - const char* lastErrorMessage(); - - int execute(const char* sqlcmd, ...); - OVSQLiteStatement* prepare(const char* sqlcmd, ...); - - // helper for table creation and detection - bool hasTable(const string& tableName); - bool dropTable(const string& tableName); - bool createTable(const string& tableName, const string& columnString = "key, value", bool dropIfExists = false); - bool createIndexOnTable(const string& indexName, const string& tableName, const string& indexColumns = "key"); - - sqlite3* connection(); - const string filename(); - - protected: - sqlite3* m_connection; - string m_filename; - OVSQLiteConnection(sqlite3* connection, const string& filename); - }; - - class OVSQLiteStatement { - public: - ~OVSQLiteStatement(); - - int reset(); - - // *nota bene* column starts from 1 ! - int bindTextToColumn(const char*str, int column); - int bindTextToColumn(const string& str, int column); - int bindIntToColumn(int value, int column); - int bindDoubleToColumn(double value, int column); - - int step(); - int columnCount(); - const char* textOfColumn(int column); - int intOfColumn(int column); - double doubleOfColumn(int column); - - protected: - sqlite3_stmt* m_statement; - - friend class OVSQLiteConnection; - OVSQLiteStatement(sqlite3_stmt* statement); - }; - - inline sqlite3* OVSQLiteConnection::connection() - { - return m_connection; - } - - inline OVSQLiteConnection* OVSQLiteConnection::Open(const string& filename) - { - sqlite3* connection; - - if (sqlite3_open(filename.c_str(), &connection) != SQLITE_OK) - return 0; - - if (!connection) - return 0; - - return new OVSQLiteConnection(connection, filename); - } - - inline OVSQLiteConnection::OVSQLiteConnection(sqlite3* connection, const string& filename) - : m_connection(connection) - , m_filename(filename) - { - } - - inline OVSQLiteConnection::~OVSQLiteConnection() - { - - int result = sqlite3_close(m_connection); - if (result) { - ; - } - } - - inline const string OVSQLiteConnection::filename() - { - return m_filename; - } - - inline int OVSQLiteConnection::lastError() - { - return sqlite3_errcode(m_connection); - } - - inline const char* OVSQLiteConnection::lastErrorMessage() - { - return sqlite3_errmsg(m_connection); - } - - inline int OVSQLiteConnection::execute(const char* sqlcmd, ...) - { - va_list l; - va_start(l, sqlcmd); - char* cmd = sqlite3_vmprintf(sqlcmd, l); - va_end(l); - int result = sqlite3_exec(m_connection, cmd, NULL, NULL, NULL); - sqlite3_free(cmd); - return result; - } - - inline OVSQLiteStatement* OVSQLiteConnection::prepare(const char* sqlcmd, ...) - { - va_list l; - va_start(l, sqlcmd); - char* cmd = sqlite3_vmprintf(sqlcmd, l); - va_end(l); - - sqlite3_stmt* stmt; - OVSQLiteStatement* result = 0; - - const char* remainingSt = 0; - if (sqlite3_prepare_v2(m_connection, cmd, -1, &stmt, &remainingSt) == SQLITE_OK) - result = new OVSQLiteStatement(stmt); - sqlite3_free(cmd); - - return result; - } - - inline bool OVSQLiteConnection::hasTable(const string& tableName) - { - bool result = false; - OVSQLiteStatement* statement = prepare("SELECT name FROM sqlite_master WHERE name = %Q", tableName.c_str()); - if (statement) { - if (statement->step() == SQLITE_ROW) { - result = true; - while (statement->step() == SQLITE_ROW) ; - } - - delete statement; - } - - return result; - } - - inline bool OVSQLiteConnection::dropTable(const string& tableName) - { - return SQLITE_OK == execute("DROP TABLE %Q", tableName.c_str()); - } - - inline bool OVSQLiteConnection::createTable(const string& tableName, const string& columnString, bool dropIfExists) - { - if (hasTable(tableName)) { - if (dropIfExists) { - if (!dropTable(tableName)) - return false; - } - else { - return false; - } - } - - - return SQLITE_OK == execute("CREATE TABLE %Q (%s)", tableName.c_str(), columnString.c_str()); - } - - inline bool OVSQLiteConnection::createIndexOnTable(const string& indexName, const string& tableName, const string& indexColumns) - { - return SQLITE_OK == execute("CREATE INDEX %Q on %Q (%s)", indexName.c_str(), tableName.c_str(), indexColumns.c_str()); - } - - inline OVSQLiteStatement::OVSQLiteStatement(sqlite3_stmt* statement) - : m_statement(statement) - { - } - - inline OVSQLiteStatement::~OVSQLiteStatement() - { - sqlite3_finalize(m_statement); - } - - inline int OVSQLiteStatement::reset() - { - return sqlite3_reset(m_statement); - } - - inline int OVSQLiteStatement::bindTextToColumn(const char* str, int column) - { - return sqlite3_bind_text(m_statement, column, str, -1, SQLITE_TRANSIENT); - } - - inline int OVSQLiteStatement::bindTextToColumn(const string& str, int column) - { - return bindTextToColumn(str.c_str(), column); - } - - inline int OVSQLiteStatement::bindIntToColumn(int value, int column) - { - return sqlite3_bind_int(m_statement, column, value); - } - - inline int OVSQLiteStatement::bindDoubleToColumn(double value, int column) - { - return sqlite3_bind_double(m_statement, column, value); - } - - inline int OVSQLiteStatement::step() - { - return sqlite3_step(m_statement); - } - - inline int OVSQLiteStatement::columnCount() - { - return sqlite3_column_count(m_statement); - } - - inline const char* OVSQLiteStatement::textOfColumn(int column) - { - return (const char*)sqlite3_column_text(m_statement, column); - } - - inline int OVSQLiteStatement::intOfColumn(int column) - { - return sqlite3_column_int(m_statement, column); - } - - inline double OVSQLiteStatement::doubleOfColumn(int column) - { - return sqlite3_column_double(m_statement, column); - } -}; - -#endif \ No newline at end of file diff --git a/Source/Engine/OpenVanilla/OVStringHelper.h b/Source/Engine/OpenVanilla/OVStringHelper.h deleted file mode 100644 index 7e2b8e2b..00000000 --- a/Source/Engine/OpenVanilla/OVStringHelper.h +++ /dev/null @@ -1,218 +0,0 @@ -// -// OVStringHelper.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVStringHelper_h -#define OVStringHelper_h - -#include -#include -#include - -namespace OpenVanilla { - using namespace std; - - class OVStringHelper { - public: - static const vector SplitBySpacesOrTabsWithDoubleQuoteSupport(const string& text) - { - vector result; - size_t index = 0, last = 0, length = text.length(); - while (index < length) { - if (text[index] == '\"') { - index++; - string tmp; - while (index < length) { - if (text[index] == '\"') { - index++; - break; - } - - if (text[index] == '\\' && index + 1 < length) { - index++; - char c = text[index]; - switch (c) { - case 'r': - tmp += '\r'; - break; - case 'n': - tmp += '\n'; - break; - case '\"': - tmp += '\"'; - break; - case '\\': - tmp += '\\'; - break; - } - } - else { - tmp += text[index]; - } - - index++; - } - result.push_back(tmp); - } - - if (text[index] != ' ' && text[index] != '\t') { - last = index; - while (index < length) { - if (text[index] == ' ' || text[index] == '\t') { - if (index - last) - result.push_back(text.substr(last, index - last)); - break; - } - index++; - } - - if (index == length && index - last) - result.push_back(text.substr(last, index - last)); - } - - index++; - } - - return result; - } - - static const vector SplitBySpacesOrTabs(const string& text) - { - vector result; - size_t index = 0, last = 0, length = text.length(); - while (index < length) { - if (text[index] != ' ' && text[index] != '\t') { - last = index; - while (index < length) { - if (text[index] == ' ' || text[index] == '\t') { - if (index - last) - result.push_back(text.substr(last, index - last)); - break; - } - index++; - } - - if (index == length && index - last) - result.push_back(text.substr(last, index - last)); - } - - index++; - } - - return result; - } - - static const vector Split(const string& text, char c) - { - vector result; - size_t index = 0, last = 0, length = text.length(); - while (index < length) { - while (index < length) { - if (text[index] == c) { - result.push_back(text.substr(last, index - last)); - last = index + 1; - break; - } - index++; - } - - index++; - } - - if (last <= index) { - result.push_back(text.substr(last, index - last)); - } - - return result; - } - - // named after Cocoa's NSString -stringByReplacingOccurrencesOfString:WithString:, horrible - static const string StringByReplacingOccurrencesOfStringWithString(const string& source, const string& substr, const string& replacement) - { - if (!substr.length()) - return source; - - size_t pos; - if ((pos = source.find(substr)) >= source.length()) - return source; - - return source.substr(0, pos) + replacement + StringByReplacingOccurrencesOfStringWithString(source.substr(pos + substr.length()), substr, replacement); - } - - static const string Join(const vector& vec) - { - string result; - for (vector::const_iterator iter = vec.begin(); iter != vec.end() ; ++iter) - result += *iter; - - return result; - } - - static const string Join(const vector& vec, const string& separator) - { - return Join(vec.begin(), vec.end(), separator); - } - - static const string Join(const vector& vec, size_t from, size_t size, const string& separator) - { - return Join(vec.begin() + from, vec.begin() + from + size, separator); - } - - static const string Join(vector::const_iterator begin, vector::const_iterator end, const string& separator) - { - string result; - for (vector::const_iterator iter = begin ; iter != end ; ) { - result += *iter; - if (++iter != end) - result += separator; - } - return result; - } - - static const string PercentEncode(const string& text) - { - stringstream sst; - sst << hex; - - for (string::const_iterator i = text.begin() ; i != text.end() ; ++i) { - if ((*i >= '0' && *i <= '9') || (*i >= 'A' && *i <= 'Z') || (*i >= 'a' && *i <= 'z') || *i == '-' || *i == '_' || *i == '.' || *i == '~') { - sst << (char)*i; - } - else { - sst << '%'; - sst.width(2); - sst.fill('0'); - unsigned char c = *i; - sst << (unsigned int)c; - } - } - - return sst.str(); - } - }; -} - -#endif diff --git a/Source/Engine/OpenVanilla/OVTextBuffer.h b/Source/Engine/OpenVanilla/OVTextBuffer.h deleted file mode 100644 index 21300c85..00000000 --- a/Source/Engine/OpenVanilla/OVTextBuffer.h +++ /dev/null @@ -1,102 +0,0 @@ -// -// OVTextBuffer.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVTextBuffer_h -#define OVTextBuffer_h - -#if defined(__APPLE__) - #include -#else - #include "OVBase.h" -#endif - -namespace OpenVanilla { - using namespace std; - - // Terminologies: - // * Text buffer = a generic term - // * Composing text = composing buffer = composition buffer - // In Windows speak, "composition buffer" doesn't contain reading - // (Reading is a separate concept in Windows) - // In Mac speak, "composing buffer" == composing text + reading text - // * Reading text = currently in-wait-state radicals - // * Pre-edit, pre-edit area or pre-edit buffer (X11 speak) = composing text + reading - // Mac's composing buffer is actually pre-edit in this sense - - - class OVTextBuffer : public OVBase { - public: - - virtual void clear() = 0; - virtual void setText(const string& text) = 0; - virtual void appendText(const string& text, bool moveCursor = true) = 0; - - // when the text buffer is committed, the buffer itself, along with settings like cursor, and tooltip (for both composing text and reading text), highlight, word segments, and suggested display style (for reading text) are cleared; the combined committed string will be available at composedCommittedText() - virtual void commit() = 0; - virtual void commitAsTextSegment() = 0; - virtual void commit(const string& text) = 0; - virtual void commitAsTextSegment(const string& text) = 0; - - virtual void updateDisplay() = 0; - virtual bool isEmpty() const = 0; - virtual size_t codePointCount() const = 0; - virtual const string codePointAt(size_t index) const = 0; - virtual const string composedText() const = 0; - virtual const string composedCommittedText() const = 0; - virtual const vector composedCommittedTextSegments() const = 0; - - // Composing text (composing buffer, composition buffer)-only members - public: - typedef pair RangePair; - - // composing buffer should support these four, but reading buffer doesn't need to (anyway it's meaningless) - virtual void setCursorPosition(size_t position) = 0; - virtual size_t cursorPosition() const = 0; - virtual void showToolTip(const string& text) = 0; - virtual void clearToolTip() = 0; - - // implementation details: composing buffer might support this, but reading buffer doesn't - virtual void setHighlightMark(const RangePair& range) = 0; - - // word segments: on Windows, this is an independent (though application-dependent) feature, on Mac OS X, word segments cannot overlap with the highlight mark, and also, when the highlight mark is on, the cursor is off - virtual void setWordSegments(const vector& segments) = 0; - - // Reading text only members - public: - enum ReadingTextStyle { - Horizontal = 0, - Vertical = 1 - }; - - // this is only for the reading buffer, and is not a required implementation - virtual void setSuggestedReadingTextStyle(ReadingTextStyle style) = 0; - virtual ReadingTextStyle defaultReadingTextStyle() const = 0; - }; -}; - -#endif - diff --git a/Source/Engine/OpenVanilla/OVUTF8Helper.h b/Source/Engine/OpenVanilla/OVUTF8Helper.h deleted file mode 100644 index cd1e0049..00000000 --- a/Source/Engine/OpenVanilla/OVUTF8Helper.h +++ /dev/null @@ -1,194 +0,0 @@ -// -// OVUTF8Helper.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVUTF8Helper_h -#define OVUTF8Helper_h - -#include -#include -#include - -#include - -namespace OpenVanilla { - using namespace std; - - class OVUTF8Helper { - public: - static const vector SplitStringByCodePoint(const string& utf8String) - { - size_t index, length = utf8String.length(); - vector result; - - for (index = 0; index < length; index++) { - unsigned char c = utf8String[index]; - - if (!(c & 0x80)) { - result.push_back(utf8String.substr(index, 1)); - } - else if ((c & (0x80 | 0x40)) && !(c & 0x20)) { - result.push_back(utf8String.substr(index, 2)); - index += 1; - } - else if ((c & (0x80 | 0x40 | 0x20)) && !(c & 0x10)) { - result.push_back(utf8String.substr(index, 3)); - index += 2; - } - else if ((c & (0x80 | 0x40 | 0x20 | 0x10)) && !(c & 0x8)) { - result.push_back(utf8String.substr(index, 4)); - index += 3; - } - } - - return result; - } - - static const string CombineCodePoints(const vector& codePoints) - { - string result; - for (vector::const_iterator iter = codePoints.begin(); iter != codePoints.end() ; ++iter) - result += *iter; - - return result; - } - - static const wstring ConvertStringToUTF16WideString(const string& utf8String) - { - wstring wideString; - vector charVector = OVUTF8Helper::SplitStringByCodePoint(utf8String); - - size_t length = charVector.size(); - for (size_t index = 0; index < length; index++) - { - unsigned int codePoint = OVUTF8Helper::CodePointFromSingleUTF8String(charVector[index]); - - if (codePoint < 0x10000) { - wideString += (wchar_t)codePoint; - } - else { - const unsigned int leadOffset = 0xD800 - (0x10000 >> 10); - unsigned int lead = leadOffset + (codePoint >> 10); - unsigned int trail = 0xdc00 + (codePoint & 0x3ff); - wideString += (wchar_t)lead; - wideString += (wchar_t)trail; - } - } - - return wideString; - } - - static const string StringFromUTF16WideString(const wstring& utf16WideString) - { - string utf8String; - size_t length = utf16WideString.length(); - - unsigned int u16; - for (size_t index = 0; index < length; index++) { - u16 = utf16WideString[index]; - - if (u16 >= 0xd800 && u16 <= 0xdbff) { - if (index + 1 < length) { - unsigned int trailing = utf16WideString[index + 1]; - if (trailing >= 0xdc00 && trailing <= 0xdfff) { - index++; - - const unsigned int surrogateOffset = 0x10000 - (0xD800 << 10) - 0xDC00; - unsigned int codePoint = (u16 << 10) + trailing + surrogateOffset; - utf8String += OVUTF8Helper::SingleUTF8StringFromCodePoint(codePoint); - } - } - } - else if (!(u16 >= 0xdc00 && u16 <= 0xdfff)) - { - utf8String += OVUTF8Helper::SingleUTF8StringFromCodePoint(u16); - } - } - - return utf8String; - } - - static const string SingleUTF8StringFromCodePoint(unsigned int codePoint) - { - string utf8String; - - if (codePoint < 0x80) { - utf8String += (unsigned char)codePoint; - } - else if (codePoint < 0x800) { - utf8String += (unsigned char)((codePoint >> 6) | 0xc0); - utf8String += (unsigned char)((codePoint & 0x3f) | 0x80); - } - else if (codePoint < 0x10000) { - utf8String += (unsigned char)((codePoint >> 12) | 0xe0); - utf8String += (unsigned char)(((codePoint >> 6) & 0x3f) | 0x80); - utf8String += (unsigned char)((codePoint & 0x3f) | 0x80); - } - else { - utf8String += (unsigned char)((codePoint >> 18) | 0xf0); - utf8String += (unsigned char)((codePoint >> 12) | 0x80); - utf8String += (unsigned char)(((codePoint >> 6) & 0x3f) | 0x80); - utf8String += (unsigned char)((codePoint & 0x3f) | 0x80); - } - - return utf8String; - } - - static unsigned int CodePointFromSingleUTF8String(const string& utf8String) - { - switch(utf8String.length()) { - case 1: - return (unsigned int)utf8String[0]; - case 2: - return (((unsigned char)utf8String[0] << 6) & 0x7ff) + ((unsigned char)utf8String[1] & 0x3f); - case 3: - return (((unsigned char)utf8String[0] << 12) & 0xffff) + (((unsigned char)utf8String[1] << 6) & 0xfff) + ((unsigned char)utf8String[2] & 0x3f); - case 4: - return (((unsigned char)utf8String[0] << 18) & 0x1fffff) + (((unsigned char)utf8String[1] << 12) & 0x3ffff) + (((unsigned char)utf8String[2] << 6) & 0xfff) + ((unsigned char)utf8String[3] & 0x3f); - } - - return 0; - } - }; - - class OVUTF8 { - public: - static const string FromUTF16(const wstring& utf16String) - { - return OVUTF8Helper::StringFromUTF16WideString(utf16String); - } - }; - - class OVUTF16 { - public: - static const wstring FromUTF8(const string& utf8String) - { - return OVUTF8Helper::ConvertStringToUTF16WideString(utf8String); - } - }; -} - -#endif diff --git a/Source/Engine/OpenVanilla/OVWildcard.h b/Source/Engine/OpenVanilla/OVWildcard.h deleted file mode 100644 index 6a7906ce..00000000 --- a/Source/Engine/OpenVanilla/OVWildcard.h +++ /dev/null @@ -1,248 +0,0 @@ -// -// OVWildcard.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OVWildcard_h -#define OVWildcard_h - -#include -#include -#include -#include - -namespace OpenVanilla { - using namespace std; - - class OVWildcard { - public: - OVWildcard(const string& expression, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false) - : m_caseSensitive(caseSensitive) - , m_expression(expression) - , m_matchEndOfLine(matchEndOfLine) - , m_matchOneChar(matchOneChar) - , m_matchZeroOrMoreChar(matchZeroOrMoreChar) - { - size_t index; - for (index = 0; index < expression.length(); index++) { - if (expression[index] == matchOneChar || expression[index] == matchZeroOrMoreChar) break; - } - - m_longestHeadMatchString = expression.substr(0, index); - - for (string::size_type i = 0; i < expression.length(); i++) { - char c = expression[i]; - if (c == matchOneChar) { - m_states.push_back(State(AnyOne, 0)); - } - else if (c == matchZeroOrMoreChar) { - char nextChar = 0; - string::size_type j; - for (j = i + 1; j < expression.length(); j++) { - char k = expression[j]; - if (k != matchZeroOrMoreChar) { - if (k == matchOneChar) k = -1; - - nextChar = k; - break; - } - } - - i = j; - m_states.push_back(State(AnyUntil, nextChar)); - } - else { - m_states.push_back(State(Exact, c)); - } - } - } - - bool match(const string& target, size_t fromState = 0) const - { - string::size_type i = 0, slength = target.length(); - vector::size_type j, vlength = m_states.size(); - - for (j = fromState; j < vlength; j++) { - State state = m_states[j]; - Directive d = state.first; - int k = state.second; - - if (i >= slength) { - if (d == AnyUntil && !k) return true; - return false; - } - - switch (d) { - case Exact: - if (!equalChars(target[i], k)) return false; - i++; - break; - - case AnyOne: - i++; - break; - - case AnyUntil: - if (k == -1) { - // means *?, equals ?, so just advance one character - i++; - } - else if (k == 0) { - // until end, always true - return true; - } - else { - bool found = false; - string::size_type backIndex; - - for (backIndex = slength - 1; backIndex >= i; backIndex--) { - if (equalChars(target[backIndex], k)) { - string substring = target.substr(backIndex + 1, slength - (backIndex + 1)); - - if (match(substring, j + 1)) { - found = true; - i = backIndex + 1; - break; - } - } - - if (!backIndex) - break; - } - - if (!found) - return false; - } - - break; - } - } - - if (m_matchEndOfLine && i != slength) - return false; - - return true; - } - - const string longestHeadMatchString() const - { - return m_longestHeadMatchString; - } - - const string expression() const - { - return m_expression; - } - - bool isCaseSensitive() const - { - return m_caseSensitive; - } - - char matchOneChar() const - { - return m_matchOneChar; - } - - char matchZeroOrMoreChar() const - { - return m_matchZeroOrMoreChar; - } - - friend ostream& operator<<(ostream& stream, const OVWildcard& wildcard); - - protected: - enum Directive { - Exact, - AnyOne, - AnyUntil - }; - - typedef pair State; - - bool equalChars(char a, char b) const - { - if (m_caseSensitive) - return a == b; - else - return tolower(a) == tolower(b); - } - - bool m_caseSensitive; - bool m_matchEndOfLine; - char m_matchOneChar; - char m_matchZeroOrMoreChar; - vector m_states; - - string m_expression; - string m_longestHeadMatchString; - - public: - static const bool Match(const string& text, const string& expression, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false) - { - OVWildcard exp(expression, matchOneChar, matchZeroOrMoreChar, matchEndOfLine, caseSensitive); - return exp.match(text); - } - - static const vector WildcardsFromStrings(const vector& expressions, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false) - { - vector result; - vector::const_iterator iter = expressions.begin(); - for ( ; iter != expressions.end(); iter++) - result.push_back(OVWildcard(*iter, matchOneChar, matchZeroOrMoreChar, matchEndOfLine, caseSensitive)); - - return result; - } - - static bool MultiWildcardMatchAny(const string& target, const vector& expressions, char matchOneChar = '?', char matchZeroOrMoreChar = '*', bool matchEndOfLine = true, bool caseSensitive = false) - { - return MultiWildcardMatchAny(target, WildcardsFromStrings(expressions, matchOneChar, matchZeroOrMoreChar, matchEndOfLine, caseSensitive)); - } - - static bool MultiWildcardMatchAny(const string& target, const vector& expressions) - { - vector::const_iterator iter = expressions.begin(); - for ( ; iter != expressions.end(); iter++) { - if ((*iter).match(target)) - return true; - } - - return false; - } - }; - - inline ostream& operator<<(ostream& stream, const OVWildcard& wildcard) - { - vector::size_type i, size = wildcard.m_states.size(); - for (i = 0; i < size; i++) { - const OVWildcard::State& state = wildcard.m_states[i]; - stream << "State " << i << ": " << state.first << ", " << state.second << endl; - } - - return stream; - } -} - -#endif diff --git a/Source/Engine/OpenVanilla/OpenVanilla.h b/Source/Engine/OpenVanilla/OpenVanilla.h deleted file mode 100644 index c78271fd..00000000 --- a/Source/Engine/OpenVanilla/OpenVanilla.h +++ /dev/null @@ -1,97 +0,0 @@ -// -// OpenVanilla.h -// -// Copyright (c) 2007-2010 Lukhnos D. Liu -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -#ifndef OpenVanilla_h -#define OpenVanilla_h - -#if defined(__APPLE__) - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #ifdef OV_USE_SQLITE - #include - #include - #endif -#else - #ifdef WIN32 - #include - #endif - - #include "OVAroundFilter.h" - #include "OVBase.h" - #include "OVBenchmark.h" - #include "OVCandidateService.h" - #include "OVCINDataTable.h" - #include "OVCINDatabaseService.h" - #include "OVDatabaseService.h" - #include "OVDateTimeHelper.h" - #include "OVEventHandlingContext.h" - #include "OVFileHelper.h" - #include "OVFrameworkInfo.h" - #include "OVInputMethod.h" - #include "OVLocalization.h" - #include "OVKey.h" - #include "OVKeyValueMap.h" - #include "OVLoaderService.h" - #include "OVModule.h" - #include "OVModulePackage.h" - #include "OVOutputFilter.h" - #include "OVPathInfo.h" - #include "OVStringHelper.h" - #include "OVTextBuffer.h" - #include "OVUTF8Helper.h" - #include "OVWildcard.h" - - #ifdef OV_USE_SQLITE - #include "OVSQLiteDatabaseService.h" - #include "OVSQLiteWrapper.h" - #endif -#endif - -#endif diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index 4194896e..701cd6bf 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -26,7 +26,6 @@ #import "McBopomofoLM.h" #import "UserOverrideModel.h" #import "LanguageModelManager+Privates.h" -#import "OVUTF8Helper.h" #import "KeyHandler.h" #import "McBopomofo-Swift.h" #import