spiegel-keyman/core/src/option.hpp
Marc Durdin 671973baab refactor(core): split context API from Core primary API
Relates to #9999.
Fixes #10384.

The context API endpoints should no longer be considered as part of the
standard Core API. The only consumers that have a need to access these
APIs are the IMX integration in Engine for Windows, and the Keyman
Developer Debugger.

These symbols are currently used by Developer:
* `km_core_context` struct
* `km_core_context_type` enum
* `km_core_context_item` struct
* `KM_CORE_CONTEXT_ITEM_END` macro
* `km_core_state_context()`
* `km_core_context_set()`
* `km_core_context_clear()`

These symbols are currently used by Windows IMX:
* `km_core_context` struct
* `km_core_context_type` enum
* `km_core_context_item` struct
* `KM_CORE_CONTEXT_ITEM_END` macro
* `km_core_context_items_dispose()`
* `km_core_context_item_list_size()`
* `km_core_state_get_intermediate_context()`

The following functions and symbols are moving to
keyman_core_api_context.h:
* `km_core_context` struct
* `km_core_context_type` enum
* `km_core_context_item` struct
* `KM_CORE_CONTEXT_ITEM_END` macro
* `km_core_state_context()` function
* `km_core_state_get_intermediate_context()` function
* `km_core_context_set()` function
* `km_core_context_clear()` function
* `km_core_context_get()` function
* `km_core_context_items_from_utf16()` function
* `km_core_context_items_from_utf8()` function
* `km_core_context_items_to_utf8()` function
* `km_core_context_items_to_utf16()` function
* `km_core_context_items_to_utf32()` function
* `km_core_context_items_dispose()` function
* `km_core_context_length()` function
* `km_core_context_append()` function
* `km_core_context_shrink()` function
* `km_core_context_item_list_size()` function
2024-01-17 14:44:25 +11:00

99 lines
2 KiB
C++

/*
Copyright: © 2018 SIL International.
Description: Internal option key value map class and adaptor class for
the API.
Create Date: 2 Oct 2018
Authors: Tim Eves (TSE)
History: 2 Oct 2018 - TSE - Refactored out of km_core_options_api.cpp.
7 Nov 2018 - TSE - Refactored into option.hpp & option.cpp.
*/
#pragma once
#include <string>
#include "keyman_core.h"
// Forward declarations
class json;
namespace km {
namespace core
{
struct option : public km_core_option_item
{
option(): km_core_option_item KM_CORE_OPTIONS_END {}
option(option const &);
option(option &&);
option(km_core_option_scope, char16_t const *, char16_t const *);
option(km_core_option_scope, std::u16string const &,
std::u16string const &);
~option() noexcept;
option & operator=(option const & rhs);
option & operator=(option && rhs);
/**
* Returns contents of this object as a C struct, releasing memory
* management of key and value, and invalidates this object.
*/
km_core_option_item release();
bool empty() const;
};
inline
option::option(km_core_option_scope s,
std::u16string const & k, std::u16string const & v)
: option(s, k.c_str(), v.c_str())
{}
inline
option::option(option const & rhs)
: option(km_core_option_scope(rhs.scope), rhs.key, rhs.value) {}
inline
option::option(option && rhs) : option()
{
std::swap(key, rhs.key);
std::swap(value, rhs.value);
scope = rhs.scope;
}
inline
option::~option() noexcept
{
delete [] key;
delete [] value;
}
inline
option & option::operator=(option && rhs) {
delete [] key;
delete [] value;
return *new (this) option(std::move(rhs));
}
inline
option & option::operator=(option const & rhs)
{
delete [] key;
delete [] value;
return *new (this) option(rhs);
}
inline
bool option::empty() const {
return key == nullptr;
}
} // namespace core
} // namespace km