mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-09 18:35:32 +00:00
Turn the keyboard class backing the km_kbp_keyboard and km_kbp_keyboard_attr objects into just keyboard_attributes. Move the abstract_processor and sublcasses as the objects that back km_kbp_keyboard and make keyboard_attrs a member of the asbtract_processor. Move kmx_processor and mock_processor declarations into their own headers. Make all vector<km_kbp_option_item> into vector<option> to handle memory management, moving and copying correctly. Update test cases accordingly
88 lines
2 KiB
C++
88 lines
2 KiB
C++
/*
|
|
Copyright: © 2018 SIL International.
|
|
Description: Implementation of the keyboard API functions using internal
|
|
data structures and functions.
|
|
Create Date: 1 Oct 2018
|
|
Authors: Tim Eves (TSE)
|
|
History: 1 Sep 2018 - TSE - Initial implementation.
|
|
5 Oct 2018 - TSE - Refactor out adaptor and internal classes
|
|
into keyboard.hpp
|
|
*/
|
|
#include <cassert>
|
|
#include <algorithm>
|
|
#include <iterator>
|
|
#include <sstream>
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <keyman/keyboardprocessor.h>
|
|
#include <kmx/kmx_processevent.hpp>
|
|
#include <mock/mock_processor.hpp>
|
|
#include <json.hpp>
|
|
|
|
#include "keyboard.hpp"
|
|
#include "option.hpp"
|
|
|
|
|
|
using namespace km::kbp;
|
|
|
|
namespace
|
|
{
|
|
abstract_processor * processor_factory(path const & kb_path)
|
|
{
|
|
// Some legacy packages may include upper-case file extensions
|
|
if (kb_path.suffix() == ".kmx" || kb_path.suffix() == ".KMX") {
|
|
return new kmx_processor(kb_path);
|
|
}
|
|
else if (kb_path.suffix() == ".mock") {
|
|
return new mock_processor(kb_path);
|
|
}
|
|
else {
|
|
return new null_processor();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
km_kbp_status
|
|
km_kbp_keyboard_load(km_kbp_path_name kb_path, km_kbp_keyboard **keyboard)
|
|
{
|
|
assert(keyboard);
|
|
if (!keyboard)
|
|
return KM_KBP_STATUS_INVALID_ARGUMENT;
|
|
|
|
try
|
|
{
|
|
abstract_processor *kp = processor_factory(kb_path);
|
|
km_kbp_status status = kp->validate();
|
|
if (status != KM_KBP_STATUS_OK) {
|
|
delete kp;
|
|
return status;
|
|
}
|
|
*keyboard = static_cast<km_kbp_keyboard *>(kp);
|
|
}
|
|
catch (std::bad_alloc)
|
|
{
|
|
return KM_KBP_STATUS_NO_MEM;
|
|
}
|
|
return KM_KBP_STATUS_OK;
|
|
}
|
|
|
|
void
|
|
km_kbp_keyboard_dispose(km_kbp_keyboard *keyboard)
|
|
{
|
|
delete keyboard;
|
|
}
|
|
|
|
km_kbp_status
|
|
km_kbp_keyboard_get_attrs(km_kbp_keyboard const *keyboard,
|
|
km_kbp_keyboard_attrs const **out)
|
|
{
|
|
assert(keyboard); assert(out);
|
|
if (!keyboard || !out)
|
|
return KM_KBP_STATUS_INVALID_ARGUMENT;
|
|
|
|
*out = &keyboard->keyboard();
|
|
return KM_KBP_STATUS_OK;
|
|
}
|