Skip to content

Commit

Permalink
fix(api): export librime 0.9 API as extern C
Browse files Browse the repository at this point in the history
use RIME_DLL for exported C++ symbols.
use RIME_API for RIME API C functions.
  • Loading branch information
lotem committed Dec 20, 2024
1 parent 09c1d4e commit 6c4f835
Show file tree
Hide file tree
Showing 38 changed files with 200 additions and 196 deletions.
8 changes: 4 additions & 4 deletions src/rime/algo/algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Schema;

class Script : public map<string, vector<Spelling>> {
public:
RIME_API bool AddSyllable(const string& syllable);
RIME_DLL bool AddSyllable(const string& syllable);
void Merge(const string& s,
const SpellingProperties& sp,
const vector<Spelling>& v);
Expand All @@ -28,11 +28,11 @@ class Script : public map<string, vector<Spelling>> {

class Projection {
public:
RIME_API bool Load(an<ConfigList> settings);
RIME_DLL bool Load(an<ConfigList> settings);
// "spelling" -> "gnilleps"
RIME_API bool Apply(string* value);
RIME_DLL bool Apply(string* value);
// {z, y, x} -> {a, b, c, d}
RIME_API bool Apply(Script* value);
RIME_DLL bool Apply(Script* value);

protected:
vector<of<Calculation>> calculation_;
Expand Down
4 changes: 2 additions & 2 deletions src/rime/algo/calculus.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Calculation {

class Calculus {
public:
RIME_API Calculus();
RIME_DLL Calculus();
void Register(const string& token, Calculation::Factory* factory);
RIME_API Calculation* Parse(const string& definition);
RIME_DLL Calculation* Parse(const string& definition);

private:
map<string, Calculation::Factory*> factories_;
Expand Down
6 changes: 3 additions & 3 deletions src/rime/algo/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace rime {

class RawCode : public vector<string> {
public:
RIME_API string ToString() const;
RIME_API void FromString(const string& code_str);
RIME_DLL string ToString() const;
RIME_DLL void FromString(const string& code_str);
};

class PhraseCollector {
Expand Down Expand Up @@ -63,7 +63,7 @@ struct TableEncodingRule {
};

// for rule-based phrase encoding
class RIME_API TableEncoder : public Encoder {
class RIME_DLL TableEncoder : public Encoder {
public:
TableEncoder(PhraseCollector* collector = NULL);

Expand Down
4 changes: 2 additions & 2 deletions src/rime/algo/syllabifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class Syllabifier {
enable_completion_(enable_completion),
strict_spelling_(strict_spelling) {}

RIME_API int BuildSyllableGraph(const string& input,
RIME_DLL int BuildSyllableGraph(const string& input,
Prism& prism,
SyllableGraph* graph);
RIME_API void EnableCorrection(Corrector* corrector);
RIME_DLL void EnableCorrection(Corrector* corrector);

protected:
void CheckOverlappedSpellings(SyllableGraph* graph, size_t start, size_t end);
Expand Down
2 changes: 1 addition & 1 deletion src/rime/composition.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Composition : public Segmentation {
string GetPrompt() const;
string GetCommitText() const;
string GetScriptText(bool keep_selection = true) const;
RIME_API string GetDebugText() const;
RIME_DLL string GetDebugText() const;
// Returns text of the last segment before the given position.
string GetTextBefore(size_t pos) const;
};
Expand Down
60 changes: 30 additions & 30 deletions src/rime/config/config_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Config : public Class<Config, const string&>, public ConfigItemRef {
public:
// CAVEAT: Config instances created without argument will NOT
// be managed by ConfigComponent
RIME_API Config();
RIME_API virtual ~Config();
RIME_DLL Config();
RIME_DLL virtual ~Config();
// instances of Config with identical config id share a copy of config data
// in the ConfigComponent
explicit Config(an<ConfigData> data);
Expand All @@ -32,33 +32,33 @@ class Config : public Class<Config, const string&>, public ConfigItemRef {
bool Save();
bool LoadFromStream(std::istream& stream);
bool SaveToStream(std::ostream& stream);
RIME_API bool LoadFromFile(const path& file_path);
RIME_API bool SaveToFile(const path& file_path);
RIME_DLL bool LoadFromFile(const path& file_path);
RIME_DLL bool SaveToFile(const path& file_path);

// access a tree node of a particular type with "path/to/node"
RIME_API bool IsNull(const string& path);
RIME_DLL bool IsNull(const string& path);
bool IsValue(const string& path);
RIME_API bool IsList(const string& path);
RIME_API bool IsMap(const string& path);
RIME_API bool GetBool(const string& path, bool* value);
RIME_API bool GetInt(const string& path, int* value);
RIME_API bool GetDouble(const string& path, double* value);
RIME_API bool GetString(const string& path, string* value);
RIME_API size_t GetListSize(const string& path);
RIME_DLL bool IsList(const string& path);
RIME_DLL bool IsMap(const string& path);
RIME_DLL bool GetBool(const string& path, bool* value);
RIME_DLL bool GetInt(const string& path, int* value);
RIME_DLL bool GetDouble(const string& path, double* value);
RIME_DLL bool GetString(const string& path, string* value);
RIME_DLL size_t GetListSize(const string& path);

an<ConfigItem> GetItem(const string& path);
an<ConfigValue> GetValue(const string& path);
RIME_API an<ConfigList> GetList(const string& path);
RIME_API an<ConfigMap> GetMap(const string& path);
RIME_DLL an<ConfigList> GetList(const string& path);
RIME_DLL an<ConfigMap> GetMap(const string& path);

// setters
bool SetBool(const string& path, bool value);
RIME_API bool SetInt(const string& path, int value);
RIME_DLL bool SetInt(const string& path, int value);
bool SetDouble(const string& path, double value);
RIME_API bool SetString(const string& path, const char* value);
RIME_DLL bool SetString(const string& path, const char* value);
bool SetString(const string& path, const string& value);
// setter for adding or replacing items in the tree
RIME_API bool SetItem(const string& path, an<ConfigItem> item);
RIME_DLL bool SetItem(const string& path, an<ConfigItem> item);
using ConfigItemRef::operator=;

protected:
Expand All @@ -73,28 +73,28 @@ class ConfigCompilerPlugin;
struct ConfigResource;

struct ConfigResourceProvider {
RIME_API static const ResourceType kDefaultResourceType;
RIME_API static ResourceResolver* CreateResourceResolver(
RIME_DLL static const ResourceType kDefaultResourceType;
RIME_DLL static ResourceResolver* CreateResourceResolver(
const ResourceType& resource_type);
};

struct DeployedConfigResourceProvider {
RIME_API static const ResourceType kDefaultResourceType;
RIME_API static ResourceResolver* CreateResourceResolver(
RIME_DLL static const ResourceType kDefaultResourceType;
RIME_DLL static ResourceResolver* CreateResourceResolver(
const ResourceType& resource_type);
};

struct UserConfigResourceProvider {
RIME_API static const ResourceType kDefaultResourceType;
RIME_API static ResourceResolver* CreateResourceResolver(
RIME_DLL static const ResourceType kDefaultResourceType;
RIME_DLL static ResourceResolver* CreateResourceResolver(
const ResourceType& resource_type);
};

class ConfigComponentBase : public Config::Component {
public:
RIME_API ConfigComponentBase(ResourceResolver* resource_resolver);
RIME_API virtual ~ConfigComponentBase();
RIME_API Config* Create(const string& file_name);
RIME_DLL ConfigComponentBase(ResourceResolver* resource_resolver);
RIME_DLL virtual ~ConfigComponentBase();
RIME_DLL Config* Create(const string& file_name);

protected:
virtual an<ConfigData> LoadConfig(const string& config_id) = 0;
Expand Down Expand Up @@ -127,7 +127,7 @@ class ConfigComponent : public ConfigComponentBase {

class ConfigLoader {
public:
RIME_API an<ConfigData> LoadConfig(ResourceResolver* resource_resolver,
RIME_DLL an<ConfigData> LoadConfig(ResourceResolver* resource_resolver,
const string& config_id);
void set_auto_save(bool auto_save) { auto_save_ = auto_save; }

Expand All @@ -137,9 +137,9 @@ class ConfigLoader {

class ConfigBuilder {
public:
RIME_API ConfigBuilder();
RIME_API virtual ~ConfigBuilder();
RIME_API an<ConfigData> LoadConfig(ResourceResolver* resource_resolver,
RIME_DLL ConfigBuilder();
RIME_DLL virtual ~ConfigBuilder();
RIME_DLL an<ConfigData> LoadConfig(ResourceResolver* resource_resolver,
const string& config_id);
void InstallPlugin(ConfigCompilerPlugin* plugin);
bool ApplyPlugins(ConfigCompiler* compiler, an<ConfigResource> resource);
Expand Down
60 changes: 30 additions & 30 deletions src/rime/config/config_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class ConfigItem {
class ConfigValue : public ConfigItem {
public:
ConfigValue() : ConfigItem(kScalar) {}
RIME_API ConfigValue(bool value);
RIME_API ConfigValue(int value);
RIME_API ConfigValue(double value);
RIME_API ConfigValue(const char* value);
RIME_API ConfigValue(const string& value);
RIME_DLL ConfigValue(bool value);
RIME_DLL ConfigValue(int value);
RIME_DLL ConfigValue(double value);
RIME_DLL ConfigValue(const char* value);
RIME_DLL ConfigValue(const string& value);

// schalar value accessors
bool GetBool(bool* value) const;
RIME_API bool GetInt(int* value) const;
RIME_DLL bool GetInt(int* value) const;
bool GetDouble(double* value) const;
RIME_API bool GetString(string* value) const;
RIME_DLL bool GetString(string* value) const;
bool SetBool(bool value);
bool SetInt(int value);
bool SetDouble(double value);
Expand All @@ -65,14 +65,14 @@ class ConfigList : public ConfigItem {
using Iterator = Sequence::iterator;

ConfigList() : ConfigItem(kList) {}
RIME_API an<ConfigItem> GetAt(size_t i) const;
RIME_API an<ConfigValue> GetValueAt(size_t i) const;
RIME_API bool SetAt(size_t i, an<ConfigItem> element);
RIME_DLL an<ConfigItem> GetAt(size_t i) const;
RIME_DLL an<ConfigValue> GetValueAt(size_t i) const;
RIME_DLL bool SetAt(size_t i, an<ConfigItem> element);
bool Insert(size_t i, an<ConfigItem> element);
RIME_API bool Append(an<ConfigItem> element);
RIME_DLL bool Append(an<ConfigItem> element);
bool Resize(size_t size);
RIME_API bool Clear();
RIME_API size_t size() const;
RIME_DLL bool Clear();
RIME_DLL size_t size() const;

Iterator begin();
Iterator end();
Expand All @@ -90,10 +90,10 @@ class ConfigMap : public ConfigItem {
using Iterator = Map::iterator;

ConfigMap() : ConfigItem(kMap) {}
RIME_API bool HasKey(const string& key) const;
RIME_API an<ConfigItem> Get(const string& key) const;
RIME_API an<ConfigValue> GetValue(const string& key) const;
RIME_API bool Set(const string& key, an<ConfigItem> element);
RIME_DLL bool HasKey(const string& key) const;
RIME_DLL an<ConfigItem> Get(const string& key) const;
RIME_DLL an<ConfigValue> GetValue(const string& key) const;
RIME_DLL bool Set(const string& key, an<ConfigItem> element);
bool Clear();

Iterator begin();
Expand Down Expand Up @@ -137,28 +137,28 @@ class ConfigItemRef {
ConfigListEntryRef operator[](size_t index);
ConfigMapEntryRef operator[](const string& key);

RIME_API bool IsNull() const;
RIME_DLL bool IsNull() const;
bool IsValue() const;
RIME_API bool IsList() const;
RIME_DLL bool IsList() const;
bool IsMap() const;

RIME_API bool ToBool() const;
RIME_API int ToInt() const;
RIME_DLL bool ToBool() const;
RIME_DLL int ToInt() const;
double ToDouble() const;
RIME_API string ToString() const;
RIME_DLL string ToString() const;

RIME_API an<ConfigList> AsList();
RIME_API an<ConfigMap> AsMap();
RIME_API void Clear();
RIME_DLL an<ConfigList> AsList();
RIME_DLL an<ConfigMap> AsMap();
RIME_DLL void Clear();

// list
RIME_API bool Append(an<ConfigItem> item);
RIME_API size_t size() const;
RIME_DLL bool Append(an<ConfigItem> item);
RIME_DLL size_t size() const;
// map
RIME_API bool HasKey(const string& key) const;
RIME_DLL bool HasKey(const string& key) const;

RIME_API bool modified() const;
RIME_API void set_modified();
RIME_DLL bool modified() const;
RIME_DLL void set_modified();

protected:
virtual an<ConfigItem> GetItem() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/rime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace rime {
class Candidate;
class KeyEvent;

class RIME_API Context {
class RIME_DLL Context {
public:
using Notifier = signal<void(Context* ctx)>;
using OptionUpdateNotifier = signal<void(Context* ctx, const string& option)>;
Expand Down
4 changes: 2 additions & 2 deletions src/rime/deployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Deployer : public Messenger {
string app_name;
// }

RIME_API Deployer();
RIME_API ~Deployer();
RIME_DLL Deployer();
RIME_DLL ~Deployer();

bool RunTask(const string& task_name,
TaskInitializer arg = TaskInitializer());
Expand Down
12 changes: 6 additions & 6 deletions src/rime/dict/corrector.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Corrections : public hash_map<SyllableId, Correction> {
class Corrector : public Class<Corrector, const Ticket&> {
public:
virtual ~Corrector() = default;
RIME_API virtual void ToleranceSearch(const Prism& prism,
RIME_DLL virtual void ToleranceSearch(const Prism& prism,
const string& key,
corrector::Corrections* results,
size_t tolerance) = 0;
Expand All @@ -77,7 +77,7 @@ class CorrectorComponent : public Corrector::Component {
class Unified : public Corrector {
public:
Unified() = default;
RIME_API void ToleranceSearch(const Prism& prism,
RIME_DLL void ToleranceSearch(const Prism& prism,
const string& key,
corrector::Corrections* results,
size_t tolerance) override;
Expand All @@ -94,14 +94,14 @@ class CorrectorComponent : public Corrector::Component {
class EditDistanceCorrector : public Corrector, public Prism {
public:
~EditDistanceCorrector() override = default;
RIME_API explicit EditDistanceCorrector(const path& file_path);
RIME_DLL explicit EditDistanceCorrector(const path& file_path);

RIME_API bool Build(const Syllabary& syllabary,
RIME_DLL bool Build(const Syllabary& syllabary,
const Script* script = nullptr,
uint32_t dict_file_checksum = 0,
uint32_t schema_file_checksum = 0);

RIME_API void ToleranceSearch(const Prism& prism,
RIME_DLL void ToleranceSearch(const Prism& prism,
const string& key,
corrector::Corrections* results,
size_t tolerance) override;
Expand All @@ -112,7 +112,7 @@ class EditDistanceCorrector : public Corrector, public Prism {
corrector::Distance threshold);
};

class RIME_API NearSearchCorrector : public Corrector {
class RIME_DLL NearSearchCorrector : public Corrector {
public:
NearSearchCorrector() = default;
~NearSearchCorrector() override = default;
Expand Down
6 changes: 3 additions & 3 deletions src/rime/dict/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Db : public Class<Db, const string&> {
Db(const path& file_path, const string& name);
virtual ~Db() = default;

RIME_API bool Exists() const;
RIME_API virtual bool Remove();
RIME_DLL bool Exists() const;
RIME_DLL virtual bool Remove();

virtual bool Open() = 0;
virtual bool OpenReadOnly() = 0;
Expand Down Expand Up @@ -93,7 +93,7 @@ class Recoverable {

class ResourceResolver;

class RIME_API DbComponentBase {
class RIME_DLL DbComponentBase {
public:
DbComponentBase();
virtual ~DbComponentBase();
Expand Down
6 changes: 3 additions & 3 deletions src/rime/dict/dict_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class DictCompiler {
kDump = 4,
};

RIME_API explicit DictCompiler(Dictionary* dictionary);
RIME_API virtual ~DictCompiler();
RIME_DLL explicit DictCompiler(Dictionary* dictionary);
RIME_DLL virtual ~DictCompiler();

RIME_API bool Compile(const path& schema_file);
RIME_DLL bool Compile(const path& schema_file);
void set_options(int options) { options_ = options; }

private:
Expand Down
Loading

0 comments on commit 6c4f835

Please sign in to comment.