| 1 |
/* |
| 2 |
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2023 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 26 февр. 2020 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_I18N_DICTIONARY_H_ |
| 23 |
#define LSP_PLUG_IN_I18N_DICTIONARY_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/i18n/IDictionary.h> |
| 27 |
#include <lsp-plug.in/lltl/parray.h> |
| 28 |
#include <lsp-plug.in/io/Path.h> |
| 29 |
#include <lsp-plug.in/resource/ILoader.h> |
| 30 |
|
| 31 |
namespace lsp |
| 32 |
{ |
| 33 |
namespace i18n |
| 34 |
{ |
| 35 |
/** |
| 36 |
* Class implements root dictionary logic which operates on all |
| 37 |
* sub-dictionaries |
| 38 |
*/ |
| 39 |
class Dictionary: public IDictionary |
| 40 |
{ |
| 41 |
private: |
| 42 |
Dictionary & operator = (const Dictionary &); |
| 43 |
|
| 44 |
protected: |
| 45 |
typedef struct node_t |
| 46 |
{ |
| 47 |
LSPString sKey; |
| 48 |
IDictionary *pDict; |
| 49 |
bool bRoot; |
| 50 |
} node_t; |
| 51 |
|
| 52 |
protected: |
| 53 |
lltl::parray<node_t> vNodes; |
| 54 |
LSPString sPath; |
| 55 |
resource::ILoader *pLoader; |
| 56 |
|
| 57 |
protected: |
| 58 |
status_t load_json(IDictionary **dict, const io::Path *path); |
| 59 |
status_t create_child(IDictionary **dict, const LSPString *path); |
| 60 |
status_t load_dictionary(const LSPString *id, IDictionary **dict); |
| 61 |
|
| 62 |
public: |
| 63 |
explicit Dictionary(resource::ILoader *loader = NULL); |
| 64 |
virtual ~Dictionary(); |
| 65 |
|
| 66 |
public: |
| 67 |
inline resource::ILoader *loader() { return pLoader; } |
| 68 |
resource::ILoader *set_loader(); |
| 69 |
|
| 70 |
public: |
| 71 |
using IDictionary::lookup; |
| 72 |
using IDictionary::init; |
| 73 |
|
| 74 |
virtual status_t lookup(const LSPString *key, LSPString *value); |
| 75 |
|
| 76 |
virtual status_t lookup(const LSPString *key, IDictionary **value); |
| 77 |
|
| 78 |
virtual status_t get_value(size_t index, LSPString *key, LSPString *value); |
| 79 |
|
| 80 |
virtual status_t get_child(size_t index, LSPString *key, IDictionary **dict); |
| 81 |
|
| 82 |
virtual size_t size(); |
| 83 |
|
| 84 |
virtual status_t init(const LSPString *path); |
| 85 |
|
| 86 |
public: |
| 87 |
/** |
| 88 |
* Clear dictionary contents |
| 89 |
*/ |
| 90 |
void clear(); |
| 91 |
|
| 92 |
}; |
| 93 |
|
| 94 |
} /* namespace i18n */ |
| 95 |
} /* namespace lsp */ |
| 96 |
|
| 97 |
#endif /* LSP_PLUG_IN_I18N_DICTIONARY_H_ */ |